Bug 851465 - Remove slim wrappers - remove various slim wrapper code and checks. r=bholley.

This commit is contained in:
Peter Van der Beken 2013-04-19 21:57:18 +02:00
parent 76ae99ee96
commit 88cdaa8f8b
12 changed files with 40 additions and 119 deletions

View File

@ -535,29 +535,24 @@ MaybeWrapValue(JSContext* cx, JS::MutableHandle<JS::Value> 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<JSObject*> 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

View File

@ -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))

View File

@ -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<XPCWrappedNative*>(xpc_GetJSPrivate(flat));
// If asked to return the wrapper we'll return a strong reference,

View File

@ -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)

View File

@ -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<nsISupports*>(xpc_GetJSPrivate(obj));
nsISupports *supports = XPCWrappedNative::Get(obj)->Native();
// For pre-Paris DOM bindings objects, we only support Node.
if (nsCOMPtr<nsINode> node = do_QueryInterface(supports)) {

View File

@ -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<nsISupports*>(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<nsISupports*>(xpc_GetJSPrivate(cur));
if (!native || !HasBitInInterfacesBitmap(cur, interfaceBit)) {
native = nullptr;
}
} else if (cur && protoDepth >= 0) {
const mozilla::dom::DOMClass* domClass =
mozilla::dom::GetDOMClass(cur);

View File

@ -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<XPCWrappedNative*>(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;
}

View File

@ -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<XPCWrappedNative*>(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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}