Skip to content

Commit 77da5c2

Browse files
committed
Merge branch 'nodeJS12' into master
2 parents d13b876 + 002d540 commit 77da5c2

19 files changed

+3317
-1079
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,6 @@ $RECYCLE.BIN/
192192
# Windows shortcuts
193193
*.lnk
194194

195-
# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij
195+
# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij
196+
197+
build*

.travis.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ os:
66

77
env:
88
matrix:
9-
- NODE_VERSION="10.15"
10-
- NODE_VERSION="8.6"
11-
- NODE_VERSION="6.11"
12-
- NODE_VERSION="4.4"
9+
- NODE_VERSION="14.12"
1310
include:
1411
- os: osx
15-
osx_image: xcode8.3
12+
osx_image: xcode12.2
1613

1714
before_install:
1815
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
@@ -31,10 +28,15 @@ before_install:
3128
- git config --global user.name "MatthD"
3229

3330
install:
34-
# - npm install --build-from-source
35-
- npm i nan
31+
- npm install
32+
- node-pre-gyp clean
3633
- node-pre-gyp configure --enable-build-type=release
3734
- node-pre-gyp build
35+
- mkdir -p Release/build/4 Release/build/5 Release/build/6 Release/build/7
36+
- mv build-tmp-napi-v4/Release/xml.node build/4/
37+
- mv build-tmp-napi-v5/Release/xml.node build/5/
38+
- mv build-tmp-napi-v6/Release/xml.node build/6/
39+
- mv build-tmp-napi-v7/Release/xml.node build/7/
3840
- node-pre-gyp package
3941

4042
script:

.vscode/launch.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "(lldb) Lancer",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "/Users/dieudonn/.nvm/versions/node/v12.13.0/bin/node",
9+
"args": [
10+
"/Users/dieudonn/Dev/node-libxml/test/libxml-test.js"
11+
],
12+
"stopAtEntry": true,
13+
"cwd": "${workspaceFolder}",
14+
"environment": [],
15+
"externalConsole": false,
16+
"MIMode": "lldb"
17+
},
18+
{
19+
"type": "lldb",
20+
"request": "launch",
21+
"name": "Launch Program",
22+
"preLaunchTask": "npm: build:dev",
23+
"program": "/Users/dieudonn/.nvm/versions/node/v12.13.0/bin/node",
24+
"args": [
25+
"/Users/dieudonn/Dev/node-libxml/test/index.js"
26+
]
27+
}
28+
]
29+
}

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"*.twig": "twig",
4+
"ios": "cpp",
5+
"vector": "cpp"
6+
}
7+
}

Readme.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Node-libxml has been thought differently than [libxmljs](https://github.com/libx
2828
- You want to validate against DTD / schema on multiple documents with just ONE dtd/schema loaded in memory (libxmljs loads it on each validation request), so it's clearly by far fastest!
2929

3030

31-
3231
## Install
3332

3433
```bash
@@ -158,3 +157,13 @@ A function of libxml to free all the memory taken by libxml2
158157
`TAKE nothing & RETURN nothin`
159158
free all memory in all instance in all fork using by libxml.
160159

160+
161+
## Contribute
162+
163+
### Install
164+
- `npm i`
165+
- then move the build-tmp-napi-*{anyversionyougot} as -> `mv build-tmp-napi-v7 build` __(for the moment I did not found how to build directly to buiuld forlder with pre-gyp for n-api)__
166+
- `npm test` should pass 😎
167+
168+
## Important notes
169+
Travis & appveyor cannot be used anymore with n-api because auto-publish from node-pre-gyp-github not working anymore + we have now n release for one node version

binding.gyp

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,34 @@
22
'targets': [
33
{
44
'target_name': 'xml',
5+
'cflags!': [ '-fno-exceptions' ],
6+
'cflags_cc!': [ '-fno-exceptions' ],
7+
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
8+
'CLANG_CXX_LIBRARY': 'libc++',
9+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
10+
},
11+
'msvs_settings': {
12+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
13+
},
514
'product_extension': 'node',
615
'type': 'shared_library',
716
'include_dirs': [
17+
'<!@(node -p "require(\'node-addon-api\').include")',
818
'vendor/libxml/include',
9-
"<!(node -e \"require('nan')\")"
19+
"<!@(node -p \"require('node-addon-api').include\")",
1020
],
1121
'cflags': [ '-Wall' ],
22+
'cflags!': [ '-fno-exceptions' ],
23+
'cflags_cc!': [ '-fno-exceptions' ],
1224
'xcode_settings': {
25+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
26+
'CLANG_CXX_LIBRARY': 'libc++',
27+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
1328
'OTHER_CFLAGS': [ '-Wall' ]
1429
},
30+
'defines': [
31+
'NAPI_VERSION=<(napi_build_version)',
32+
],
1533
'sources': [
1634
'libxml.cpp',
1735
'libxml-syntax-error.cpp',
@@ -56,7 +74,9 @@
5674
],
5775
'conditions': [
5876
['OS=="mac"', {
77+
'cflags+': ['-fvisibility=hidden'],
5978
'xcode_settings': {
79+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
6080
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
6181
'OTHER_LDFLAGS': [
6282
'-undefined dynamic_lookup'

libxml-syntax-error.cpp

+48-32
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,73 @@
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>
66
#include "libxml-syntax-error.h"
77

8-
void setStringField(v8::Local<v8::Object> obj, const char* name, const char* value) {
9-
Nan::HandleScope scope;
10-
if (!value) {
8+
void setStringField(Napi::Object obj, const char *name, const char *value, Napi::Env env)
9+
{
10+
Napi::HandleScope scope(env);
11+
if (!value)
12+
{
1113
return;
1214
}
13-
Nan::Set(obj, Nan::New<v8::String>(name).ToLocalChecked(), Nan::New<v8::String>(value, strlen(value)).ToLocalChecked());
15+
obj.Set(name, Napi::String::New(env, value));
1416
}
1517

16-
void setNumericField(v8::Local<v8::Object> obj, const char* name, const int value) {
17-
Nan::HandleScope scope;
18-
Nan::Set(obj, Nan::New<v8::String>(name).ToLocalChecked(), Nan::New<v8::Int32>(value));
18+
void setNumericField(Napi::Object obj, const char *name, const int value, Napi::Env env)
19+
{
20+
Napi::HandleScope scope(env);
21+
obj.Set(name, Napi::Number::New(env, value));
1922
}
2023

21-
v8::Local<v8::Value>
22-
XmlSyntaxError::BuildSyntaxError(xmlError* error) {
23-
Nan::EscapableHandleScope scope;
24+
Napi::Value
25+
XmlSyntaxError::BuildSyntaxError(xmlError *error, Napi::Env env)
26+
{
27+
Napi::EscapableHandleScope scope(env);
2428

25-
v8::Local<v8::Value> err = v8::Exception::Error(
26-
Nan::New<v8::String>(error->message).ToLocalChecked());
27-
v8::Local<v8::Object> out = v8::Local<v8::Object>::Cast(err);
29+
auto err = Napi::TypeError::New(env,
30+
Napi::String::New(env, error->message));
31+
Napi::Object out = Napi::Object::New(env);
2832

29-
setStringField(out, "message", error->message);
30-
setNumericField(out, "level", error->level);
31-
setNumericField(out, "column", error->int2);
32-
setStringField(out, "file", error->file);
33-
setNumericField(out, "line", error->line);
33+
setStringField(out, "message", error->message, env);
34+
setNumericField(out, "level", error->level, env);
35+
setNumericField(out, "column", error->int2, env);
36+
setStringField(out, "file", error->file, env);
37+
setNumericField(out, "line", error->line, env);
3438

35-
if (error->int1) {
36-
setNumericField(out, "int1", error->int1);
39+
if (error->int1)
40+
{
41+
setNumericField(out, "int1", error->int1, env);
3742
}
38-
return scope.Escape(err);
43+
return out;
3944
}
4045

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

43-
void XmlSyntaxError::ChangeMaxNumberOfError(int max){
49+
void XmlSyntaxError::ChangeMaxNumberOfError(int max)
50+
{
4451
XmlSyntaxError::maxError = max;
4552
}
4653

47-
void
48-
XmlSyntaxError::PushToArray(void* errs, xmlError* error) {
49-
Nan::HandleScope scope;
50-
v8::Local<v8::Array> errors = *reinterpret_cast<v8::Local<v8::Array>*>(errs);
51-
if(errors->Length() >= maxError){
54+
void XmlSyntaxError::PushToArray(void *errs, xmlError *error)
55+
{
56+
Napi::Array errors = *reinterpret_cast<Napi::Array *>(errs);
57+
if (errors.Length() >= maxError)
58+
{
5259
return;
5360
}
54-
v8::Local<v8::Function> push = v8::Local<v8::Function>::Cast(errors->Get(Nan::New<v8::String>("push").ToLocalChecked()));
55-
v8::Local<v8::Value> argv[1] = { XmlSyntaxError::BuildSyntaxError(error) };
56-
push->Call(errors, 1, argv);
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);
5773
}

libxml-syntax-error.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55

66
#include "libxml.h"
77

8-
class XmlSyntaxError {
9-
static int maxError;
8+
class XmlSyntaxError
9+
{
10+
static uint32_t maxError;
11+
1012
public:
13+
static Napi::Env* env;
1114
static void ChangeMaxNumberOfError(int max);
1215

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

16-
// create a v8 object for the syntax eror
17-
static v8::Local<v8::Value> BuildSyntaxError(xmlError* error);
20+
// create a Napi object for the syntax eror
21+
static Napi::Value BuildSyntaxError(xmlError *error, Napi::Env env);
1822
};
1923

2024
// LIBXML_SYNTAX_ERROR
21-
#endif
25+
#endif

0 commit comments

Comments
 (0)