mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Automatic update from web-platform-tests Fire error events for invalid speculation rules This CL introduces error handling for <script type=speculationrules>, mirroring the behavior of <script type=importmap>. Specifically, it adds error events for two cases: - Inline speculation rules with unparsable JSON. - External speculation rules, which are not yet supported. This is verified by new web platform tests. This follows the spec change at https://github.com/whatwg/html/pull/11426. Change-Id: I9b0776b86059f6c8734d57c17f50ed26e89215da Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6758353 Reviewed-by: Hiroki Nakagawa <[email protected]> Commit-Queue: Domenic Denicola <[email protected]> Cr-Commit-Position: refs/heads/main@{#1488632} -- wpt-commits: 1d91c36a40b59a975a869f4d5749ff3004839dab wpt-pr: 53821
37 lines
1.2 KiB
HTML
37 lines
1.2 KiB
HTML
<!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>
|