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());
nsRefPtr<FrameRequestCallback> callback =
new FrameRequestCallback(callbackObj, GetIncumbentGlobal());
new FrameRequestCallback(cx, callbackObj, GetIncumbentGlobal());
ErrorResult rv;
*aHandle = RequestAnimationFrame(*callback, rv);

View File

@ -25,9 +25,10 @@ namespace dom {
class CallbackFunction : public CallbackObject
{
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)
: CallbackObject(aCallable, aIncumbentGlobal)
: CallbackObject(aCx, aCallable, aIncumbentGlobal)
{
}

View File

@ -24,9 +24,10 @@ namespace dom {
class CallbackInterface : public CallbackObject
{
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)
: 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
// 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(JS::Handle<JSObject*> aCallback, nsIGlobalObject *aIncumbentGlobal)
// caller should pass null. |aCx| is used to capture the current
// 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);
}

View File

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

View File

@ -287,7 +287,7 @@ DOMEventTargetHelper::SetEventHandler(nsIAtom* aType,
nsRefPtr<EventHandlerNonNull> handler;
JS::Rooted<JSObject*> callable(aCx);
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);
return NS_OK;

View File

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

View File

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

View File

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