diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index dbfba4f5854..f667c7cf260 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1332,15 +1332,18 @@ nsXPConnect::GetNativeOfWrapper(JSContext * aJSContext, return nullptr; } - JSObject* obj2 = nullptr; - nsIXPConnectWrappedNative* wrapper = - XPCWrappedNative::GetWrappedNativeOfJSObject(aJSContext, aJSObj, nullptr, - &obj2); - if (wrapper) - return wrapper->Native(); - - if (obj2) - return (nsISupports*)xpc_GetJSPrivate(obj2); + aJSObj = js::UnwrapObjectChecked(aJSObj, /* stopAtOuter = */ false); + if (!aJSObj) { + JS_ReportError(aJSContext, "Permission denied to get native of security wrapper"); + return nullptr; + } + if (IS_WRAPPER_CLASS(js::GetObjectClass(aJSObj))) { + if (IS_SLIM_WRAPPER_OBJECT(aJSObj)) + return (nsISupports*)xpc_GetJSPrivate(aJSObj); + else if (XPCWrappedNative *wn = XPCWrappedNative::Get(aJSObj)) + return wn->Native(); + return nullptr; + } JSObject* unsafeObj = XPCWrapper::Unwrap(aJSContext, aJSObj, /* stopAtOuter = */ false); diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index c41430b1899..d36afa30279 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -2765,18 +2765,16 @@ public: static XPCWrappedNative* GetAndMorphWrappedNativeOfJSObject(JSContext* cx, JSObject* obj) { - JSObject *obj2 = nullptr; - XPCWrappedNative* wrapper = - GetWrappedNativeOfJSObject(cx, obj, nullptr, &obj2); - if (wrapper || !obj2) - return wrapper; + obj = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false); + if (!obj) + return nullptr; + if (!IS_WRAPPER_CLASS(js::GetObjectClass(obj))) + return nullptr; - NS_ASSERTION(IS_SLIM_WRAPPER(obj2), - "Hmm, someone changed GetWrappedNativeOfJSObject?"); - SLIM_LOG_WILL_MORPH(cx, obj2); - return MorphSlimWrapper(cx, obj2) ? - (XPCWrappedNative*)xpc_GetJSPrivate(obj2) : - nullptr; + if (IS_SLIM_WRAPPER_OBJECT(obj) && !MorphSlimWrapper(cx, obj)) + return nullptr; + MOZ_ASSERT(IS_WN_WRAPPER(obj)); + return XPCWrappedNative::Get(obj); } static nsresult