| 1 |
<!doctype html> |
| 2 |
<meta charset=utf-8> |
| 3 |
<title>Insert non-async module script</title> |
| 4 |
<script src=/resources/testharness.js></script> |
| 5 |
<script src=/resources/testharnessreport.js></script> |
| 6 |
<script> |
| 7 |
setup({allow_uncaught_exception: true}); |
| 8 |
|
| 9 |
const test = async_test("Test error event properties"); |
| 10 |
|
| 11 |
let errorCount = 0; |
| 12 |
let eventCount = 0; |
| 13 |
window.addEventListener("error", handleError); |
| 14 |
window.addEventListener("load", handleLoaded); |
| 15 |
|
| 16 |
function handleEvent(event) { |
| 17 |
eventCount++; |
| 18 |
test.step(() => assert_equals(typeof event, "object")); |
| 19 |
test.step(() => assert_true(event instanceof Event)); |
| 20 |
} |
| 21 |
|
| 22 |
function handleError(event) { |
| 23 |
errorCount++; |
| 24 |
test.step(() => assert_equals(typeof event, "object")); |
| 25 |
test.step(() => assert_true(event instanceof ErrorEvent)); |
| 26 |
switch (errorCount) { |
| 27 |
case 1: |
| 28 |
test.step(() => assert_true(event.error instanceof SyntaxError)); |
| 29 |
test.step(() => assert_true(event.filename.endsWith("/bad_local_export.js"))); |
| 30 |
test.step(() => assert_equals(event.lineno, 3)); |
| 31 |
test.step(() => assert_equals(event.colno, 8)); |
| 32 |
break; |
| 33 |
case 2: |
| 34 |
test.step(() => assert_true(event.error instanceof TypeError)); |
| 35 |
test.step(() => assert_true(event.filename.endsWith("/import_resolve_failure.js"))); |
| 36 |
test.step(() => assert_equals(event.lineno, 2)); |
| 37 |
test.step(() => assert_equals(event.colno, 17)); |
| 38 |
break; |
| 39 |
case 3: |
| 40 |
test.step(() => assert_true(event.error instanceof TypeError)); |
| 41 |
test.step(() => assert_true(event.filename.endsWith("/indirect_export_resolve_failure.js"))); |
| 42 |
test.step(() => assert_equals(event.lineno, 2)); |
| 43 |
test.step(() => assert_equals(event.colno, 20)); |
| 44 |
break; |
| 45 |
case 4: |
| 46 |
test.step(() => assert_true(event.error instanceof SyntaxError)); |
| 47 |
test.step(() => assert_true(event.filename.endsWith("/missing_import.js"))); |
| 48 |
test.step(() => assert_equals(event.lineno, 2)); |
| 49 |
test.step(() => assert_equals(event.colno, 9)); |
| 50 |
break; |
| 51 |
case 5: |
| 52 |
test.step(() => assert_true(event.error instanceof SyntaxError)); |
| 53 |
test.step(() => assert_true(event.filename.endsWith("/missing_indirect_export.js"))); |
| 54 |
test.step(() => assert_equals(event.lineno, 2)); |
| 55 |
test.step(() => assert_equals(event.colno, 12)); |
| 56 |
break; |
| 57 |
case 6: |
| 58 |
test.step(() => assert_true(event.error instanceof SyntaxError)); |
| 59 |
test.step(() => assert_true(event.filename.endsWith("/module_eval_error.js"))); |
| 60 |
test.step(() => assert_equals(event.lineno, 3)); |
| 61 |
test.step(() => assert_equals(event.colno, 1)); |
| 62 |
break; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
function testNoError() { |
| 67 |
test.step(() => assert_unreached("No event expected here")); |
| 68 |
test.done(); |
| 69 |
} |
| 70 |
|
| 71 |
function handleLoaded() { |
| 72 |
test.step(() => assert_equals(eventCount, 2)); |
| 73 |
test.step(() => assert_equals(errorCount, 6)); |
| 74 |
test.done(); |
| 75 |
} |
| 76 |
|
| 77 |
</script> |
| 78 |
|
| 79 |
<!-- Errors that fire an event on the script element --> |
| 80 |
<script type="module" src="" onerror="handleEvent(event)"></script> |
| 81 |
<script type="module" src="./does_not_exist" onerror="handleEvent(event)"></script> |
| 82 |
|
| 83 |
<!-- Errors that fire an error event on the global --> |
| 84 |
<script type="module" src="./support/bad_local_export.js" onerror="handleEvent(event)"></script> |
| 85 |
<script type="module" src="./support/import_resolve_failure.js" onerror="testNoError()"></script> |
| 86 |
<script type="module" src="./support/indirect_export_resolve_failure.js" onerror="testNoError()"></script> |
| 87 |
<script type="module" src="./support/missing_import.js" onerror="testNoError()"></script> |
| 88 |
<script type="module" src="./support/missing_indirect_export.js" --onerror="testNoError()"></script> |
| 89 |
<script type="module" src="./support/module_eval_error.js" onerror="testNoError()"></script> |