LibWeb: Run the object representation task when the active state changes

Currently, the following JS snippet will hang indefinitely:

    new DOMParser().parseFromString("<object>", "text/html");

Because the document into which the object is inserted is not active. So
the task queued to run the representation steps will never run.

This patch implements the spec steps to rerun the representation steps
when the active state changes, and avoid the hang when the object is
created in an inactive document.
This commit is contained in:
Timothy Flynn 2024-12-11 13:18:21 -05:00 committed by Andrew Kaster
commit 68164aa7ec
Notes: github-actions[bot] 2024-12-12 00:39:30 +00:00
5 changed files with 681 additions and 0 deletions

View file

@ -0,0 +1,74 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test of interfaces</title>
<link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/">
<link rel="help" href="https://webidl.spec.whatwg.org/#host-objects">
<link rel="help" href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf#page=96">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src=interfaces.js></script>
<div id="log"></div>
<script>
function do_test(local_name, iface, variant) {
test(function() {
var e;
var i = "HTML" + iface + "Element";
if (variant === "useNS") {
// Use createElementNS here to preserve the case of local_name.
e = document.createElementNS("http://www.w3.org/1999/xhtml", local_name);
} else if (variant === "useParser") {
e = new DOMParser().parseFromString("<" + local_name + ">", "text/html").querySelector(local_name);
} else {
e = document.createElement(local_name);
}
assert_class_string(e, i,
"Element " + local_name + " should have " + i +
" as its primary interface.");
assert_true(e instanceof window[i],
"Element " + local_name + " should implement " + i + ".");
assert_true(e instanceof HTMLElement,
"Element " + local_name + " should implement HTMLElement.");
assert_true(e instanceof Element,
"Element " + local_name + " should implement Element.");
assert_true(e instanceof Node,
"Element " + local_name + " should implement Node.");
}, "Interfaces for " + local_name + ": " + variant);
}
// Some elements have weird parser behavior / insertion modes and would be
// skipped by the parser, so skip those.
function should_do_parser_test(local_name) {
return ![
"foo-BAR",
"tbody",
"td",
"tfoot",
"th",
"thead",
"tr",
"å-bar",
"caption",
"col",
"colgroup",
"frame",
"image",
"frameset",
].includes(local_name)
}
elements.forEach(function(a) {
do_test(a[0], a[1], "useNS");
if (should_do_parser_test(a[0])) {
do_test(a[0], a[1], "useParser");
}
// Only run the createElement variant if the input is all-lowercase, because createElement
// case-folds to lowercase. Custom elements are required to use all-lowercase to implement
// HTMLElement, otherwise they use HTMLUnknownElement per spec. Example: "foo-BAR".
if (a[0] === a[0].toLowerCase()) {
do_test(a[0].toUpperCase(), a[1], "createElement");
}
})
</script>

View file

@ -0,0 +1,150 @@
var elements = [
["a", "Anchor"],
["abbr", ""],
["acronym", ""],
["address", ""],
["applet", "Unknown"],
["area", "Area"],
["article", ""],
["aside", ""],
["audio", "Audio"],
["b", ""],
["base", "Base"],
["basefont", ""],
["bdi", ""],
["bdo", ""],
["bgsound", "Unknown"],
["big", ""],
["blink", "Unknown"],
["blockquote", "Quote"],
["body", "Body"],
["br", "BR"],
["button", "Button"],
["canvas", "Canvas"],
["caption", "TableCaption"],
["center", ""],
["cite", ""],
["code", ""],
["col", "TableCol"],
["colgroup", "TableCol"],
["command", "Unknown"],
["data", "Data"],
["datalist", "DataList"],
["dd", ""],
["del", "Mod"],
["details", "Details"],
["dfn", ""],
["dialog", "Dialog"],
["dir", "Directory"],
["directory", "Unknown"],
["div", "Div"],
["dl", "DList"],
["dt", ""],
["em", ""],
["embed", "Embed"],
["fieldset", "FieldSet"],
["figcaption", ""],
["figure", ""],
["font", "Font"],
["foo-BAR", "Unknown"], // not a valid custom element name
["foo-bar", ""], // valid custom element name
["foo", "Unknown"],
["footer", ""],
["form", "Form"],
["frame", "Frame"],
["frameset", "FrameSet"],
["h1", "Heading"],
["h2", "Heading"],
["h3", "Heading"],
["h4", "Heading"],
["h5", "Heading"],
["h6", "Heading"],
["head", "Head"],
["header", ""],
["hgroup", ""],
["hr", "HR"],
["html", "Html"],
["i", ""],
["iframe", "IFrame"],
["image", "Unknown"],
["img", "Image"],
["input", "Input"],
["ins", "Mod"],
["isindex", "Unknown"],
["kbd", ""],
["keygen", "Unknown"],
["label", "Label"],
["legend", "Legend"],
["li", "LI"],
["link", "Link"],
["listing", "Pre"],
["main", ""],
["map", "Map"],
["mark", ""],
["marquee", "Marquee"],
["menu", "Menu"],
["meta", "Meta"],
["meter", "Meter"],
["mod", "Unknown"],
["multicol", "Unknown"],
["nav", ""],
["nextid", "Unknown"],
["nobr", ""],
["noembed", ""],
["noframes", ""],
["noscript", ""],
["object", "Object"],
["ol", "OList"],
["optgroup", "OptGroup"],
["option", "Option"],
["output", "Output"],
["p", "Paragraph"],
["param", "Param"],
["permission", "Permission"],
["picture", "Picture"],
["plaintext", ""],
["pre", "Pre"],
["progress", "Progress"],
["q", "Quote"],
["quasit", "Unknown"],
["rb", ""],
["rp", ""],
["rt", ""],
["rtc", ""],
["ruby", ""],
["s", ""],
["samp", ""],
["script", "Script"],
["section", ""],
["select", "Select"],
["slot", "Slot"],
["small", ""],
["source", "Source"],
["spacer", "Unknown"],
["span", "Span"],
["strike", ""],
["strong", ""],
["style", "Style"],
["sub", ""],
["summary", ""],
["sup", ""],
["table", "Table"],
["tbody", "TableSection"],
["td", "TableCell"],
["textarea", "TextArea"],
["tfoot", "TableSection"],
["th", "TableCell"],
["thead", "TableSection"],
["time", "Time"],
["title", "Title"],
["tr", "TableRow"],
["track", "Track"],
["tt", ""],
["u", ""],
["ul", "UList"],
["var", ""],
["video", "Video"],
["wbr", ""],
["xmp", "Pre"],
["\u00E5-bar", "Unknown"], // not a valid custom element name
];