Bug 975042 - Implement createHolder. r=peterv

This commit is contained in:
Bobby Holley 2014-03-23 11:02:13 -03:00
parent 8a57cf0534
commit 27bc1e0d24

View File

@ -354,13 +354,62 @@ public:
// nothing to do here.
}
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper) {
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
enum {
SLOT_PROTOKEY = 0,
SLOT_ISPROTOTYPE,
SLOT_COUNT
};
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper);
static JSProtoKey getProtoKey(JSObject *holder) {
int32_t key = js::GetReservedSlot(holder, SLOT_PROTOKEY).toInt32();
return static_cast<JSProtoKey>(key);
}
static bool isPrototype(JSObject *holder) {
return js::GetReservedSlot(holder, SLOT_ISPROTOTYPE).toBoolean();
}
static const JSClass HolderClass;
static JSXrayTraits singleton;
};
const JSClass JSXrayTraits::HolderClass = {
"JSXrayHolder", JSCLASS_HAS_RESERVED_SLOTS(SLOT_COUNT),
JS_PropertyStub, JS_DeletePropertyStub,
JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
};
JSObject*
JSXrayTraits::createHolder(JSContext *cx, JSObject *wrapper)
{
RootedObject global(cx, JS_GetGlobalForObject(cx, wrapper));
RootedObject target(cx, getTargetObject(wrapper));
RootedObject holder(cx, JS_NewObjectWithGivenProto(cx, &HolderClass,
JS::NullPtr(), global));
if (!holder)
return nullptr;
// Compute information about the target.
bool isPrototype = false;
JSProtoKey key = IdentifyStandardInstance(target);
if (key == JSProto_Null) {
isPrototype = true;
key = IdentifyStandardPrototype(target);
}
MOZ_ASSERT(key != JSProto_Null);
// Store it on the holder.
RootedValue v(cx);
v.setNumber(static_cast<uint32_t>(key));
js::SetReservedSlot(holder, SLOT_PROTOKEY, v);
v.setBoolean(isPrototype);
js::SetReservedSlot(holder, SLOT_ISPROTOTYPE, v);
return holder;
}
XPCWrappedNativeXrayTraits XPCWrappedNativeXrayTraits::singleton;
DOMXrayTraits DOMXrayTraits::singleton;
JSXrayTraits JSXrayTraits::singleton;