Skip to content

Commit 2c942a3

Browse files
Merge pull request sqlanywhere#41 from jeffalbion/nodejs12
Nodejs12
2 parents 1075a00 + 330e591 commit 2c942a3

File tree

4 files changed

+86
-37
lines changed

4 files changed

+86
-37
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
},
1616
"dependencies": {
1717
"help": "^3.0.2",
18-
"nan": "2.11.1"
18+
"nan": "2.14.2"
1919
}
2020
}

src/h/sqlany_utils.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ void callBack( std::string * str,
157157
#endif
158158

159159
bool getBindParameters( std::vector<ExecuteData *> &execData
160-
, Handle<Value> arg
160+
, Isolate * isolate
161+
, Local<Value> arg
161162
, std::vector<a_sqlany_bind_param> &params
162163
, unsigned &num_rows
163164
);
@@ -204,7 +205,7 @@ void executeAfter( uv_work_t *req );
204205
void executeWork( uv_work_t *req );
205206

206207
#if NODE_MAJOR_VERSION > 0 || NODE_MINOR_VERSION > 10
207-
void HashToString( Local<Object> obj, Persistent<String> &ret );
208+
void HashToString( Isolate *isolate, Local<Object> obj, Persistent<String> &ret );
208209
#else
209210
Persistent<String> HashToString( Local<Object> obj );
210211
Handle<Value> CreateConnection( const Arguments &args );

src/sqlanywhere.cpp

+33-10
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ NODE_API_FUNC( StmtObject::exec )
225225
baton->callback_required = callback_required;
226226

227227
if( bind_required ) {
228-
if( !getBindParameters( baton->execData, args[0], baton->params,
228+
if( !getBindParameters( baton->execData, isolate, args[0], baton->params,
229229
baton->num_rows ) ) {
230230
delete baton;
231231
std::string error_msg;
@@ -412,6 +412,7 @@ NODE_API_FUNC( Connection::exec )
412412
/*******************************/
413413
{
414414
Isolate *isolate = args.GetIsolate();
415+
Local<Context> context = isolate->GetCurrentContext();
415416
HandleScope scope( isolate );
416417
Local<Value> undef = Local<Value>::New( isolate, Undefined( isolate ) );
417418

@@ -453,9 +454,13 @@ NODE_API_FUNC( Connection::exec )
453454
args.GetReturnValue().SetUndefined();
454455
return;
455456
}
456-
457-
String::Utf8Value param0( args[0]->ToString() );
458-
457+
458+
#if NODE_MAJOR_VERSION >= 12
459+
String::Utf8Value param0( isolate, (args[0]->ToString(context)).ToLocalChecked() );
460+
#else
461+
String::Utf8Value param0( (args[0]->ToString(context)).ToLocalChecked() );
462+
#endif
463+
459464
executeBaton *baton = new executeBaton();
460465
baton->obj = obj;
461466
baton->callback_required = callback_required;
@@ -464,7 +469,7 @@ NODE_API_FUNC( Connection::exec )
464469
baton->stmt = std::string(*param0);
465470

466471
if( bind_required ) {
467-
if( !getBindParameters( baton->execData, args[1], baton->params,
472+
if( !getBindParameters( baton->execData, isolate, args[1], baton->params,
468473
baton->num_rows ) ) {
469474
delete baton;
470475
std::string error_msg;
@@ -596,6 +601,7 @@ NODE_API_FUNC( Connection::prepare )
596601
/**********************************/
597602
{
598603
Isolate *isolate = args.GetIsolate();
604+
Local<Context> context = isolate->GetCurrentContext();
599605
HandleScope scope( isolate );
600606
bool callback_required = false;
601607
int cbfunc_arg = -1;
@@ -640,8 +646,12 @@ NODE_API_FUNC( Connection::prepare )
640646
p_stmt.Reset();
641647
return;
642648
}
643-
644-
String::Utf8Value param0( args[0]->ToString() );
649+
650+
#if NODE_MAJOR_VERSION >= 12
651+
String::Utf8Value param0( isolate, (args[0]->ToString(context)).ToLocalChecked());
652+
#else
653+
String::Utf8Value param0( (args[0]->ToString(context)).ToLocalChecked() );
654+
#endif
645655

646656
prepareBaton *baton = new prepareBaton();
647657
baton->obj = obj;
@@ -797,6 +807,7 @@ NODE_API_FUNC( Connection::connect )
797807
/**********************************/
798808
{
799809
Isolate *isolate = args.GetIsolate();
810+
Local<Context> context = isolate->GetCurrentContext();
800811
HandleScope scope( isolate );
801812
int num_args = args.Length();
802813
Connection *obj;
@@ -856,26 +867,38 @@ NODE_API_FUNC( Connection::connect )
856867
baton->sqlca_connection = sqlca_connection;
857868

858869
if( sqlca_connection ) {
859-
baton->sqlca = (void *)(long)args[0]->NumberValue();
870+
baton->sqlca = (void *)(long)(args[0]->NumberValue(context)).FromJust();
860871

861872
} else {
862873
Local<String> localArg = Local<String>::New( isolate, obj->_arg );
863874
if( localArg->Length() > 0 ) {
875+
#if NODE_MAJOR_VERSION >= 12
876+
String::Utf8Value param0( isolate, localArg );
877+
#else
864878
String::Utf8Value param0( localArg );
879+
#endif
865880
baton->conn_string = std::string(*param0);
866881
} else {
867882
baton->conn_string = std::string();
868883
}
869884
if( arg_is_string ) {
870-
String::Utf8Value param0( args[0]->ToString() );
885+
#if NODE_MAJOR_VERSION >= 12
886+
String::Utf8Value param0( isolate, (args[0]->ToString(context)).ToLocalChecked());
887+
#else
888+
String::Utf8Value param0( (args[0]->ToString(context)).ToLocalChecked() );
889+
#endif
871890
baton->conn_string.append( ";" );
872891
baton->conn_string.append(*param0);
873892
} else if( arg_is_object ) {
874893
Persistent<String> arg_string;
875-
HashToString( args[0]->ToObject(), arg_string );
894+
HashToString( isolate, args[0]->ToObject(isolate), arg_string );
876895
Local<String> local_arg_string =
877896
Local<String>::New( isolate, arg_string );
897+
#if NODE_MAJOR_VERSION >= 12
898+
String::Utf8Value param0( isolate, local_arg_string );
899+
#else
878900
String::Utf8Value param0( local_arg_string );
901+
#endif
879902
baton->conn_string.append( ";" );
880903
baton->conn_string.append(*param0);
881904
arg_string.Reset();

src/utils.cpp

+49-24
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,17 @@ void callBack( std::string * str,
194194
}
195195

196196
static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
197-
Handle<Value> arg,
197+
Isolate * isolate,
198+
Local<Value> arg,
198199
std::vector<a_sqlany_bind_param> & params,
199200
unsigned &num_rows )
200201
/*********************************************************************************/
201202
{
202-
Handle<Array> rows = Handle<Array>::Cast( arg );
203+
Local<Context> context = isolate->GetCurrentContext();
204+
Local<Array> rows = Local<Array>::Cast( arg );
203205
num_rows = rows->Length();
204206

205-
Handle<Array> row0 = Handle<Array>::Cast( rows->Get(0) );
207+
Local<Array> row0 = Local<Array>::Cast( rows->Get(0) );
206208
unsigned num_cols = row0->Length();
207209
unsigned c;
208210

@@ -216,10 +218,10 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
216218
// Make sure that each array in the list has the same number and types
217219
// of values
218220
for( unsigned int r = 1; r < num_rows; r++ ) {
219-
Handle<Array> row = Handle<Array>::Cast( rows->Get(r) );
221+
Local<Array> row = Local<Array>::Cast( rows->Get(r) );
220222
for( c = 0; c < num_cols; c++ ) {
221-
Handle<Value> val0 = row0->Get(c);
222-
Handle<Value> val = row->Get(c);
223+
Local<Value> val0 = row0->Get(c);
224+
Local<Value> val = row->Get(c);
223225

224226
if( ( val0->IsInt32() || val0->IsNumber() ) &&
225227
( !val->IsInt32() && !val->IsNumber() && !val->IsNull() ) ) {
@@ -276,14 +278,18 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
276278
}
277279

278280
for( unsigned int r = 0; r < num_rows; r++ ) {
279-
Handle<Array> bind_params = Handle<Array>::Cast( rows->Get(r) );
281+
Local<Array> bind_params = Local<Array>::Cast( rows->Get(r) );
280282

281283
is_null[r] = false;
282284
if( bind_params->Get(c)->IsInt32() || bind_params->Get(c)->IsNumber() ) {
283-
param_double[r] = bind_params->Get(c)->NumberValue();
285+
param_double[r] = bind_params->Get(c)->NumberValue(context).FromJust();
284286

285287
} else if( bind_params->Get(c)->IsString() ) {
286-
String::Utf8Value paramValue( bind_params->Get(c)->ToString() );
288+
#if NODE_MAJOR_VERSION >= 12
289+
String::Utf8Value paramValue( isolate, (bind_params->Get(c)->ToString(context)).ToLocalChecked() );
290+
#else
291+
String::Utf8Value paramValue( (bind_params->Get(c)->ToString(context)).ToLocalChecked() );
292+
#endif
287293
const char* param_string = (*paramValue);
288294
len[r] = (size_t)paramValue.length();
289295
char *param_char = new char[len[r] + 1];
@@ -308,12 +314,14 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
308314
}
309315

310316
bool getBindParameters( std::vector<ExecuteData *> &execData,
311-
Handle<Value> arg,
317+
Isolate * isolate,
318+
Local<Value> arg,
312319
std::vector<a_sqlany_bind_param> & params,
313320
unsigned &num_rows )
314321
/*************************************************************************/
315322
{
316-
Handle<Array> bind_params = Handle<Array>::Cast( arg );
323+
Local<Context> context = isolate->GetCurrentContext();
324+
Local<Array> bind_params = Local<Array>::Cast( arg );
317325

318326
if( bind_params->Length() == 0 ) {
319327
// if an empty array was passed in, we still need ExecuteData
@@ -323,7 +331,7 @@ bool getBindParameters( std::vector<ExecuteData *> &execData,
323331
}
324332

325333
if( bind_params->Get(0)->IsArray() ) {
326-
return getWideBindParameters( execData, arg, params, num_rows );
334+
return getWideBindParameters( execData, isolate, arg, params, num_rows );
327335
}
328336
num_rows = 1;
329337

@@ -336,20 +344,24 @@ bool getBindParameters( std::vector<ExecuteData *> &execData,
336344

337345
if( bind_params->Get(i)->IsInt32() ) {
338346
int *param_int = new int;
339-
*param_int = bind_params->Get(i)->Int32Value();
347+
*param_int = bind_params->Get(i)->Int32Value(context).FromJust();
340348
ex->addInt( param_int );
341349
param.value.buffer = (char *)( param_int );
342350
param.value.type = A_VAL32;
343351

344352
} else if( bind_params->Get(i)->IsNumber() ) {
345353
double *param_double = new double;
346-
*param_double = bind_params->Get(i)->NumberValue(); // Remove Round off Error
354+
*param_double = bind_params->Get(i)->NumberValue(context).FromJust(); // Remove Round off Error
347355
ex->addNum( param_double );
348356
param.value.buffer = (char *)( param_double );
349357
param.value.type = A_DOUBLE;
350358

351359
} else if( bind_params->Get(i)->IsString() ) {
352-
String::Utf8Value paramValue( bind_params->Get(i)->ToString() );
360+
#if NODE_MAJOR_VERSION >= 12
361+
String::Utf8Value paramValue( isolate, (bind_params->Get(i)->ToString(context)).ToLocalChecked() );
362+
#else
363+
String::Utf8Value paramValue( (bind_params->Get(i)->ToString(context)).ToLocalChecked() );
364+
#endif
353365
const char* param_string = (*paramValue);
354366
size_t *len = new size_t;
355367
*len = (size_t)paramValue.length();
@@ -764,7 +776,8 @@ void StmtObject::Init( Isolate *isolate )
764776
NODE_SET_PROTOTYPE_METHOD( tpl, "exec", exec );
765777
NODE_SET_PROTOTYPE_METHOD( tpl, "drop", drop );
766778
NODE_SET_PROTOTYPE_METHOD( tpl, "getMoreResults", getMoreResults );
767-
constructor.Reset( isolate, tpl->GetFunction() );
779+
Local<Context> context = isolate->GetCurrentContext();
780+
constructor.Reset( isolate, tpl->GetFunction( context ).ToLocalChecked() );
768781
}
769782

770783
void StmtObject::New( const FunctionCallbackInfo<Value> &args )
@@ -791,7 +804,7 @@ void StmtObject::CreateNewInstance( const FunctionCallbackInfo<Value> & args,
791804
Isolate *isolate = args.GetIsolate();
792805
HandleScope scope(isolate);
793806
const unsigned argc = 1;
794-
Handle<Value> argv[argc] = { args[0] };
807+
Local<Value> argv[argc] = { args[0] };
795808
Local<Function>cons = Local<Function>::New( isolate, constructor );
796809
#if NODE_MAJOR_VERSION >= 10
797810
Local<Context> env = isolate->GetCurrentContext();
@@ -824,20 +837,25 @@ void StmtObject::removeConnection( void )
824837

825838
// Connection Functions
826839

827-
void HashToString( Local<Object> obj, Persistent<String> &ret )
840+
void HashToString( Isolate *isolate, Local<Object> obj, Persistent<String> &ret )
828841
/*************************************************************/
829842
{
830-
Isolate *isolate = Isolate::GetCurrent();
843+
Local<Context> context = isolate->GetCurrentContext();
831844
HandleScope scope(isolate);
832-
Local<Array> props = obj->GetOwnPropertyNames();
845+
Local<Array> props = (obj->GetOwnPropertyNames(context)).ToLocalChecked();
833846
int length = props->Length();
834847
std::string params = "";
835848
bool first = true;
836849
for( int i = 0; i < length; i++ ) {
837850
Local<String> key = props->Get(i).As<String>();
838851
Local<String> val = obj->Get(key).As<String>();
852+
#if NODE_MAJOR_VERSION >= 12
853+
String::Utf8Value key_utf8( isolate, key );
854+
String::Utf8Value val_utf8( isolate, val );
855+
#else
839856
String::Utf8Value key_utf8( key );
840857
String::Utf8Value val_utf8( val );
858+
#endif
841859
if( !first ) {
842860
params += ";";
843861
}
@@ -911,14 +929,20 @@ Connection::Connection( const FunctionCallbackInfo<Value> &args )
911929
if( args.Length() == 1 ) {
912930
//CheckArgType( args[0] );
913931
if( args[0]->IsString() ) {
914-
Local<String> str = args[0]->ToString();
932+
Local<String> str = args[0]->ToString(isolate);
933+
#if NODE_MAJOR_VERSION >= 12
934+
int string_len = str->Utf8Length(isolate);
935+
char *buf = new char[string_len + 1];
936+
str->WriteUtf8(isolate, buf);
937+
#else
915938
int string_len = str->Utf8Length();
916939
char *buf = new char[string_len+1];
917940
str->WriteUtf8( buf );
941+
#endif
918942
_arg.Reset( isolate, String::NewFromUtf8( isolate, buf ) );
919943
delete [] buf;
920944
} else if( args[0]->IsObject() ) {
921-
HashToString( args[0]->ToObject(), _arg );
945+
HashToString( isolate, args[0]->ToObject(isolate), _arg );
922946
} else if( !args[0]->IsUndefined() && !args[0]->IsNull() ) {
923947
throwError( JS_ERR_INVALID_ARGUMENTS );
924948
} else {
@@ -992,7 +1016,8 @@ void Connection::Init( Isolate *isolate )
9921016
NODE_SET_PROTOTYPE_METHOD( tpl, "rollback", rollback );
9931017
NODE_SET_PROTOTYPE_METHOD( tpl, "connected", connected );
9941018

995-
constructor.Reset( isolate, tpl->GetFunction() );
1019+
Local<Context> context = isolate->GetCurrentContext();
1020+
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
9961021
}
9971022

9981023
void Connection::New( const FunctionCallbackInfo<Value> &args )
@@ -1026,7 +1051,7 @@ void Connection::NewInstance( const FunctionCallbackInfo<Value> &args )
10261051
Isolate *isolate = args.GetIsolate();
10271052
HandleScope scope( isolate );
10281053
const unsigned argc = 1;
1029-
Handle<Value> argv[argc] = { args[0] };
1054+
Local<Value> argv[argc] = { args[0] };
10301055
Local<Function> cons = Local<Function>::New( isolate, constructor );
10311056
#if NODE_MAJOR_VERSION >= 10
10321057
Local<Context> env = isolate->GetCurrentContext();

0 commit comments

Comments
 (0)