Skip to content

Commit 418c79f

Browse files
domfarolinoBruceDai
authored andcommitted
WPT: Script child removal does not trigger execution
Given the old Chromium change that introduced this behavior: - https://source.chromium.org/chromium/chromium/src/+/604e798ec6ee30f44d57a5c4a44ce3dab3a871ed ... the old discussion in: - whatwg/dom#732 (review) - whatwg/html#4354 (comment) ... and the much newer discussion in: - whatwg/dom#1261 - whatwg/html#10188 This CL upstreams an old test ensuring that removal of a child node from a script node that has not "already started" [1], does not trigger script execution. Only the *insertion* of child nodes (to a non-already-started script node) should trigger that script's execution. [1]: https://html.spec.whatwg.org/C#already-started [email protected] Bug: 40150299 Change-Id: I750ccee0a2be834360c557042e975547c8ddd32c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5367238 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1272330}
1 parent c067603 commit 418c79f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// See:
2+
// - https://github.com/whatwg/dom/issues/808
3+
// - https://github.com/whatwg/dom/pull/1261
4+
// - https://github.com/whatwg/html/pull/10188
5+
// - https://source.chromium.org/chromium/chromium/src/+/604e798ec6ee30f44d57a5c4a44ce3dab3a871ed
6+
// - https://github.com/whatwg/dom/pull/732#pullrequestreview-328249015
7+
// - https://github.com/whatwg/html/pull/4354#issuecomment-476038918
8+
test(() => {
9+
window.script_did_run = false;
10+
11+
const script = document.createElement('script');
12+
// This prevents execution on insertion.
13+
script.type = '0';
14+
script.textContent = `script_did_run = true;`;
15+
document.body.append(script);
16+
assert_false(script_did_run,
17+
'Appending script with invalid type does not trigger execution');
18+
19+
const div = document.createElement('div');
20+
script.append(div);
21+
assert_false(script_did_run,
22+
'Appending a child to an invalid-type script does not trigger execution');
23+
24+
// This enables, but does not trigger, execution.
25+
script.type = '';
26+
assert_false(script_did_run,
27+
'Unsetting script type does not trigger execution');
28+
29+
div.remove();
30+
assert_false(script_did_run,
31+
'Removing child from valid script that has not already run, does not ' +
32+
'trigger execution');
33+
}, "Script execution is never triggered on child removals");

0 commit comments

Comments
 (0)