Avoid calling nsXPConnect::GetWrapperFor in the common case of wrapping a global object in its own scope. r=jst

This commit is contained in:
Blake Kaplan 2010-05-19 18:26:15 -07:00
Родитель 0d2ffef49a
Коммит 507771115c
2 изменённых файлов: 25 добавлений и 2 удалений

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

@ -406,8 +406,10 @@ WrapObject(JSContext *cx, JSObject *parent, jsval *vp, XPCWrappedNative* wn)
}
}
XPCWrappedNativeScope *parentScope =
XPCWrappedNativeScope::FindInJSObjectScope(cx, parent, nsnull, rt);
XPCWrappedNative *parentwn =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, parent);
NS_ASSERTION(parentwn, "parent must be a wrapped native");
XPCWrappedNativeScope *parentScope = parentwn->GetScope();
#ifdef DEBUG_mrbkap_off
printf("Wrapping object at %p (%s) [%p]\n",

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

@ -1507,6 +1507,27 @@ XPC_WN_JSOp_ThisObject(JSContext *cx, JSObject *obj)
AutoPopJSContext popper(threadData->GetJSContextStack());
popper.PushIfNotTop(cx);
JSObject* outerscope = scope;
OBJ_TO_OUTER_OBJECT(cx, outerscope);
if(!outerscope)
return nsnull;
if(obj == outerscope)
{
// Fast-path for the common case: a window being wrapped in its own
// scope. Check to see if the object actually needs a XOW, and then
// give it one in its own scope.
if(!XPCCrossOriginWrapper::ClassNeedsXOW(obj->getClass()->name))
return obj;
js::AutoValueRooter tvr(cx, OBJECT_TO_JSVAL(obj));
if(!XPCCrossOriginWrapper::WrapObject(cx, scope, tvr.addr()))
return nsnull;
return JSVAL_TO_OBJECT(tvr.value());
}
nsIScriptSecurityManager* secMan = XPCWrapper::GetSecurityManager();
if(!secMan)
{