diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 1f2b18f1b99..2b730469582 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -6,11 +6,13 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; -use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, NodeCast}; +use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, ElementCast}; +use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::error::{Fallible, ErrorResult}; use dom::bindings::error::Error::IndexSize; -use dom::bindings::js::JSRef; +use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; +use dom::element::Element; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::node::{Node, NodeHelpers, NodeTypeId}; @@ -127,5 +129,17 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { let node: JSRef = NodeCast::from_ref(self); node.remove_self(); } + + // https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling + fn GetPreviousElementSibling(self) -> Option> { + NodeCast::from_ref(self).preceding_siblings() + .filter_map(ElementCast::to_temporary).next() + } + + // https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling + fn GetNextElementSibling(self) -> Option> { + NodeCast::from_ref(self).following_siblings() + .filter_map(ElementCast::to_temporary).next() + } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 5b5aa57e3e5..418dd124158 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1178,6 +1178,18 @@ impl<'a> ElementMethods for JSRef<'a, Element> { Ok(()) } + // https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling + fn GetPreviousElementSibling(self) -> Option> { + NodeCast::from_ref(self).preceding_siblings() + .filter_map(ElementCast::to_temporary).next() + } + + // https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling + fn GetNextElementSibling(self) -> Option> { + NodeCast::from_ref(self).following_siblings() + .filter_map(ElementCast::to_temporary).next() + } + // http://dom.spec.whatwg.org/#dom-parentnode-children fn Children(self) -> Temporary { let window = window_from_node(self).root(); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 55d60966b27..5368a012846 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -415,6 +415,7 @@ pub trait NodeHelpers<'a> { fn rev_children(self) -> ReverseChildrenIterator; fn child_elements(self) -> ChildElementIterator; fn following_siblings(self) -> NodeChildrenIterator; + fn preceding_siblings(self) -> ReverseChildrenIterator; fn is_in_doc(self) -> bool; fn is_inclusive_ancestor_of(self, parent: JSRef) -> bool; fn is_parent_of(self, child: JSRef) -> bool; @@ -764,6 +765,12 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } } + fn preceding_siblings(self) -> ReverseChildrenIterator { + ReverseChildrenIterator { + current: self.prev_sibling(), + } + } + fn is_parent_of(self, child: JSRef) -> bool { match child.parent_node() { Some(ref parent) if parent == &Temporary::from_rooted(self) => true, diff --git a/components/script/dom/webidls/CharacterData.webidl b/components/script/dom/webidls/CharacterData.webidl index d1b222bc168..39f304e0e39 100644 --- a/components/script/dom/webidls/CharacterData.webidl +++ b/components/script/dom/webidls/CharacterData.webidl @@ -26,3 +26,4 @@ interface CharacterData : Node { }; CharacterData implements ChildNode; +CharacterData implements NonDocumentTypeChildNode; diff --git a/components/script/dom/webidls/ChildNode.webidl b/components/script/dom/webidls/ChildNode.webidl index 16562fbafbf..fbcf8ea1208 100644 --- a/components/script/dom/webidls/ChildNode.webidl +++ b/components/script/dom/webidls/ChildNode.webidl @@ -16,10 +16,10 @@ interface ChildNode { void remove(); }; -// [NoInterfaceObject] -// interface NonDocumentTypeChildNode { -// [Pure] -// readonly attribute Element? previousElementSibling; -// [Pure] -// readonly attribute Element? nextElementSibling; -// }; +[NoInterfaceObject] +interface NonDocumentTypeChildNode { + [Pure] + readonly attribute Element? previousElementSibling; + [Pure] + readonly attribute Element? nextElementSibling; +}; diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl index 8d08717cd31..1090ad91588 100644 --- a/components/script/dom/webidls/Element.webidl +++ b/components/script/dom/webidls/Element.webidl @@ -70,4 +70,5 @@ partial interface Element { }; Element implements ChildNode; +Element implements NonDocumentTypeChildNode; Element implements ParentNode; diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 09001ad6270..e93857fa4ab 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -246,12 +246,6 @@ [Element interface: operation queryAll(DOMString)] expected: FAIL - [Element interface: attribute previousElementSibling] - expected: FAIL - - [Element interface: attribute nextElementSibling] - expected: FAIL - [Element interface: operation before([object Object\],[object Object\])] expected: FAIL @@ -315,12 +309,6 @@ [Element interface: calling queryAll(DOMString) on element with too few arguments must throw TypeError] expected: FAIL - [Element interface: element must inherit property "previousElementSibling" with the proper type (37)] - expected: FAIL - - [Element interface: element must inherit property "nextElementSibling" with the proper type (38)] - expected: FAIL - [Element interface: element must inherit property "before" with the proper type (39)] expected: FAIL @@ -339,12 +327,6 @@ [NamedNodeMap interface: operation setNamedItemNS(Attr)] expected: FAIL - [CharacterData interface: attribute previousElementSibling] - expected: FAIL - - [CharacterData interface: attribute nextElementSibling] - expected: FAIL - [CharacterData interface: operation before([object Object\],[object Object\])] expected: FAIL @@ -369,12 +351,6 @@ [Text interface: document.createTextNode("abc") must inherit property "wholeText" with the proper type (1)] expected: FAIL - [CharacterData interface: document.createTextNode("abc") must inherit property "previousElementSibling" with the proper type (7)] - expected: FAIL - - [CharacterData interface: document.createTextNode("abc") must inherit property "nextElementSibling" with the proper type (8)] - expected: FAIL - [CharacterData interface: document.createTextNode("abc") must inherit property "before" with the proper type (9)] expected: FAIL @@ -387,12 +363,6 @@ [CharacterData interface: calling after([object Object\],[object Object\]) on document.createTextNode("abc") with too few arguments must throw TypeError] expected: FAIL - [CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "previousElementSibling" with the proper type (7)] - expected: FAIL - - [CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "nextElementSibling" with the proper type (8)] - expected: FAIL - [CharacterData interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "before" with the proper type (9)] expected: FAIL @@ -408,12 +378,6 @@ [Comment interface object length] expected: FAIL - [CharacterData interface: document.createComment("abc") must inherit property "previousElementSibling" with the proper type (7)] - expected: FAIL - - [CharacterData interface: document.createComment("abc") must inherit property "nextElementSibling" with the proper type (8)] - expected: FAIL - [CharacterData interface: document.createComment("abc") must inherit property "before" with the proper type (9)] expected: FAIL diff --git a/tests/wpt/metadata/dom/nodes/Element-nextElementSibling.html.ini b/tests/wpt/metadata/dom/nodes/Element-nextElementSibling.html.ini deleted file mode 100644 index 500ad7ddfd9..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-nextElementSibling.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-nextElementSibling.html] - type: testharness - [nextElementSibling] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-previousElementSibling.html.ini b/tests/wpt/metadata/dom/nodes/Element-previousElementSibling.html.ini deleted file mode 100644 index 9fc5b61136c..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-previousElementSibling.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-previousElementSibling.html] - type: testharness - [previousElementSibling] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Element-siblingElement-null.html.ini b/tests/wpt/metadata/dom/nodes/Element-siblingElement-null.html.ini deleted file mode 100644 index 77c3ddfa89e..00000000000 --- a/tests/wpt/metadata/dom/nodes/Element-siblingElement-null.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Element-siblingElement-null.html] - type: testharness - [Null test] - expected: FAIL - diff --git a/tests/wpt/metadata/dom/nodes/Node-properties.html.ini b/tests/wpt/metadata/dom/nodes/Node-properties.html.ini index 4f0913ec1a4..a286ce6e019 100644 --- a/tests/wpt/metadata/dom/nodes/Node-properties.html.ini +++ b/tests/wpt/metadata/dom/nodes/Node-properties.html.ini @@ -1,50 +1,5 @@ [Node-properties.html] type: testharness - [testDiv.previousElementSibling] - expected: FAIL - - [detachedDiv.previousElementSibling] - expected: FAIL - - [detachedDiv.nextElementSibling] - expected: FAIL - - [detachedPara1.previousElementSibling] - expected: FAIL - - [detachedPara1.nextElementSibling] - expected: FAIL - - [detachedPara2.previousElementSibling] - expected: FAIL - - [detachedPara2.nextElementSibling] - expected: FAIL - - [foreignPara1.previousElementSibling] - expected: FAIL - - [foreignPara1.nextElementSibling] - expected: FAIL - - [foreignPara2.previousElementSibling] - expected: FAIL - - [foreignPara2.nextElementSibling] - expected: FAIL - - [xmlElement.previousElementSibling] - expected: FAIL - - [xmlElement.nextElementSibling] - expected: FAIL - - [detachedXmlElement.previousElementSibling] - expected: FAIL - - [detachedXmlElement.nextElementSibling] - expected: FAIL - [detachedTextNode.wholeText] expected: FAIL @@ -60,33 +15,3 @@ [detachedXmlTextNode.wholeText] expected: FAIL - [paras[0\].previousElementSibling] - expected: FAIL - - [paras[0\].nextElementSibling] - expected: FAIL - - [paras[1\].previousElementSibling] - expected: FAIL - - [paras[1\].nextElementSibling] - expected: FAIL - - [paras[2\].previousElementSibling] - expected: FAIL - - [paras[2\].nextElementSibling] - expected: FAIL - - [paras[3\].previousElementSibling] - expected: FAIL - - [paras[3\].nextElementSibling] - expected: FAIL - - [paras[4\].previousElementSibling] - expected: FAIL - - [paras[4\].nextElementSibling] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 4c2f7bacd96..8fb6bc647dc 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -2214,12 +2214,6 @@ [Element interface: calling queryAll(DOMString) on document.createElement("noscript") with too few arguments must throw TypeError] expected: FAIL - [Element interface: document.createElement("noscript") must inherit property "previousElementSibling" with the proper type (37)] - expected: FAIL - - [Element interface: document.createElement("noscript") must inherit property "nextElementSibling" with the proper type (38)] - expected: FAIL - [Element interface: document.createElement("noscript") must inherit property "before" with the proper type (39)] expected: FAIL