Fix for bug 531542 ("ASSERTION: DOM_MIN_TIMEOUT_VALUE lies" with negative setTimeout). r=jst.

This commit is contained in:
Peter Van der Beken 2009-11-30 10:58:32 +01:00
parent 110cb44583
commit b169f2dccb
3 changed files with 53 additions and 5 deletions

View File

@ -7730,12 +7730,18 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
}
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...
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;
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");

View File

@ -108,6 +108,7 @@ _TEST_FILES = \
utils_bug260264.js \
test_bug534362.html \
iframe_bug534362.html \
test_bug531542.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -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>