Bug 705019 - Introduce CType::IsCTypeProto() and CData::isCDataProto(). r=jorendorff

This commit is contained in:
Bobby Holley 2011-11-29 18:26:12 -08:00
parent 0977d91a9a
commit 457374946b
2 changed files with 18 additions and 4 deletions

View File

@ -2829,6 +2829,12 @@ CType::IsCType(JSContext* cx, JSObject* obj)
return JS_GET_CLASS(cx, obj) == &sCTypeClass;
}
bool
CType::IsCTypeProto(JSContext* cx, JSObject* obj)
{
return JS_GET_CLASS(cx, obj) == &sCTypeProtoClass;
}
TypeCode
CType::GetTypeCode(JSContext* cx, JSObject* typeObj)
{
@ -3034,7 +3040,7 @@ CType::GetProtoFromCtor(JSContext* cx, JSObject* obj, CTypeProtoSlot slot)
ASSERT_OK(JS_GetReservedSlot(cx, obj, SLOT_FN_CTORPROTO, &protoslot));
JSObject* proto = JSVAL_TO_OBJECT(protoslot);
JS_ASSERT(proto);
JS_ASSERT(JS_GET_CLASS(cx, proto) == &sCTypeProtoClass);
JS_ASSERT(CType::IsCTypeProto(cx, proto));
// Get the desired prototype.
jsval result;
@ -3050,7 +3056,7 @@ CType::GetProtoFromType(JSContext* cx, JSObject* obj, CTypeProtoSlot slot)
// Get the prototype of the type object.
JSObject* proto = JS_GetPrototype(cx, obj);
JS_ASSERT(proto);
JS_ASSERT(JS_GET_CLASS(cx, proto) == &sCTypeProtoClass);
JS_ASSERT(CType::IsCTypeProto(cx, proto));
// Get the requested ctypes.{Pointer,Array,Struct,Function}Type.prototype.
jsval result;
@ -3196,7 +3202,7 @@ CType::HasInstance(JSContext* cx, JSObject* obj, const jsval* v, JSBool* bp)
ASSERT_OK(JS_GetReservedSlot(cx, obj, SLOT_PROTO, &slot));
JSObject* prototype = JSVAL_TO_OBJECT(slot);
JS_ASSERT(prototype);
JS_ASSERT(JS_GET_CLASS(cx, prototype) == &sCDataProtoClass);
JS_ASSERT(CData::IsCDataProto(cx, prototype));
*bp = JS_FALSE;
if (JSVAL_IS_PRIMITIVE(*v))
@ -5269,7 +5275,7 @@ CClosure::Create(JSContext* cx,
// which stores our JSContext for use with the closure.
JSObject* proto = JS_GetPrototype(cx, typeObj);
JS_ASSERT(proto);
JS_ASSERT(JS_GET_CLASS(cx, proto) == &sCTypeProtoClass);
JS_ASSERT(CType::IsCTypeProto(cx, proto));
// Get a JSContext for use with the closure.
jsval slot;
@ -5699,6 +5705,12 @@ CData::IsCData(JSContext* cx, JSObject* obj)
return JS_GET_CLASS(cx, obj) == &sCDataClass;
}
bool
CData::IsCDataProto(JSContext* cx, JSObject* obj)
{
return JS_GET_CLASS(cx, obj) == &sCDataProtoClass;
}
JSBool
CData::ValueGetter(JSContext* cx, JSObject* obj, jsid idval, jsval* vp)
{

View File

@ -457,6 +457,7 @@ namespace CType {
jsval size, jsval align, ffi_type* ffiType);
bool IsCType(JSContext* cx, JSObject* obj);
bool IsCTypeProto(JSContext* cx, JSObject* obj);
TypeCode GetTypeCode(JSContext* cx, JSObject* typeObj);
bool TypesEqual(JSContext* cx, JSObject* t1, JSObject* t2);
size_t GetSize(JSContext* cx, JSObject* obj);
@ -520,6 +521,7 @@ namespace CData {
JSObject* GetCType(JSContext* cx, JSObject* dataObj);
void* GetData(JSContext* cx, JSObject* dataObj);
bool IsCData(JSContext* cx, JSObject* obj);
bool IsCDataProto(JSContext* cx, JSObject* obj);
// Attached by JSAPI as the function 'ctypes.cast'
JSBool Cast(JSContext* cx, uintN argc, jsval* vp);