Fix for bug 531542 ("ASSERTION: DOM_MIN_TIMEOUT_VALUE lies" with negative setTimeout). r=jst.
authorPeter Van der Beken <peterv@propagandism.org>
Mon, 30 Nov 2009 10:58:32 +0100
changeset 35709 50cc41c7a17698106e4c8320cee3f49d5b29a34b
parent 35708 1c53517269200bd7436b7f15c04ef0dfdc1c45d0
child 35710 8f6bdbf8e7017fb0bdfe875035402c60701a8cdb
push id10687
push userpvanderbeken@mozilla.com
push dateMon, 14 Dec 2009 05:10:28 +0000
treeherdermozilla-central@8f6bdbf8e701 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs531542
milestone1.9.3a1pre
Fix for bug 531542 ("ASSERTION: DOM_MIN_TIMEOUT_VALUE lies" with negative setTimeout). r=jst.
dom/base/nsGlobalWindow.cpp
dom/tests/mochitest/bugs/Makefile.in
dom/tests/mochitest/bugs/test_bug531542.html
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -7725,22 +7725,28 @@ nsGlobalWindow::SetTimeoutOrInterval(nsI
 
   // If we don't have a document (we could have been unloaded since
   // the call to setTimeout was made), do nothing.
   if (!mDocument) {
     return NS_OK;
   }
 
   PRUint32 nestingLevel = sNestingLevel + 1;
-  if (interval < DOM_MIN_TIMEOUT_VALUE &&
-      (aIsInterval || nestingLevel >= DOM_CLAMP_TIMEOUT_NESTING_LEVEL)) {
-    // Don't allow timeouts less than DOM_MIN_TIMEOUT_VALUE from
-    // now...
-
-    interval = DOM_MIN_TIMEOUT_VALUE;
+  if (interval < DOM_MIN_TIMEOUT_VALUE) {
+    if (aIsInterval || nestingLevel >= DOM_CLAMP_TIMEOUT_NESTING_LEVEL) {
+      // Don't allow timeouts less than DOM_MIN_TIMEOUT_VALUE from
+      // now...
+
+      interval = DOM_MIN_TIMEOUT_VALUE;
+    }
+    else if (interval < 0) {
+      // Clamp negative intervals to 0.
+
+      interval = 0;
+    }
   }
 
   NS_ASSERTION(interval >= 0, "DOM_MIN_TIMEOUT_VALUE lies");
   PRUint32 realInterval = interval;
 
   // Make sure we don't proceed with a interval larger than our timer
   // code can handle.
   if (realInterval > PR_IntervalToMilliseconds(DOM_MAX_TIMEOUT_VALUE)) {
--- a/dom/tests/mochitest/bugs/Makefile.in
+++ b/dom/tests/mochitest/bugs/Makefile.in
@@ -103,12 +103,13 @@ include $(topsrcdir)/config/rules.mk
 		file_bug504862.html \
 		test_bug260264.html \
 		test_bug260264_nested.html \
 		child_bug260264.html \
 		grandchild_bug260264.html \
 		utils_bug260264.js \
 		test_bug534362.html \
 		iframe_bug534362.html \
+		test_bug531542.html \
 		$(NULL)
 
 libs:: 	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/bugs/test_bug531542.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=531542
+-->
+<head>
+  <title>Test for Bug 531542</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=531542">Mozilla Bug 531542</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 531542 **/
+
+var negativeTimeoutFired = false;
+function negativeTimeout()
+{
+  negativeTimeoutFired = true;
+}
+function testFinished()
+{
+  ok(negativeTimeoutFired, "Timeout with negative delay should fire.");
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+setTimeout(negativeTimeout, -1);
+setTimeout(testFinished, 0);
+
+</script>
+</pre>
+</body>
+</html>