From 108d77ceaa9ff37460232e343dfc0b615c579c06 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Wed, 28 Sep 2005 23:03:08 +0000 Subject: [PATCH] Attempt to fix splitwindow focus stuff -- bug 305032. Issue found by mrbkap, patch by bzbarsky, r=mrbkap, sr=jst a=asa git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@181184 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xbl/src/nsXBLDocumentInfo.cpp | 4 +-- .../document/src/nsXULPrototypeDocument.cpp | 4 +-- mozilla/dom/public/nsIScriptGlobalObject.h | 12 ++++--- mozilla/dom/src/base/nsGlobalWindow.cpp | 36 +++++++++++++++---- mozilla/dom/src/base/nsGlobalWindow.h | 3 +- .../windowwatcher/src/nsWindowWatcher.cpp | 18 ++-------- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp b/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp index c9ac8d15c3c..3588f677e17 100644 --- a/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp @@ -83,7 +83,7 @@ public: virtual JSObject *GetGlobalJSObject(); virtual void OnFinalize(JSObject *aObject); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); - virtual nsresult SetNewArguments(JSObject *aArguments); + virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv); // nsIScriptObjectPrincipal methods virtual nsIPrincipal* GetPrincipal(); @@ -309,7 +309,7 @@ nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) } nsresult -nsXBLDocGlobalObject::SetNewArguments(JSObject *aArguments) +nsXBLDocGlobalObject::SetNewArguments(PRUint32 aArgc, jsval* aArgv) { NS_NOTREACHED("waaah!"); return NS_ERROR_UNEXPECTED; diff --git a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp index 2833c2148b3..6761c5c5788 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -105,7 +105,7 @@ public: virtual JSObject *GetGlobalJSObject(); virtual void OnFinalize(JSObject *aObject); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); - virtual nsresult SetNewArguments(JSObject *aArguments); + virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv); // nsIScriptObjectPrincipal methods virtual nsIPrincipal* GetPrincipal(); @@ -936,7 +936,7 @@ nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) } nsresult -nsXULPDGlobalObject::SetNewArguments(JSObject *aArguments) +nsXULPDGlobalObject::SetNewArguments(PRUint32 aArgc, jsval* aArgv) { NS_NOTREACHED("waaah!"); return NS_ERROR_UNEXPECTED; diff --git a/mozilla/dom/public/nsIScriptGlobalObject.h b/mozilla/dom/public/nsIScriptGlobalObject.h index 8a9a7aa399f..b1011cce72b 100644 --- a/mozilla/dom/public/nsIScriptGlobalObject.h +++ b/mozilla/dom/public/nsIScriptGlobalObject.h @@ -50,10 +50,11 @@ class nsIDocShell; class nsIDOMWindowInternal; class nsIScriptGlobalObjectOwner; struct JSObject; +typedef long jsval; #define NS_ISCRIPTGLOBALOBJECT_IID \ -{ 0xd4ddb2f8, 0x385f, 0x4baa, \ - { 0xba, 0x69, 0x6c, 0x42, 0xb3, 0xc2, 0xd0, 0xd0 } } +{ 0xd0db67fc, 0x50f7, 0x4573, \ + { 0x87, 0x3e, 0x5b, 0x33, 0x0b, 0x13, 0x21, 0x81 } } /** * The JavaScript specific global object. This often used to store @@ -110,12 +111,13 @@ public: */ virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; - /** Set a new arguments object for this window. This will be set on + /** + * Set a new arguments array for this window. This will be set on * the window right away (if there's an existing document) and it * will also be installed on the window when the next document is - * loaded. + * loaded. If argc is nonzero, argv must be non-null. */ - virtual nsresult SetNewArguments(JSObject *aArguments) = 0; + virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv) = 0; }; #endif diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 9701540a934..ec1d49d12cd 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -1639,19 +1639,43 @@ nsGlobalWindow::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) } nsresult -nsGlobalWindow::SetNewArguments(JSObject *aArguments) +nsGlobalWindow::SetNewArguments(PRUint32 aArgc, jsval* aArgv) { - FORWARD_TO_OUTER(SetNewArguments, (aArguments), NS_ERROR_NOT_INITIALIZED); + FORWARD_TO_OUTER(SetNewArguments, (aArgc, aArgv), NS_ERROR_NOT_INITIALIZED); JSContext *cx; - NS_ENSURE_TRUE(aArguments && mContext && + NS_ENSURE_TRUE(mContext && (cx = (JSContext *)mContext->GetNativeContext()), NS_ERROR_NOT_INITIALIZED); + if (mArguments) { + ::JS_UnlockGCThing(cx, mArguments); + mArguments = nsnull; + } + + if (aArgc == 0) { + return NS_OK; + } + + NS_ASSERTION(aArgv, "Must have argv!"); + + // Freeze the outer here so that we don't create a bogus new inner + // just because we're trying to resolve the Array class on cx. + // Resolving it for window.arguments on the outer window should be + // fine, I think. + Freeze(); + JSObject *argArray = ::JS_NewArrayObject(cx, aArgc, aArgv); + Thaw(); + + NS_ENSURE_TRUE(argArray, NS_ERROR_OUT_OF_MEMORY); + + // Note that currentInner may be non-null if someone's doing a + // window.open with an existing window name. nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal(); + + jsval args = OBJECT_TO_JSVAL(argArray); - jsval args = OBJECT_TO_JSVAL(aArguments); - + // The object newborn keeps argArray alive across this set. if (currentInner && currentInner->mJSObject) { if (!::JS_SetProperty(cx, currentInner->mJSObject, "arguments", &args)) { return NS_ERROR_FAILURE; @@ -1660,7 +1684,7 @@ nsGlobalWindow::SetNewArguments(JSObject *aArguments) // Hold on to the arguments so that we can re-set them once the next // document is loaded. - mArguments = aArguments; + mArguments = argArray; ::JS_LockGCThing(cx, mArguments); return NS_OK; diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 9e91d0a327f..00648b4c4a6 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -169,7 +169,7 @@ public: virtual JSObject *GetGlobalJSObject(); virtual void OnFinalize(JSObject *aJSObject); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); - virtual nsresult SetNewArguments(JSObject *aArguments); + virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv); // nsIScriptObjectPrincipal virtual nsIPrincipal* GetPrincipal(); @@ -398,6 +398,7 @@ protected: void Freeze() { + NS_ASSERTION(!IsFrozen(), "Double-freezing?"); mIsFrozen = PR_TRUE; } diff --git a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index b3c585293e9..36d802255cf 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -1744,25 +1744,11 @@ nsWindowWatcher::AttachArguments(nsIDOMWindow *aWindow, if (argc == 0) return NS_OK; - // copy the extra parameters into a JS Array and attach it nsCOMPtr scriptGlobal(do_QueryInterface(aWindow)); NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED); - nsIScriptContext *scriptContext = scriptGlobal->GetContext(); - nsresult rv = NS_OK; - - if (scriptContext) { - JSContext *cx; - cx = (JSContext *)scriptContext->GetNativeContext(); - - JSObject *args; - args = ::JS_NewArrayObject(cx, argc, argv); - if (args) { - rv = scriptGlobal->SetNewArguments(args); - } - } - - return rv; + // Just ask the global to attach the args for us + return scriptGlobal->SetNewArguments(argc, argv); } nsresult