Skip to content

Commit

Permalink
WPT: Script child removal does not trigger execution
Browse files Browse the repository at this point in the history
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

R=nrosenthal@chromium.org

Bug: 40150299
Change-Id: I750ccee0a2be834360c557042e975547c8ddd32c
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Mar 13, 2024
1 parent 553237c commit bd798b8
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// See:
// - https://github.com/whatwg/dom/issues/808
// - https://github.com/whatwg/dom/pull/1261
// - https://github.com/whatwg/html/pull/10188
// - https://source.chromium.org/chromium/chromium/src/+/604e798ec6ee30f44d57a5c4a44ce3dab3a871ed
// - https://github.com/whatwg/dom/pull/732#pullrequestreview-328249015
// - https://github.com/whatwg/html/pull/4354#issuecomment-476038918
test(() => {
window.script_did_run = false;

const script = document.createElement('script');
// This prevents execution on insertion.
script.type = '0';
script.textContent = `script_did_run = true;`;
document.body.append(script);
assert_false(script_did_run,
'Appending script with invalid type does not trigger execution');

const div = document.createElement('div');
script.append(div);
assert_false(script_did_run,
'Appending a child to an invalid-type script does not trigger execution');

// This enables, but does not trigger, execution.
script.type = '';
assert_false(script_did_run,
'Unsetting script type does not trigger execution');

div.remove();
assert_false(script_did_run,
'Removing child from valid script that has not already run, does not ' +
'trigger execution');
}, "Script execution is never triggered on child removals");

0 comments on commit bd798b8

Please sign in to comment.