diff --git a/js/xpconnect/src/XPCCallContext.cpp b/js/xpconnect/src/XPCCallContext.cpp index a52577ba5ec..01b0394d908 100644 --- a/js/xpconnect/src/XPCCallContext.cpp +++ b/js/xpconnect/src/XPCCallContext.cpp @@ -60,6 +60,8 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage, nullptr, nullptr); } +#define IS_TEAROFF_CLASS(clazz) ((clazz) == &XPC_WN_Tearoff_JSClass) + void XPCCallContext::Init(XPCContext::LangType callerLanguage, JSBool callBeginRequest, @@ -144,10 +146,10 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage, mTearOff = nullptr; if (wrapperInitOptions == INIT_SHOULD_LOOKUP_WRAPPER) { - // If the object is a security wrapper, GetWrappedNativeOfJSObject can't // handle it. Do special handling here to make cross-origin Xrays work. - if (WrapperFactory::IsSecurityWrapper(obj)) { + JSObject *unwrapped = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false); + if (!unwrapped) { mWrapper = UnwrapThisIfAllowed(obj, funobj, argc); if (!mWrapper) { JS_ReportError(mJSContext, "Permission denied to call method on |this|"); @@ -155,10 +157,16 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage, return; } } else { - mWrapper = XPCWrappedNative::GetWrappedNativeOfJSObject(mJSContext, - obj, funobj, - &mFlattenedJSObject, - &mTearOff); + js::Class *clasp = js::GetObjectClass(unwrapped); + if (IS_WRAPPER_CLASS(clasp)) { + if (IS_SLIM_WRAPPER_OBJECT(unwrapped)) + mFlattenedJSObject = unwrapped; + else + mWrapper = XPCWrappedNative::Get(unwrapped); + } else if (IS_TEAROFF_CLASS(clasp)) { + mTearOff = (XPCWrappedNativeTearOff*)js::GetObjectPrivate(unwrapped); + mWrapper = XPCWrappedNative::Get(js::GetObjectParent(unwrapped)); + } } if (mWrapper) { mFlattenedJSObject = mWrapper->GetFlatJSObject(); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index df068face00..5122f016a9b 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1751,48 +1751,6 @@ XPCWrappedNative::RescueOrphans(XPCCallContext& ccx) return ::RescueOrphans(ccx, mFlatJSObject); } -#define IS_TEAROFF_CLASS(clazz) \ - ((clazz) == &XPC_WN_Tearoff_JSClass) - -// static -XPCWrappedNative* -XPCWrappedNative::GetWrappedNativeOfJSObject(JSContext* cx, - JSObject* obj, - JSObject* funobj, - JSObject** pobj2, - XPCWrappedNativeTearOff** pTearOff) -{ - NS_PRECONDITION(obj, "bad param"); - - // fubobj must be null if called without cx. - NS_PRECONDITION(cx || !funobj, "bad param"); - - // *pTeaorOff must be null if pTearOff is given - NS_PRECONDITION(!pTearOff || !*pTearOff, "bad param"); - if (pobj2) - *pobj2 = nullptr; - - obj = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false); - if (!obj) - return nullptr; - js::Class *clasp = js::GetObjectClass(obj); - if (IS_WRAPPER_CLASS(clasp)) { - if (IS_WN_WRAPPER_OBJECT(obj)) { - return (XPCWrappedNative*)js::GetObjectPrivate(obj); - } else { - MOZ_ASSERT(IS_SLIM_WRAPPER_OBJECT(obj)); - if (pobj2) - *pobj2 = obj; - return nullptr; - } - } else if (IS_TEAROFF_CLASS(clasp)) { - if (pTearOff) - *pTearOff = (XPCWrappedNativeTearOff*)js::GetObjectPrivate(obj); - return (XPCWrappedNative*)js::GetObjectPrivate(js::GetObjectParent(obj)); - } - return nullptr; -} - JSBool XPCWrappedNative::ExtendSet(XPCCallContext& ccx, XPCNativeInterface* aInterface) { diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index d36afa30279..bbcf5435706 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -2753,15 +2753,6 @@ public: XPCNativeInterface* Interface, XPCWrappedNative** wrapper); - // If pobj2 is not null and *pobj2 is not null after the call then *pobj2 - // points to an object for which IS_SLIM_WRAPPER_OBJECT is true. - // cx is null when invoked from the marking phase of the GC. In this case - // fubobj must be null as well. - static XPCWrappedNative* - GetWrappedNativeOfJSObject(JSContext* cx, JSObject* obj, - JSObject* funobj = nullptr, - JSObject** pobj2 = nullptr, - XPCWrappedNativeTearOff** pTearOff = nullptr); static XPCWrappedNative* GetAndMorphWrappedNativeOfJSObject(JSContext* cx, JSObject* obj) {