Bug 509557 - Don't do a bunch of extra work and create a bunch of extra objects during window creation.

This commit is contained in:
Blake Kaplan 2009-08-18 21:02:05 -07:00
parent a6fdb48b85
commit fc4b1187b7
3 changed files with 42 additions and 10 deletions

View File

@ -2532,15 +2532,9 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
// properties will be forwarded to the inner window.
::JS_ClearScope(mContext, global);
// Tell XPConnect to re-initialize the global object to do things like
// define the Components object on the global again and forget all
// old prototypes in this scope.
// XXX Except that now, the global is thawed and has an inner window. So
// anything that XPConnect does to our global will be forwarded. So I
// think the only thing that this does for real is to call SetGlobal on
// our XPCWrappedNativeScope. Perhaps XPConnect should have a more
// targeted API?
rv = xpc->InitClasses(mContext, global);
// Now that the inner and outer windows are connected, tell XPConnect to
// re-initialize the prototypes on the outer window's scope.
rv = xpc->InitClassesForOuterObject(mContext, global);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIClassInfo> ci(do_QueryInterface(aGlobalObject));

View File

@ -394,17 +394,37 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%}
[uuid(b76828b8-3ac5-469e-946d-3401c6a2104d)]
[uuid(c29f5d27-21b1-4b87-8282-d724d535ef7b)]
interface nsIXPConnect : nsISupports
{
%{ C++
NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID)
%}
/**
* Initializes classes on a global object that has already been created.
*/
void
initClasses(in JSContextPtr aJSContext,
in JSObjectPtr aGlobalJSObj);
/**
* Like initClasses, but only does some of the initialization on the
* existing global. In particular this function assumes that the outer
* window has already been connected to an inner window, so
* re-initializing things like XPCNativeWrapper is useless.
*/
void
initClassesForOuterObject(in JSContextPtr aJSContext,
in JSObjectPtr aGlobalJSObj);
/**
* Creates a new global object using the given aCOMObj as the global
* object. The object will be set up according to the flags (defined
* below). If you do not pass INIT_JS_STANDARD_CLASSES, then aCOMObj
* must implement nsIXPCScriptable so it can resolve the standard
* classes when asked by the JS engine.
*/
nsIXPConnectJSObjectHolder
initClassesWithNewWrappedGlobal(
in JSContextPtr aJSContext,

View File

@ -1077,6 +1077,24 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
return NS_OK;
}
/* void initClassesForOuterObject (in JSContextPtr aJSContext, in JSObjectPtr aGlobalJSObj); */
NS_IMETHODIMP nsXPConnect::InitClassesForOuterObject(JSContext * aJSContext, JSObject * aGlobalJSObj)
{
SaveFrame sf(aJSContext);
XPCCallContext ccx(NATIVE_CALLER, aJSContext);
if(!ccx.IsValid())
return UnexpectedFailure(NS_ERROR_FAILURE);
XPCWrappedNativeScope* scope =
XPCWrappedNativeScope::GetNewOrUsed(ccx, aGlobalJSObj);
if(!scope)
return UnexpectedFailure(NS_ERROR_FAILURE);
scope->RemoveWrappedNativeProtos();
return NS_OK;
}
static JSBool
TempGlobalResolve(JSContext *aJSContext, JSObject *obj, jsval id)
{