mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
LibWeb: Implement Document named properties with light caching
We now cache potentially named elements on the Document when elements are inserted and removed. This allows us to do lookup of what names are supported much faster than if we had to iterate the tree every time. This first cut doesn't implement the rules for 'exposed' object and embed elements.
This commit is contained in:
parent
faaf5b9652
commit
94149db073
6 changed files with 285 additions and 8 deletions
16
Tests/LibWeb/Text/expected/DOM/Document-named-properties.txt
Normal file
16
Tests/LibWeb/Text/expected/DOM/Document-named-properties.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
Submit <FORM >
|
||||
document.bob === document.forms[0]: true
|
||||
<BUTTON id="fred" >
|
||||
img element with name 'foo' and id 'bar':
|
||||
<IMG id="bar" >
|
||||
img element with id 'baz', but no name:
|
||||
baz === undefined: true
|
||||
Multiple elements with name 'foo':
|
||||
foos.length = 2
|
||||
<IMG id="bar" >
|
||||
<FORM >
|
||||
obj element with name 'greg' and id 'banana':
|
||||
<OBJECT id="banana" >
|
||||
<OBJECT id="banana" >
|
||||
goodbye greg/banana
|
||||
no more greg or banana: true, true
|
45
Tests/LibWeb/Text/input/DOM/Document-named-properties.html
Normal file
45
Tests/LibWeb/Text/input/DOM/Document-named-properties.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
<form name="bob">
|
||||
<button type="submit" id="fred" name="george" value="submit">Submit</button>
|
||||
</form>
|
||||
<img name="foo" id="bar" src="http://www.example.com" alt="Example" />
|
||||
<img id="baz" src="http://www.example.com" alt="Example" />
|
||||
<form name="foo">
|
||||
</form>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
printElement(document.bob);
|
||||
println(`document.bob === document.forms[0]: ${document.bob === document.forms[0]}`);
|
||||
printElement(document.bob.fred);
|
||||
|
||||
println("img element with name 'foo' and id 'bar':");
|
||||
printElement(document.bar);
|
||||
|
||||
println("img element with id 'baz', but no name:");
|
||||
let baz = document.baz;
|
||||
println(`baz === undefined: ${baz === undefined}`);
|
||||
|
||||
println("Multiple elements with name 'foo':");
|
||||
let foos = document.foo;
|
||||
|
||||
println(`foos.length = ${foos.length}`);
|
||||
for (let i = 0; i < foos.length; i++) {
|
||||
printElement(foos[i]);
|
||||
}
|
||||
|
||||
let obj = document.createElement("object");
|
||||
obj.name = "greg";
|
||||
obj.id = "banana";
|
||||
|
||||
document.body.insertBefore(obj, document.foo[0]);
|
||||
|
||||
println("obj element with name 'greg' and id 'banana':");
|
||||
printElement(document.greg);
|
||||
printElement(document.banana);
|
||||
|
||||
println("goodbye greg/banana");
|
||||
document.body.removeChild(document.greg);
|
||||
|
||||
println(`no more greg or banana: ${document.greg === undefined}, ${document.banana === undefined}`);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue