blob: 07327c0b94353d22dd9a422055d4b664c717ff55 [file] [log] [blame]
promise_test(() => {
var counter = 0;
self.queueMicrotask(() => {
assert_equals(counter++, 1);
self.queueMicrotask(() => {
assert_equals(counter++, 2);
});
});
var promise = new Promise((resolve, reject) => {
setTimeout(() => {
assert_equals(counter++, 3);
resolve();
}, 0);
});
assert_equals(counter++, 0);
return promise;
}, `Queued microtasks should be drained before executing macrotasks`);
promise_test(() => {
return new Promise((resolve, reject) => {
self.queueMicrotask(function () {
try {
assert_equals(arguments.length, 0);
assert_equals(this, self);
self.queueMicrotask(function () {
try {
assert_equals(this, self);
self.queueMicrotask(function () {
'use strict';
try {
assert_equals(this, undefined);
resolve();
} catch (e) {
reject(e);
}
});
} catch (e) {
reject(e);
}
});
} catch (e) {
reject(e);
}
});
});
}, `queueMicrotask's callback has zero arguments and self as |this|`);
promise_test(() => {
return new Promise((resolve ,reject) => {
var counter = 0;
Promise.resolve().then(() => {
assert_equals(counter++, 1);
self.queueMicrotask(() => {
assert_equals(counter++, 3);
resolve();
});
});
self.queueMicrotask(() => {
assert_equals(counter++, 2);
});
assert_equals(counter++, 0);
});
}, `queueMicrotask and Promise uses the same Microtask queue`);
test(() => {
assert_throws(new TypeError, () => {
self.queueMicrotask();
});
assert_throws(new TypeError, () => {
self.queueMicrotask(null);
});
assert_throws(new TypeError, () => {
self.queueMicrotask(undefined);
});
assert_throws(new TypeError, () => {
self.queueMicrotask(42);
});
assert_throws(new TypeError, () => {
self.queueMicrotask("42");
});
assert_throws(new TypeError, () => {
self.queueMicrotask(true);
});
assert_throws(new TypeError, () => {
self.queueMicrotask(Symbol("42"));
});
assert_throws(new TypeError, () => {
self.queueMicrotask({});
});
assert_throws(new TypeError, () => {
self.queueMicrotask({ handleEvent() { } });
});
}, `queueMicrotask should reject non-function arguments`);