From 80aa98036535070b384490a17201a02fe538f192 Mon Sep 17 00:00:00 2001 From: Steve Fink Date: Wed, 11 Dec 2013 17:51:58 -0800 Subject: [PATCH] Bug 937317 - Root around GC call GetIncumbentGlobal. r=bz --- content/events/src/nsDOMEventTargetHelper.cpp | 2 +- dom/base/nsGlobalWindow.cpp | 9 +++++---- dom/bindings/CallbackFunction.h | 2 +- dom/bindings/CallbackInterface.h | 2 +- dom/bindings/CallbackObject.h | 2 +- dom/bindings/Codegen.py | 12 +++++++++--- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/content/events/src/nsDOMEventTargetHelper.cpp b/content/events/src/nsDOMEventTargetHelper.cpp index a54519a6b67a..fdebfff23502 100644 --- a/content/events/src/nsDOMEventTargetHelper.cpp +++ b/content/events/src/nsDOMEventTargetHelper.cpp @@ -272,7 +272,7 @@ nsDOMEventTargetHelper::SetEventHandler(nsIAtom* aType, const JS::Value& aValue) { nsRefPtr handler; - JSObject* callable; + JS::Rooted callable(aCx); if (aValue.isObject() && JS_ObjectIsCallable(aCx, callable = &aValue.toObject())) { handler = new EventHandlerNonNull(callable, mozilla::dom::GetIncumbentGlobal()); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3b3413e24ff4..b8bf96e9298a 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -4946,8 +4946,9 @@ nsGlobalWindow::RequestAnimationFrame(const JS::Value& aCallback, return NS_ERROR_INVALID_ARG; } + JS::Rooted callbackObj(cx, &aCallback.toObject()); nsRefPtr callback = - new FrameRequestCallback(&aCallback.toObject(), GetIncumbentGlobal()); + new FrameRequestCallback(callbackObj, GetIncumbentGlobal()); ErrorResult rv; *aHandle = RequestAnimationFrame(*callback, rv); @@ -13231,7 +13232,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType) NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \ const JS::Value &v) { \ nsRefPtr handler; \ - JSObject *callable; \ + JS::Rooted callable(cx); \ if (v.isObject() && \ JS_ObjectIsCallable(cx, callable = &v.toObject())) { \ handler = new EventHandlerNonNull(callable, GetIncumbentGlobal()); \ @@ -13261,7 +13262,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType) } \ \ nsRefPtr handler; \ - JSObject *callable; \ + JS::Rooted callable(cx); \ if (v.isObject() && \ JS_ObjectIsCallable(cx, callable = &v.toObject())) { \ handler = new OnErrorEventHandlerNonNull(callable, GetIncumbentGlobal()); \ @@ -13292,7 +13293,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType) } \ \ nsRefPtr handler; \ - JSObject *callable; \ + JS::Rooted callable(cx); \ if (v.isObject() && \ JS_ObjectIsCallable(cx, callable = &v.toObject())) { \ handler = new OnBeforeUnloadEventHandlerNonNull(callable, GetIncumbentGlobal()); \ diff --git a/dom/bindings/CallbackFunction.h b/dom/bindings/CallbackFunction.h index a065ce27c9b5..63a48af53744 100644 --- a/dom/bindings/CallbackFunction.h +++ b/dom/bindings/CallbackFunction.h @@ -25,7 +25,7 @@ namespace dom { class CallbackFunction : public CallbackObject { public: - explicit CallbackFunction(JSObject* aCallable, + explicit CallbackFunction(JS::Handle aCallable, nsIGlobalObject* aIncumbentGlobal) : CallbackObject(aCallable, aIncumbentGlobal) { diff --git a/dom/bindings/CallbackInterface.h b/dom/bindings/CallbackInterface.h index 5555d0830792..f6f36057851a 100644 --- a/dom/bindings/CallbackInterface.h +++ b/dom/bindings/CallbackInterface.h @@ -24,7 +24,7 @@ namespace dom { class CallbackInterface : public CallbackObject { public: - explicit CallbackInterface(JSObject* aCallback, + explicit CallbackInterface(JS::Handle aCallback, nsIGlobalObject *aIncumbentGlobal) : CallbackObject(aCallback, aIncumbentGlobal) { diff --git a/dom/bindings/CallbackObject.h b/dom/bindings/CallbackObject.h index 9f9693984f69..8511d6849f16 100644 --- a/dom/bindings/CallbackObject.h +++ b/dom/bindings/CallbackObject.h @@ -49,7 +49,7 @@ public: // incumbent script settings object when the callback is invoked (overriding // the entry point computed from aCallback). If no override is required, the // caller should pass null. - explicit CallbackObject(JSObject* aCallback, nsIGlobalObject *aIncumbentGlobal) + explicit CallbackObject(JS::Handle aCallback, nsIGlobalObject *aIncumbentGlobal) { Init(aCallback, aIncumbentGlobal); } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 6165d76b058f..d9d1ef26ee68 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3396,7 +3396,10 @@ for (uint32_t i = 0; i < length; ++i) { else: declType = CGGeneric("OwningNonNull<%s>" % name) conversion = ( - "${declName} = new %s(&${val}.toObject(), mozilla::dom::GetIncumbentGlobal());\n" % name) + "{ // Scope for tempRoot\n" + " JS::Rooted tempRoot(cx, &${val}.toObject());\n" + " ${declName} = new %s(tempRoot, mozilla::dom::GetIncumbentGlobal());\n" + "}" % name) template = wrapObjectTemplate(conversion, type, "${declName} = nullptr", @@ -3729,7 +3732,10 @@ for (uint32_t i = 0; i < length; ++i) { else: declType = CGGeneric("OwningNonNull<%s>" % name) conversion = ( - " ${declName} = new %s(&${val}.toObject(), mozilla::dom::GetIncumbentGlobal());\n" % name) + "{ // Scope for tempRoot\n" + " JS::Rooted tempRoot(cx, &${val}.toObject());\n" + " ${declName} = new %s(tempRoot, mozilla::dom::GetIncumbentGlobal());\n" + "}\n" % name) if allowTreatNonCallableAsNull and type.treatNonCallableAsNull(): haveCallable = "JS_ObjectIsCallable(cx, &${val}.toObject())" @@ -10676,7 +10682,7 @@ class CGCallback(CGClass): def getConstructors(self): return [ClassConstructor( - [Argument("JSObject*", "aCallback"), Argument("nsIGlobalObject*", "aIncumbentGlobal")], + [Argument("JS::Handle", "aCallback"), Argument("nsIGlobalObject*", "aIncumbentGlobal")], bodyInHeader=True, visibility="public", explicit=True,