зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1176083. Remove the now-dead code for the XPCOM version of setTimeout/setInterval. r=smaug
I claim this code is dead because on the one hand it's no longer called from JS (because Window is always on WebIDL bindings, but on the other hand it can't really be called from C++ because it depends on examining the XPConnect call information. I think removing this completely, including from the IDL, is safe, because nothing directly returns nsIDOMJSWindow, so anyone using its vtable would have to QI to it and we're changing the IID.
This commit is contained in:
Родитель
606f67f584
Коммит
506ddeedf8
|
@ -7590,18 +7590,6 @@ nsGlobalWindow::ClearInterval(int32_t aHandle)
|
|||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalWindow::SetTimeout(int32_t *_retval)
|
||||
{
|
||||
return SetTimeoutOrInterval(false, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalWindow::SetInterval(int32_t *_retval)
|
||||
{
|
||||
return SetTimeoutOrInterval(true, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalWindow::SetResizable(bool aResizable)
|
||||
{
|
||||
|
@ -11945,50 +11933,6 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
|||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::SetTimeoutOrInterval(bool aIsInterval, int32_t *aReturn)
|
||||
{
|
||||
// This needs to forward to the inner window, but since the current
|
||||
// inner may not be the inner in the calling scope, we need to treat
|
||||
// this specially here as we don't want timeouts registered in a
|
||||
// dying inner window to get registered and run on the current inner
|
||||
// window. To get this right, we need to forward this call to the
|
||||
// inner window that's calling window.setTimeout().
|
||||
|
||||
if (IsOuterWindow()) {
|
||||
nsGlobalWindow* callerInner = CallerInnerWindow();
|
||||
NS_ENSURE_TRUE(callerInner || nsContentUtils::IsCallerChrome(), NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
// If the caller and the callee share the same outer window,
|
||||
// forward to the callee inner. Else, we forward to the current
|
||||
// inner (e.g. someone is calling setTimeout() on a reference to
|
||||
// some other window).
|
||||
|
||||
if (callerInner &&
|
||||
callerInner->GetOuterWindow() == this &&
|
||||
callerInner->IsInnerWindow()) {
|
||||
return callerInner->SetTimeoutOrInterval(aIsInterval, aReturn);
|
||||
}
|
||||
|
||||
FORWARD_TO_INNER(SetTimeoutOrInterval, (aIsInterval, aReturn),
|
||||
NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
int32_t interval = 0;
|
||||
bool isInterval = aIsInterval;
|
||||
nsCOMPtr<nsIScriptTimeoutHandler> handler;
|
||||
nsresult rv = NS_CreateJSTimeoutHandler(this,
|
||||
&isInterval,
|
||||
&interval,
|
||||
getter_AddRefs(handler));
|
||||
if (!handler) {
|
||||
*aReturn = 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
return SetTimeoutOrInterval(handler, interval, isInterval, aReturn);
|
||||
}
|
||||
|
||||
int32_t
|
||||
nsGlobalWindow::SetTimeoutOrInterval(Function& aFunction, int32_t aTimeout,
|
||||
const Sequence<JS::Value>& aArguments,
|
||||
|
|
|
@ -129,12 +129,6 @@ class VRHMDInfo;
|
|||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
extern nsresult
|
||||
NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
|
||||
bool *aIsInterval,
|
||||
int32_t *aInterval,
|
||||
nsIScriptTimeoutHandler **aRet);
|
||||
|
||||
extern already_AddRefed<nsIScriptTimeoutHandler>
|
||||
NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
|
||||
mozilla::dom::Function& aFunction,
|
||||
|
@ -1335,7 +1329,6 @@ public:
|
|||
}
|
||||
|
||||
// JS specific timeout functions (JS args grabbed from context).
|
||||
nsresult SetTimeoutOrInterval(bool aIsInterval, int32_t* aReturn);
|
||||
nsresult ResetTimersForNonBackgroundWindow();
|
||||
|
||||
// The timeout implementation functions.
|
||||
|
|
|
@ -58,9 +58,6 @@ public:
|
|||
return mArgs;
|
||||
}
|
||||
|
||||
nsresult Init(nsGlobalWindow *aWindow, bool *aIsInterval,
|
||||
int32_t *aInterval, bool* aAllowEval);
|
||||
|
||||
void ReleaseJSObjects();
|
||||
|
||||
private:
|
||||
|
@ -248,136 +245,6 @@ nsJSScriptTimeoutHandler::ReleaseJSObjects()
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
|
||||
int32_t *aInterval, bool *aAllowEval)
|
||||
{
|
||||
if (!aWindow->GetContextInternal() || !aWindow->FastGetGlobalJSObject()) {
|
||||
// This window was already closed, or never properly initialized,
|
||||
// don't let a timer be scheduled on such a window.
|
||||
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
nsAXPCNativeCallContext *ncc = nullptr;
|
||||
nsresult rv = nsContentUtils::XPConnect()->
|
||||
GetCurrentNativeCallContext(&ncc);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!ncc)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
JSContext *cx = nullptr;
|
||||
|
||||
rv = ncc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t argc;
|
||||
JS::Value *argv = nullptr;
|
||||
|
||||
ncc->GetArgc(&argc);
|
||||
ncc->GetArgvPtr(&argv);
|
||||
|
||||
JS::Rooted<JSFlatString*> expr(cx);
|
||||
JS::Rooted<JSObject*> funobj(cx);
|
||||
|
||||
if (argc < 1) {
|
||||
::JS_ReportError(cx, "Function %s requires at least 2 parameter",
|
||||
*aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
}
|
||||
|
||||
int32_t interval = 0;
|
||||
if (argc > 1) {
|
||||
JS::Rooted<JS::Value> arg(cx, argv[1]);
|
||||
|
||||
if (!JS::ToInt32(cx, arg, &interval)) {
|
||||
::JS_ReportError(cx,
|
||||
"Second argument to %s must be a millisecond interval",
|
||||
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
// If no interval was specified, treat this like a timeout, to avoid
|
||||
// setting an interval of 0 milliseconds.
|
||||
*aIsInterval = false;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> arg(cx, argv[0]);
|
||||
switch (::JS_TypeOfValue(cx, arg)) {
|
||||
case JSTYPE_FUNCTION:
|
||||
funobj = &arg.toObject();
|
||||
break;
|
||||
|
||||
case JSTYPE_STRING:
|
||||
case JSTYPE_OBJECT:
|
||||
{
|
||||
JSString *str = JS::ToString(cx, arg);
|
||||
if (!str)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
expr = ::JS_FlattenString(cx, str);
|
||||
if (!expr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
argv[0] = JS::StringValue(str);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
::JS_ReportError(cx, "useless %s call (missing quotes around argument?)",
|
||||
*aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
||||
|
||||
// Return an error that nsGlobalWindow can recognize and turn into NS_OK.
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
}
|
||||
|
||||
if (expr) {
|
||||
// if CSP is enabled, and setTimeout/setInterval was called with a string,
|
||||
// disable the registration and log an error
|
||||
ErrorResult error;
|
||||
*aAllowEval = CheckCSPForEval(cx, aWindow, error);
|
||||
if (error.Failed() || !*aAllowEval) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mExpr.IsEmpty());
|
||||
AssignJSFlatString(mExpr, expr);
|
||||
|
||||
// Get the calling location.
|
||||
nsJSUtils::GetCallingLocation(cx, mFileName, &mLineNo);
|
||||
} else if (funobj) {
|
||||
*aAllowEval = true;
|
||||
|
||||
mozilla::HoldJSObjects(this);
|
||||
|
||||
mFunction = new Function(funobj, GetIncumbentGlobal());
|
||||
|
||||
// Create our arg array. argc is the number of arguments passed
|
||||
// to setTimeout or setInterval; the first two are our callback
|
||||
// and the delay, so only arguments after that need to go in our
|
||||
// array.
|
||||
// std::max(argc - 2, 0) wouldn't work right because argc is unsigned.
|
||||
uint32_t argCount = std::max(argc, 2u) - 2;
|
||||
|
||||
FallibleTArray<JS::Heap<JS::Value> > args;
|
||||
if (!args.SetCapacity(argCount, fallible)) {
|
||||
// No need to drop here, since we already have a non-null mFunction
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
for (uint32_t idx = 0; idx < argCount; ++idx) {
|
||||
*args.AppendElement(fallible) = argv[idx + 2];
|
||||
}
|
||||
args.SwapElements(mArgs);
|
||||
} else {
|
||||
NS_WARNING("No func and no expr - why are we here?");
|
||||
}
|
||||
*aInterval = interval;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const char16_t *
|
||||
nsJSScriptTimeoutHandler::GetHandlerText()
|
||||
{
|
||||
|
@ -385,24 +252,6 @@ nsJSScriptTimeoutHandler::GetHandlerText()
|
|||
return mExpr.get();
|
||||
}
|
||||
|
||||
nsresult NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
|
||||
bool *aIsInterval,
|
||||
int32_t *aInterval,
|
||||
nsIScriptTimeoutHandler **aRet)
|
||||
{
|
||||
*aRet = nullptr;
|
||||
nsRefPtr<nsJSScriptTimeoutHandler> handler = new nsJSScriptTimeoutHandler();
|
||||
bool allowEval;
|
||||
nsresult rv = handler->Init(aWindow, aIsInterval, aInterval, &allowEval);
|
||||
if (NS_FAILED(rv) || !allowEval) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
handler.forget(aRet);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIScriptTimeoutHandler>
|
||||
NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, Function& aFunction,
|
||||
const Sequence<JS::Value>& aArguments,
|
||||
|
|
|
@ -5,20 +5,11 @@
|
|||
|
||||
#include "domstubs.idl"
|
||||
|
||||
[scriptable, uuid(4237c376-d637-4b6e-9f8a-1da57e867834)]
|
||||
[scriptable, uuid(e0f739e3-47e2-4007-af30-181939e97a51)]
|
||||
interface nsIDOMJSWindow : nsISupports
|
||||
{
|
||||
void dump(in DOMString str);
|
||||
|
||||
/**
|
||||
* These methods take typeless arguments and optional arguments, the
|
||||
* first argument is either a function or a string, the second
|
||||
* argument must be a number (ms) and the rest of the arguments (2
|
||||
* ... n) are passed to the callback function
|
||||
*/
|
||||
long setTimeout();
|
||||
long setInterval();
|
||||
|
||||
/**
|
||||
* These methods take one optional argument that's the timer ID to
|
||||
* clear. Often in existing code these methods are passed undefined,
|
||||
|
|
Загрузка…
Ссылка в новой задаче