Skip to content

Commit

Permalink
[blink][wpt] Add more module evaluation order tests
Browse files Browse the repository at this point in the history
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, 1096455, 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: Dominic Farolino <dom@chromium.org>
Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798126}
  • Loading branch information
camillobruni authored and chromium-wpt-export-bot committed Aug 14, 2020
1 parent 23c0ffe commit f36b6b4
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
window.log = [];

window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);

const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => {
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);
}));

function logLoad() { log.push("load") }

function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="throw.js" onerror="unreachable()"></script>
<script type="module" src="throw.js" onerror="unreachable()"></script>
<script type="module" src="throw.js" async onerror="unreachable()"></script>
<script type="module" src="throw.js" nomodule onerror="unreachable()"></script>
<script type="module" src="throw.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="throw.js" onerror="unreachable()"
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>
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
window.log = [];

window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);

const test_load = async_test(
"Test that ill-founded cyclic dependencies cause ReferenceError " +
"during evaluation, which leads to error events on window, and that " +
"exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => {
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);
}));

function logLoad() { log.push("load"); }

function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="cycle-tdz-access.js" async onerror="unreachable()"></script>
<script type="module" src="cycle-tdz-access.js" nomodule onerror="unreachable()"></script>
<script type="module" src="cycle-tdz-access.js" onerror="unreachable()"></script>
<script type="module" src="cycle-tdz-access.js" async onerror="unreachable()"
onload="logLoad()"></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>
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@
window.log = [];

window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);

const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => {
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);
}));

function logLoad() { log.push("load"); }
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./throw.js" onerror="unreachable()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script>
<script type="module" src="./throw.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>
<script type="module" src="./throw.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"
onload="logLoad()"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@
window.log = [];

window.addEventListener("error", ev => log.push(ev.error));
window.addEventListener("onunhandledrejection", unreachable);

const test_load = async_test(
"Test that exceptions during evaluation lead to error events on " +
"window, and that exceptions are remembered.\n");
window.addEventListener("load", test_load.step_func_done(ev => {
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);
}));

function logLoad() { log.push("load"); }
function unreachable() { log.push("unexpected"); }
</script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script>
<script type="module" src="./throw-nested.js" onerror="unreachable()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"></script>
<script type="module" src="./throw-nested.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>
<script type="module" src="./throw-nested.js" onerror="unreachable()"
onload="logLoad()"></script>
<script type="module" src="./throw.js" onerror="unreachable()"
onload="logLoad()"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";

import "./evaluation-order-1-nothrow-worker.mjs";

import "./evaluation-order-1-nothrow.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"microtask",
];

globalThis.test_load.step_timeout(() => globalThis.testDone(), 0);
done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globalThis.log.push("step-1-1");
queueMicrotask(() => globalThis.log.push("microtask"));
globalThis.log.push("step-1-2");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";

import "./evaluation-order-1-worker.mjs";

import "./evaluation-order-1.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
globalThis.expectedLog = [
"step-1-1", "step-1-2",
"global-error", "error",
"microtask",
];

globalThis.test_load.step_timeout(() => globalThis.testDone(), 0);

done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
globalThis.log.push("step-1-1");
queueMicrotask(() => log.push("microtask"));
globalThis.log.push("step-1-2");

throw new Error("error");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";

import "./evaluation-order-2-import-worker.mjs";

import "./evaluation-order-2.1.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
globalThis.expectedLog = [
"step-2.2-1", "step-2.2-2",
"microtask-2.2",
"global-error", "error",
];

done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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>
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "/resources/testharness.js";
import "./evaluation-order-setup.mjs";

import "./evaluation-order-3-dynamic-worker.mjs";

import "./evaluation-order-3.1.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!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>
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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);
});

0 comments on commit f36b6b4

Please sign in to comment.