Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (70 sloc) 2.551 kb
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
1 // Copyright 2009, Squish Tech, LLC.
9778356 @polotek Another round of memory leak fixes. Also fixed include syntax
polotek authored
2 #include "xml_syntax_error.h"
3 #include "xml_parser.h"
4 #include "xml_sax_parser.h"
5 #include "xml_document.h"
a08f0c2 @sprsquish new naming convention
sprsquish authored
6
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
7 namespace libxmljs {
936b1c7 @sprsquish cleanup
sprsquish authored
8
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
9 inline v8::Handle<v8::Value>
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
10 BuildDoc(xmlDoc *doc, v8::Persistent<v8::Array> jsErrArray) {
9778356 @polotek Another round of memory leak fixes. Also fixed include syntax
polotek authored
11 v8::HandleScope scope;
e52b22b @polotek fixed a few memory leaks and that annoying attribute adding thing
polotek authored
12 if (!doc) {
1937be2 @polotek use xmlFree everywhere
polotek authored
13 xmlFree(doc);
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
14 xmlError *error = xmlGetLastError();
15 if (error) {
dcd0066 @polotek convert syntax error macro to inline member func
polotek authored
16 return v8::ThrowException(XmlSyntaxError::BuildSyntaxError(error));
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
17
18 } else {
19 return v8::ThrowException(v8::Exception::Error(
20 v8::String::New("Could not parse XML string")));
21 }
22 return v8::Null();
23 }
24
25 v8::Handle<v8::Object> jsDoc =
bea23d6 @polotek Major change to object creation. Using default node ObjectWrap instea…
polotek authored
26 LibXmlObj::GetMaybeBuild<XmlDocument, xmlDoc>(doc);
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
27 XmlDocument *document = LibXmlObj::Unwrap<XmlDocument>(jsDoc);
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
28 document->errors = jsErrArray;
9778356 @polotek Another round of memory leak fixes. Also fixed include syntax
polotek authored
29 return scope.Close(jsDoc);
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
30 }
31
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
32 v8::Handle<v8::Value>
9a4e091 @sprsquish "namespace" parser methods
sprsquish authored
33 ParseXmlString(const v8::Arguments& args) {
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
34 v8::HandleScope scope;
a8d7f75 @sprsquish add some meat to the skeleton
sprsquish authored
35
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
36 if (!args[0]->IsString())
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
37 return v8::ThrowException(v8::Exception::Error(
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
38 v8::String::New("Must supply parseXmlString with a string")));
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
39
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
40 v8::Persistent<v8::Array> errors = v8::Persistent<v8::Array>::New(
41 v8::Array::New());
d014314 @sprsquish Don't use the parser context for the normal parser
sprsquish authored
42 xmlResetLastError();
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
43 xmlSetStructuredErrorFunc(reinterpret_cast<void *>(*errors),
584f3aa @sprsquish cpplint the entire src directory
sprsquish authored
44 XmlSyntaxError::PushToArray);
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
45
46 v8::String::Utf8Value str(args[0]->ToString());
6261be2 @sprsquish Refactor and test syntax errors
sprsquish authored
47 xmlDoc *doc = xmlReadMemory(*str, str.length(), NULL, "UTF-8", 0);
d014314 @sprsquish Don't use the parser context for the normal parser
sprsquish authored
48
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
49 xmlSetStructuredErrorFunc(NULL, NULL);
50
9778356 @polotek Another round of memory leak fixes. Also fixed include syntax
polotek authored
51 return scope.Close(BuildDoc(doc, errors));
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
52 }
a8d7f75 @sprsquish add some meat to the skeleton
sprsquish authored
53
b4e0542 @sprsquish parse files
sprsquish authored
54 v8::Handle<v8::Value>
9a4e091 @sprsquish "namespace" parser methods
sprsquish authored
55 ParseXmlFile(const v8::Arguments& args) {
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
56 v8::HandleScope scope;
b4e0542 @sprsquish parse files
sprsquish authored
57
58 if (!args[0]->IsString())
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
59 return v8::ThrowException(v8::Exception::Error(
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
60 v8::String::New("Must supply parseXmlFile with a filename")));
b4e0542 @sprsquish parse files
sprsquish authored
61
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
62 v8::Persistent<v8::Array> errors = v8::Persistent<v8::Array>::New(
63 v8::Array::New());
d014314 @sprsquish Don't use the parser context for the normal parser
sprsquish authored
64 xmlResetLastError();
11ef0f2 @sprsquish kill off JsObj
sprsquish authored
65 xmlSetStructuredErrorFunc(reinterpret_cast<void *>(*errors),
584f3aa @sprsquish cpplint the entire src directory
sprsquish authored
66 XmlSyntaxError::PushToArray);
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
67
68 v8::String::Utf8Value str(args[0]->ToString());
6261be2 @sprsquish Refactor and test syntax errors
sprsquish authored
69 xmlDoc *doc = xmlReadFile(*str, "UTF-8", 0);
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
70
e282f74 @sprsquish Attach syntax errors to a document if recoverable or throw them as an…
sprsquish authored
71 xmlSetStructuredErrorFunc(NULL, NULL);
72
9778356 @polotek Another round of memory leak fixes. Also fixed include syntax
polotek authored
73 return scope.Close(BuildDoc(doc, errors));
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
74 }
75
76 void
3148272 @sprsquish Cleanup some of the namespacing issues
sprsquish authored
77 XmlParser::Initialize(v8::Handle<v8::Object> target) {
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
78 v8::HandleScope scope;
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
79
3148272 @sprsquish Cleanup some of the namespacing issues
sprsquish authored
80 LIBXMLJS_SET_METHOD(target,
9a4e091 @sprsquish "namespace" parser methods
sprsquish authored
81 "parseXmlString",
82 ParseXmlString);
3148272 @sprsquish Cleanup some of the namespacing issues
sprsquish authored
83
84 LIBXMLJS_SET_METHOD(target,
9a4e091 @sprsquish "namespace" parser methods
sprsquish authored
85 "parseXmlFile",
86 ParseXmlFile);
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
87
3148272 @sprsquish Cleanup some of the namespacing issues
sprsquish authored
88 XmlSaxParser::Initialize(target);
22309ac @sprsquish Got to the point where we can parse a string (Woo!)
sprsquish authored
89 }
1b920d5 @sprsquish apply cpplint to parser.cc and parser.h
sprsquish authored
90 } // namespace libxmljs
Something went wrong with that request. Please try again.