@@ -194,15 +194,17 @@ void callBack( std::string * str,
194194}
195195
196196static 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
310316bool 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
770783void 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
9981023void 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