Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setTimeout/setInterval to return a numeric ID
- Loading branch information
1 parent
28f00b3
commit f53876a
Showing
2 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...web-platform-tests/to-upstream/html/webappapis/timers/settimeout-setinterval-handles.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!doctype html> | ||
<title>Handles returned by setTimeout and setInterval</title> | ||
<link rel="author" title="Alvaro Dias" href="mailto:alvarorahul@gmail.com"> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout"> | ||
<link rel="help" href="https://heycam.github.io/webidl/#es-operations"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<script> | ||
"use strict"; | ||
|
||
async_test(t => { | ||
const a = setTimeout(() => { | ||
// shouldn't execute since we clear immediately | ||
assert_true(false); | ||
}, 50); | ||
clearTimeout(a); | ||
|
||
let c; | ||
|
||
const b = setTimeout(() => { | ||
// this callback should execute since we haven't cleared the timeout | ||
const d = setInterval(() => { | ||
clearInterval(d); | ||
t.done(); | ||
}, 50); | ||
|
||
assert_equals(d, c + 1); // since we created the interval after the handle c | ||
}, 50); | ||
assert_equals(b, a + 1); | ||
|
||
c = setInterval(() => { | ||
// shouldn't execute since we clear immediately | ||
assert_true(false); | ||
}, 50); | ||
clearInterval(c); | ||
assert_equals(c, b + 1); | ||
|
||
}, "setTimeout and setInterval should return numeric handles which increment"); | ||
</script> |