Bug 1200484 (part 11) - Set source location when initializing an nsJSScriptTimeoutHandler from a Function. r=peterv.

Because we currently set the source location of a nsJSScriptTimeoutHandler when
initializing from an expression, but not when initializing from a function,
which is an undesirable inconsistency. This requires plumbing through the
JSContext in a few places.
This commit is contained in:
Nicholas Nethercote 2015-09-03 16:03:19 -07:00
parent 2a0c4d030c
commit eecf255d31
3 changed files with 20 additions and 11 deletions

View File

@ -12369,7 +12369,8 @@ nsGlobalWindow::SetTimeout(JSContext* aCx, Function& aFunction,
const Sequence<JS::Value>& aArguments,
ErrorResult& aError)
{
return SetTimeoutOrInterval(aFunction, aTimeout, aArguments, false, aError);
return SetTimeoutOrInterval(aCx, aFunction, aTimeout, aArguments, false,
aError);
}
int32_t
@ -12403,7 +12404,7 @@ nsGlobalWindow::SetInterval(JSContext* aCx, Function& aFunction,
{
int32_t timeout;
bool isInterval = IsInterval(aTimeout, timeout);
return SetTimeoutOrInterval(aFunction, timeout, aArguments, isInterval,
return SetTimeoutOrInterval(aCx, aFunction, timeout, aArguments, isInterval,
aError);
}
@ -12545,7 +12546,8 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
}
int32_t
nsGlobalWindow::SetTimeoutOrInterval(Function& aFunction, int32_t aTimeout,
nsGlobalWindow::SetTimeoutOrInterval(JSContext *aCx, Function& aFunction,
int32_t aTimeout,
const Sequence<JS::Value>& aArguments,
bool aIsInterval, ErrorResult& aError)
{
@ -12555,12 +12557,12 @@ nsGlobalWindow::SetTimeoutOrInterval(Function& aFunction, int32_t aTimeout,
}
if (inner != this) {
return inner->SetTimeoutOrInterval(aFunction, aTimeout, aArguments,
return inner->SetTimeoutOrInterval(aCx, aFunction, aTimeout, aArguments,
aIsInterval, aError);
}
nsCOMPtr<nsIScriptTimeoutHandler> handler =
NS_CreateJSTimeoutHandler(this, aFunction, aArguments, aError);
NS_CreateJSTimeoutHandler(aCx, this, aFunction, aArguments, aError);
if (!handler) {
return 0;
}

View File

@ -130,7 +130,7 @@ class VRHMDInfo;
} // namespace mozilla
extern already_AddRefed<nsIScriptTimeoutHandler>
NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
mozilla::dom::Function& aFunction,
const mozilla::dom::Sequence<JS::Value>& aArguments,
mozilla::ErrorResult& aError);
@ -1394,7 +1394,8 @@ public:
nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
int32_t interval,
bool aIsInterval, int32_t* aReturn) override;
int32_t SetTimeoutOrInterval(mozilla::dom::Function& aFunction,
int32_t SetTimeoutOrInterval(JSContext* aCx,
mozilla::dom::Function& aFunction,
int32_t aTimeout,
const mozilla::dom::Sequence<JS::Value>& aArguments,
bool aIsInterval, mozilla::ErrorResult& aError);

View File

@ -35,7 +35,8 @@ public:
nsJSScriptTimeoutHandler();
// This will call SwapElements on aArguments with an empty array.
nsJSScriptTimeoutHandler(nsGlobalWindow *aWindow, Function& aFunction,
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
Function& aFunction,
FallibleTArray<JS::Heap<JS::Value> >& aArguments,
ErrorResult& aError);
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
@ -188,7 +189,8 @@ nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler() :
{
}
nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler(nsGlobalWindow *aWindow,
nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler(JSContext* aCx,
nsGlobalWindow *aWindow,
Function& aFunction,
FallibleTArray<JS::Heap<JS::Value> >& aArguments,
ErrorResult& aError) :
@ -204,6 +206,9 @@ nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler(nsGlobalWindow *aWindow,
mozilla::HoldJSObjects(this);
mArgs.SwapElements(aArguments);
// Get the calling location.
nsJSUtils::GetCallingLocation(aCx, mFileName, &mLineNo);
}
nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler(JSContext* aCx,
@ -253,7 +258,8 @@ nsJSScriptTimeoutHandler::GetHandlerText()
}
already_AddRefed<nsIScriptTimeoutHandler>
NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, Function& aFunction,
NS_CreateJSTimeoutHandler(JSContext *aCx, nsGlobalWindow *aWindow,
Function& aFunction,
const Sequence<JS::Value>& aArguments,
ErrorResult& aError)
{
@ -264,7 +270,7 @@ NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, Function& aFunction,
}
nsRefPtr<nsJSScriptTimeoutHandler> handler =
new nsJSScriptTimeoutHandler(aWindow, aFunction, args, aError);
new nsJSScriptTimeoutHandler(aCx, aWindow, aFunction, args, aError);
return aError.Failed() ? nullptr : handler.forget();
}