1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<!DOCTYPE html>
<meta charset="utf-8">
<title>Inline async="" module scripts execute or throw parse errors asynchronously</title>
<link rel="help" href="https://github.com/whatwg/html/issues/9864">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
"use strict";
setup({ allow_uncaught_exception: true });
promise_test(async t => {
window.log = ["before any script execution"];
window.addEventListener("error", ev => {
window.log.push("error event on Window");
});
const noErrorScript = document.createElement("script");
noErrorScript.type = "module";
noErrorScript.async = true;
noErrorScript.textContent = "window.log.push('no error script executed');";
// This should queue a task to run the script, but not run it immediately.
document.head.append(noErrorScript);
log.push("after inserting noErrorScript");
assert_array_equals(window.log, [
"before any script execution",
"after inserting noErrorScript"
]);
const parseErrorScript = document.createElement("script");
parseErrorScript.type = "module";
parseErrorScript.async = true;
parseErrorScript.textContent = "+++++";
// This should queue a task to fire the error event, but not fire it immediately.
document.head.append(parseErrorScript);
log.push("after inserting parseErrorScript");
assert_array_equals(window.log, [
"before any script execution",
"after inserting noErrorScript",
"after inserting parseErrorScript"
]);
// After a microtask, the script run / error event must not happen.
queueMicrotask(t.step_func(() => {
assert_array_equals(window.log, [
"before any script execution",
"after inserting noErrorScript",
"after inserting parseErrorScript"
]);
}));
// But it must eventually happen, after a full task.
await t.step_wait(() => window.log.length == 5, "5 items must eventually be logged");
// And when it does the order must be correct.
assert_array_equals(window.log, [
"before any script execution",
"after inserting noErrorScript",
"after inserting parseErrorScript",
"no error script executed",
"error event on Window"
]);
});
</script>
|