Skip to content

Commit

Permalink
Removed code that copied the inserted element if its document and the…
Browse files Browse the repository at this point in the history
… target document were not the same. This produced some unexpected behavior: after A.addChild(B), B would NOT be a child of A. xmlAddChild automatically updates the node's document so this is not needed.
  • Loading branch information
dachev committed Aug 2, 2010
1 parent e52b22b commit d9dd85e
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/xml_element.cc
Expand Up @@ -142,7 +142,7 @@ XmlElement::AddChild(const v8::Arguments& args) {
XmlElement *child = LibXmlObj::Unwrap<XmlElement>(args[0]->ToObject());
assert(child);

child = element->import_element(child);
//child = element->import_element(child);

if(child == NULL) {
LIBXMLJS_THROW_EXCEPTION("Could not add child. Failed to copy node to new Document.");
Expand Down Expand Up @@ -267,7 +267,7 @@ XmlElement::AddPrevSibling(const v8::Arguments& args) {
XmlElement* new_sibling = LibXmlObj::Unwrap<XmlElement>(args[0]->ToObject());
assert(new_sibling);

new_sibling = element->import_element(new_sibling);
//new_sibling = element->import_element(new_sibling);

element->add_prev_sibling(new_sibling);

Expand All @@ -283,7 +283,7 @@ XmlElement::AddNextSibling(const v8::Arguments& args) {
XmlElement* new_sibling = LibXmlObj::Unwrap<XmlElement>(args[0]->ToObject());
assert(new_sibling);

new_sibling = element->import_element(new_sibling);
//new_sibling = element->import_element(new_sibling);

element->add_next_sibling(new_sibling);

Expand Down Expand Up @@ -472,27 +472,6 @@ XmlElement::add_next_sibling(XmlElement* element) {
xmlAddNextSibling(xml_obj, element->xml_obj);
}

XmlElement *
XmlElement::import_element(XmlElement *element) {
xmlNode *new_child;
if(xml_obj->doc == element->xml_obj->doc) {
return element;
} else {
new_child = xmlDocCopyNode(element->xml_obj, xml_obj->doc, 1);
if(new_child == NULL) {
return NULL;
}

element->remove();

UpdateV8Memory();

v8::Handle<v8::Object> obj =
LibXmlObj::GetMaybeBuild<XmlElement, xmlNode>(new_child);
return LibXmlObj::Unwrap<XmlElement>(obj);
}
}

void
XmlElement::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
Expand Down

0 comments on commit d9dd85e

Please sign in to comment.