Bug 1148593 - Pass JSContext to CallbackObject constructor. r=bz

This commit is contained in:
Tom Tromey 2015-07-17 07:47:00 -04:00
parent 4bff378e10
commit e32d5166aa
9 changed files with 24 additions and 17 deletions

View File

@ -5555,7 +5555,7 @@ nsGlobalWindow::RequestAnimationFrame(JS::Handle<JS::Value> aCallback,
JS::Rooted<JSObject*> callbackObj(cx, &aCallback.toObject()); JS::Rooted<JSObject*> callbackObj(cx, &aCallback.toObject());
nsRefPtr<FrameRequestCallback> callback = nsRefPtr<FrameRequestCallback> callback =
new FrameRequestCallback(callbackObj, GetIncumbentGlobal()); new FrameRequestCallback(cx, callbackObj, GetIncumbentGlobal());
ErrorResult rv; ErrorResult rv;
*aHandle = RequestAnimationFrame(*callback, rv); *aHandle = RequestAnimationFrame(*callback, rv);

View File

@ -25,9 +25,10 @@ namespace dom {
class CallbackFunction : public CallbackObject class CallbackFunction : public CallbackObject
{ {
public: public:
explicit CallbackFunction(JS::Handle<JSObject*> aCallable, // See CallbackObject for an explanation of the arguments.
explicit CallbackFunction(JSContext* aCx, JS::Handle<JSObject*> aCallable,
nsIGlobalObject* aIncumbentGlobal) nsIGlobalObject* aIncumbentGlobal)
: CallbackObject(aCallable, aIncumbentGlobal) : CallbackObject(aCx, aCallable, aIncumbentGlobal)
{ {
} }

View File

@ -24,9 +24,10 @@ namespace dom {
class CallbackInterface : public CallbackObject class CallbackInterface : public CallbackObject
{ {
public: public:
explicit CallbackInterface(JS::Handle<JSObject*> aCallback, // See CallbackObject for an explanation of the arguments.
explicit CallbackInterface(JSContext* aCx, JS::Handle<JSObject*> aCallback,
nsIGlobalObject *aIncumbentGlobal) nsIGlobalObject *aIncumbentGlobal)
: CallbackObject(aCallback, aIncumbentGlobal) : CallbackObject(aCx, aCallback, aIncumbentGlobal)
{ {
} }

View File

@ -49,8 +49,12 @@ public:
// The caller may pass a global object which will act as an override for the // The caller may pass a global object which will act as an override for the
// incumbent script settings object when the callback is invoked (overriding // incumbent script settings object when the callback is invoked (overriding
// the entry point computed from aCallback). If no override is required, the // the entry point computed from aCallback). If no override is required, the
// caller should pass null. // caller should pass null. |aCx| is used to capture the current
explicit CallbackObject(JS::Handle<JSObject*> aCallback, nsIGlobalObject *aIncumbentGlobal) // stack, which is later used as an async parent when the callback
// is invoked. aCx can be nullptr, in which case no stack is
// captured.
explicit CallbackObject(JSContext* aCx, JS::Handle<JSObject*> aCallback,
nsIGlobalObject *aIncumbentGlobal)
{ {
Init(aCallback, aIncumbentGlobal); Init(aCallback, aIncumbentGlobal);
} }

View File

@ -3976,7 +3976,7 @@ class CGCallbackTempRoot(CGGeneric):
define = dedent(""" define = dedent("""
{ // Scope for tempRoot { // Scope for tempRoot
JS::Rooted<JSObject*> tempRoot(cx, &${val}.toObject()); JS::Rooted<JSObject*> tempRoot(cx, &${val}.toObject());
${declName} = new %s(tempRoot, mozilla::dom::GetIncumbentGlobal()); ${declName} = new %s(cx, tempRoot, mozilla::dom::GetIncumbentGlobal());
} }
""") % name """) % name
CGGeneric.__init__(self, define=define) CGGeneric.__init__(self, define=define)
@ -13908,7 +13908,7 @@ class CGJSImplClass(CGBindingImplClass):
destructor = ClassDestructor(virtual=False, visibility="private") destructor = ClassDestructor(virtual=False, visibility="private")
baseConstructors = [ baseConstructors = [
("mImpl(new %s(aJSImplObject, /* aIncumbentGlobal = */ nullptr))" % ("mImpl(new %s(nullptr, aJSImplObject, /* aIncumbentGlobal = */ nullptr))" %
jsImplName(descriptor.name)), jsImplName(descriptor.name)),
"mParent(aParent)"] "mParent(aParent)"]
parentInterface = descriptor.interface.parent parentInterface = descriptor.interface.parent
@ -14053,13 +14053,14 @@ class CGCallback(CGClass):
# CallbackObject does that already. # CallbackObject does that already.
body = "" body = ""
return [ClassConstructor( return [ClassConstructor(
[Argument("JS::Handle<JSObject*>", "aCallback"), [Argument("JSContext*", "aCx"),
Argument("JS::Handle<JSObject*>", "aCallback"),
Argument("nsIGlobalObject*", "aIncumbentGlobal")], Argument("nsIGlobalObject*", "aIncumbentGlobal")],
bodyInHeader=True, bodyInHeader=True,
visibility="public", visibility="public",
explicit=True, explicit=True,
baseConstructors=[ baseConstructors=[
"%s(aCallback, aIncumbentGlobal)" % self.baseName, "%s(aCx, aCallback, aIncumbentGlobal)" % self.baseName,
], ],
body=body)] body=body)]

View File

@ -287,7 +287,7 @@ DOMEventTargetHelper::SetEventHandler(nsIAtom* aType,
nsRefPtr<EventHandlerNonNull> handler; nsRefPtr<EventHandlerNonNull> handler;
JS::Rooted<JSObject*> callable(aCx); JS::Rooted<JSObject*> callable(aCx);
if (aValue.isObject() && JS::IsCallable(callable = &aValue.toObject())) { if (aValue.isObject() && JS::IsCallable(callable = &aValue.toObject())) {
handler = new EventHandlerNonNull(callable, dom::GetIncumbentGlobal()); handler = new EventHandlerNonNull(aCx, callable, dom::GetIncumbentGlobal());
} }
SetEventHandler(aType, EmptyString(), handler); SetEventHandler(aType, EmptyString(), handler);
return NS_OK; return NS_OK;

View File

@ -950,15 +950,15 @@ EventListenerManager::CompileEventHandlerInternal(Listener* aListener,
if (jsEventHandler->EventName() == nsGkAtoms::onerror && win) { if (jsEventHandler->EventName() == nsGkAtoms::onerror && win) {
nsRefPtr<OnErrorEventHandlerNonNull> handlerCallback = nsRefPtr<OnErrorEventHandlerNonNull> handlerCallback =
new OnErrorEventHandlerNonNull(handler, /* aIncumbentGlobal = */ nullptr); new OnErrorEventHandlerNonNull(nullptr, handler, /* aIncumbentGlobal = */ nullptr);
jsEventHandler->SetHandler(handlerCallback); jsEventHandler->SetHandler(handlerCallback);
} else if (jsEventHandler->EventName() == nsGkAtoms::onbeforeunload && win) { } else if (jsEventHandler->EventName() == nsGkAtoms::onbeforeunload && win) {
nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handlerCallback = nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handlerCallback =
new OnBeforeUnloadEventHandlerNonNull(handler, /* aIncumbentGlobal = */ nullptr); new OnBeforeUnloadEventHandlerNonNull(nullptr, handler, /* aIncumbentGlobal = */ nullptr);
jsEventHandler->SetHandler(handlerCallback); jsEventHandler->SetHandler(handlerCallback);
} else { } else {
nsRefPtr<EventHandlerNonNull> handlerCallback = nsRefPtr<EventHandlerNonNull> handlerCallback =
new EventHandlerNonNull(handler, /* aIncumbentGlobal = */ nullptr); new EventHandlerNonNull(nullptr, handler, /* aIncumbentGlobal = */ nullptr);
jsEventHandler->SetHandler(handlerCallback); jsEventHandler->SetHandler(handlerCallback);
} }

View File

@ -1312,7 +1312,7 @@ Promise::ResolveInternal(JSContext* aCx,
} }
nsRefPtr<PromiseInit> thenCallback = nsRefPtr<PromiseInit> thenCallback =
new PromiseInit(thenObj, mozilla::dom::GetIncumbentGlobal()); new PromiseInit(nullptr, thenObj, mozilla::dom::GetIncumbentGlobal());
nsRefPtr<ThenableResolverTask> task = nsRefPtr<ThenableResolverTask> task =
new ThenableResolverTask(this, valueObj, thenCallback); new ThenableResolverTask(this, valueObj, thenCallback);
DispatchToMicroTask(task); DispatchToMicroTask(task);

View File

@ -316,7 +316,7 @@ nsXBLPrototypeHandler::ExecuteHandler(EventTarget* aTarget,
NS_ENSURE_TRUE(bound, NS_ERROR_FAILURE); NS_ENSURE_TRUE(bound, NS_ERROR_FAILURE);
nsRefPtr<EventHandlerNonNull> handlerCallback = nsRefPtr<EventHandlerNonNull> handlerCallback =
new EventHandlerNonNull(bound, /* aIncumbentGlobal = */ nullptr); new EventHandlerNonNull(nullptr, bound, /* aIncumbentGlobal = */ nullptr);
TypedEventHandler typedHandler(handlerCallback); TypedEventHandler typedHandler(handlerCallback);