From 36940470e19f72db59408b68153a0958114f88cf Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 29 Oct 2011 22:06:17 +0200 Subject: [PATCH] Bug 694759 - Make nsIScriptContext::GetNativeGlobal return JSObject; r=jst --- .../document/src/nsXULPrototypeDocument.cpp | 8 +++---- dom/base/nsGlobalWindow.cpp | 2 +- dom/base/nsIScriptContext.h | 6 +++--- dom/base/nsJSEnvironment.cpp | 21 +++++++++---------- dom/base/nsJSEnvironment.h | 4 ++-- dom/indexedDB/AsyncConnectionHelper.cpp | 3 +-- dom/indexedDB/IDBRequest.cpp | 2 +- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp index bb201cf77ead..9df15c252ccd 100644 --- a/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -695,16 +695,16 @@ nsXULPDGlobalObject::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aScrip NS_ASSERTION(!aScriptContext || !mContext, "Bad call to SetContext()!"); - void* script_glob = NULL; + JSObject* global = NULL; if (aScriptContext) { aScriptContext->SetGCOnDestruction(false); aScriptContext->DidInitializeContext(); - script_glob = aScriptContext->GetNativeGlobal(); - NS_ASSERTION(script_glob, "GetNativeGlobal returned NULL!"); + global = aScriptContext->GetNativeGlobal(); + NS_ASSERTION(global, "GetNativeGlobal returned NULL!"); } mContext = aScriptContext; - mJSObject = static_cast(script_glob); + mJSObject = global; return NS_OK; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index e560081dd8df..98d11e1c741f 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2157,7 +2157,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, mContext->CreateOuterObject(this, newInnerWindow); mContext->DidInitializeContext(); - mJSObject = (JSObject *)mContext->GetNativeGlobal(); + mJSObject = mContext->GetNativeGlobal(); SetWrapper(mJSObject); } else { JSObject *outerObject = diff --git a/dom/base/nsIScriptContext.h b/dom/base/nsIScriptContext.h index 0d21fa146493..e0c61d03531a 100644 --- a/dom/base/nsIScriptContext.h +++ b/dom/base/nsIScriptContext.h @@ -74,8 +74,8 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContextPrincipal, NS_ISCRIPTCONTEXTPRINCIPAL_IID) #define NS_ISCRIPTCONTEXT_IID \ -{ 0x827d1e82, 0x5aab, 0x4e3a, \ - { 0x88, 0x76, 0x53, 0xf7, 0xed, 0x1e, 0x3f, 0xbe } } +{ 0x21529edb, 0x29b6, 0x47ba, \ + { 0x8e, 0xe1, 0x51, 0xf2, 0xb5, 0x95, 0xe2, 0x02 } } /* This MUST match JSVERSION_DEFAULT. This version stuff if we don't know what language we have is a little silly... */ @@ -296,7 +296,7 @@ public: * Return the native global object for this context. * **/ - virtual void *GetNativeGlobal() = 0; + virtual JSObject* GetNativeGlobal() = 0; /** * Create a new global object that will be used for an inner window. diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index d420f1b89500..1066a839a850 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2202,10 +2202,10 @@ nsJSContext::GetGlobalObject() return sgo; } -void * +JSObject* nsJSContext::GetNativeGlobal() { - return ::JS_GetGlobalObject(mContext); + return JS_GetGlobalObject(mContext); } nsresult @@ -2396,7 +2396,7 @@ nsJSContext::SetProperty(void *aTarget, const char *aPropName, nsISupports *aArg nsresult nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, - void *aScope, + JSObject *aScope, PRUint32 *aArgc, jsval **aArgv, Maybe &aTempStorage) @@ -2452,8 +2452,7 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, } nsCOMPtr variant(do_QueryInterface(arg)); if (variant != nsnull) { - rv = xpc->VariantToJS(mContext, (JSObject *)aScope, variant, - thisval); + rv = xpc->VariantToJS(mContext, aScope, variant, thisval); } else { // And finally, support the nsISupportsPrimitives supplied // by the AppShell. It generally will pass only strings, but @@ -2471,8 +2470,8 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, #endif nsCOMPtr wrapper; jsval v; - rv = nsContentUtils::WrapNative(mContext, (JSObject *)aScope, arg, - &v, getter_AddRefs(wrapper)); + rv = nsContentUtils::WrapNative(mContext, aScope, arg, &v, + getter_AddRefs(wrapper)); if (NS_SUCCEEDED(rv)) { *thisval = v; } @@ -2480,10 +2479,10 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, } } } else { - nsCOMPtr variant(do_QueryInterface(aArgs)); - if (variant) - rv = xpc->VariantToJS(mContext, (JSObject *)aScope, variant, argv); - else { + nsCOMPtr variant = do_QueryInterface(aArgs); + if (variant) { + rv = xpc->VariantToJS(mContext, aScope, variant, argv); + } else { NS_ERROR("Not an array, not an interface?"); rv = NS_ERROR_UNEXPECTED; } diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index 4ff0ccb1c874..e4b707b9a650 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -130,7 +130,7 @@ public: virtual void SetDefaultLanguageVersion(PRUint32 aVersion); virtual nsIScriptGlobalObject *GetGlobalObject(); virtual JSContext* GetNativeContext(); - virtual void *GetNativeGlobal(); + virtual JSObject* GetNativeGlobal(); virtual nsresult CreateNativeGlobalForInner( nsIScriptGlobalObject *aGlobal, bool aIsChrome, @@ -201,7 +201,7 @@ protected: // Helper to convert xpcom datatypes to jsvals. nsresult ConvertSupportsTojsvals(nsISupports *aArgs, - void *aScope, + JSObject *aScope, PRUint32 *aArgc, jsval **aArgv, mozilla::Maybe &aPoolRelease); diff --git a/dom/indexedDB/AsyncConnectionHelper.cpp b/dom/indexedDB/AsyncConnectionHelper.cpp index df2b7b340d43..638a33e05832 100644 --- a/dom/indexedDB/AsyncConnectionHelper.cpp +++ b/dom/indexedDB/AsyncConnectionHelper.cpp @@ -148,8 +148,7 @@ HelperBase::WrapNative(JSContext* aCx, NS_ASSERTION(aResult, "Null pointer!"); NS_ASSERTION(mRequest, "Null request!"); - JSObject* global = - static_cast(mRequest->ScriptContext()->GetNativeGlobal()); + JSObject* global = mRequest->ScriptContext()->GetNativeGlobal(); NS_ENSURE_TRUE(global, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); nsresult rv = diff --git a/dom/indexedDB/IDBRequest.cpp b/dom/indexedDB/IDBRequest.cpp index 04d1f883f0ee..c5246ec96949 100644 --- a/dom/indexedDB/IDBRequest.cpp +++ b/dom/indexedDB/IDBRequest.cpp @@ -148,7 +148,7 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper) JSContext* cx = mScriptContext->GetNativeContext(); NS_ASSERTION(cx, "Failed to get a context!"); - JSObject* global = static_cast(mScriptContext->GetNativeGlobal()); + JSObject* global = mScriptContext->GetNativeGlobal(); NS_ASSERTION(global, "Failed to get global object!"); JSAutoRequest ar(cx);