Bug 851465 - Remove slim wrappers - stop morphing slim wrappers. r=bholley.

This commit is contained in:
Peter Van der Beken 2013-04-19 21:57:15 +02:00
Родитель 583f9d98a8
Коммит a6f9979ef0
10 изменённых файлов: 34 добавлений и 298 удалений

Просмотреть файл

@ -401,13 +401,6 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
AutoJSContext cx; AutoJSContext cx;
nsresult rv; nsresult rv;
JS::RootedObject wrapper(cx);
bool isDOMBinding;
if (aReparentScope && (wrapper = aNode->GetWrapper()) &&
!(isDOMBinding = IsDOMObject(wrapper))) {
rv = xpc_MorphSlimWrapper(cx, aNode);
NS_ENSURE_SUCCESS(rv, rv);
}
nsNodeInfoManager *nodeInfoManager = aNewNodeInfoManager; nsNodeInfoManager *nodeInfoManager = aNewNodeInfoManager;
@ -523,19 +516,22 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
elem->RecompileScriptEventListeners(); elem->RecompileScriptEventListeners();
} }
if (aReparentScope && wrapper) { if (aReparentScope) {
if (isDOMBinding) { JS::Rooted<JSObject*> wrapper(cx);
rv = ReparentWrapper(cx, wrapper); if ((wrapper = aNode->GetWrapper())) {
} else { if (IsDOMObject(wrapper)) {
nsIXPConnect *xpc = nsContentUtils::XPConnect(); rv = ReparentWrapper(cx, wrapper);
if (xpc) { } else {
rv = xpc->ReparentWrappedNativeIfFound(cx, wrapper, aReparentScope, aNode); nsIXPConnect *xpc = nsContentUtils::XPConnect();
if (xpc) {
rv = xpc->ReparentWrappedNativeIfFound(cx, wrapper, aReparentScope, aNode);
}
} }
} if (NS_FAILED(rv)) {
if (NS_FAILED(rv)) { aNode->mNodeInfo.swap(nodeInfo);
aNode->mNodeInfo.swap(nodeInfo);
return rv; return rv;
}
} }
} }
} }

Просмотреть файл

@ -2684,10 +2684,6 @@ nsXPCComponents_Utils::LookupMethod(const JS::Value& object,
// Enter the target compartment. // Enter the target compartment.
JSAutoCompartment ac(cx, obj); JSAutoCompartment ac(cx, obj);
// Morph slim wrappers.
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
return NS_ERROR_FAILURE;
// Now, try to create an Xray wrapper around the object. This won't work // Now, try to create an Xray wrapper around the object. This won't work
// if the object isn't Xray-able. In that case, we throw. // if the object isn't Xray-able. In that case, we throw.
JSObject *xray = WrapperFactory::WrapForSameCompartmentXray(cx, obj); JSObject *xray = WrapperFactory::WrapForSameCompartmentXray(cx, obj);

Просмотреть файл

@ -887,17 +887,6 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
wrapper->FindTearOff(iface, false, &rv); wrapper->FindTearOff(iface, false, &rv);
else else
rv = NS_OK; rv = NS_OK;
} else {
NS_ASSERTION(IS_SLIM_WRAPPER(flat),
"What kind of wrapper is this?");
SLIM_LOG(("***** morphing from XPCConvert::NativeInterface2JSObject"
"(%p)\n",
static_cast<nsISupports*>(xpc_GetJSPrivate(flat))));
rv = XPCWrappedNative::Morph(flat, iface, cache,
getter_AddRefs(strongWrapper));
wrapper = strongWrapper;
} }
if (NS_FAILED(rv) && pErr) if (NS_FAILED(rv) && pErr)

Просмотреть файл

@ -505,7 +505,6 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
NS_ASSERTION(obj, "when is an object not an object?"); NS_ASSERTION(obj, "when is an object not an object?");
nsISupports *identity = nullptr;
// is this really a native xpcom object with a wrapper? // is this really a native xpcom object with a wrapper?
const nsIID* iid; const nsIID* iid;
mInfo->GetIIDShared(&iid); mInfo->GetIIDShared(&iid);
@ -514,30 +513,16 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
if (!obj) if (!obj)
return NS_OK; return NS_OK;
if (IS_SLIM_WRAPPER(obj)) { if (IsDOMObject(obj)) {
XPCWrappedNativeProto* proto = GetSlimWrapperProto(obj); // Not all DOM objects implement nsISupports. But if they don't,
if (proto->GetSet()->HasInterfaceWithAncestor(iid)) { // there's nothing to do in this HasInstance hook.
*bp = true; nsISupports *identity = UnwrapDOMObjectToISupports(obj);
if (!identity)
return NS_OK; return NS_OK;
} nsCOMPtr<nsISupports> supp;
identity->QueryInterface(*iid, getter_AddRefs(supp));
#ifdef DEBUG_slimwrappers *bp = supp;
char foo[NSID_LENGTH]; return NS_OK;
iid->ToProvidedString(foo);
SLIM_LOG_WILL_MORPH_FOR_PROP(cx, obj, foo);
#endif
if (!MorphSlimWrapper(cx, obj))
return NS_ERROR_FAILURE;
} else if (IsDOMObject(obj)) {
// Not all DOM objects implement nsISupports. But if they don't,
// there's nothing to do in this HasInstance hook.
identity = UnwrapDOMObjectToISupports(obj);
if (!identity)
return NS_OK;
nsCOMPtr<nsISupports> supp;
identity->QueryInterface(*iid, getter_AddRefs(supp));
*bp = supp;
return NS_OK;
} }
MOZ_ASSERT(IS_WN_WRAPPER(obj)); MOZ_ASSERT(IS_WN_WRAPPER(obj));

Просмотреть файл

@ -532,15 +532,8 @@ XPCWrappedNative::GetNewOrUsed(xpcObjectHelper& helper,
if (cache) { if (cache) {
RootedObject cached(cx, cache->GetWrapper()); RootedObject cached(cx, cache->GetWrapper());
if (cached) { if (cached)
if (IS_SLIM_WRAPPER_OBJECT(cached)) { wrapper = static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(cached));
if (NS_FAILED(XPCWrappedNative::Morph(cached,
Interface, cache, getter_AddRefs(wrapper))))
return NS_ERROR_FAILURE;
} else {
wrapper = static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(cached));
}
}
} else { } else {
// scoped lock // scoped lock
XPCAutoLock lock(mapLock); XPCAutoLock lock(mapLock);
@ -711,67 +704,6 @@ FinishCreate(XPCWrappedNativeScope* Scope,
return NS_OK; return NS_OK;
} }
// static
nsresult
XPCWrappedNative::Morph(HandleObject existingJSObject,
XPCNativeInterface* Interface,
nsWrapperCache *cache,
XPCWrappedNative** resultWrapper)
{
AutoJSContext cx;
NS_ASSERTION(IS_SLIM_WRAPPER(existingJSObject),
"Trying to morph a JSObject that's not a slim wrapper?");
nsISupports *identity =
static_cast<nsISupports*>(xpc_GetJSPrivate(existingJSObject));
XPCWrappedNativeProto *proto = GetSlimWrapperProto(existingJSObject);
#if DEBUG
// FIXME Can't assert this until
// https://bugzilla.mozilla.org/show_bug.cgi?id=343141 is fixed.
#if 0
if (proto->GetScriptableInfo()->GetFlags().WantPreCreate()) {
JSObject* parent = JS_GetParent(existingJSObject);
JSObject* plannedParent = parent;
nsresult rv =
proto->GetScriptableInfo()->GetCallback()->PreCreate(identity, ccx,
parent,
&parent);
if (NS_FAILED(rv))
return rv;
NS_ASSERTION(parent == plannedParent,
"PreCreate returned a different parent");
}
#endif
#endif
nsRefPtr<XPCWrappedNative> wrapper = new XPCWrappedNative(dont_AddRef(identity), proto);
if (!wrapper)
return NS_ERROR_FAILURE;
NS_ASSERTION(!xpc::WrapperFactory::IsXrayWrapper(js::GetObjectParent(existingJSObject)),
"Xray wrapper being used to parent XPCWrappedNative?");
// We use an AutoMarkingPtr here because it is possible for JS gc to happen
// after we have Init'd the wrapper but *before* we add it to the hashtable.
// This would cause the mSet to get collected and we'd later crash. I've
// *seen* this happen.
AutoMarkingWrappedNativePtr wrapperMarker(cx, wrapper);
JSAutoCompartment ac(cx, existingJSObject);
if (!wrapper->Init(existingJSObject))
return NS_ERROR_FAILURE;
nsresult rv;
if (Interface && !wrapper->FindTearOff(Interface, false, &rv)) {
NS_ASSERTION(NS_FAILED(rv), "returning NS_OK on failure");
return rv;
}
return FinishCreate(wrapper->GetScope(), Interface, cache, wrapper, resultWrapper);
}
// static // static
nsresult nsresult
XPCWrappedNative::GetUsedOnly(nsISupports* Object, XPCWrappedNative::GetUsedOnly(nsISupports* Object,
@ -787,17 +719,11 @@ XPCWrappedNative::GetUsedOnly(nsISupports* Object,
CallQueryInterface(Object, &cache); CallQueryInterface(Object, &cache);
if (cache) { if (cache) {
RootedObject flat(cx, cache->GetWrapper()); RootedObject flat(cx, cache->GetWrapper());
if (flat && IS_SLIM_WRAPPER_OBJECT(flat) && !MorphSlimWrapper(cx, flat)) if (!flat) {
return NS_ERROR_FAILURE;
wrapper = flat ?
static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(flat)) :
nullptr;
if (!wrapper) {
*resultWrapper = nullptr; *resultWrapper = nullptr;
return NS_OK; return NS_OK;
} }
wrapper = static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(flat));
NS_ADDREF(wrapper); NS_ADDREF(wrapper);
} else { } else {
nsCOMPtr<nsISupports> identity = do_QueryInterface(Object); nsCOMPtr<nsISupports> identity = do_QueryInterface(Object);
@ -1067,10 +993,6 @@ XPCWrappedNative::GatherScriptableCreateInfo(nsISupports* obj,
return sciProto; return sciProto;
} }
#ifdef DEBUG_slimwrappers
static uint32_t sMorphedSlimWrappers;
#endif
JSBool JSBool
XPCWrappedNative::Init(HandleObject parent, XPCWrappedNative::Init(HandleObject parent,
const XPCNativeScriptableCreateInfo* sci) const XPCNativeScriptableCreateInfo* sci)
@ -1129,33 +1051,12 @@ XPCWrappedNative::Init(HandleObject parent,
return FinishInit(); return FinishInit();
} }
JSBool
XPCWrappedNative::Init(JSObject *existingJSObject)
{
// Set up the private to point to the WN.
JS_SetPrivate(existingJSObject, this);
// Officially mark us as non-slim.
MorphMultiSlot(existingJSObject);
mScriptableInfo = GetProto()->GetScriptableInfo();
mFlatJSObject = existingJSObject;
SLIM_LOG(("----- %i morphed slim wrapper (mFlatJSObject: %p, %p)\n",
++sMorphedSlimWrappers, mFlatJSObject,
static_cast<nsISupports*>(xpc_GetJSPrivate(mFlatJSObject))));
return FinishInit();
}
JSBool JSBool
XPCWrappedNative::FinishInit() XPCWrappedNative::FinishInit()
{ {
AutoJSContext cx; AutoJSContext cx;
// For all WNs, we want to make sure that the multislot starts out as null. // For all WNs, we want to make sure that the multislot starts out as null.
// This happens explicitly when morphing a slim wrapper, but we need to
// make sure it happens in the other cases too.
JS_SetReservedSlot(mFlatJSObject, WRAPPER_MULTISLOT, JSVAL_NULL); JS_SetReservedSlot(mFlatJSObject, WRAPPER_MULTISLOT, JSVAL_NULL);
// This reference will be released when mFlatJSObject is finalized. // This reference will be released when mFlatJSObject is finalized.
@ -1693,12 +1594,6 @@ RescueOrphans(HandleObject obj)
} }
} }
// Morph any slim wrappers, lest they confuse us.
if (IS_SLIM_WRAPPER(parentObj)) {
bool ok = MorphSlimWrapper(cx, parentObj);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
}
// Recursively fix up orphans on the parent chain. // Recursively fix up orphans on the parent chain.
rv = RescueOrphans(parentObj); rv = RescueOrphans(parentObj);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -3553,18 +3448,3 @@ XPCJSObjectHolder::newHolder(JSObject* obj)
} }
return new XPCJSObjectHolder(obj); return new XPCJSObjectHolder(obj);
} }
JSBool
MorphSlimWrapper(JSContext *cx, HandleObject obj)
{
SLIM_LOG(("***** morphing from MorphSlimToWrapper (%p, %p)\n",
obj, static_cast<nsISupports*>(xpc_GetJSPrivate(obj))));
nsISupports* object = static_cast<nsISupports*>(xpc_GetJSPrivate(obj));
nsWrapperCache *cache = nullptr;
CallQueryInterface(object, &cache);
nsRefPtr<XPCWrappedNative> wn;
nsresult rv = XPCWrappedNative::Morph(obj, nullptr, cache,
getter_AddRefs(wn));
return NS_SUCCEEDED(rv);
}

Просмотреть файл

@ -30,13 +30,6 @@ static JSBool Throw(nsresult errNum, JSContext* cx)
// Handy macro used in many callback stub below. // Handy macro used in many callback stub below.
#define MORPH_SLIM_WRAPPER(cx, obj) \
PR_BEGIN_MACRO \
SLIM_LOG_WILL_MORPH(cx, obj); \
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj)) \
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx); \
PR_END_MACRO
#define THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper) \ #define THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper) \
PR_BEGIN_MACRO \ PR_BEGIN_MACRO \
if (!wrapper) \ if (!wrapper) \
@ -173,7 +166,6 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, unsigned argc, jsval *vp)
if (!obj) if (!obj)
return false; return false;
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -513,7 +505,6 @@ XPC_WN_Shared_Convert(JSContext *cx, JSHandleObject obj, JSType type, JSMutableH
return true; return true;
} }
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -566,7 +557,6 @@ XPC_WN_Shared_Convert(JSContext *cx, JSHandleObject obj, JSType type, JSMutableH
static JSBool static JSBool
XPC_WN_Shared_Enumerate(JSContext *cx, JSHandleObject obj) XPC_WN_Shared_Enumerate(JSContext *cx, JSHandleObject obj)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -693,7 +683,6 @@ XPC_WN_NoHelper_Trace(JSTracer *trc, JSObject *obj)
static JSBool static JSBool
XPC_WN_NoHelper_Resolve(JSContext *cx, JSHandleObject obj, JSHandleId id) XPC_WN_NoHelper_Resolve(JSContext *cx, JSHandleObject obj, JSHandleId id)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj, NullPtr(), id); XPCCallContext ccx(JS_CALLER, cx, obj, NullPtr(), id);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -826,7 +815,6 @@ XPCWrappedNativeJSClass XPC_WN_NoHelper_JSClass = {
static JSBool static JSBool
XPC_WN_MaybeResolvingPropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) XPC_WN_MaybeResolvingPropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -846,7 +834,6 @@ XPC_WN_MaybeResolvingStrictPropertyStub(JSContext *cx, JSHandleObject obj, JSHan
static JSBool static JSBool
XPC_WN_MaybeResolvingDeletePropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool *succeeded) XPC_WN_MaybeResolvingDeletePropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool *succeeded)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -859,13 +846,6 @@ XPC_WN_MaybeResolvingDeletePropertyStub(JSContext *cx, JSHandleObject obj, JSHan
} }
// macro fun! // macro fun!
#define PRE_HELPER_STUB_NO_SLIM \
XPCWrappedNative* wrapper = \
XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(cx, obj); \
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); \
bool retval = true; \
nsresult rv = wrapper->GetScriptableCallback()->
#define PRE_HELPER_STUB \ #define PRE_HELPER_STUB \
XPCWrappedNative* wrapper; \ XPCWrappedNative* wrapper; \
nsIXPCScriptable* si; \ nsIXPCScriptable* si; \
@ -934,8 +914,7 @@ XPC_WN_Helper_SetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBo
static JSBool static JSBool
XPC_WN_Helper_Convert(JSContext *cx, JSHandleObject obj, JSType type, JSMutableHandleValue vp) XPC_WN_Helper_Convert(JSContext *cx, JSHandleObject obj, JSType type, JSMutableHandleValue vp)
{ {
SLIM_LOG_WILL_MORPH(cx, obj); PRE_HELPER_STUB
PRE_HELPER_STUB_NO_SLIM
Convert(wrapper, cx, obj, type, vp.address(), &retval); Convert(wrapper, cx, obj, type, vp.address(), &retval);
POST_HELPER_STUB POST_HELPER_STUB
} }
@ -963,8 +942,7 @@ XPC_WN_Helper_Call(JSContext *cx, unsigned argc, jsval *vp)
MOZ_ASSERT(obj == ccx.GetFlattenedJSObject()); MOZ_ASSERT(obj == ccx.GetFlattenedJSObject());
SLIM_LOG_WILL_MORPH(cx, obj); PRE_HELPER_STUB
PRE_HELPER_STUB_NO_SLIM
Call(wrapper, cx, obj, args, &retval); Call(wrapper, cx, obj, args, &retval);
POST_HELPER_STUB POST_HELPER_STUB
} }
@ -984,8 +962,7 @@ XPC_WN_Helper_Construct(JSContext *cx, unsigned argc, jsval *vp)
MOZ_ASSERT(obj == ccx.GetFlattenedJSObject()); MOZ_ASSERT(obj == ccx.GetFlattenedJSObject());
SLIM_LOG_WILL_MORPH(cx, obj); PRE_HELPER_STUB
PRE_HELPER_STUB_NO_SLIM
Construct(wrapper, cx, obj, args, &retval); Construct(wrapper, cx, obj, args, &retval);
POST_HELPER_STUB POST_HELPER_STUB
} }
@ -993,9 +970,8 @@ XPC_WN_Helper_Construct(JSContext *cx, unsigned argc, jsval *vp)
static JSBool static JSBool
XPC_WN_Helper_HasInstance(JSContext *cx, JSHandleObject obj, JSMutableHandleValue valp, JSBool *bp) XPC_WN_Helper_HasInstance(JSContext *cx, JSHandleObject obj, JSMutableHandleValue valp, JSBool *bp)
{ {
SLIM_LOG_WILL_MORPH(cx, obj);
bool retval2; bool retval2;
PRE_HELPER_STUB_NO_SLIM PRE_HELPER_STUB
HasInstance(wrapper, cx, obj, valp, &retval2, &retval); HasInstance(wrapper, cx, obj, valp, &retval2, &retval);
*bp = retval2; *bp = retval2;
POST_HELPER_STUB POST_HELPER_STUB
@ -1158,8 +1134,6 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSHandleObject obj, JSIterateOp enum_op,
return JS_EnumerateState(cx, obj, enum_op, statep, idp); return JS_EnumerateState(cx, obj, enum_op, statep, idp);
} }
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -1453,18 +1427,6 @@ XPC_WN_CallMethod(JSContext *cx, unsigned argc, jsval *vp)
if (!obj) if (!obj)
return false; return false;
#ifdef DEBUG_slimwrappers
{
JSFunction* fun = funobj->getFunctionPrivate();
JSString *funid = JS_GetFunctionDisplayId(fun);
JSAutoByteString bytes;
const char *funname = !funid ? "" : bytes.encodeLatin1(cx, funid) ? bytes.ptr() : "<error>";
SLIM_LOG_WILL_MORPH_FOR_PROP(cx, obj, funname);
}
#endif
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
obj = FixUpThisIfBroken(obj, funobj); obj = FixUpThisIfBroken(obj, funobj);
XPCCallContext ccx(JS_CALLER, cx, obj, funobj, JSID_VOIDHANDLE, argc, XPCCallContext ccx(JS_CALLER, cx, obj, funobj, JSID_VOIDHANDLE, argc,
JS_ARGV(cx, vp), vp); JS_ARGV(cx, vp), vp);
@ -1490,21 +1452,6 @@ XPC_WN_GetterSetter(JSContext *cx, unsigned argc, jsval *vp)
if (!obj) if (!obj)
return false; return false;
#ifdef DEBUG_slimwrappers
{
const char* funname = nullptr;
JSAutoByteString bytes;
if (JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION) {
JSString *funid = JS_GetFunctionDisplayId(funobj->getFunctionPrivate());
funname = !funid ? "" : bytes.encodeLatin1(cx, funid) ? bytes.ptr() : "<error>";
}
SLIM_LOG_WILL_MORPH_FOR_PROP(cx, obj, funname);
}
#endif
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
obj = FixUpThisIfBroken(obj, funobj); obj = FixUpThisIfBroken(obj, funobj);
XPCCallContext ccx(JS_CALLER, cx, obj, funobj, JSID_VOIDHANDLE, argc, XPCCallContext ccx(JS_CALLER, cx, obj, funobj, JSID_VOIDHANDLE, argc,
JS_ARGV(cx, vp), vp); JS_ARGV(cx, vp), vp);
@ -1787,7 +1734,6 @@ js::Class XPC_WN_NoMods_NoCall_Proto_JSClass = {
static JSBool static JSBool
XPC_WN_TearOff_Enumerate(JSContext *cx, JSHandleObject obj) XPC_WN_TearOff_Enumerate(JSContext *cx, JSHandleObject obj)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
@ -1810,7 +1756,6 @@ XPC_WN_TearOff_Enumerate(JSContext *cx, JSHandleObject obj)
static JSBool static JSBool
XPC_WN_TearOff_Resolve(JSContext *cx, JSHandleObject obj, JSHandleId id) XPC_WN_TearOff_Resolve(JSContext *cx, JSHandleObject obj, JSHandleId id)
{ {
MORPH_SLIM_WRAPPER(cx, obj);
XPCCallContext ccx(JS_CALLER, cx, obj); XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper(); XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper); THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);

Просмотреть файл

@ -1080,21 +1080,6 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
return NS_OK; return NS_OK;
} }
nsresult
xpc_MorphSlimWrapper(JSContext *cx, nsISupports *tomorph)
{
nsWrapperCache *cache;
CallQueryInterface(tomorph, &cache);
if (!cache)
return NS_OK;
RootedObject obj(cx, cache->GetWrapper());
if (!obj || !IS_SLIM_WRAPPER(obj))
return NS_OK;
NS_ENSURE_STATE(MorphSlimWrapper(cx, obj));
return NS_OK;
}
static nsresult static nsresult
NativeInterface2JSObject(HandleObject aScope, NativeInterface2JSObject(HandleObject aScope,
nsISupports *aCOMObj, nsISupports *aCOMObj,
@ -1236,12 +1221,9 @@ nsXPConnect::GetWrappedNativeOfJSObject(JSContext * aJSContext,
NS_ASSERTION(_retval, "bad param"); NS_ASSERTION(_retval, "bad param");
RootedObject aJSObj(aJSContext, aJSObjArg); RootedObject aJSObj(aJSContext, aJSObjArg);
SLIM_LOG_WILL_MORPH(aJSContext, aJSObj); aJSObj = js::CheckedUnwrap(aJSObj, /* stopAtOuter = */ false);
nsIXPConnectWrappedNative* wrapper = if (aJSObj && IS_WN_WRAPPER(aJSObj)) {
XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(aJSContext, aJSObj); NS_IF_ADDREF(*_retval = XPCWrappedNative::Get(aJSObj));
if (wrapper) {
NS_ADDREF(wrapper);
*_retval = wrapper;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -304,16 +304,6 @@ inline XPCWrappedNativeProto* GetSlimWrapperProto(JSObject *obj)
return static_cast<XPCWrappedNativeProto*>(v.toPrivate()); return static_cast<XPCWrappedNativeProto*>(v.toPrivate());
} }
// A slim wrapper is identified by having a native pointer in its reserved slot.
// This function, therefore, does the official transition from a slim wrapper to
// a non-slim wrapper.
inline void MorphMultiSlot(JSObject *obj)
{
MOZ_ASSERT(IS_SLIM_WRAPPER(obj));
JS_SetReservedSlot(obj, WRAPPER_MULTISLOT, JSVAL_NULL);
MOZ_ASSERT(!IS_SLIM_WRAPPER(obj));
}
inline void SetWNExpandoChain(JSObject *obj, JSObject *chain) inline void SetWNExpandoChain(JSObject *obj, JSObject *chain)
{ {
MOZ_ASSERT(IS_WN_WRAPPER(obj)); MOZ_ASSERT(IS_WN_WRAPPER(obj));
@ -2241,8 +2231,6 @@ private:
XPCNativeScriptableInfo* mScriptableInfo; XPCNativeScriptableInfo* mScriptableInfo;
}; };
extern JSBool MorphSlimWrapper(JSContext *cx, JS::HandleObject obj);
/***********************************************/ /***********************************************/
// XPCWrappedNativeTearOff represents the info needed to make calls to one // XPCWrappedNativeTearOff represents the info needed to make calls to one
// interface on the underlying native object of a XPCWrappedNative. // interface on the underlying native object of a XPCWrappedNative.
@ -2489,22 +2477,6 @@ public:
XPCNativeInterface* Interface, XPCNativeInterface* Interface,
XPCWrappedNative** wrapper); XPCWrappedNative** wrapper);
static XPCWrappedNative*
GetAndMorphWrappedNativeOfJSObject(JSContext* cx, JSObject* obj_)
{
JS::RootedObject obj(cx, obj_);
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
if (!obj)
return nullptr;
if (!IS_WRAPPER_CLASS(js::GetObjectClass(obj)))
return nullptr;
if (IS_SLIM_WRAPPER_OBJECT(obj) && !MorphSlimWrapper(cx, obj))
return nullptr;
MOZ_ASSERT(IS_WN_WRAPPER(obj));
return XPCWrappedNative::Get(obj);
}
static nsresult static nsresult
ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope, ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope,
XPCWrappedNativeScope* aNewScope, XPCWrappedNativeScope* aNewScope,
@ -2668,7 +2640,6 @@ private:
private: private:
JSBool Init(JS::HandleObject parent, const XPCNativeScriptableCreateInfo* sci); JSBool Init(JS::HandleObject parent, const XPCNativeScriptableCreateInfo* sci);
JSBool Init(JSObject *existingJSObject);
JSBool FinishInit(); JSBool FinishInit();
JSBool ExtendSet(XPCNativeInterface* aInterface); JSBool ExtendSet(XPCNativeInterface* aInterface);

Просмотреть файл

@ -82,9 +82,6 @@ xpc_LocalizeRuntime(JSRuntime *rt);
NS_EXPORT_(void) NS_EXPORT_(void)
xpc_DelocalizeRuntime(JSRuntime *rt); xpc_DelocalizeRuntime(JSRuntime *rt);
nsresult
xpc_MorphSlimWrapper(JSContext *cx, nsISupports *tomorph);
static inline bool IS_WRAPPER_CLASS(js::Class* clazz) static inline bool IS_WRAPPER_CLASS(js::Class* clazz)
{ {
return clazz->ext.isWrappedNative; return clazz->ext.isWrappedNative;

Просмотреть файл

@ -152,11 +152,6 @@ WrapperFactory::PrepareForWrapping(JSContext *cx, HandleObject scope,
// We should never get a proxy here (the JS engine unwraps those for us). // We should never get a proxy here (the JS engine unwraps those for us).
MOZ_ASSERT(!IsWrapper(obj)); MOZ_ASSERT(!IsWrapper(obj));
// As soon as an object is wrapped in a security wrapper, it morphs to be
// a fat wrapper. (see also: bug XXX).
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
return nullptr;
// If the object being wrapped is a prototype for a standard class and the // If the object being wrapped is a prototype for a standard class and the
// wrapper does not subsumes the wrappee, use the one from the content // wrapper does not subsumes the wrappee, use the one from the content
// compartment. This is generally safer all-around, and in the COW case this // compartment. This is generally safer all-around, and in the COW case this