Bug 1784187 - Process scripts even if they contain no text content. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D156086
This commit is contained in:
Adam Vandolder 2022-10-05 15:16:28 +00:00
parent 00fc04265e
commit 825aa106dd
3 changed files with 53 additions and 1 deletions

View File

@ -269,6 +269,7 @@ skip-if = (os == "android" || headless) # See
[test_bug1739957.html] [test_bug1739957.html]
support-files = support-files =
bug1739957.sjs bug1739957.sjs
[test_bug1784187.html]
[test_bug5141.html] [test_bug5141.html]
[test_bug28293.html] [test_bug28293.html]
[test_bug28293.xhtml] [test_bug28293.xhtml]

View File

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1784187
-->
<head>
<title>Test for Bug 1784187</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
function observeTest(mutationsList) {
for (let mutation of mutationsList) {
for (let n of mutation.addedNodes) {
if (n.id === 'content') {
is(n.innerHTML.trim(), "<script><\/script>", "Comment should not have been observed.");
SimpleTest.finish();
}
}
}
}
var observer = new MutationObserver(observeTest);
observer.observe(document.body, { childList: true, subtree: true });
</script>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1784187">Mozilla Bug 1784187</a>
<p id="display"></p>
<div id="content" style="display: none">
<script></script>
<!-- Test comment that shouldn't be observed -->
</div>
</body>
</html>

View File

@ -7,10 +7,12 @@
#include "ScriptElement.h" #include "ScriptElement.h"
#include "ScriptLoader.h" #include "ScriptLoader.h"
#include "mozilla/BasicEvents.h" #include "mozilla/BasicEvents.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/EventDispatcher.h" #include "mozilla/EventDispatcher.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsIParser.h" #include "nsIParser.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
@ -93,7 +95,18 @@ bool ScriptElement::MaybeProcessScript() {
"You forgot to add self as observer"); "You forgot to add self as observer");
if (mAlreadyStarted || !mDoneAddingChildren || !cont->GetComposedDoc() || if (mAlreadyStarted || !mDoneAddingChildren || !cont->GetComposedDoc() ||
mMalformed || !HasScriptContent()) { mMalformed) {
return false;
}
if (!HasScriptContent()) {
// In the case of an empty, non-external classic script, there is nothing
// to process. However, we must perform a microtask checkpoint afterwards,
// as per https://html.spec.whatwg.org/#clean-up-after-running-script
if (mKind == JS::loader::ScriptKind::eClassic && !mExternal) {
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
"ScriptElement::MaybeProcessScript", []() { nsAutoMicroTask mt; }));
}
return false; return false;
} }