diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources')
17 files changed, 208 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker-module.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker-module.js new file mode 100644 index 0000000000..b9ae7142d5 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker-module.js @@ -0,0 +1,2 @@ +import "/resources/testharness.js"; +import "./checkpoint-after-error-event.js"; diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker.js new file mode 100644 index 0000000000..4694db1e44 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event-worker.js @@ -0,0 +1,2 @@ +importScripts("/resources/testharness.js"); +importScripts("checkpoint-after-error-event.js"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.js new file mode 100644 index 0000000000..1a2b9404a7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/checkpoint-after-error-event.js @@ -0,0 +1,89 @@ +// The `then` handlers for `Promise.resolve()` are evaluated in the first +// microtasks checkpoint after `Promise.resolve()`. + +self.setup({allow_uncaught_exception: true}); + +// ---------------------------------------------------------------- +// Check when microtasks checkpoint is performed +// - Around `self`'s error event fired via +// https://html.spec.whatwg.org/C/#report-the-error during +// - https://html.spec.whatwg.org/C/#run-a-classic-script or +// - https://html.spec.whatwg.org/C/#run-a-module-script. + +// The expectation is: the `then` handlers are evaluated after all error event +// handlers are evaluated, not after each error event handler. + +// Just after each event handler is invoked, +// https://webidl.spec.whatwg.org/#call-a-user-objects-operation +// calls #clean-up-after-running-script, but this doesn't execute new +// microtasks immediately, because: +// - Before https://github.com/whatwg/html/pull/4352: +// #report-the-error is called before #clean-up-after-running-script by +// #run-a-classic-script/#run-a-module-script, so microtask checkpoint +// is not performed because JavaScript execution context stack is not empty. +// - After https://github.com/whatwg/html/pull/4352: +// #report-the-error is called during #perform-a-microtask-checkpoint (because +// it is called on rejection of promises), so #perform-a-microtask-checkpoint +// is executed but early exited. +self.log = []; + +self.addEventListener('error', () => { + log.push('handler 1'); + Promise.resolve().then(() => log.push('handler 1 promise')); +}); +self.addEventListener('error', () => { + log.push('handler 2'); + Promise.resolve().then(() => log.push('handler 2 promise')); +}); + +// Microtasks should be executed before +// #run-a-classic-script/#run-a-module-script is completed, and thus before +// script evaluation scheduled by setTimeout(). +async_test(t => { + t.step_timeout(() => { + assert_array_equals(log, [ + 'handler 1', + 'handler 2', + 'handler 1 promise', + 'handler 2 promise' + ]); + t.done(); + }, + 0); +}, "Promise resolved during #report-the-error"); + +// ---------------------------------------------------------------- +// Check when microtasks checkpoint is performed +// around event events other than the `self` error event cases above. +// In this case, microtasks are executed just after each event handler is +// invoked via #clean-up-after-running-script called from +// https://webidl.spec.whatwg.org/#call-a-user-objects-operation, +// because the event handlers are executed outside the +// #prepare-to-run-script/#clean-up-after-running-script scopes in +// #run-a-classic-script/#run-a-module-script. +self.log2 = []; +self.t2 = async_test( + "Promise resolved during event handlers other than error"); + +self.addEventListener('message', () => { + log2.push('handler 1'); + Promise.resolve().then(() => log2.push('handler 1 promise')); +}); +self.addEventListener('message', () => { + log2.push('handler 2'); + Promise.resolve().then(t2.step_func_done(() => { + log2.push('handler 2 promise'); + assert_array_equals(log2, [ + 'handler 1', + 'handler 1 promise', + 'handler 2', + 'handler 2 promise' + ]); + })); +}); + +// ---------------------------------------------------------------- + +done(); + +throw new Error('script 1'); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow-setup.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow-setup.js new file mode 100644 index 0000000000..1b42e99593 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow-setup.js @@ -0,0 +1,5 @@ +// Spec: https://html.spec.whatwg.org/C/#run-a-module-script +setupTest("Module script queueing a microtask", [ + "body", // Step 6. + "microtask", // "Clean up after running script" at Step 8. +]); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow.js new file mode 100644 index 0000000000..e19d9b1b13 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-nothrow.js @@ -0,0 +1,2 @@ +queueMicrotask(() => globalThis.log.push("microtask")); +globalThis.log.push("body"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw-setup.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw-setup.js new file mode 100644 index 0000000000..651a494e53 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw-setup.js @@ -0,0 +1,10 @@ +// Spec: https://html.spec.whatwg.org/C/#run-a-module-script +setupTest("Module script queueing a microtask then throwing an exception", [ + "body", // Step 6. + "microtask", // "Clean up after running script" at Step 8. + "global-error", // "Clean up after running script" at Step 8, because + // `evaluationPromise` is synchronously rejected and the rejection is + // processed in the microtask checkpoint here (See also Step 7). + // As `evaluationPromise` is rejected after the microtask queued during + // evaluation, "global-error" occurs after "microtask". +]); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw.js new file mode 100644 index 0000000000..2451df1c15 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-1-throw.js @@ -0,0 +1,4 @@ +queueMicrotask(() => globalThis.log.push("microtask")); +globalThis.log.push("body"); + +throw new Error("error"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2-setup.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2-setup.js new file mode 100644 index 0000000000..46f7354538 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2-setup.js @@ -0,0 +1,10 @@ +// Spec: https://html.spec.whatwg.org/C/#run-a-module-script +setupTest("Module script queueing a microtask then throwing an exception", [ + "step-2.2-1", "step-2.2-2", // Step 6. + "microtask-2.2", // "Clean up after running script" at Step 8. + "global-error", // "Clean up after running script" at Step 8, + // because `evaluationPromise` is synchronously rejected and the rejection + // is processed in the microtask checkpoint here (See also Step 7). + // As `evaluationPromise` is rejected after the microtask queued during + // evaluation, "global-error" occurs after "microtask". +]); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.1.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.1.mjs new file mode 100644 index 0000000000..d6c2afa2f7 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.1.mjs @@ -0,0 +1,8 @@ +globalThis.log.push("step-2.1-1"); +queueMicrotask(() => globalThis.log.push("microtask-2.1")); +globalThis.log.push("step-2.1-2"); + +// import is evaluated first. +import "./evaluation-order-2.2.mjs"; + +globalThis.log.push("step-2.1-3"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.2.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.2.mjs new file mode 100644 index 0000000000..5c67c4f9a2 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-2.2.mjs @@ -0,0 +1,7 @@ +globalThis.log.push("step-2.2-1"); +queueMicrotask(() => globalThis.log.push("microtask-2.2")); +globalThis.log.push("step-2.2-2"); + +globalThis.test_load.step_timeout(() => globalThis.testDone(), 0); + +throw new Error("error"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3-setup.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3-setup.js new file mode 100644 index 0000000000..edc046910e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3-setup.js @@ -0,0 +1,7 @@ +setupTest("Module script queueing a microtask then throwing an exception", [ + "step-3.1-1", "step-3.1-2", "step-3.1-3", + "microtask-3.1", + "step-3.2-1", "step-3.2-2", + "microtask-3.2", + "import-catch", "error", +]); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.1.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.1.mjs new file mode 100644 index 0000000000..ef320632af --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.1.mjs @@ -0,0 +1,11 @@ +globalThis.log.push("step-3.1-1"); +queueMicrotask(() => globalThis.log.push("microtask-3.1")); +globalThis.log.push("step-3.1-2"); + +import("./evaluation-order-3.2.mjs").catch( + exception => { + globalThis.log.push("import-catch", exception.message); + globalThis.testDone(); + }); + +globalThis.log.push("step-3.1-3"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.2.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.2.mjs new file mode 100644 index 0000000000..8ccb581206 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-3.2.mjs @@ -0,0 +1,5 @@ +globalThis.log.push("step-3.2-1"); +queueMicrotask(() => globalThis.log.push("microtask-3.2")); +globalThis.log.push("step-3.2-2"); + +throw new Error("error"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.1.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.1.mjs new file mode 100644 index 0000000000..f3347c1d28 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.1.mjs @@ -0,0 +1,8 @@ +log.push("step-4.1-1"); +queueMicrotask(() => log.push("microtask-4.1")); +log.push("step-4.1-2"); + +await import("./evaluation-order-4.2.mjs"); + +// Not happening as we throw in the above module. +log.push("step-4.1-3"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.2.mjs b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.2.mjs new file mode 100644 index 0000000000..96a5cca3a6 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-4.2.mjs @@ -0,0 +1,5 @@ +log.push("step-4.2-1"); +queueMicrotask(() => log.push("microtask-4.2")); +log.push("step-4.2-2"); + +throw new Error("error"); diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js new file mode 100644 index 0000000000..d2e28935c4 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js @@ -0,0 +1,30 @@ +globalThis.setup({allow_uncaught_exception: true}); + +// Must be called after previous tests are completed. +globalThis.setupTest = (description, expectedLog) => { + globalThis.log = []; + globalThis.onerror = message => { + globalThis.log.push("global-error"); + return true; + }; + globalThis.onunhandledrejection = + () => globalThis.log.push('unhandled-promise-rejection'); + + globalThis.unreachable = () => globalThis.log.push("unreachable"); + + globalThis.test_load = async_test(description); + globalThis.testDone = globalThis.test_load.step_func_done(() => { + assert_array_equals(globalThis.log, expectedLog); + }); + + if (!('Window' in globalThis && globalThis instanceof Window)) { + // In workers, there are no <script> load event, so scheduling `testDone()` + // here, assuming the target script is loaded and evaluated soon. + globalThis.test_load.step_timeout(() => globalThis.testDone(), 1000); + + // In workers, call `done()` here because the auto-generated `done()` calls + // by `any.js` etc. are at the end of main script and thus are not + // evaluated when the target script throws an exception. + done(); + } +}; diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/resolve-then-throw.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/resolve-then-throw.js new file mode 100644 index 0000000000..a841eb780a --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/resolve-then-throw.js @@ -0,0 +1,3 @@ +self.log.push('importScripts()ed script'); +Promise.resolve().then(() => self.log.push('promise')); +throw new Error('foo'); |