Commit f99cd179 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[blink][wpt] Add more module evaluation order tests

Add tests for upcoming microtask checkpoint fixes and top-level-await
for modules. The added test cover in more detail the following items:
- onload events
- onerror events
- queueMicrotask

drive-by-fix: Check for onunhandledrejection

Bug: 1022182, 1096455c, 1114034, v8:9344
Change-Id: Ieaa7691bf44e2758ed873ca53bcc6852812dd723
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346251
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarDominic Farolino <dom@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798126}
parent c71b9857
...@@ -9,19 +9,27 @@ ...@@ -9,19 +9,27 @@
window.log = []; window.log = [];
window.addEventListener("error", ev => log.push(ev.error)); window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);
const test_load = async_test( const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " + "Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n"); "window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => { window.addEventListener("load", test_load.step_func_done(ev => {
const exn = log[1]; const exn = log[1];
assert_array_equals(log, ["throw", exn, exn, exn, exn]); assert_array_equals(log,
["throw", exn, "load", exn, "load", exn, "load", exn, "load"]);
assert_true(exn.foo); assert_true(exn.foo);
})); }));
function logLoad() { log.push("load") }
function unreachable() { log.push("unexpected"); } function unreachable() { log.push("unexpected"); }
</script> </script>
<script type="module" src="throw.js" onerror="unreachable()"></script> <script type="module" src="throw.js" onerror="unreachable()"
<script type="module" src="throw.js" onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="throw.js" async onerror="unreachable()"></script> <script type="module" src="throw.js" onerror="unreachable()"
<script type="module" src="throw.js" nomodule onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="throw.js" async onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="throw.js" nomodule onerror="unreachable()"
onload="logLoad()"></script>
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
window.log = []; window.log = [];
window.addEventListener("error", ev => log.push(ev.error)); window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);
const test_load = async_test( const test_load = async_test(
"Test that ill-founded cyclic dependencies cause ReferenceError " + "Test that ill-founded cyclic dependencies cause ReferenceError " +
...@@ -16,12 +17,18 @@ ...@@ -16,12 +17,18 @@
"exceptions are remembered.\n"); "exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => { window.addEventListener("load", test_load.step_func_done(ev => {
const exn = log[1]; const exn = log[1];
assert_array_equals(log, ["cycle-tdz-access-a", exn, exn, exn]); assert_array_equals(log,
["cycle-tdz-access-a", exn, "load", exn, "load", exn, "load"]);
assert_equals(exn.constructor, ReferenceError); assert_equals(exn.constructor, ReferenceError);
})); }));
function logLoad() { log.push("load"); }
function unreachable() { log.push("unexpected"); } function unreachable() { log.push("unexpected"); }
</script> </script>
<script type="module" src="cycle-tdz-access.js" async onerror="unreachable()"></script> <script type="module" src="cycle-tdz-access.js" async onerror="unreachable()"
<script type="module" src="cycle-tdz-access.js" nomodule onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="cycle-tdz-access.js" onerror="unreachable()"></script> <script type="module" src="cycle-tdz-access.js" nomodule onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="cycle-tdz-access.js" onerror="unreachable()"
onload="logLoad()"></script>
...@@ -9,20 +9,29 @@ ...@@ -9,20 +9,29 @@
window.log = []; window.log = [];
window.addEventListener("error", ev => log.push(ev.error)); window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);
const test_load = async_test( const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " + "Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n"); "window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => { window.addEventListener("load", test_load.step_func_done(ev => {
const exn = log[1]; const exn = log[1];
assert_array_equals(log, ["throw", exn, exn, exn, exn, exn]); assert_array_equals(log,
["throw", exn, "load", exn, "load", exn, "load", exn, "load",
exn, "load"]);
assert_true(exn.foo); assert_true(exn.foo);
})); }));
function logLoad() { log.push("load"); }
function unreachable() { log.push("unexpected"); } function unreachable() { log.push("unexpected"); }
</script> </script>
<script type="module" src="./throw.js" onerror="unreachable()"></script> <script type="module" src="./throw.js" onerror="unreachable()"
<script type="module" src="./throw.js" onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script> <script type="module" src="./throw.js" onerror="unreachable()"
<script type="module" src="./throw.js" onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script> <script type="module" src="./throw-nested.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"
onload="logLoad()"></script>
...@@ -9,20 +9,29 @@ ...@@ -9,20 +9,29 @@
window.log = []; window.log = [];
window.addEventListener("error", ev => log.push(ev.error)); window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);
const test_load = async_test( const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " + "Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n"); "window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => { window.addEventListener("load", test_load.step_func_done(ev => {
const exn = log[1]; const exn = log[1];
assert_array_equals(log, ["throw", exn, exn, exn, exn, exn]); assert_array_equals(log,
["throw", exn, "load", exn, "load", exn, "load", exn, "load",
exn, "load"]);
assert_true(exn.foo); assert_true(exn.foo);
})); }));
function logLoad() { log.push("load"); }
function unreachable() { log.push("unexpected"); } function unreachable() { log.push("unexpected"); }
</script> </script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script> <script type="module" src="./throw-nested.js" onerror="unreachable()"
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script> <script type="module" src="./throw-nested.js" onerror="unreachable()"
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script> onload="logLoad()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script> <script type="module" src="./throw.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"
onload="logLoad()"></script>
This is a testharness.js-based test.
FAIL Test evaluation order of modules assert_array_equals: expected property 2 to be "global-error" but got "microtask" (expected array ["step-1-1", "step-1-2", "global-error", "error", "microtask", "script-load", "global-load"] got ["step-1-1", "step-1-2", "microtask", "global-error", "error", "script-load", "global-load"])
Harness: the test ran to completion.
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";
import "./evaluation-order-1-nothrow-worker.mjs";
import "./evaluation-order-1-nothrow.mjs";
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const worker = new Worker(
"evaluation-order-1-nothrow-worker-setup.mjs", {type:"module"});
fetch_tests_from_worker(worker);
</script>
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"microtask",
];
globalThis.test_load.step_timeout(() => globalThis.testDone(), 0);
done();
\ No newline at end of file
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import "./evaluation-order-setup.mjs";
window.addEventListener("load", ev => globalThis.testDone());
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"microtask",
"script-load",
"global-load",
];
</script>
<script type="module" src="evaluation-order-1-nothrow.mjs"
onerror="globalThis.unreachable()"
onload="globalThis.log.push('script-load')"></script>
globalThis.log.push("step-1-1");
queueMicrotask(() => globalThis.log.push("microtask"));
globalThis.log.push("step-1-2");
This is a testharness.js-based test.
FAIL Test evaluation order of modules assert_array_equals: expected property 2 to be "global-error" but got "microtask" (expected array ["step-1-1", "step-1-2", "global-error", "error", "microtask"] got ["step-1-1", "step-1-2", "microtask", "global-error", "error"])
Harness: the test ran to completion.
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";
import "./evaluation-order-1-worker.mjs";
import "./evaluation-order-1.mjs";
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const worker = new Worker(
"evaluation-order-1-worker-setup.mjs", {type:"module"});
fetch_tests_from_worker(worker);
</script>
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"global-error", "error",
"microtask",
];
globalThis.test_load.step_timeout(() => globalThis.testDone(), 0);
done();
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import "./evaluation-order-setup.mjs";
window.addEventListener("load", event => globalThis.testDone());
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"global-error", "error",
"microtask",
"script-load",
"global-load"
];
</script>
<script type="module" src="evaluation-order-1.mjs"
onerror="unreachable()" onload="log.push('script-load')"></script>
globalThis.log.push("step-1-1");
queueMicrotask(() => log.push("microtask"));
globalThis.log.push("step-1-2");
throw new Error("error");
This is a testharness.js-based test.
FAIL Test evaluation order of modules assert_array_equals: expected property 2 to be "global-error" but got "microtask-2.2" (expected array ["step-2.2-1", "step-2.2-2", "global-error", "error", "microtask-2.2", "script-load", "global-load"] got ["step-2.2-1", "step-2.2-2", "microtask-2.2", "global-error", "error", "script-load", "global-load"])
Harness: the test ran to completion.
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";
import "./evaluation-order-2-import-worker.mjs";
import "./evaluation-order-2.1.mjs";
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const worker = new Worker(
"evaluation-order-2-import-worker-setup.mjs", {type:"module"});
fetch_tests_from_worker(worker);
</script>
globalThis.expectedLog = [
"step-2.2-1", "step-2.2-2",
"microtask-2.2",
"global-error", "error",
];
done();
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import "./evaluation-order-setup.mjs";
globalThis.expectedLog = [
"step-2.2-1", "step-2.2-2",
"global-error", "error",
"microtask-2.2",
"script-load",
"global-load",
];
</script>
<script type="module" src="evaluation-order-2.1.mjs"
onerror="globalThis.unreachable()"
onload="globalThis.log.push('script-load')">
</script>
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");
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");
This is a testharness.js-based test.
FAIL Test evaluation order of modules assert_array_equals: lengths differ, expected array ["step-3.1-1", "step-3.1-2", "step-3.1-3", "microtask-3.1", "script-load", "step-3.2-1", "step-3.2-2", "microtask-3.2", "import-catch", "error"] length 10, got ["step-3.1-1", "step-3.1-2", "step-3.1-3", "microtask-3.1", "script-load", "global-load", "step-3.2-1", "step-3.2-2", "microtask-3.2", "import-catch", "error"] length 11
Harness: the test ran to completion.
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";
import "./evaluation-order-3-dynamic-worker.mjs";
import "./evaluation-order-3.1.mjs";
\ No newline at end of file
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const worker = new Worker(
"evaluation-order-3-dynamic-worker-setup.mjs", {type:"module"});
fetch_tests_from_worker(worker);
</script>
globalThis.expectedLog = [
"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",
];
done();
\ No newline at end of file
<!DOCTYPE html>
<title>Testing evaluation order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import "./evaluation-order-setup.mjs";
globalThis.expectedLog = [
"step-3.1-1", "step-3.1-2", "step-3.1-3", "microtask-3.1",
"script-load",
"step-3.2-1", "step-3.2-2", "microtask-3.2",
"import-catch", "error"
];
</script>
<script type="module" src="evaluation-order-3.1.mjs"
onerror="globalThis.unreachable()"
onload="globalThis.log.push('script-load')">
</script>
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");
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");
globalThis.setup({allow_uncaught_exception: true});
globalThis.log = [];
globalThis.addEventListener("error",
event => globalThis.log.push("global-error", event.error.message));
globalThis.addEventListener("onunhandledrejection",
event => globalThis.log.push('unhandled-promise-rejection'));
globalThis.addEventListener("load",
event => globalThis.log.push("global-load"));
globalThis.unreachable = function() {
globalThis.log.push("unreachable");
}
globalThis.test_load = async_test("Test evaluation order of modules");
globalThis.testDone = globalThis.test_load.step_func_done(() => {
assert_array_equals(globalThis.log, globalThis.expectedLog);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment