Skip to content

Commit ec9d207

Browse files
Report an exception in certain error cases for <script type="webbundle">
When creating a WebBundle using <script type="webbundle"> API, we can encounter cases when parsing of JSON rule fails, or a ResourceFetcher is not present for the script element's document; in both cases we want to report an exception instead of throwing an error event. Bug: 1263783 Change-Id: I8d32da13b2fde5d9566b373efdb4f4bde50150de Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3283909 Reviewed-by: Yutaka Hirano <[email protected]> Reviewed-by: Kunihiko Sakamoto <[email protected]> Reviewed-by: Hayato Ito <[email protected]> Commit-Queue: Miras Myrzakerey <[email protected]> Cr-Commit-Position: refs/heads/main@{#982352}
1 parent afa1677 commit ec9d207

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<title>WebBundle subresource loading with script API and invalid JSON</title>
3+
<link
4+
rel="help"
5+
href="https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading.md"
6+
/>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<body>
10+
<script>
11+
setup(() => {
12+
assert_true(HTMLScriptElement.supports('webbundle'));
13+
}, {allow_uncaught_exception: true});
14+
</script>
15+
<script>
16+
promise_test((t) => {
17+
const script = document.createElement("script");
18+
script.type = "webbundle";
19+
const json_rule = {"resources": []};
20+
script.textContent = JSON.stringify(json_rule);
21+
return new Promise(((resolve, reject) => {
22+
script.onload = () => reject(script);
23+
script.onerror = () => reject(script);
24+
window.onerror = function (message, url, line, col, error) {
25+
assert_equals(message, "Uncaught SyntaxError: Failed to parse web bundle: invalid JSON");
26+
assert_equals(error.name, "SyntaxError");
27+
resolve(script);
28+
}
29+
document.body.appendChild(script);
30+
}));
31+
}, "Invalid JSON rule should make the script loader report an exception and throw error on the window.");
32+
</script>
33+
</body>

0 commit comments

Comments
 (0)