Permalink
Browse files

Another round of memory leak fixes. Also fixed include syntax

  • Loading branch information...
1 parent 61d1a5b commit 97783566f8a95e2d19fe736b029206ce88402417 @polotek polotek committed Apr 13, 2010
View
@@ -1,5 +1,5 @@
// Copyright 2009, Squish Tech, LLC.
-#include "./html_document.h"
+#include "html_document.h"
namespace libxmljs {
View
@@ -2,8 +2,8 @@
#ifndef SRC_HTML_DOCUMENT_H_
#define SRC_HTML_DOCUMENT_H_
-#include "./libxmljs.h"
-#include "./xml_document.h"
+#include "libxmljs.h"
+#include "xml_document.h"
namespace libxmljs {
View
@@ -1,12 +1,13 @@
// Copyright 2009, Squish Tech, LLC.
-#include "./xml_syntax_error.h"
-#include "./html_parser.h"
-#include "./html_document.h"
+#include "xml_syntax_error.h"
+#include "html_parser.h"
+#include "html_document.h"
namespace libxmljs {
inline v8::Handle<v8::Value>
BuildDoc(xmlDoc *doc, v8::Handle<v8::Array> errors) {
+ v8::HandleScope scope;
if (doc == NULL) {
xmlFreeDoc(doc);
xmlError *error = xmlGetLastError();
@@ -24,7 +25,7 @@ BuildDoc(xmlDoc *doc, v8::Handle<v8::Array> errors) {
LXJS_GET_MAYBE_BUILD(HtmlDocument, doc);
HtmlDocument *document = LibXmlObj::Unwrap<HtmlDocument>(jsDoc);
document->errors = v8::Persistent<v8::Array>::New(errors);
- return jsDoc;
+ return scope.Close(jsDoc);
}
v8::Handle<v8::Value>
@@ -46,7 +47,7 @@ ParseHtmlString(const v8::Arguments& args) {
xmlSetStructuredErrorFunc(NULL, NULL);
- return BuildDoc(doc, errors);
+ return scope.Close(BuildDoc(doc, errors));
}
v8::Handle<v8::Value>
@@ -68,7 +69,7 @@ ParseHtmlFile(const v8::Arguments& args) {
xmlSetStructuredErrorFunc(NULL, NULL);
- return BuildDoc(doc, errors);
+ return scope.Close(BuildDoc(doc, errors));
}
void
View
@@ -2,7 +2,7 @@
#ifndef SRC_HTML_PARSER_H_
#define SRC_HTML_PARSER_H_
-#include "./libxmljs.h"
+#include "libxmljs.h"
namespace libxmljs {
View
@@ -1,10 +1,10 @@
// Copyright 2009, Squish Tech, LLC.
-#include "./libxmljs.h"
-#include "./xml_syntax_error.h"
-#include "./xml_document.h"
-#include "./xml_node.h"
-#include "./xml_parser.h"
-#include "./html_parser.h"
+#include "libxmljs.h"
+#include "xml_syntax_error.h"
+#include "xml_document.h"
+#include "xml_node.h"
+#include "xml_parser.h"
+#include "html_parser.h"
namespace libxmljs {
View
@@ -84,7 +84,7 @@ class LibXMLJS {
} // namespace libxmljs
-#include "./natives.h"
-#include "./object_wrap.h"
+#include "natives.h"
+#include "object_wrap.h"
#endif // SRC_LIBXMLJS_H_
View
@@ -2,7 +2,7 @@
#ifndef SRC_OBJECT_WRAP_H_
#define SRC_OBJECT_WRAP_H_
-#include "./libxmljs.h"
+#include "libxmljs.h"
namespace libxmljs {
@@ -49,6 +49,8 @@ class LibXmlObj {
WeakCallback(v8::Persistent<v8::Value> value, void *data) {
LibXmlObj *obj = static_cast<LibXmlObj*>(data);
assert(value == obj->_handle);
+ //value.Dispose();
+ //value.Clear();
delete obj;
}
};
View
@@ -1,5 +1,5 @@
// Copyright 2009, Squish Tech, LLC.
-#include "./xml_attribute.h"
+#include "xml_attribute.h"
namespace libxmljs {
@@ -10,7 +10,7 @@ XmlAttribute::New(const v8::Arguments& args) {
v8::HandleScope scope;
// was created by BUILD_NODE
if (args.Length() == 1 && args[0]->StrictEquals(v8::Null()))
- return args.This();
+ return scope.Close(args.This());
XmlElement *element = LibXmlObj::Unwrap<XmlElement>(args[0]->ToObject());
@@ -41,7 +41,7 @@ XmlAttribute::Name(const v8::Arguments& args) {
XmlAttribute *attr = LibXmlObj::Unwrap<XmlAttribute>(args.This());
assert(attr);
- return attr->get_name();
+ return scope.Close(attr->get_name());
}
v8::Handle<v8::Value>
@@ -53,11 +53,11 @@ XmlAttribute::Value(const v8::Arguments& args) {
// attr.value('new value');
if (args.Length() > 0) {
attr->set_value(*v8::String::Utf8Value(args[0]));
- return args.This();
+ return scope.Close(args.This());
}
// attr.value();
- return attr->get_value();
+ return scope.Close(attr->get_value());
}
v8::Handle<v8::Value>
@@ -66,7 +66,7 @@ XmlAttribute::Node(const v8::Arguments& args) {
XmlAttribute *attr = LibXmlObj::Unwrap<XmlAttribute>(args.This());
assert(attr);
- return attr->get_element();
+ return scope.Close(attr->get_element());
}
v8::Handle<v8::Value>
@@ -80,12 +80,13 @@ XmlAttribute::get_name() {
v8::Handle<v8::Value>
XmlAttribute::get_value() {
+ v8::HandleScope scope;
xmlChar* value = xmlNodeGetContent(xml_obj);
if (value != NULL) {
v8::Handle<v8::String> ret_value = v8::String::New((const char*)value,
xmlStrlen(value));
xmlFree(value);
- return ret_value;
+ return scope.Close(ret_value);
}
return v8::Null();
View
@@ -2,9 +2,9 @@
#ifndef SRC_XML_ATTRIBUTE_H_
#define SRC_XML_ATTRIBUTE_H_
-#include "./libxmljs.h"
-#include "./xml_element.h"
-#include "./xml_namespace.h"
+#include "libxmljs.h"
+#include "xml_element.h"
+#include "xml_namespace.h"
namespace libxmljs {
View
@@ -1,7 +1,7 @@
// Copyright 2009, Squish Tech, LLC.
-#include "./xml_document.h"
-#include "./xml_element.h"
-#include "./xml_namespace.h"
+#include "xml_document.h"
+#include "xml_element.h"
+#include "xml_namespace.h"
namespace libxmljs {
@@ -10,7 +10,7 @@ v8::Persistent<v8::FunctionTemplate> XmlDocument::constructor_template;
v8::Handle<v8::Value>
XmlDocument::Doc(const v8::Arguments& args) {
v8::HandleScope scope;
- return args.This();
+ return scope.Close(args.This());
}
v8::Handle<v8::Value>
@@ -19,7 +19,7 @@ XmlDocument::Errors(const v8::Arguments& args) {
XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(args.This());
assert(document);
- return document->errors;
+ return scope.Close(document->errors);
}
v8::Handle<v8::Value>
@@ -29,11 +29,11 @@ XmlDocument::Encoding(const v8::Arguments& args) {
assert(document);
if (args.Length() == 0)
- return document->get_encoding();
+ return scope.Close(document->get_encoding());
v8::String::Utf8Value encoding(args[0]->ToString());
document->set_encoding(*encoding);
- return args.This();
+ return scope.Close(args.This());
}
v8::Handle<v8::Value>
@@ -42,7 +42,7 @@ XmlDocument::Version(const v8::Arguments& args) {
XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(args.This());
assert(document);
- return document->get_version();
+ return scope.Close(document->get_version());
}
v8::Handle<v8::Value>
@@ -52,7 +52,7 @@ XmlDocument::Root(const v8::Arguments& args) {
assert(document);
if (args.Length() == 0)
- return document->get_root();
+ return scope.Close(document->get_root());
if (document->has_root())
return ThrowException(v8::Exception::Error(
@@ -61,15 +61,15 @@ XmlDocument::Root(const v8::Arguments& args) {
XmlElement *element = LibXmlObj::Unwrap<XmlElement>(args[0]->ToObject());
assert(element);
document->set_root(element->xml_obj);
- return args[0];
+ return scope.Close(args[0]);
}
v8::Handle<v8::Value>
XmlDocument::ToString(const v8::Arguments& args) {
v8::HandleScope scope;
XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(args.This());
assert(document);
- return document->to_string();
+ return scope.Close(document->to_string());
}
@@ -87,7 +87,7 @@ XmlDocument::New(const v8::Arguments& args) {
case 1: // newDocument(version|callback)
// was created by BUILD_NODE
if (args[0]->StrictEquals(v8::Null()))
- return args.This();
+ return scope.Close(args.This());
if (args[0]->IsString()) {
version = new v8::String::Utf8Value(args[0]->ToString());
@@ -151,7 +151,7 @@ XmlDocument::New(const v8::Arguments& args) {
if (encoding)
delete encoding;
- return obj;
+ return scope.Close(obj);
}
XmlDocument::~XmlDocument() {
@@ -193,7 +193,7 @@ XmlDocument::to_string() {
v8::Local<v8::String> str = v8::String::New((const char*)buffer, len);
xmlFree(buffer);
- return str;
+ return scope.Close(str);
}
bool
View
@@ -2,7 +2,7 @@
#ifndef SRC_XML_DOCUMENT_H_
#define SRC_XML_DOCUMENT_H_
-#include "./libxmljs.h"
+#include "libxmljs.h"
namespace libxmljs {
Oops, something went wrong.

0 comments on commit 9778356

Please sign in to comment.