From 88cdaa8f8b91119379d2531c33757090dbe4239f Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Fri, 19 Apr 2013 21:57:18 +0200 Subject: [PATCH] Bug 851465 - Remove slim wrappers - remove various slim wrapper code and checks. r=bholley. --- dom/bindings/BindingUtils.h | 39 +++++++++------------ js/xpconnect/src/XPCCallContext.cpp | 8 ++--- js/xpconnect/src/XPCConvert.cpp | 6 ++-- js/xpconnect/src/XPCJSID.cpp | 3 +- js/xpconnect/src/XPCJSRuntime.cpp | 6 +--- js/xpconnect/src/XPCQuickStubs.cpp | 29 ++++------------ js/xpconnect/src/XPCWrappedNative.cpp | 5 ++- js/xpconnect/src/XPCWrappedNativeJSOps.cpp | 40 ++-------------------- js/xpconnect/src/nsXPConnect.cpp | 4 +-- js/xpconnect/src/xpcprivate.h | 7 ---- js/xpconnect/src/xpcpublic.h | 6 +--- js/xpconnect/wrappers/XrayWrapper.cpp | 6 ++-- 12 files changed, 40 insertions(+), 119 deletions(-) diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 25fa820284e..aab790d2a78 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -535,29 +535,24 @@ MaybeWrapValue(JSContext* cx, JS::MutableHandle rval) return true; } - if (rval.isObject()) { - JSObject* obj = &rval.toObject(); - if (js::GetObjectCompartment(obj) != js::GetContextCompartment(cx)) { - return JS_WrapValue(cx, rval.address()); - } - - // We're same-compartment, but even then we might need to wrap - // objects specially. Check for that. - if (GetSameCompartmentWrapperForDOMBinding(obj)) { - // We're a new-binding object, and "obj" now points to the right thing - rval.set(JS::ObjectValue(*obj)); - return true; - } - - if (!IS_SLIM_WRAPPER(obj)) { - // We might need a SOW - return JS_WrapValue(cx, rval.address()); - } - - // Fall through to returning true + if (!rval.isObject()) { + return true; } - return true; + JSObject* obj = &rval.toObject(); + if (js::GetObjectCompartment(obj) != js::GetContextCompartment(cx)) { + return JS_WrapValue(cx, rval.address()); + } + + // We're same-compartment, but even then we might need to wrap + // objects specially. Check for that. + if (GetSameCompartmentWrapperForDOMBinding(obj)) { + // We're a new-binding object, and "obj" now points to the right thing + rval.set(JS::ObjectValue(*obj)); + return true; + } + + return JS_WrapValue(cx, rval.address()); } static inline void @@ -642,7 +637,7 @@ WrapNewBindingObject(JSContext* cx, JS::Handle scope, T* value, } rval.set(JS::ObjectValue(*obj)); - return (sameCompartment && IS_SLIM_WRAPPER(obj)) || JS_WrapValue(cx, rval.address()); + return JS_WrapValue(cx, rval.address()); } // Create a JSObject wrapping "value", for cases when "value" is a diff --git a/js/xpconnect/src/XPCCallContext.cpp b/js/xpconnect/src/XPCCallContext.cpp index ca20ff70711..41f67570e8a 100644 --- a/js/xpconnect/src/XPCCallContext.cpp +++ b/js/xpconnect/src/XPCCallContext.cpp @@ -99,10 +99,7 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage, } else { js::Class *clasp = js::GetObjectClass(unwrapped); if (IS_WRAPPER_CLASS(clasp)) { - if (IS_SLIM_WRAPPER_OBJECT(unwrapped)) - mFlattenedJSObject = unwrapped; - else - mWrapper = XPCWrappedNative::Get(unwrapped); + mWrapper = XPCWrappedNative::Get(unwrapped); } else if (IS_TEAROFF_CLASS(clasp)) { mTearOff = (XPCWrappedNativeTearOff*)js::GetObjectPrivate(unwrapped); mWrapper = XPCWrappedNative::Get(js::GetObjectParent(unwrapped)); @@ -116,8 +113,7 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage, else mScriptableInfo = mWrapper->GetScriptableInfo(); } else { - NS_ABORT_IF_FALSE(!mFlattenedJSObject || IS_SLIM_WRAPPER(mFlattenedJSObject), - "should have a slim wrapper"); + NS_ABORT_IF_FALSE(!mFlattenedJSObject, "What object do we have?"); } if (!JSID_IS_VOID(name)) diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 20309e8b58b..c20fd223ceb 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -838,8 +838,6 @@ XPCConvert::NativeInterface2JSObject(jsval* d, return CreateHolderIfNeeded(flat, d, dest); } } - - MOZ_ASSERT_IF(flat, !IS_SLIM_WRAPPER_OBJECT(flat)); } else { flat = nullptr; } @@ -875,7 +873,9 @@ XPCConvert::NativeInterface2JSObject(jsval* d, getter_AddRefs(strongWrapper)); wrapper = strongWrapper; - } else if (IS_WN_WRAPPER_OBJECT(flat)) { + } else { + MOZ_ASSERT(IS_WN_WRAPPER_OBJECT(flat)); + wrapper = static_cast(xpc_GetJSPrivate(flat)); // If asked to return the wrapper we'll return a strong reference, diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index 477eb1e9590..c194d94798f 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -470,8 +470,7 @@ nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper, * there's chrome code that relies on this. * * This static method handles both complexities, returning either an XPCWN, a - * slim wrapper, a DOM object, or null. The object may well be cross-compartment - * from |cx|. + * DOM object, or null. The object may well be cross-compartment from |cx|. */ static JSObject * FindObjectForHasInstance(JSContext *cx, HandleObject objArg) diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index cd3e312f784..5f9118467bf 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -2540,11 +2540,7 @@ PreserveWrapper(JSContext *cx, JSObject *objArg) if (!IS_WRAPPER_CLASS(js::GetObjectClass(obj))) return mozilla::dom::TryPreserveWrapper(obj); - nsISupports *supports = nullptr; - if (IS_WN_WRAPPER_OBJECT(obj)) - supports = XPCWrappedNative::Get(obj)->Native(); - else - supports = static_cast(xpc_GetJSPrivate(obj)); + nsISupports *supports = XPCWrappedNative::Get(obj)->Native(); // For pre-Paris DOM bindings objects, we only support Node. if (nsCOMPtr node = do_QueryInterface(supports)) { diff --git a/js/xpconnect/src/XPCQuickStubs.cpp b/js/xpconnect/src/XPCQuickStubs.cpp index 924b95f33b6..f09fadf05d5 100644 --- a/js/xpconnect/src/XPCQuickStubs.cpp +++ b/js/xpconnect/src/XPCQuickStubs.cpp @@ -565,14 +565,10 @@ getWrapper(JSContext *cx, obj = js::GetObjectParent(obj); } - // If we've got a WN or slim wrapper, store things the way callers expect. - // Otherwise, leave things null and return. - if (IS_WRAPPER_CLASS(clasp)) { - if (IS_WN_WRAPPER_OBJECT(obj)) - *wrapper = (XPCWrappedNative*) js::GetObjectPrivate(obj); - else - *cur = obj; - } + // If we've got a WN, store things the way callers expect. Otherwise, leave + // things null and return. + if (IS_WRAPPER_CLASS(clasp)) + *wrapper = XPCWrappedNative::Get(obj); return NS_OK; } @@ -597,12 +593,8 @@ castNative(JSContext *cx, } else if (cur) { nsISupports *native; if (!(native = mozilla::dom::UnwrapDOMObjectToISupports(cur))) { - if (IS_SLIM_WRAPPER(cur)) { - native = static_cast(xpc_GetJSPrivate(cur)); - } else { - *pThisRef = nullptr; - return NS_ERROR_ILLEGAL_VALUE; - } + *pThisRef = nullptr; + return NS_ERROR_ILLEGAL_VALUE; } if (NS_SUCCEEDED(getNative(native, cur, iid, ppThis, pThisRef, vp))) { @@ -630,9 +622,7 @@ castNativeFromWrapper(JSContext *cx, if (IS_WRAPPER_CLASS(js::GetObjectClass(obj))) { cur = obj; - wrapper = IS_WN_WRAPPER_OBJECT(cur) ? - (XPCWrappedNative*)xpc_GetJSPrivate(obj) : - nullptr; + wrapper = (XPCWrappedNative*)xpc_GetJSPrivate(obj); tearoff = nullptr; } else { *rv = getWrapper(cx, obj, &wrapper, &cur, &tearoff); @@ -647,11 +637,6 @@ castNativeFromWrapper(JSContext *cx, if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) { native = nullptr; } - } else if (cur && IS_SLIM_WRAPPER(cur)) { - native = static_cast(xpc_GetJSPrivate(cur)); - if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) { - native = nullptr; - } } else if (cur && protoDepth >= 0) { const mozilla::dom::DOMClass* domClass = mozilla::dom::GetDOMClass(cur); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 9d60bd2ba75..fb3e59614e9 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1320,7 +1320,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope, CallQueryInterface(aCOMObj, &cache); if (cache) { flat = cache->GetWrapper(); - if (flat && !IS_SLIM_WRAPPER_OBJECT(flat)) { + if (flat) { wrapper = static_cast(xpc_GetJSPrivate(flat)); NS_ASSERTION(wrapper->GetScope() == aOldScope, "Incorrect scope passed"); @@ -1341,8 +1341,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope, // ReparentWrapperIfFound is really only meant to be called from DOM code // which must happen only on the main thread. Bail if we're on some other // thread or have a non-main-thread-only wrapper. - if (wrapper && - wrapper->GetProto() && + if (wrapper->GetProto() && !wrapper->GetProto()->ClassIsMainThreadOnly()) { return NS_ERROR_FAILURE; } diff --git a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp index 4954a7aedbf..2b987e55340 100644 --- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp +++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp @@ -593,10 +593,6 @@ XPC_WN_Shared_Enumerate(JSContext *cx, JSHandleObject obj) /***************************************************************************/ -#ifdef DEBUG_slimwrappers -static uint32_t sFinalizedSlimWrappers; -#endif - enum WNHelperType { WN_NOHELPER, WN_HELPER @@ -613,20 +609,6 @@ WrappedNativeFinalize(js::FreeOp *fop, JSObject *obj, WNHelperType helperType) if (!p) return; - if (IS_SLIM_WRAPPER_OBJECT(obj)) { - SLIM_LOG(("----- %i finalized slim wrapper (%p, %p)\n", - ++sFinalizedSlimWrappers, obj, p)); - - nsWrapperCache* cache; - CallQueryInterface(p, &cache); - cache->ClearWrapper(); - - XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); - MOZ_ASSERT(rt, "XPCJSRuntime should exist during a GC."); - rt->DeferredRelease(p); - return; - } - XPCWrappedNative* wrapper = static_cast(p); if (helperType == WN_HELPER) wrapper->GetScriptableCallback()->Finalize(wrapper, js::CastToJSFreeOp(fop), obj); @@ -639,12 +621,6 @@ XPC_WN_NoHelper_Finalize(js::FreeOp *fop, JSObject *obj) WrappedNativeFinalize(fop, obj, WN_NOHELPER); } -static void -TraceInsideSlimWrapper(JSTracer *trc, JSObject *obj) -{ - GetSlimWrapperProto(obj)->TraceSelf(trc); -} - /* * General comment about XPConnect tracing: Given a C++ object |wrapper| and its * corresponding JS object |obj|, calling |wrapper->TraceSelf| will ask the JS @@ -662,16 +638,9 @@ MarkWrappedNative(JSTracer *trc, JSObject *obj) } MOZ_ASSERT(IS_WRAPPER_CLASS(clazz)); - if (IS_WN_WRAPPER_OBJECT(obj)) { - XPCWrappedNative *wrapper = XPCWrappedNative::Get(obj); - if (wrapper) { - if (wrapper->IsValid()) - wrapper->TraceInside(trc); - } - } else { - MOZ_ASSERT(IS_SLIM_WRAPPER_OBJECT(obj)); - TraceInsideSlimWrapper(trc, obj); - } + XPCWrappedNative *wrapper = XPCWrappedNative::Get(obj); + if (wrapper && wrapper->IsValid()) + wrapper->TraceInside(trc); } static void @@ -1371,9 +1340,6 @@ XPCNativeScriptableShared::PopulateJSClass() if (mFlags.WantOuterObject()) mJSClass.base.ext.outerObject = XPC_WN_OuterObject; - if (!(mFlags & nsIXPCScriptable::WANT_OUTER_OBJECT)) - mCanBeSlim = true; - mJSClass.base.ext.isWrappedNative = true; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 1d48c27d780..576ed933be4 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1246,9 +1246,7 @@ nsXPConnect::GetNativeOfWrapper(JSContext * aJSContext, 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)) + if (XPCWrappedNative *wn = XPCWrappedNative::Get(aJSObj)) return wn->Native(); return nullptr; } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 83d9068d078..6bf0878b1b3 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -15,13 +15,6 @@ * additional C++ object involved of type XPCWrappedNative. The XPCWrappedNative * holds pointers to the C++ object and the flat JS object. * - * As an optimization, some C++ objects don't have XPCWrappedNatives, although - * they still have a corresponding flattened JS object. These are called "slim - * wrappers": all the wrapping information is stored in extra fields of the C++ - * object and the JS object. Slim wrappers are only used for DOM objects. As a - * deoptimization, slim wrappers can be "morphed" into XPCWrappedNatives if the - * extra fields of the XPCWrappedNative become necessary. - * * All XPCWrappedNative objects belong to an XPCWrappedNativeScope. These scopes * are essentially in 1:1 correspondence with JS global objects. The * XPCWrappedNativeScope has a pointer to the JS global object. The parent of a diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index bc14096cc03..6b9fd1af075 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -131,14 +131,10 @@ xpc_FastGetCachedWrapper(nsWrapperCache *cache, JSObject *scope, jsval *vp) { if (cache) { JSObject* wrapper = cache->GetWrapper(); - NS_ASSERTION(!wrapper || - !cache->IsDOMBinding() || - !IS_SLIM_WRAPPER(wrapper), - "Should never have a slim wrapper when IsDOMBinding()"); if (wrapper && js::GetObjectCompartment(wrapper) == js::GetObjectCompartment(scope) && (cache->IsDOMBinding() ? !cache->HasSystemOnlyWrapper() : - (IS_SLIM_WRAPPER(wrapper) || xpc_OkToHandOutWrapper(cache)))) { + xpc_OkToHandOutWrapper(cache))) { *vp = OBJECT_TO_JSVAL(wrapper); return wrapper; } diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 548a8fd9847..070c50f8d7b 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -61,11 +61,9 @@ GetXrayType(JSObject *obj) return XrayForDOMObject; js::Class* clasp = js::GetObjectClass(obj); - if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) { - NS_ASSERTION(clasp->ext.innerObject || IS_WN_WRAPPER_OBJECT(obj), - "We forgot to Morph a slim wrapper!"); + if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) return XrayForWrappedNative; - } + return NotXray; }