From e2c99615af0e3523e4f6048135764a38f6fce80f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 23 Mar 2017 03:06:25 -0400 Subject: [PATCH] Bug 1348095 part 2. Give all the Xray holders a JSClass that has a slot for caching a prototype. r=bholley MozReview-Commit-ID: ID9vMG3iJfZ --- js/xpconnect/wrappers/XrayWrapper.cpp | 7 +++++-- js/xpconnect/wrappers/XrayWrapper.h | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 6d4d565e059f..42a4a4ddc3d8 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -201,9 +201,12 @@ XPCWrappedNativeXrayTraits::getWN(JSObject* wrapper) } const JSClass XPCWrappedNativeXrayTraits::HolderClass = { - "NativePropertyHolder" + "NativePropertyHolder", JSCLASS_HAS_RESERVED_SLOTS(HOLDER_SHARED_SLOT_COUNT) }; +const JSClass XrayTraits::HolderClass = { + "XrayHolder", JSCLASS_HAS_RESERVED_SLOTS(HOLDER_SHARED_SLOT_COUNT) +}; const JSClass JSXrayTraits::HolderClass = { "JSXrayHolder", JSCLASS_HAS_RESERVED_SLOTS(SLOT_COUNT) @@ -1854,7 +1857,7 @@ DOMXrayTraits::preserveWrapper(JSObject* target) JSObject* DOMXrayTraits::createHolder(JSContext* cx, JSObject* wrapper) { - return JS_NewObjectWithGivenProto(cx, nullptr, nullptr); + return JS_NewObjectWithGivenProto(cx, &HolderClass, nullptr); } const JSClass* diff --git a/js/xpconnect/wrappers/XrayWrapper.h b/js/xpconnect/wrappers/XrayWrapper.h index 5630982c28c4..4527e3b0a1f0 100644 --- a/js/xpconnect/wrappers/XrayWrapper.h +++ b/js/xpconnect/wrappers/XrayWrapper.h @@ -99,6 +99,12 @@ public: JSObject* ensureExpandoObject(JSContext* cx, JS::HandleObject wrapper, JS::HandleObject target); + // Slots for holder objects. + enum { + HOLDER_SLOT_CACHED_PROTO = 0, + HOLDER_SHARED_SLOT_COUNT + }; + JSObject* getHolder(JSObject* wrapper); JSObject* ensureHolder(JSContext* cx, JS::HandleObject wrapper); virtual JSObject* createHolder(JSContext* cx, JSObject* wrapper) = 0; @@ -108,6 +114,8 @@ public: bool cloneExpandoChain(JSContext* cx, JS::HandleObject dst, JS::HandleObject src); protected: + static const JSClass HolderClass; + // Get the JSClass we should use for our expando object. virtual const JSClass* getExpandoClass(JSContext* cx, JS::HandleObject target) const; @@ -301,7 +309,7 @@ public: } enum { - SLOT_PROTOKEY = 0, + SLOT_PROTOKEY = HOLDER_SHARED_SLOT_COUNT, SLOT_ISPROTOTYPE, SLOT_CONSTRUCTOR_FOR, SLOT_COUNT @@ -421,7 +429,7 @@ public: virtual JSObject* createHolder(JSContext* cx, JSObject* wrapper) override { - return JS_NewObjectWithGivenProto(cx, nullptr, nullptr); + return JS_NewObjectWithGivenProto(cx, &HolderClass, nullptr); } static OpaqueXrayTraits singleton;