diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-02-13 20:11:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 20:11:20 -0500 |
commit | f02053621505c1e290793fb6f27efea38d81fb5b (patch) | |
tree | 87d7c6357efe23f69ebe0ac24cbbcde987da7260 /components/script/dom/node.rs | |
parent | e697e6cca70bec57b5ed9512b95c2a72359d6ca1 (diff) | |
parent | e48eac6879add4512dd42cbed0216508ace2c31e (diff) | |
download | servo-f02053621505c1e290793fb6f27efea38d81fb5b.tar.gz servo-f02053621505c1e290793fb6f27efea38d81fb5b.zip |
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. -->
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r-- | components/script/dom/node.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 0081e997bb9..457c1f0d55c 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -85,6 +85,7 @@ use script_traits::UntrustedNodeAddress; use selectors::matching::{matches_selector_list, MatchingContext, MatchingMode}; use selectors::parser::SelectorList; use servo_arc::Arc; +use servo_atoms::Atom; use servo_url::ServoUrl; use smallvec::SmallVec; use std::borrow::ToOwned; @@ -1212,6 +1213,34 @@ impl Node { ); } } + + // https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter + pub fn is_document_named_item(&self, name: &Atom) -> bool { + let html_elem_type = match self.type_id() { + NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_, + _ => return false, + }; + let elem = self + .downcast::<Element>() + .expect("Node with an Element::HTMLElement NodeTypeID must be an Element"); + match html_elem_type { + HTMLElementTypeId::HTMLFormElement | HTMLElementTypeId::HTMLIFrameElement => { + elem.get_name().map_or(false, |n| n == *name) + }, + HTMLElementTypeId::HTMLImageElement => + // Images can match by id, but only when their name is non-empty. + { + elem.get_name().map_or(false, |n| { + n == *name || elem.get_id().map_or(false, |i| i == *name) + }) + }, + // TODO: Handle <embed> and <object>; these depend on + // whether the element is "exposed", a concept which + // doesn't fully make sense until embed/object behaviors + // are actually implemented. + _ => false, + } + } } /// Iterate through `nodes` until we find a `Node` that is not in `not_in` |