XmlDocument::New(xmlDoc* doc)
{
    Nan::EscapableHandleScope scope;

    if (doc->_private) {
        return scope.Escape(static_cast<XmlDocument*>(doc->_private)->handle());
    }

    v8::Local<v8::Object> obj = Nan::NewInstance(Nan::GetFunction(Nan::New(constructor_template)).ToLocalChecked()).ToLocalChecked();

    XmlDocument* document = Nan::ObjectWrap::Unwrap<XmlDocument>(obj);

    // replace the document we created
    document->xml_obj->_private = NULL;
    xmlFreeDoc(document->xml_obj);
    document->xml_obj = doc;

    // store ourselves in the document
    // this is how we can get instances or already existing v8 objects
    doc->_private = document;

    return scope.Escape(obj);
}
XmlDocument::New(xmlDoc* doc)
{
    Nan::EscapableHandleScope scope;

    if (doc->_private) {
        return scope.Escape(static_cast<XmlDocument*>(doc->_private)->handle());
    }

    v8::Local<v8::Object> obj = Nan::NewInstance(Nan::GetFunction(Nan::New(constructor_template)).ToLocalChecked()).ToLocalChecked();

    XmlDocument* document = Nan::ObjectWrap::Unwrap<XmlDocument>(obj);

     
    document->xml_obj->_private = NULL;
    xmlFreeDoc(document->xml_obj);
    document->xml_obj = doc;

     
     
    doc->_private = document;

    return scope.Escape(obj);
}