Skip to content

Commit

Permalink
Merge branch 'nodeJS12' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthD committed Jan 2, 2021
2 parents d13b876 + 002d540 commit 77da5c2
Show file tree
Hide file tree
Showing 19 changed files with 3,317 additions and 1,079 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij
# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij

build*
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ os:

env:
matrix:
- NODE_VERSION="10.15"
- NODE_VERSION="8.6"
- NODE_VERSION="6.11"
- NODE_VERSION="4.4"
- NODE_VERSION="14.12"
include:
- os: osx
osx_image: xcode8.3
osx_image: xcode12.2

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

install:
# - npm install --build-from-source
- npm i nan
- npm install
- node-pre-gyp clean
- node-pre-gyp configure --enable-build-type=release
- node-pre-gyp build
- mkdir -p Release/build/4 Release/build/5 Release/build/6 Release/build/7
- mv build-tmp-napi-v4/Release/xml.node build/4/
- mv build-tmp-napi-v5/Release/xml.node build/5/
- mv build-tmp-napi-v6/Release/xml.node build/6/
- mv build-tmp-napi-v7/Release/xml.node build/7/
- node-pre-gyp package

script:
Expand Down
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "/Users/dieudonn/.nvm/versions/node/v12.13.0/bin/node",
"args": [
"/Users/dieudonn/Dev/node-libxml/test/libxml-test.js"
],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"type": "lldb",
"request": "launch",
"name": "Launch Program",
"preLaunchTask": "npm: build:dev",
"program": "/Users/dieudonn/.nvm/versions/node/v12.13.0/bin/node",
"args": [
"/Users/dieudonn/Dev/node-libxml/test/index.js"
]
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"*.twig": "twig",
"ios": "cpp",
"vector": "cpp"
}
}
11 changes: 10 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Node-libxml has been thought differently than [libxmljs](https://github.com/libx
- 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!



## Install

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


## Contribute

### Install
- `npm i`
- 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)__
- `npm test` should pass 😎

## Important notes
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
22 changes: 21 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@
'targets': [
{
'target_name': 'xml',
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
},
'msvs_settings': {
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
},
'product_extension': 'node',
'type': 'shared_library',
'include_dirs': [
'<!@(node -p "require(\'node-addon-api\').include")',
'vendor/libxml/include',
"<!(node -e \"require('nan')\")"
"<!@(node -p \"require('node-addon-api').include\")",
],
'cflags': [ '-Wall' ],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'OTHER_CFLAGS': [ '-Wall' ]
},
'defines': [
'NAPI_VERSION=<(napi_build_version)',
],
'sources': [
'libxml.cpp',
'libxml-syntax-error.cpp',
Expand Down Expand Up @@ -56,7 +74,9 @@
],
'conditions': [
['OS=="mac"', {
'cflags+': ['-fvisibility=hidden'],
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'OTHER_LDFLAGS': [
'-undefined dynamic_lookup'
Expand Down
80 changes: 48 additions & 32 deletions libxml-syntax-error.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,73 @@
/**
* This is the Errros Class script, for wellformed & validation DTD
* This is the Errors Class script, for wellformed & validation DTD
*/
#include <cstring>
#include <iostream>
#include "libxml-syntax-error.h"

void setStringField(v8::Local<v8::Object> obj, const char* name, const char* value) {
Nan::HandleScope scope;
if (!value) {
void setStringField(Napi::Object obj, const char *name, const char *value, Napi::Env env)
{
Napi::HandleScope scope(env);
if (!value)
{
return;
}
Nan::Set(obj, Nan::New<v8::String>(name).ToLocalChecked(), Nan::New<v8::String>(value, strlen(value)).ToLocalChecked());
obj.Set(name, Napi::String::New(env, value));
}

void setNumericField(v8::Local<v8::Object> obj, const char* name, const int value) {
Nan::HandleScope scope;
Nan::Set(obj, Nan::New<v8::String>(name).ToLocalChecked(), Nan::New<v8::Int32>(value));
void setNumericField(Napi::Object obj, const char *name, const int value, Napi::Env env)
{
Napi::HandleScope scope(env);
obj.Set(name, Napi::Number::New(env, value));
}

v8::Local<v8::Value>
XmlSyntaxError::BuildSyntaxError(xmlError* error) {
Nan::EscapableHandleScope scope;
Napi::Value
XmlSyntaxError::BuildSyntaxError(xmlError *error, Napi::Env env)
{
Napi::EscapableHandleScope scope(env);

v8::Local<v8::Value> err = v8::Exception::Error(
Nan::New<v8::String>(error->message).ToLocalChecked());
v8::Local<v8::Object> out = v8::Local<v8::Object>::Cast(err);
auto err = Napi::TypeError::New(env,
Napi::String::New(env, error->message));
Napi::Object out = Napi::Object::New(env);

setStringField(out, "message", error->message);
setNumericField(out, "level", error->level);
setNumericField(out, "column", error->int2);
setStringField(out, "file", error->file);
setNumericField(out, "line", error->line);
setStringField(out, "message", error->message, env);
setNumericField(out, "level", error->level, env);
setNumericField(out, "column", error->int2, env);
setStringField(out, "file", error->file, env);
setNumericField(out, "line", error->line, env);

if (error->int1) {
setNumericField(out, "int1", error->int1);
if (error->int1)
{
setNumericField(out, "int1", error->int1, env);
}
return scope.Escape(err);
return out;
}

int XmlSyntaxError::maxError {100};
uint32_t XmlSyntaxError::maxError{100};
Napi::Env* XmlSyntaxError::env = nullptr;

void XmlSyntaxError::ChangeMaxNumberOfError(int max){
void XmlSyntaxError::ChangeMaxNumberOfError(int max)
{
XmlSyntaxError::maxError = max;
}

void
XmlSyntaxError::PushToArray(void* errs, xmlError* error) {
Nan::HandleScope scope;
v8::Local<v8::Array> errors = *reinterpret_cast<v8::Local<v8::Array>*>(errs);
if(errors->Length() >= maxError){
void XmlSyntaxError::PushToArray(void *errs, xmlError *error)
{
Napi::Array errors = *reinterpret_cast<Napi::Array *>(errs);
if (errors.Length() >= maxError)
{
return;
}
v8::Local<v8::Function> push = v8::Local<v8::Function>::Cast(errors->Get(Nan::New<v8::String>("push").ToLocalChecked()));
v8::Local<v8::Value> argv[1] = { XmlSyntaxError::BuildSyntaxError(error) };
push->Call(errors, 1, argv);
Napi::Value castedError = {XmlSyntaxError::BuildSyntaxError(error, *XmlSyntaxError::env)};
errors.Set(errors.Length(), castedError);
}

void XmlSyntaxError::PushToArray(Napi::Array& errors, const char* errorMessage)
{
if (errors.Length() >= maxError)
{
return;
}
Napi::String messageToPush = Napi::String::New(*XmlSyntaxError::env, errorMessage);
errors.Set(errors.Length(), messageToPush);
}
18 changes: 11 additions & 7 deletions libxml-syntax-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@

#include "libxml.h"

class XmlSyntaxError {
static int maxError;
class XmlSyntaxError
{
static uint32_t maxError;

public:
static Napi::Env* env;
static void ChangeMaxNumberOfError(int max);

// push xmlError onto v8::Array
static void PushToArray(void* errs, xmlError* error);
// push xmlError onto Napi::Array
static void PushToArray(void *errs, xmlError *error);
static void PushToArray(Napi::Array& errs, const char* errorMessage);

// create a v8 object for the syntax eror
static v8::Local<v8::Value> BuildSyntaxError(xmlError* error);
// create a Napi object for the syntax eror
static Napi::Value BuildSyntaxError(xmlError *error, Napi::Env env);
};

// LIBXML_SYNTAX_ERROR
#endif
#endif
Loading

0 comments on commit 77da5c2

Please sign in to comment.