From a8dba5714a852990ac1960d07f303bbfe934182a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 29 Oct 2011 22:09:04 +0200 Subject: [PATCH] Bug 694769 - Remove nsIScriptContext::GetScriptGlobal in favour of GetGlobalJSObject; r=smaug --- content/base/src/nsScriptLoader.cpp | 3 +-- content/events/src/nsEventListenerManager.cpp | 5 ++--- content/xbl/src/nsXBLDocumentInfo.cpp | 9 --------- content/xbl/src/nsXBLPrototypeHandler.cpp | 8 +++----- content/xul/document/src/nsXULDocument.cpp | 12 ++++-------- .../xul/document/src/nsXULPrototypeDocument.cpp | 8 +++----- dom/base/nsGlobalWindow.cpp | 16 ++-------------- dom/base/nsGlobalWindow.h | 1 - dom/base/nsIScriptGlobalObject.h | 14 +++----------- dom/base/nsJSEnvironment.cpp | 2 +- 10 files changed, 19 insertions(+), 59 deletions(-) diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 89a7fc01c274..a203e0fd86ea 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -899,8 +899,7 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest, nsContentUtils::GetWrapperSafeScriptFilename(mDocument, uri, url); bool isUndefined; - rv = context->EvaluateString(aScript, - globalObject->GetScriptGlobal(stid), + rv = context->EvaluateString(aScript, globalObject->GetGlobalJSObject(), mDocument->NodePrincipal(), url.get(), aRequest->mLineNo, aRequest->mJSVersion, nsnull, &isUndefined); diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 77010d55232a..38aee9eb6d17 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -442,7 +442,6 @@ nsEventListenerManager::AddScriptEventListener(nsIAtom *aName, { NS_PRECONDITION(aLanguage != nsIProgrammingLanguage::UNKNOWN, "Must know the language for the script event listener"); - nsIScriptContext *context = nsnull; // |aPermitUntrustedEvents| is set to False for chrome - events // *generated* from an unknown source are not allowed. @@ -532,10 +531,10 @@ nsEventListenerManager::AddScriptEventListener(nsIAtom *aName, // but fall through and let the inevitable failure below handle it. } - context = global->GetScriptContext(aLanguage); + nsIScriptContext* context = global->GetScriptContext(aLanguage); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - void *scope = global->GetScriptGlobal(aLanguage); + JSObject* scope = global->GetGlobalJSObject(); nsListenerStruct *ls; rv = SetJSEventListener(context, scope, aName, nsnull, diff --git a/content/xbl/src/nsXBLDocumentInfo.cpp b/content/xbl/src/nsXBLDocumentInfo.cpp index 7335a03e94ad..5b8e1e9327ce 100644 --- a/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/content/xbl/src/nsXBLDocumentInfo.cpp @@ -95,7 +95,6 @@ protected: void SetContext(nsIScriptContext *aContext); nsIScriptContext *GetScriptContext(PRUint32 language); - void *GetScriptGlobal(PRUint32 language); nsCOMPtr mScriptContext; JSObject *mJSObject; // XXX JS language rabies bigotry badness @@ -289,14 +288,6 @@ nsXBLDocGlobalObject::GetScriptContext(PRUint32 language) return GetContext(); } -void * -nsXBLDocGlobalObject::GetScriptGlobal(PRUint32 language) -{ - // This impl still assumes JS - NS_ENSURE_TRUE(language==nsIProgrammingLanguage::JAVASCRIPT, nsnull); - return GetGlobalJSObject(); -} - nsresult nsXBLDocGlobalObject::EnsureScriptEnvironment(PRUint32 aLangID) { diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index 4e8d6d4b1d45..86c679e5277e 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -265,9 +265,6 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget, nsCOMPtr onEventAtom = do_GetAtom(NS_LITERAL_STRING("onxbl") + nsDependentAtomString(mEventName)); - // Compile the event handler. - PRUint32 stID = nsIProgrammingLanguage::JAVASCRIPT; - // Compile the handler and bind it to the element. nsCOMPtr boundGlobal; nsCOMPtr winRoot(do_QueryInterface(aTarget)); @@ -301,7 +298,8 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget, if (!boundGlobal) return NS_OK; - nsIScriptContext *boundContext = boundGlobal->GetScriptContext(stID); + nsIScriptContext *boundContext = + boundGlobal->GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT); if (!boundContext) return NS_OK; @@ -318,7 +316,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget, NS_ENSURE_SUCCESS(rv, rv); // Bind it to the bound element - void *scope = boundGlobal->GetScriptGlobal(stID); + JSObject* scope = boundGlobal->GetGlobalJSObject(); nsScriptObjectHolder boundHandler(boundContext); rv = boundContext->BindCompiledEventHandler(scriptTarget, scope, handler, boundHandler); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 940616e4065c..04ec6d97c430 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -3631,15 +3631,11 @@ nsXULDocument::ExecuteScript(nsIScriptContext * aContext, void * aScriptObject) NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED); + NS_ABORT_IF_FALSE(aContext->GetScriptTypeID() == nsIProgrammingLanguage::JAVASCRIPT, + "Should have a JavaScript nsIScriptContext."); // Execute the precompiled script with the given version - nsresult rv; - void *global = mScriptGlobalObject->GetScriptGlobal( - aContext->GetScriptTypeID()); - rv = aContext->ExecuteScript(aScriptObject, - global, - nsnull, nsnull); - - return rv; + JSObject* global = mScriptGlobalObject->GetGlobalJSObject(); + return aContext->ExecuteScript(aScriptObject, global, nsnull, nsnull); } nsresult diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp index 9df15c252ccd..e9bdf05f794e 100644 --- a/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -84,7 +84,7 @@ public: virtual void OnFinalize(JSObject* aObject); virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts); - virtual void *GetScriptGlobal(PRUint32 lang); + virtual JSObject* GetGlobalJSObject(); virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID); virtual nsIScriptContext *GetScriptContext(PRUint32 lang); @@ -769,11 +769,9 @@ nsXULPDGlobalObject::GetScriptContext(PRUint32 lang_id) return mContext; } -void* -nsXULPDGlobalObject::GetScriptGlobal(PRUint32 lang_id) +JSObject* +nsXULPDGlobalObject::GetGlobalJSObject() { - NS_ABORT_IF_FALSE(lang_id == nsIProgrammingLanguage::JAVASCRIPT, - "We don't support this language ID"); return mJSObject; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 590cb590861b..40e91e056e6a 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1575,14 +1575,6 @@ nsGlobalWindow::GetScriptContext(PRUint32 lang) return mContext; } -void * -nsGlobalWindow::GetScriptGlobal(PRUint32 lang) -{ - NS_ASSERTION(lang == nsIProgrammingLanguage::JAVASCRIPT, - "We don't support this language ID"); - return mJSObject; -} - nsIScriptContext * nsGlobalWindow::GetContext() { @@ -1597,8 +1589,6 @@ nsGlobalWindow::GetContext() JSObject * nsGlobalWindow::GetGlobalJSObject() { - NS_ASSERTION(mJSObject == GetScriptGlobal(nsIProgrammingLanguage::JAVASCRIPT), - "GetGlobalJSObject confused?"); return FastGetGlobalJSObject(); } @@ -9304,8 +9294,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout) NS_TIME_FUNCTION_MARK("(file: %s, line: %d)", filename, lineNo); bool is_undefined; - scx->EvaluateString(nsDependentString(script), - GetScriptGlobal(handler->GetScriptTypeID()), + scx->EvaluateString(nsDependentString(script), FastGetGlobalJSObject(), timeout->mPrincipal, filename, lineNo, handler->GetScriptVersion(), nsnull, &is_undefined); @@ -9318,8 +9307,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout) nsCOMPtr dummy; nsCOMPtr me(static_cast(this)); - scx->CallEventHandler(me, - GetScriptGlobal(handler->GetScriptTypeID()), + scx->CallEventHandler(me, FastGetGlobalJSObject(), scriptObject, handler->GetArgv(), // XXXmarkh - consider allowing CallEventHandler to // accept nsnull? diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 26bace8eb09d..080859176564 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -321,7 +321,6 @@ public: virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID); virtual nsIScriptContext *GetScriptContext(PRUint32 lang); - virtual void *GetScriptGlobal(PRUint32 lang); // Set a new script language context for this global. The native global // for the context is created by the context's GetNativeGlobal() method. diff --git a/dom/base/nsIScriptGlobalObject.h b/dom/base/nsIScriptGlobalObject.h index b06de8d3aff4..26f40c06ebde 100644 --- a/dom/base/nsIScriptGlobalObject.h +++ b/dom/base/nsIScriptGlobalObject.h @@ -100,8 +100,8 @@ NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal, #define NS_ISCRIPTGLOBALOBJECT_IID \ -{ 0x4eb16819, 0x4e81, 0x406e, \ - { 0x93, 0x05, 0x6f, 0x30, 0xfc, 0xd2, 0x62, 0x4a } } +{ 0x08f73284, 0x26e3, 0x4fa6, \ + { 0xbf, 0x89, 0x83, 0x26, 0xf9, 0x2a, 0x94, 0xb3 } } /** * The global object which keeps a script context for each supported script @@ -128,15 +128,7 @@ public: */ virtual nsIScriptContext *GetScriptContext(PRUint32 lang) = 0; - /** - * Get the opaque "global" object for the specified lang. - */ - virtual void *GetScriptGlobal(PRUint32 lang) = 0; - - // Set/GetContext deprecated methods - use GetScriptContext/Global - virtual JSObject *GetGlobalJSObject() { - return (JSObject *)GetScriptGlobal(nsIProgrammingLanguage::JAVASCRIPT); - } + virtual JSObject* GetGlobalJSObject() = 0; virtual nsIScriptContext *GetContext() { return GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT); diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 1066a839a850..254dd0d567d5 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2244,7 +2244,7 @@ nsJSContext::ConnectToInner(nsIScriptGlobalObject *aNewInner, void *aOuterGlobal { NS_ENSURE_ARG(aNewInner); #ifdef DEBUG - JSObject *newInnerJSObject = (JSObject *)aNewInner->GetScriptGlobal(JAVASCRIPT); + JSObject *newInnerJSObject = aNewInner->GetGlobalJSObject(); #endif JSObject *outerGlobal = (JSObject *)aOuterGlobal;