@@ -194,15 +194,17 @@ void callBack( std::string * str,
194
194
}
195
195
196
196
static bool getWideBindParameters ( std::vector<ExecuteData *> &execData,
197
- Handle <Value> arg,
197
+ Isolate * isolate,
198
+ Local<Value> arg,
198
199
std::vector<a_sqlany_bind_param> & params,
199
200
unsigned &num_rows )
200
201
/* ********************************************************************************/
201
202
{
202
- Handle <Array> rows = Handle <Array>::Cast ( arg );
203
+ Local<Context> context = isolate->GetCurrentContext ();
204
+ Local<Array> rows = Local<Array>::Cast ( arg );
203
205
num_rows = rows->Length ();
204
206
205
- Handle <Array> row0 = Handle <Array>::Cast ( rows->Get (0 ) );
207
+ Local <Array> row0 = Local <Array>::Cast ( rows->Get (0 ) );
206
208
unsigned num_cols = row0->Length ();
207
209
unsigned c;
208
210
@@ -216,10 +218,10 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
216
218
// Make sure that each array in the list has the same number and types
217
219
// of values
218
220
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) );
220
222
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);
223
225
224
226
if ( ( val0->IsInt32 () || val0->IsNumber () ) &&
225
227
( !val->IsInt32 () && !val->IsNumber () && !val->IsNull () ) ) {
@@ -276,14 +278,18 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
276
278
}
277
279
278
280
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) );
280
282
281
283
is_null[r] = false ;
282
284
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 ( );
284
286
285
287
} 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
287
293
const char * param_string = (*paramValue);
288
294
len[r] = (size_t )paramValue.length ();
289
295
char *param_char = new char [len[r] + 1 ];
@@ -308,12 +314,14 @@ static bool getWideBindParameters( std::vector<ExecuteData *> &execData,
308
314
}
309
315
310
316
bool getBindParameters ( std::vector<ExecuteData *> &execData,
311
- Handle <Value> arg,
317
+ Isolate * isolate,
318
+ Local<Value> arg,
312
319
std::vector<a_sqlany_bind_param> & params,
313
320
unsigned &num_rows )
314
321
/* ************************************************************************/
315
322
{
316
- Handle <Array> bind_params = Handle <Array>::Cast ( arg );
323
+ Local<Context> context = isolate->GetCurrentContext ();
324
+ Local<Array> bind_params = Local<Array>::Cast ( arg );
317
325
318
326
if ( bind_params->Length () == 0 ) {
319
327
// if an empty array was passed in, we still need ExecuteData
@@ -323,7 +331,7 @@ bool getBindParameters( std::vector<ExecuteData *> &execData,
323
331
}
324
332
325
333
if ( bind_params->Get (0 )->IsArray () ) {
326
- return getWideBindParameters ( execData, arg, params, num_rows );
334
+ return getWideBindParameters ( execData, isolate, arg, params, num_rows );
327
335
}
328
336
num_rows = 1 ;
329
337
@@ -336,20 +344,24 @@ bool getBindParameters( std::vector<ExecuteData *> &execData,
336
344
337
345
if ( bind_params->Get (i)->IsInt32 () ) {
338
346
int *param_int = new int ;
339
- *param_int = bind_params->Get (i)->Int32Value ();
347
+ *param_int = bind_params->Get (i)->Int32Value (context). FromJust ( );
340
348
ex->addInt ( param_int );
341
349
param.value .buffer = (char *)( param_int );
342
350
param.value .type = A_VAL32;
343
351
344
352
} else if ( bind_params->Get (i)->IsNumber () ) {
345
353
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
347
355
ex->addNum ( param_double );
348
356
param.value .buffer = (char *)( param_double );
349
357
param.value .type = A_DOUBLE;
350
358
351
359
} 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
353
365
const char * param_string = (*paramValue);
354
366
size_t *len = new size_t ;
355
367
*len = (size_t )paramValue.length ();
@@ -764,7 +776,8 @@ void StmtObject::Init( Isolate *isolate )
764
776
NODE_SET_PROTOTYPE_METHOD ( tpl, " exec" , exec );
765
777
NODE_SET_PROTOTYPE_METHOD ( tpl, " drop" , drop );
766
778
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 () );
768
781
}
769
782
770
783
void StmtObject::New ( const FunctionCallbackInfo<Value> &args )
@@ -791,7 +804,7 @@ void StmtObject::CreateNewInstance( const FunctionCallbackInfo<Value> & args,
791
804
Isolate *isolate = args.GetIsolate ();
792
805
HandleScope scope (isolate);
793
806
const unsigned argc = 1 ;
794
- Handle <Value> argv[argc] = { args[0 ] };
807
+ Local <Value> argv[argc] = { args[0 ] };
795
808
Local<Function>cons = Local<Function>::New ( isolate, constructor );
796
809
#if NODE_MAJOR_VERSION >= 10
797
810
Local<Context> env = isolate->GetCurrentContext ();
@@ -824,20 +837,25 @@ void StmtObject::removeConnection( void )
824
837
825
838
// Connection Functions
826
839
827
- void HashToString ( Local<Object> obj, Persistent<String> &ret )
840
+ void HashToString ( Isolate *isolate, Local<Object> obj, Persistent<String> &ret )
828
841
/* ************************************************************/
829
842
{
830
- Isolate *isolate = Isolate::GetCurrent ();
843
+ Local<Context> context = isolate-> GetCurrentContext ();
831
844
HandleScope scope (isolate);
832
- Local<Array> props = obj->GetOwnPropertyNames ();
845
+ Local<Array> props = ( obj->GetOwnPropertyNames (context)). ToLocalChecked ();
833
846
int length = props->Length ();
834
847
std::string params = " " ;
835
848
bool first = true ;
836
849
for ( int i = 0 ; i < length; i++ ) {
837
850
Local<String> key = props->Get (i).As <String>();
838
851
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
839
856
String::Utf8Value key_utf8 ( key );
840
857
String::Utf8Value val_utf8 ( val );
858
+ #endif
841
859
if ( !first ) {
842
860
params += " ;" ;
843
861
}
@@ -911,14 +929,20 @@ Connection::Connection( const FunctionCallbackInfo<Value> &args )
911
929
if ( args.Length () == 1 ) {
912
930
// CheckArgType( args[0] );
913
931
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
915
938
int string_len = str->Utf8Length ();
916
939
char *buf = new char [string_len+1 ];
917
940
str->WriteUtf8 ( buf );
941
+ #endif
918
942
_arg.Reset ( isolate, String::NewFromUtf8 ( isolate, buf ) );
919
943
delete [] buf;
920
944
} else if ( args[0 ]->IsObject () ) {
921
- HashToString ( args[0 ]->ToObject (), _arg );
945
+ HashToString ( isolate, args[0 ]->ToObject (isolate ), _arg );
922
946
} else if ( !args[0 ]->IsUndefined () && !args[0 ]->IsNull () ) {
923
947
throwError ( JS_ERR_INVALID_ARGUMENTS );
924
948
} else {
@@ -992,7 +1016,8 @@ void Connection::Init( Isolate *isolate )
992
1016
NODE_SET_PROTOTYPE_METHOD ( tpl, " rollback" , rollback );
993
1017
NODE_SET_PROTOTYPE_METHOD ( tpl, " connected" , connected );
994
1018
995
- constructor.Reset ( isolate, tpl->GetFunction () );
1019
+ Local<Context> context = isolate->GetCurrentContext ();
1020
+ constructor.Reset (isolate, tpl->GetFunction (context).ToLocalChecked ());
996
1021
}
997
1022
998
1023
void Connection::New ( const FunctionCallbackInfo<Value> &args )
@@ -1026,7 +1051,7 @@ void Connection::NewInstance( const FunctionCallbackInfo<Value> &args )
1026
1051
Isolate *isolate = args.GetIsolate ();
1027
1052
HandleScope scope ( isolate );
1028
1053
const unsigned argc = 1 ;
1029
- Handle <Value> argv[argc] = { args[0 ] };
1054
+ Local <Value> argv[argc] = { args[0 ] };
1030
1055
Local<Function> cons = Local<Function>::New ( isolate, constructor );
1031
1056
#if NODE_MAJOR_VERSION >= 10
1032
1057
Local<Context> env = isolate->GetCurrentContext ();
0 commit comments