From b744235be1b4bfd1097a4313b1edcde03257399e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 26 Nov 2011 11:11:35 +0100 Subject: [PATCH] Bug 698394 - Pass JSObject handler to nsIScriptContext::BindCompiledEventHandler; r=sicking --- content/events/src/nsEventListenerManager.cpp | 2 +- content/xbl/src/nsXBLPrototypeHandler.cpp | 2 +- dom/base/nsDOMScriptObjectHolder.h | 7 +++++++ dom/base/nsGlobalWindow.cpp | 2 +- dom/base/nsIScriptContext.h | 6 +++--- dom/base/nsJSEnvironment.cpp | 20 ++++++++++--------- dom/base/nsJSEnvironment.h | 2 +- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 0d9a752e1a8..213d948d233 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -701,7 +701,7 @@ nsEventListenerManager::CompileEventHandlerInternal(nsListenerStruct *aListenerS // Bind it nsScriptObjectHolder boundHandler(context); context->BindCompiledEventHandler(mTarget, listener->GetEventScope(), - handler, boundHandler); + handler.getObject(), boundHandler); listener->SetHandler( static_cast( static_cast(boundHandler))); diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index fa2c3b9a0ed..c098e5b459d 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -323,7 +323,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget, JSObject* scope = boundGlobal->GetGlobalJSObject(); nsScriptObjectHolder boundHandler(boundContext); rv = boundContext->BindCompiledEventHandler(scriptTarget, scope, - handler, boundHandler); + handler.getObject(), boundHandler); NS_ENSURE_SUCCESS(rv, rv); // Execute it. diff --git a/dom/base/nsDOMScriptObjectHolder.h b/dom/base/nsDOMScriptObjectHolder.h index cbcefec4fef..93df103995e 100644 --- a/dom/base/nsDOMScriptObjectHolder.h +++ b/dom/base/nsDOMScriptObjectHolder.h @@ -86,6 +86,9 @@ public: JSScript* getScript() const { return static_cast(mObject); } + JSObject* getObject() const { + return static_cast(mObject); + } // Drop the script object - but *not* the nsIScriptContext. nsresult drop() { @@ -96,6 +99,10 @@ public: } return rv; } + + nsresult setObject(JSObject* aObject) { + return set(aObject); + } nsresult set(void *object) { NS_ASSERTION(getScriptTypeID() != nsIProgrammingLanguage::UNKNOWN, "Must know the language!"); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 37f3c575ab5..5be2b6c39e8 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -9305,7 +9305,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout) } nsCOMPtr handler(timeout->mScriptHandler); - void *scriptObject = handler->GetScriptObject(); + JSObject* scriptObject = static_cast(handler->GetScriptObject()); if (!scriptObject) { // Evaluate the timeout expression. const PRUnichar *script = handler->GetHandlerText(); diff --git a/dom/base/nsIScriptContext.h b/dom/base/nsIScriptContext.h index 59b262d1ff4..bc8079815a4 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 \ -{ 0x1843adb8, 0xd646, 0x4103, \ - { 0x8d, 0xa3, 0xc5, 0x12, 0xb9, 0xca, 0xfb, 0xcd } } +{ 0xe0ff5703, 0xc92b, 0x46b5, \ + { 0x87, 0x82, 0xd0, 0xdc, 0x61, 0xba, 0x44, 0x03 } } /* This MUST match JSVERSION_DEFAULT. This version stuff if we don't know what language we have is a little silly... */ @@ -247,7 +247,7 @@ public: */ virtual nsresult BindCompiledEventHandler(nsISupports* aTarget, JSObject* aScope, - void* aHandler, + JSObject* aHandler, nsScriptObjectHolder& aBoundHandler) = 0; /** diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 13d08a0e99e..f3e9c0aaf4e 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1966,7 +1966,7 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, JSObject* aScope, nsresult nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, JSObject* aScope, - void *aHandler, + JSObject* aHandler, nsScriptObjectHolder& aBoundHandler) { NS_ENSURE_ARG(aHandler); @@ -1980,17 +1980,15 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, JSObject* aScope, nsresult rv = JSObjectFromInterface(aTarget, aScope, &target); NS_ENSURE_SUCCESS(rv, rv); - JSObject *funobj = (JSObject*) aHandler; - #ifdef DEBUG { JSAutoEnterCompartment ac; - if (!ac.enter(mContext, funobj)) { + if (!ac.enter(mContext, aHandler)) { return NS_ERROR_FAILURE; } NS_ASSERTION(JS_TypeOfValue(mContext, - OBJECT_TO_JSVAL(funobj)) == JSTYPE_FUNCTION, + OBJECT_TO_JSVAL(aHandler)) == JSTYPE_FUNCTION, "Event handler object not a function"); } #endif @@ -2000,14 +1998,18 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, JSObject* aScope, return NS_ERROR_FAILURE; } + JSObject* funobj; // Make sure the handler function is parented by its event target object - if (funobj) { // && ::JS_GetParent(mContext, funobj) != target) { - funobj = ::JS_CloneFunctionObject(mContext, funobj, target); - if (!funobj) + if (aHandler) { + funobj = JS_CloneFunctionObject(mContext, aHandler, target); + if (!funobj) { rv = NS_ERROR_OUT_OF_MEMORY; + } + } else { + funobj = NULL; } - aBoundHandler.set(funobj); + aBoundHandler.setObject(funobj); return rv; } diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index 764da8a9680..9d47525ff01 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -113,7 +113,7 @@ public: nsIArray *argv, nsIVariant **rv); virtual nsresult BindCompiledEventHandler(nsISupports *aTarget, JSObject *aScope, - void *aHandler, + JSObject* aHandler, nsScriptObjectHolder& aBoundHandler); virtual nsresult CompileFunction(JSObject* aTarget, const nsACString& aName,