Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({ allow_uncaught_exception: true });
promise_test(async t => {
const script = document.createElement('script');
script.type = 'speculationrules';
script.textContent = 'invalid json';
const log = [];
const elementError = new Promise(resolve => {
script.addEventListener('error', e => {
assert_equals(e.constructor, Event, 'event should be a simple Event');
log.push('element error');
resolve();
}, { once: true });
});
const globalError = new Promise(resolve => {
window.addEventListener('error', e => {
e.preventDefault();
assert_equals(e.constructor, ErrorEvent, 'global event should be an ErrorEvent');
assert_equals(e.error.constructor, TypeError, 'e.error should be a TypeError');
log.push('global error');
resolve();
}, { once: true });
});
document.head.appendChild(script);
await Promise.all([elementError, globalError]);
assert_array_equals(log, ['element error', 'global error']);
}, 'A script with invalid JSON should fire error events on the element and window');
</script>