Skip to content

Commit be4241c

Browse files
authored
Merge pull request #10 from Nagyjano/nodeJS12
Node JS12 🎉
2 parents 8421f45 + 82b39b4 commit be4241c

File tree

7 files changed

+679
-229
lines changed

7 files changed

+679
-229
lines changed

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
'sources': [
3131
'libxml.cpp',
32-
# 'libxml-syntax-error.cpp',
32+
'libxml-syntax-error.cpp',
3333
'vendor/libxml/buf.c',
3434
'vendor/libxml/catalog.c',
3535
'vendor/libxml/chvalid.c',

libxml-syntax-error.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This is the Errros Class script, for wellformed & validation DTD
2+
* This is the Errors Class script, for wellformed & validation DTD
33
*/
44
#include <cstring>
55
#include <iostream>
@@ -12,13 +12,13 @@ void setStringField(Napi::Object obj, const char *name, const char *value, Napi:
1212
{
1313
return;
1414
}
15-
(obj).Set(Napi::String::New(env, name), Napi::String::New(env, value, strlen(value)));
15+
obj.Set(name, Napi::String::New(env, value));
1616
}
1717

1818
void setNumericField(Napi::Object obj, const char *name, const int value, Napi::Env env)
1919
{
2020
Napi::HandleScope scope(env);
21-
(obj).Set(Napi::String::New(env, name), Napi::Number::New(env, value));
21+
obj.Set(name, Napi::Number::New(env, value));
2222
}
2323

2424
Napi::Value
@@ -28,7 +28,7 @@ XmlSyntaxError::BuildSyntaxError(xmlError *error, Napi::Env env)
2828

2929
auto err = Napi::TypeError::New(env,
3030
Napi::String::New(env, error->message));
31-
Napi::Object out = Napi::Object();
31+
Napi::Object out = Napi::Object::New(env);
3232

3333
setStringField(out, "message", error->message, env);
3434
setNumericField(out, "level", error->level, env);
@@ -43,7 +43,8 @@ XmlSyntaxError::BuildSyntaxError(xmlError *error, Napi::Env env)
4343
return out;
4444
}
4545

46-
int XmlSyntaxError::maxError{100};
46+
uint32_t XmlSyntaxError::maxError{100};
47+
Napi::Env* XmlSyntaxError::env = nullptr;
4748

4849
void XmlSyntaxError::ChangeMaxNumberOfError(int max)
4950
{
@@ -53,10 +54,20 @@ void XmlSyntaxError::ChangeMaxNumberOfError(int max)
5354
void XmlSyntaxError::PushToArray(void *errs, xmlError *error)
5455
{
5556
Napi::Array errors = *reinterpret_cast<Napi::Array *>(errs);
56-
if (errors.Length >= maxError)
57+
if (errors.Length() >= maxError)
5758
{
5859
return;
5960
}
60-
Napi::Value castedError = {XmlSyntaxError::BuildSyntaxError(error, XmlSyntaxError::env)};
61-
errors.Set(errors.Length, castedError);
61+
Napi::Value castedError = {XmlSyntaxError::BuildSyntaxError(error, *XmlSyntaxError::env)};
62+
errors.Set(errors.Length(), castedError);
63+
}
64+
65+
void XmlSyntaxError::PushToArray(Napi::Array& errors, const char* errorMessage)
66+
{
67+
if (errors.Length() >= maxError)
68+
{
69+
return;
70+
}
71+
Napi::String messageToPush = Napi::String::New(*XmlSyntaxError::env, errorMessage);
72+
errors.Set(errors.Length(), messageToPush);
6273
}

libxml-syntax-error.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
class XmlSyntaxError
99
{
10-
static int maxError;
10+
static uint32_t maxError;
1111

1212
public:
13-
static Napi::Env env;
13+
static Napi::Env* env;
1414
static void ChangeMaxNumberOfError(int max);
1515

16-
// push xmlError onto v8::Array
16+
// push xmlError onto Napi::Array
1717
static void PushToArray(void *errs, xmlError *error);
18+
static void PushToArray(Napi::Array& errs, const char* errorMessage);
1819

19-
// create a v8 object for the syntax eror
20+
// create a Napi object for the syntax eror
2021
static Napi::Value BuildSyntaxError(xmlError *error, Napi::Env env);
2122
};
2223

0 commit comments

Comments
 (0)