Implemented Node.adoptNode

Spec:
http://dom.spec.whatwg.org/#dom-document-adoptnode
This commit is contained in:
Bruno de Oliveira Abinader 2014-03-17 00:56:21 -04:00
parent 8a457a2caa
commit 990545c310
4 changed files with 19 additions and 1 deletions

View file

@ -26,6 +26,7 @@ DOMInterfaces = {
'Console': {}, 'Console': {},
'Document': { 'Document': {
'needsAbstract': [ 'needsAbstract': [
'adoptNode',
'anchors', 'anchors',
'applets', 'applets',
'body', 'body',

View file

@ -311,6 +311,21 @@ impl Document {
Ok(Node::clone(node, Some(abstract_self), clone_children)) Ok(Node::clone(node, Some(abstract_self), clone_children))
} }
// http://dom.spec.whatwg.org/#dom-document-adoptnode
pub fn AdoptNode(&self, abstract_self: &JS<Document>, node: &JS<Node>) -> Fallible<JS<Node>> {
// Step 1.
if node.is_document() {
return Err(NotSupported);
}
// Step 2.
let mut adoptee = node.clone();
Node::adopt(&mut adoptee, abstract_self);
// Step 3.
Ok(adoptee)
}
// http://dom.spec.whatwg.org/#dom-document-createevent // http://dom.spec.whatwg.org/#dom-document-createevent
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<JS<Event>> { pub fn CreateEvent(&self, interface: DOMString) -> Fallible<JS<Event>> {
match interface.as_slice() { match interface.as_slice() {

View file

@ -1016,7 +1016,7 @@ impl Node {
} }
// http://dom.spec.whatwg.org/#concept-node-adopt // http://dom.spec.whatwg.org/#concept-node-adopt
fn adopt(node: &mut JS<Node>, document: &JS<Document>) { pub fn adopt(node: &mut JS<Node>, document: &JS<Document>) {
// Step 1. // Step 1.
match node.parent_node() { match node.parent_node() {
Some(ref mut parent) => Node::remove(node, parent, Unsuppressed), Some(ref mut parent) => Node::remove(node, parent, Unsuppressed),

View file

@ -38,6 +38,8 @@ interface Document : Node {
[Throws] [Throws]
Node importNode(Node node, optional boolean deep = false); Node importNode(Node node, optional boolean deep = false);
[Throws]
Node adoptNode(Node node);
[Creator, Throws] [Creator, Throws]
Event createEvent(DOMString interface_); Event createEvent(DOMString interface_);