mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 02:09:24 +00:00
LibWeb/HTML: Use DOM's post connection steps for <script> elements
This aligns our behaviour with WebKit and Chrome.
See: ddd2d0dd
This commit is contained in:
parent
02efb64e64
commit
0a216f9c14
Notes:
github-actions[bot]
2024-12-10 10:39:52 +00:00
Author: https://github.com/shannonbooth
Commit: 0a216f9c14
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2863
Reviewed-by: https://github.com/Lubrsi ✅
6 changed files with 82 additions and 16 deletions
|
@ -0,0 +1,42 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<link rel=help href=https://github.com/whatwg/html/pull/10188#discussion_r1719338657>
|
||||
<title>Adding/changing src attribute does "prepare the script"</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
// The "old" HTML Standard specification text around `src` attribute mutation
|
||||
// for non-parser-inserted scripts *ONLY* "prepared"/run the script iff the src
|
||||
// attribute "previously had no such attribute". This changed in
|
||||
// https://github.com/whatwg/html/pull/10188 to align with a majority of
|
||||
// browsers. This test ensures that `src` mutations on these kinds of scripts
|
||||
// *where a previous valid `src` attribute existed* do indeed "prepare" the
|
||||
// script.
|
||||
promise_test(async () => {
|
||||
window.didExecute = false;
|
||||
|
||||
const script = document.createElement('script');
|
||||
// Invalid type, so the script won't execute upon insertion.
|
||||
script.type = 'invalid';
|
||||
script.src = 'resources/flag-setter.js';
|
||||
document.body.append(script);
|
||||
assert_false(window.didExecute);
|
||||
|
||||
// Make script valid, but don't immediately execute it.
|
||||
script.type = '';
|
||||
|
||||
const scriptPromise = new Promise(resolve => {
|
||||
script.onload = resolve;
|
||||
});
|
||||
|
||||
// Mutating the `src` attribute, which has an existing valid value, triggers
|
||||
// the "prepare a script" algorithm via the post-connection steps.
|
||||
script.src = 'resources/flag-setter-different.js';
|
||||
|
||||
await scriptPromise;
|
||||
assert_true(window.didExecute);
|
||||
}, "Mutating `src` attribute from an already-valid value does 'prepare' the script");
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
window.didExecute = true;
|
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
window.didExecute = true;
|
Loading…
Add table
Add a link
Reference in a new issue