Auto merge of #25548 - pshaughn:docnamedgetter, r=jdm

Add SupportedPropertyNames to Document (also fix iframe getting)

Existing test of named-getting an iframe now succeeds. I added a new test for Object.getOwnPropertyNames(document) based on my understanding of the spec; that test could use a second opinion.

UPDATE: This was trying to do too many things in one PR as originally submitted. It is now using #25572 as a base, and I suggest reviewing that PR before this one to avoid duplicating review effort.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7273 for all implemented named getters, fix #25146, and fix the iframe case only of #25145.

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-13 20:11:20 -05:00 committed by GitHub
commit f020536215
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 405 additions and 113 deletions

View file

@ -363877,6 +363877,12 @@
{}
]
],
"html/dom/documents/dom-tree-accessors/nameditem-names.html": [
[
"html/dom/documents/dom-tree-accessors/nameditem-names.html",
{}
]
],
"html/dom/documents/resource-metadata-management/document-compatmode-01.html": [
[
"html/dom/documents/resource-metadata-management/document-compatmode-01.html",
@ -682171,6 +682177,10 @@
"bb024d9e781fc99d4f60d5d50d6a83970c661f6f",
"testharness"
],
"html/dom/documents/dom-tree-accessors/nameditem-names.html": [
"3f76d85a1bca783df916b159409a94c30488a2dd",
"testharness"
],
"html/dom/documents/resource-metadata-management/document-compatmode-01.html": [
"218a3fe84388111133e493ef50f1dd44f2c60923",
"testharness"

View file

@ -1,20 +0,0 @@
[nameditem-02.html]
type: testharness
[If the only named item is an iframe, the contentWindow should be returned.]
expected: FAIL
[If there are two iframes, a collection should be returned.]
expected: FAIL
[If there are an iframe and another element (iframe first), a collection should be returned.]
expected: FAIL
[If there are an iframe and another element (iframe last), a collection should be returned.]
expected: FAIL
[If an iframe has a name and a different id, it should be returned by its name.]
expected: FAIL
[An iframe whose name looks like an array index should work.]
expected: FAIL

View file

@ -1,5 +0,0 @@
[nameditem-06.html]
type: testharness
[If there are two imgs, nothing should be returned. (id)]
expected: FAIL

View file

@ -0,0 +1,10 @@
[nameditem-names.html]
type: testharness
[An embed name appears in a document's property names if the embed is exposed.]
expected: FAIL
[An object name appears in a document's property names if the object is exposed.]
expected: FAIL
[An object id appears in a document's property names if the object is exposed.]
expected: FAIL

View file

@ -8,4 +8,3 @@
[Trying to set an expando that would shadow an already-existing named property]
expected: FAIL

View file

@ -0,0 +1,101 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: supported property names</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-document-nameditem">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<embed name="exposed_embed">
<embed name="not_exposed_embed">
</embed>
</embed>
<form name="form">
</form>
<iframe name="iframe">
</iframe>
<img name="img">
<object name="exposed_object_with_name">
<object name="not_exposed_object_with_name">
</object>
</object>
<object id="exposed_object_with_id">
<object id="not_exposed_object_with_id">
</object>
</object>
<img name="img_with_id" id="img_id">
<img id="img_with_just_id">
<template id="template">
<img name="img_in_template">
</template>
<img name="42">
<script>
var names = Object.getOwnPropertyNames(document);
test(function() {
assert_true(names.includes("exposed_embed"))
}, "An embed name appears in a document's property names if the embed is exposed.");
test(function() {
assert_false(names.includes("not_exposed_embed"))
}, "An embed name does not appears in a document's property names if the embed is inside another embed.");
test(function() {
assert_true(names.includes("form"))
}, "A form name appears in a document's property names.");
test(function() {
assert_true(names.includes("iframe"))
}, "An iframe name appears in a document's property names.");
test(function() {
assert_true(names.includes("img"))
}, "An img name appears in a document's property names when the img has no id.");
test(function() {
assert_true(names.includes("exposed_object"))
}, "An object name appears in a document's property names if the object is exposed.");
test(function() {
assert_true(names.includes("exposed_object_with_id"))
}, "An object id appears in a document's property names if the object is exposed.");
test(function() {
assert_false(names.includes("not_exposed_object_with_name"))
}, "An object name does not appear in a document's property names if the object is inside another object.");
test(function() {
assert_false(names.includes("not_exposed_object_with_id"))
}, "An object id does not appear in a document's property names if the object is inside another object.");
test(function() {
assert_true(names.includes("img_with_id"))
}, "An img name appears in a document's property names when the img has an id.");
test(function() {
assert_true(names.includes("img_id"))
}, "An img id appears in a document's property names when the img has a name.");
test(function() {
assert_false(names.includes("img_with_just_id"))
}, "An img id does not appear in a document's property names when the img has no name.");
test(function() {
assert_true(names.includes("42"))
}, "A document's property names can include integer strings.");
test(function() {
assert_false(names.includes("template"))
}, "A template name does not appear in a document's property names.");
test(function() {
assert_false(names.includes("img_in_template"))
}, "An img name does not appear in a document's property names when the img is in a template's document fragment.");
test(function() {
var form_index = names.indexOf("form");
assert_equals(names.indexOf("iframe"), form_index + 1);
assert_equals(names.indexOf("img"), form_index + 2);
assert_greater_than(names.indexOf("img_id"), names.indexOf("img"));
assert_greater_than(names.indexOf("42"), names.indexOf("img_id"));
}, "A document's property names appear in tree order.");
</script>