Empty scripts should be executed too
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox107 | --- | fixed |
People
(Reporter: tristan.fraipont, Assigned: avandolder)
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0
Steps to reproduce:
See https://github.com/web-platform-tests/wpt/issues/35393.
Register a MutationObserver on the body looking for added nodes in the body's subtree, which will log the innerHTML of an element with id "parent".
Below in the markup, set this one:
<div id="parent">
<script></script>
<!--Further content-->
</div>
Actual results:
When the MutationObserver fires the whole "parent" element has been completely parsed and the innerHTML includes the comment "<!--Further content-->".
Expected results:
Basically, the innerHTML should have contained only "<script></script>".
Reasoning: the empty <script></script> should have triggered the "run a classic script" algorithm, which itself should have called the cleanup after running a script steps, which should have triggered a microtask-checkpoint, ultimately forcing the MutationObserver's pending records to be signaled and handled, with what the parser had until the end tag </script>.
If you want to go the full route, when the end tag </script> is met, we're in https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-incdata:prepare-the-script-element. From there in "prepare the script element" source text is set to the empty string, and further down no special handling of the empty string is ever mentioned, so it should get executed normally, just like it happens when we had just a single white space character between the script's tags.
Ps: this is not a regression, I went back to M61 where it also did reproduce.
Comment 1•3 years ago
|
||
This seems to be a Gecko bug for MutationObserver.
Olli, are we still actively working on MutationObserver? Is this something that we should fix?
Comment 2•3 years ago
|
||
Doesn't look like a MutationObserver issue, but rather an issue with script handling. We're returning early somewhere because of empty content.
I think https://searchfox.org/mozilla-central/rev/f3616b887b8627d8ad841bb1a11138ed658206c5/dom/script/ScriptElement.cpp#89,96
which calls https://searchfox.org/mozilla-central/rev/f3616b887b8627d8ad841bb1a11138ed658206c5/dom/html/HTMLScriptElement.cpp#243,245
| Assignee | ||
Comment 4•3 years ago
|
||
I will give it a shot!
Comment 5•3 years ago
|
||
Worth to check if https://searchfox.org/mozilla-central/rev/db4b1d66c4b409bdbce43f3f3498401f5303d961/dom/script/ScriptLoader.cpp#1121-1129 should affect to microtask checkpoint handling (I mean in the spec). If yes, they we may need to move https://searchfox.org/mozilla-central/rev/db4b1d66c4b409bdbce43f3f3498401f5303d961/dom/script/ScriptLoader.cpp#1835 higher up in the callstack.
| Assignee | ||
Comment 6•3 years ago
|
||
Comment 8•3 years ago
|
||
| bugherder | ||
Description
•