diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 4fb2012c4d7..3979a866b15 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -9360,12 +9360,6 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout) handler->GetScriptVersion(), nsnull, &is_undefined); } else { - // Let the script handler know about the "secret" final argument that - // indicates timeout lateness in milliseconds - TimeDuration lateness = now - timeout->mWhen; - - handler->SetLateness(lateness.ToMilliseconds()); - nsCOMPtr dummy; nsCOMPtr me(static_cast(this)); scx->CallEventHandler(me, FastGetGlobalJSObject(), diff --git a/dom/base/nsIScriptTimeoutHandler.h b/dom/base/nsIScriptTimeoutHandler.h index af3271f288c..af5a5f11a9e 100644 --- a/dom/base/nsIScriptTimeoutHandler.h +++ b/dom/base/nsIScriptTimeoutHandler.h @@ -42,9 +42,9 @@ class nsIArray; #define NS_ISCRIPTTIMEOUTHANDLER_IID \ -{ /* {21ba4f96-30b8-4215-a75d-d438eb16a50c} */ \ - 0x21ba4f96, 0x30b8, 0x4215, \ - { 0xa7, 0x5d, 0xd4, 0x38, 0xeb, 0x16, 0xa5, 0x0c } } +{ /* {17a9ce1a-d73b-45d1-8145-a0ae57bcc76e} */ \ + 0x17a9ce1a, 0xd73b, 0x45d1, \ + { 0x81, 0x45, 0xa0, 0xae, 0x57, 0xbc, 0xc7, 0x6e } } /** * Abstraction of the script objects etc required to do timeouts in a @@ -78,10 +78,6 @@ public: // Get the language version for this timeout. virtual PRUint32 GetScriptVersion() = 0; - - // Set the "secret" final lateness arg. This will be called before - // GetArgv(), which should reflect this lateness value. - virtual void SetLateness(PRIntervalTime aHowLate) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptTimeoutHandler, diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 913052dea88..7b47bc5eee4 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -4117,10 +4117,6 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSArgArray) nsresult nsJSArgArray::GetArgs(PRUint32 *argc, void **argv) { - if (!mArgv) { - NS_WARNING("nsJSArgArray has no argv!"); - return NS_ERROR_UNEXPECTED; - } *argv = (void *)mArgv; *argc = mArgc; return NS_OK; diff --git a/dom/base/nsJSTimeoutHandler.cpp b/dom/base/nsJSTimeoutHandler.cpp index 425344bc286..97e4e32f3b3 100644 --- a/dom/base/nsJSTimeoutHandler.cpp +++ b/dom/base/nsJSTimeoutHandler.cpp @@ -51,6 +51,7 @@ #include "nsDOMError.h" #include "nsGlobalWindow.h" #include "nsIContentSecurityPolicy.h" +#include "nsAlgorithm.h" static const char kSetIntervalStr[] = "setInterval"; static const char kSetTimeoutStr[] = "setTimeout"; @@ -85,9 +86,6 @@ public: virtual nsIArray *GetArgv() { return mArgv; } - // Called by the timeout mechanism so the secret 'lateness' arg can be - // added. - virtual void SetLateness(PRIntervalTime aHowLate); nsresult Init(nsGlobalWindow *aWindow, bool *aIsInterval, PRInt32 *aInterval); @@ -324,11 +322,13 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval, mFunObj = funobj; - // Create our arg array - leave an extra slot for a secret final argument - // that indicates to the called function how "late" the timeout is. We - // will fill that in when SetLateness is called. + // 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. nsCOMPtr array; - rv = NS_CreateJSArgv(cx, (argc > 1) ? argc - 1 : argc, nsnull, + // NS_MAX(argc - 2, 0) wouldn't work right because argc is unsigned. + rv = NS_CreateJSArgv(cx, NS_MAX(argc, 2u) - 2, nsnull, getter_AddRefs(array)); if (NS_FAILED(rv)) { return NS_ERROR_OUT_OF_MEMORY; @@ -339,12 +339,14 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval, nsCOMPtr jsarray(do_QueryInterface(array)); jsarray->GetArgs(&dummy, reinterpret_cast(&jsargv)); - // must have worked - we own the impl! :) - NS_ASSERTION(jsargv, "No argv!"); - for (PRInt32 i = 2; (PRUint32)i < argc; ++i) { - jsargv[i - 2] = argv[i]; + // jsargv might be null if we have argc <= 2 + if (jsargv) { + for (PRInt32 i = 2; (PRUint32)i < argc; ++i) { + jsargv[i - 2] = argv[i]; + } + } else { + NS_ASSERTION(argc <= 2, "Why do we have no jsargv when we have arguments?"); } - // final arg slot remains null, array has rooted vals. mArgv = array; } else { NS_WARNING("No func and no expr - why are we here?"); @@ -353,20 +355,6 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval, return NS_OK; } -void nsJSScriptTimeoutHandler::SetLateness(PRIntervalTime aHowLate) -{ - nsCOMPtr jsarray(do_QueryInterface(mArgv)); - if (jsarray) { - PRUint32 argc; - jsval *jsargv; - nsresult rv = jsarray->GetArgs(&argc, reinterpret_cast(&jsargv)); - if (NS_SUCCEEDED(rv) && jsargv && argc) - jsargv[argc-1] = INT_TO_JSVAL((jsint) aHowLate); - } else { - NS_ERROR("How can our argv not handle this?"); - } -} - const PRUnichar * nsJSScriptTimeoutHandler::GetHandlerText() { diff --git a/dom/tests/mochitest/bugs/Makefile.in b/dom/tests/mochitest/bugs/Makefile.in index b6646d213d8..14e6f010585 100644 --- a/dom/tests/mochitest/bugs/Makefile.in +++ b/dom/tests/mochitest/bugs/Makefile.in @@ -73,6 +73,7 @@ _TEST_FILES = \ test_bug384122.html \ test_bug389366.html \ test_bug393974.html \ + test_bug394769.html \ test_bug396843.html \ test_bug397571.html \ test_bug400204.html \ diff --git a/dom/tests/mochitest/bugs/test_bug394769.html b/dom/tests/mochitest/bugs/test_bug394769.html new file mode 100644 index 00000000000..c9925269f01 --- /dev/null +++ b/dom/tests/mochitest/bugs/test_bug394769.html @@ -0,0 +1,42 @@ + + + + + + Test for Bug 394769 + + + + +Mozilla Bug 394769 +

+ +
+
+
+ +