diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 2e5ffc5f5725..b007624811fd 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -5651,9 +5651,7 @@ nsContentUtils::WrapNative(JSContext *cx, nsISupports *native, return NS_OK; } - JS::Rooted scope(cx, JS::CurrentGlobalOrNull(cx)); - - JSObject *wrapper = xpc_FastGetCachedWrapper(cache, scope, vp); + JSObject *wrapper = xpc_FastGetCachedWrapper(cx, cache, vp); if (wrapper) { return NS_OK; } @@ -5665,6 +5663,7 @@ nsContentUtils::WrapNative(JSContext *cx, nsISupports *native, } nsresult rv = NS_OK; + JS::Rooted scope(cx, JS::CurrentGlobalOrNull(cx)); AutoPushJSContext context(cx); rv = sXPConnect->WrapNativeToJSVal(context, scope, native, cache, aIID, aAllowWrapping, vp); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index b16e1a96f1ad..ff697f066bff 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -563,12 +563,12 @@ WrapNative(JSContext *cx, nsISupports *native, return NS_OK; } - JS::Rooted scope(cx, JS::CurrentGlobalOrNull(cx)); - JSObject *wrapper = xpc_FastGetCachedWrapper(cache, scope, vp); + JSObject *wrapper = xpc_FastGetCachedWrapper(cx, cache, vp); if (wrapper) { return NS_OK; } + JS::Rooted scope(cx, JS::CurrentGlobalOrNull(cx)); return nsDOMClassInfo::XPConnect()->WrapNativeToJSVal(cx, scope, native, cache, aIID, aAllowWrapping, vp); diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 70c75924027f..c0f8903ad9a3 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1167,7 +1167,8 @@ WrapObject(JSContext* cx, JS::Handle scope, T* p, nsWrapperCache* cache, const nsIID* iid, JS::MutableHandle rval) { - if (xpc_FastGetCachedWrapper(cache, scope, rval)) + MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx)); + if (xpc_FastGetCachedWrapper(cx, cache, rval)) return true; qsObjectHelper helper(p, cache); return XPCOMObjectToJsval(cx, scope, helper, iid, true, rval); diff --git a/js/xpconnect/src/qsgen.py b/js/xpconnect/src/qsgen.py index 773f719f525d..3da4ed1291e2 100644 --- a/js/xpconnect/src/qsgen.py +++ b/js/xpconnect/src/qsgen.py @@ -706,7 +706,7 @@ def writeResultConv(f, type, jsvalPtr, jsvalRef): " return true;\n" " }\n" " nsWrapperCache* cache = xpc_qsGetWrapperCache(result);\n" - " if (xpc_FastGetCachedWrapper(cache, obj, %s)) {\n" + " if (xpc_FastGetCachedWrapper(cx, cache, %s)) {\n" " return true;\n" " }\n" " // After this point do not use 'result'!\n" diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 151ebfad86c8..14f51b4b44dc 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -144,12 +144,12 @@ struct RuntimeStats; #define XPCONNECT_GLOBAL_FLAGS XPCONNECT_GLOBAL_FLAGS_WITH_EXTRA_SLOTS(0) inline JSObject* -xpc_FastGetCachedWrapper(nsWrapperCache *cache, JSObject *scope, JS::MutableHandleValue vp) +xpc_FastGetCachedWrapper(JSContext *cx, nsWrapperCache *cache, JS::MutableHandleValue vp) { if (cache) { JSObject* wrapper = cache->GetWrapper(); if (wrapper && - js::GetObjectCompartment(wrapper) == js::GetObjectCompartment(scope)) + js::GetObjectCompartment(wrapper) == js::GetContextCompartment(cx)) { vp.setObject(*wrapper); return wrapper;