mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Implement ParentNode#replaceChildren
This commit is contained in:
parent
0baa1ea7bd
commit
66f80fbf4f
7 changed files with 29 additions and 100 deletions
|
@ -4753,6 +4753,11 @@ impl DocumentMethods for Document {
|
||||||
self.upcast::<Node>().append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
|
||||||
|
fn ReplaceChildren(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
|
self.upcast::<Node>().replace_children(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||||
let root = self.upcast::<Node>();
|
let root = self.upcast::<Node>();
|
||||||
|
|
|
@ -100,6 +100,11 @@ impl DocumentFragmentMethods for DocumentFragment {
|
||||||
self.upcast::<Node>().append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
|
||||||
|
fn ReplaceChildren(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
|
self.upcast::<Node>().replace_children(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||||
self.upcast::<Node>().query_selector(selectors)
|
self.upcast::<Node>().query_selector(selectors)
|
||||||
|
|
|
@ -2637,6 +2637,11 @@ impl ElementMethods for Element {
|
||||||
self.upcast::<Node>().append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
|
||||||
|
fn ReplaceChildren(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
|
self.upcast::<Node>().replace_children(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||||
let root = self.upcast::<Node>();
|
let root = self.upcast::<Node>();
|
||||||
|
|
|
@ -934,6 +934,18 @@ impl Node {
|
||||||
self.AppendChild(&node).map(|_| ())
|
self.AppendChild(&node).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-parentnode-replacechildren
|
||||||
|
pub fn replace_children(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
|
// Step 1.
|
||||||
|
let doc = self.owner_doc();
|
||||||
|
let node = doc.node_from_nodes_and_strings(nodes)?;
|
||||||
|
// Step 2.
|
||||||
|
Node::ensure_pre_insertion_validity(&node, self, None)?;
|
||||||
|
// Step 3.
|
||||||
|
Node::replace_all(Some(&node), self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
|
|
|
@ -20,6 +20,8 @@ interface mixin ParentNode {
|
||||||
void prepend((Node or DOMString)... nodes);
|
void prepend((Node or DOMString)... nodes);
|
||||||
[CEReactions, Throws, Unscopable]
|
[CEReactions, Throws, Unscopable]
|
||||||
void append((Node or DOMString)... nodes);
|
void append((Node or DOMString)... nodes);
|
||||||
|
[CEReactions, Throws, Unscopable]
|
||||||
|
void replaceChildren((Node or DOMString)... nodes);
|
||||||
|
|
||||||
[Pure, Throws]
|
[Pure, Throws]
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
|
|
|
@ -716,18 +716,6 @@
|
||||||
[Element interface: operation before((Node or DOMString)...)]
|
[Element interface: operation before((Node or DOMString)...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Element interface: element must inherit property "replaceChildren((Node or DOMString)...)" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Document interface: calling replaceChildren((Node or DOMString)...) on xmlDoc with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Document interface: calling replaceChildren((Node or DOMString)...) on new Document() with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: document.createDocumentFragment() must inherit property "replaceChildren((Node or DOMString)...)" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: operation replaceChildren((Node or DOMString)...)]
|
[DocumentFragment interface: operation replaceChildren((Node or DOMString)...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -737,18 +725,6 @@
|
||||||
[Document interface: operation replaceChildren((Node or DOMString)...)]
|
[Document interface: operation replaceChildren((Node or DOMString)...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Element interface: calling replaceChildren((Node or DOMString)...) on element with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Document interface: new Document() must inherit property "replaceChildren((Node or DOMString)...)" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: calling replaceChildren((Node or DOMString)...) on document.createDocumentFragment() with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Document interface: xmlDoc must inherit property "replaceChildren((Node or DOMString)...)" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XPathNSResolver interface: document.createNSResolver(document.body) must inherit property "lookupNamespaceURI(DOMString?)" with the proper type]
|
[XPathNSResolver interface: document.createNSResolver(document.body) must inherit property "lookupNamespaceURI(DOMString?)" with the proper type]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
[ParentNode-replaceChildren.html]
|
|
||||||
[DocumentFragment.replaceChildren() with null as an argument, on a parent having a child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() with only text as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with null as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() without any argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a host-including inclusive ancestor of parent, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is an Element and parent is a document with another element, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() with null as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() with one element and text as argument, on a parent having a child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with null as an argument, on a parent having a child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() with only one element as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() should move nodes in the right order]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a Text node and parent is a document, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a DocumentFragment with an element and parent is a document with another element, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() with undefined as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a doctype and parent is not a document, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a doctype and parent is a document with another doctype, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a DocumentFragment with multiple elements and parent is a document, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with undefined as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with only one element as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with one element and text as argument, on a parent having a child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() should move nodes in the right order]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is a doctype and parent is a document with an element, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Element.replaceChildren() with only text as an argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment.replaceChildren() without any argument, on a parent having no child.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[If node is not a DocumentFragment, DocumentType, Element, Text, ProcessingInstruction, or Comment node, then throw a HierarchyRequestError DOMException.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue