|
| 1 | +// META: global=window,worker |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +test(() => { |
| 5 | + assert_equals(typeof queueMicrotask, "function"); |
| 6 | +}, "It exists and is a function"); |
| 7 | + |
| 8 | +test(() => { |
| 9 | + assert_throws(new TypeError(), () => queueMicrotask(), "no argument"); |
| 10 | + assert_throws(new TypeError(), () => queueMicrotask(undefined), "undefined"); |
| 11 | + assert_throws(new TypeError(), () => queueMicrotask(null), "null"); |
| 12 | + assert_throws(new TypeError(), () => queueMicrotask(0), "0"); |
| 13 | + assert_throws(new TypeError(), () => queueMicrotask({ handleEvent() { } }), "an event handler object"); |
| 14 | + assert_throws(new TypeError(), () => queueMicrotask("window.x = 5;"), "a string"); |
| 15 | +}, "It throws when given non-functions"); |
| 16 | + |
| 17 | +async_test(t => { |
| 18 | + let called = false; |
| 19 | + queueMicrotask(t.step_func_done(() => { |
| 20 | + called = true; |
| 21 | + })); |
| 22 | + assert_false(called); |
| 23 | +}, "It calls the callback asynchronously"); |
| 24 | + |
| 25 | +async_test(t => { |
| 26 | + queueMicrotask(t.step_func_done(function () { // note: intentionally not an arrow function |
| 27 | + assert_array_equals(arguments, []); |
| 28 | + }), "x", "y"); |
| 29 | +}, "It does not pass any arguments"); |
| 30 | + |
| 31 | +async_test(t => { |
| 32 | + const happenings = []; |
| 33 | + Promise.resolve().then(() => happenings.push("a")); |
| 34 | + queueMicrotask(() => happenings.push("b")); |
| 35 | + Promise.reject().catch(() => happenings.push("c")); |
| 36 | + queueMicrotask(t.step_func_done(() => { |
| 37 | + assert_array_equals(happenings, ["a", "b", "c"]); |
| 38 | + })); |
| 39 | +}, "It interleaves with promises as expected"); |
0 commit comments