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 ( Napi::String::New (env, name), Napi::String::New (env, value, strlen (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 (Napi::String::New (env, 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( );
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+ int XmlSyntaxError::maxError{100 };
4247
43- void XmlSyntaxError::ChangeMaxNumberOfError (int max){
48+ void XmlSyntaxError::ChangeMaxNumberOfError (int max)
49+ {
4450 XmlSyntaxError::maxError = max;
4551}
4652
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) {
53+ void XmlSyntaxError::PushToArray ( void *errs, xmlError *error)
54+ {
55+ Napi::Array errors = * reinterpret_cast <Napi::Array *>(errs) ;
56+ if ( errors. Length >= maxError)
57+ {
5258 return ;
5359 }
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);
60+ Napi::Value castedError = {XmlSyntaxError::BuildSyntaxError (error, XmlSyntaxError::env)};
61+ errors.Set (errors.Length , castedError);
5762}
0 commit comments