Bug 1669664 - Don't speculatively load scripts, etc inside a template element. r=hsivonen

I guess in order to make this 100% sound we should check the whole
template mode stack, but that seemed more expensive than what I'd really
like, and I think it's not likely to be an issue in practice (maybe we
can too-eagerly preload some images inside tables inside templates, or
something of that sort?).

Differential Revision: https://phabricator.services.mozilla.com/D92773
This commit is contained in:
Emilio Cobos Álvarez 2020-10-08 10:58:27 +00:00
Родитель ca7456a2d0
Коммит 35ada269d3
3 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -167,7 +167,7 @@ nsIContentHandle* nsHtml5TreeBuilder::createElement(
// Start wall of code for speculative loading and line numbers // Start wall of code for speculative loading and line numbers
if (mSpeculativeLoadStage) { if (mSpeculativeLoadStage && mode != IN_TEMPLATE) {
switch (aNamespace) { switch (aNamespace) {
case kNameSpaceID_XHTML: case kNameSpaceID_XHTML:
if (nsGkAtoms::img == aName) { if (nsGkAtoms::img == aName) {

Просмотреть файл

@ -0,0 +1,35 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<template>
<script src="resources/dummy.js?in-template"></script>
<link rel=stylesheet href="resources/dummy.css?in-template-1">
<style>
@import url("resources/dummy.css?in-template-2");
</style>
</template>
<script>
let t = async_test("Things inside templates are not preloaded");
window.addEventListener("load", t.step_func(function() {
let script = document.createElement("script");
script.onload = t.step_func_done(function() {
let entries = performance.getEntriesByType('resource');
let found_outside_template = false;
let found_in_template = [];
for (let entry of entries) {
if (entry.name.includes("outside-template")) {
found_outside_template = true;
}
if (entry.name.includes("in-template")) {
found_in_template.push(entry.name);
}
}
assert_equals(found_in_template.length, 0, "Should not have preloaded stuff inside template element, got: " + found_in_template.join(", "));
assert_true(found_outside_template, "Should have loaded script outside template element");
});
// The test is a bit racy because it expects that the first load ends
// before this one. We try to make it the case via the tickle mechanism.
script.src = "resources/dummy.js?outside-template&pipe=trickle(d1)";
document.body.appendChild(script);
}));
</script>

Просмотреть файл

@ -0,0 +1 @@
/* Nothing to see here */