@@ -26,6 +26,7 @@ using v8::ConstructorBehavior;
26
26
using v8::Context;
27
27
using v8::DictionaryTemplate;
28
28
using v8::DontDelete;
29
+ using v8::EscapableHandleScope;
29
30
using v8::Exception;
30
31
using v8::Function;
31
32
using v8::FunctionCallback;
@@ -2209,12 +2210,13 @@ Maybe<void> ExtractRowValues(Environment* env,
2209
2210
return JustVoid ();
2210
2211
}
2211
2212
2212
- Local <Value> StatementExecutionHelper::All (Environment* env,
2213
- DatabaseSync* db,
2214
- sqlite3_stmt* stmt,
2215
- bool return_arrays,
2216
- bool use_big_ints) {
2213
+ MaybeLocal <Value> StatementExecutionHelper::All (Environment* env,
2214
+ DatabaseSync* db,
2215
+ sqlite3_stmt* stmt,
2216
+ bool return_arrays,
2217
+ bool use_big_ints) {
2217
2218
Isolate* isolate = env->isolate ();
2219
+ EscapableHandleScope scope (isolate);
2218
2220
int r;
2219
2221
int num_cols = sqlite3_column_count (stmt);
2220
2222
LocalVector<Value> rows (isolate);
@@ -2224,7 +2226,7 @@ Local<Value> StatementExecutionHelper::All(Environment* env,
2224
2226
while ((r = sqlite3_step (stmt)) == SQLITE_ROW) {
2225
2227
if (ExtractRowValues (env, stmt, num_cols, use_big_ints, &row_values)
2226
2228
.IsNothing ()) {
2227
- return Undefined (isolate );
2229
+ return MaybeLocal<Value>( );
2228
2230
}
2229
2231
2230
2232
if (return_arrays) {
@@ -2236,8 +2238,9 @@ Local<Value> StatementExecutionHelper::All(Environment* env,
2236
2238
row_keys.reserve (num_cols);
2237
2239
for (int i = 0 ; i < num_cols; ++i) {
2238
2240
Local<Name> key;
2239
- if (!ColumnNameToName (env, stmt, i).ToLocal (&key))
2240
- return Undefined (isolate);
2241
+ if (!ColumnNameToName (env, stmt, i).ToLocal (&key)) {
2242
+ return MaybeLocal<Value>();
2243
+ }
2241
2244
row_keys.emplace_back (key);
2242
2245
}
2243
2246
}
@@ -2248,18 +2251,19 @@ Local<Value> StatementExecutionHelper::All(Environment* env,
2248
2251
}
2249
2252
}
2250
2253
2251
- CHECK_ERROR_OR_THROW (isolate, db, r, SQLITE_DONE, Undefined (isolate ));
2252
- return Array::New (isolate, rows.data (), rows.size ());
2254
+ CHECK_ERROR_OR_THROW (isolate, db, r, SQLITE_DONE, MaybeLocal<Value>( ));
2255
+ return scope. Escape ( Array::New (isolate, rows.data (), rows.size () ));
2253
2256
}
2254
2257
2255
- Local <Object> StatementExecutionHelper::Run (Environment* env,
2256
- DatabaseSync* db,
2257
- sqlite3_stmt* stmt,
2258
- bool use_big_ints) {
2258
+ MaybeLocal <Object> StatementExecutionHelper::Run (Environment* env,
2259
+ DatabaseSync* db,
2260
+ sqlite3_stmt* stmt,
2261
+ bool use_big_ints) {
2259
2262
Isolate* isolate = env->isolate ();
2263
+ EscapableHandleScope scope (isolate);
2260
2264
sqlite3_step (stmt);
2261
2265
int r = sqlite3_reset (stmt);
2262
- CHECK_ERROR_OR_THROW (isolate, db, r, SQLITE_OK, Object::New (isolate ));
2266
+ CHECK_ERROR_OR_THROW (isolate, db, r, SQLITE_OK, MaybeLocal< Object>( ));
2263
2267
Local<Object> result = Object::New (isolate);
2264
2268
sqlite3_int64 last_insert_rowid = sqlite3_last_insert_rowid (db->Connection ());
2265
2269
sqlite3_int64 changes = sqlite3_changes64 (db->Connection ());
@@ -2281,10 +2285,10 @@ Local<Object> StatementExecutionHelper::Run(Environment* env,
2281
2285
.IsNothing () ||
2282
2286
result->Set (env->context (), env->changes_string (), changes_val)
2283
2287
.IsNothing ()) {
2284
- return Object::New (isolate );
2288
+ return MaybeLocal< Object>( );
2285
2289
}
2286
2290
2287
- return result;
2291
+ return scope. Escape ( result) ;
2288
2292
}
2289
2293
2290
2294
BaseObjectPtr<StatementSyncIterator> StatementExecutionHelper::Iterate (
@@ -2321,19 +2325,20 @@ BaseObjectPtr<StatementSyncIterator> StatementExecutionHelper::Iterate(
2321
2325
return iter;
2322
2326
}
2323
2327
2324
- Local <Value> StatementExecutionHelper::Get (Environment* env,
2325
- DatabaseSync* db,
2326
- sqlite3_stmt* stmt,
2327
- bool return_arrays,
2328
- bool use_big_ints) {
2328
+ MaybeLocal <Value> StatementExecutionHelper::Get (Environment* env,
2329
+ DatabaseSync* db,
2330
+ sqlite3_stmt* stmt,
2331
+ bool return_arrays,
2332
+ bool use_big_ints) {
2329
2333
Isolate* isolate = env->isolate ();
2334
+ EscapableHandleScope scope (isolate);
2330
2335
auto reset = OnScopeLeave ([&]() { sqlite3_reset (stmt); });
2331
2336
2332
2337
int r = sqlite3_step (stmt);
2333
- if (r == SQLITE_DONE) return Undefined (isolate);
2338
+ if (r == SQLITE_DONE) return scope. Escape ( Undefined (isolate) );
2334
2339
if (r != SQLITE_ROW) {
2335
2340
THROW_ERR_SQLITE_ERROR (isolate, db);
2336
- return Undefined (isolate );
2341
+ return MaybeLocal<Value>( );
2337
2342
}
2338
2343
2339
2344
int num_cols = sqlite3_column_count (stmt);
@@ -2344,25 +2349,26 @@ Local<Value> StatementExecutionHelper::Get(Environment* env,
2344
2349
LocalVector<Value> row_values (isolate);
2345
2350
if (ExtractRowValues (env, stmt, num_cols, use_big_ints, &row_values)
2346
2351
.IsNothing ()) {
2347
- return Undefined (isolate );
2352
+ return MaybeLocal<Value>( );
2348
2353
}
2349
2354
2350
2355
if (return_arrays) {
2351
- return Array::New (isolate, row_values.data (), row_values.size ());
2356
+ return scope.Escape (
2357
+ Array::New (isolate, row_values.data (), row_values.size ()));
2352
2358
} else {
2353
2359
LocalVector<Name> keys (isolate);
2354
2360
keys.reserve (num_cols);
2355
2361
for (int i = 0 ; i < num_cols; ++i) {
2356
2362
Local<Name> key;
2357
2363
if (!ColumnNameToName (env, stmt, i).ToLocal (&key)) {
2358
- return Undefined (isolate );
2364
+ return MaybeLocal<Value>( );
2359
2365
}
2360
2366
keys.emplace_back (key);
2361
2367
}
2362
2368
2363
2369
DCHECK_EQ (keys.size (), row_values.size ());
2364
- return Object::New (
2365
- isolate, Null (isolate), keys.data (), row_values.data (), num_cols);
2370
+ return scope. Escape ( Object::New (
2371
+ isolate, Null (isolate), keys.data (), row_values.data (), num_cols)) ;
2366
2372
}
2367
2373
}
2368
2374
@@ -2381,11 +2387,16 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {
2381
2387
}
2382
2388
2383
2389
auto reset = OnScopeLeave ([&]() { sqlite3_reset (stmt->statement_ ); });
2384
- args.GetReturnValue ().Set (StatementExecutionHelper::All (env,
2385
- stmt->db_ .get (),
2386
- stmt->statement_ ,
2387
- stmt->return_arrays_ ,
2388
- stmt->use_big_ints_ ));
2390
+
2391
+ Local<Value> result;
2392
+ if (StatementExecutionHelper::All (env,
2393
+ stmt->db_ .get (),
2394
+ stmt->statement_ ,
2395
+ stmt->return_arrays_ ,
2396
+ stmt->use_big_ints_ )
2397
+ .ToLocal (&result)) {
2398
+ args.GetReturnValue ().Set (result);
2399
+ }
2389
2400
}
2390
2401
2391
2402
void StatementSync::Iterate (const FunctionCallbackInfo<Value>& args) {
@@ -2424,11 +2435,15 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
2424
2435
return ;
2425
2436
}
2426
2437
2427
- args.GetReturnValue ().Set (StatementExecutionHelper::Get (env,
2428
- stmt->db_ .get (),
2429
- stmt->statement_ ,
2430
- stmt->return_arrays_ ,
2431
- stmt->use_big_ints_ ));
2438
+ Local<Value> result;
2439
+ if (StatementExecutionHelper::Get (env,
2440
+ stmt->db_ .get (),
2441
+ stmt->statement_ ,
2442
+ stmt->return_arrays_ ,
2443
+ stmt->use_big_ints_ )
2444
+ .ToLocal (&result)) {
2445
+ args.GetReturnValue ().Set (result);
2446
+ }
2432
2447
}
2433
2448
2434
2449
void StatementSync::Run (const FunctionCallbackInfo<Value>& args) {
@@ -2444,8 +2459,12 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) {
2444
2459
return ;
2445
2460
}
2446
2461
2447
- args.GetReturnValue ().Set (StatementExecutionHelper::Run (
2448
- env, stmt->db_ .get (), stmt->statement_ , stmt->use_big_ints_ ));
2462
+ Local<Object> result;
2463
+ if (StatementExecutionHelper::Run (
2464
+ env, stmt->db_ .get (), stmt->statement_ , stmt->use_big_ints_ )
2465
+ .ToLocal (&result)) {
2466
+ args.GetReturnValue ().Set (result);
2467
+ }
2449
2468
}
2450
2469
2451
2470
void StatementSync::Columns (const FunctionCallbackInfo<Value>& args) {
@@ -2691,8 +2710,12 @@ void SQLTagStore::Run(const FunctionCallbackInfo<Value>& info) {
2691
2710
}
2692
2711
}
2693
2712
2694
- info.GetReturnValue ().Set (StatementExecutionHelper::Run (
2695
- env, stmt->db_ .get (), stmt->statement_ , stmt->use_big_ints_ ));
2713
+ Local<Object> result;
2714
+ if (StatementExecutionHelper::Run (
2715
+ env, stmt->db_ .get (), stmt->statement_ , stmt->use_big_ints_ )
2716
+ .ToLocal (&result)) {
2717
+ info.GetReturnValue ().Set (result);
2718
+ }
2696
2719
}
2697
2720
2698
2721
void SQLTagStore::Iterate (const FunctionCallbackInfo<Value>& args) {
@@ -2758,11 +2781,15 @@ void SQLTagStore::Get(const FunctionCallbackInfo<Value>& args) {
2758
2781
}
2759
2782
}
2760
2783
2761
- args.GetReturnValue ().Set (StatementExecutionHelper::Get (env,
2762
- stmt->db_ .get (),
2763
- stmt->statement_ ,
2764
- stmt->return_arrays_ ,
2765
- stmt->use_big_ints_ ));
2784
+ Local<Value> result;
2785
+ if (StatementExecutionHelper::Get (env,
2786
+ stmt->db_ .get (),
2787
+ stmt->statement_ ,
2788
+ stmt->return_arrays_ ,
2789
+ stmt->use_big_ints_ )
2790
+ .ToLocal (&result)) {
2791
+ args.GetReturnValue ().Set (result);
2792
+ }
2766
2793
}
2767
2794
2768
2795
void SQLTagStore::All (const FunctionCallbackInfo<Value>& args) {
@@ -2794,11 +2821,15 @@ void SQLTagStore::All(const FunctionCallbackInfo<Value>& args) {
2794
2821
}
2795
2822
2796
2823
auto reset = OnScopeLeave ([&]() { sqlite3_reset (stmt->statement_ ); });
2797
- args.GetReturnValue ().Set (StatementExecutionHelper::All (env,
2798
- stmt->db_ .get (),
2799
- stmt->statement_ ,
2800
- stmt->return_arrays_ ,
2801
- stmt->use_big_ints_ ));
2824
+ Local<Value> result;
2825
+ if (StatementExecutionHelper::All (env,
2826
+ stmt->db_ .get (),
2827
+ stmt->statement_ ,
2828
+ stmt->return_arrays_ ,
2829
+ stmt->use_big_ints_ )
2830
+ .ToLocal (&result)) {
2831
+ args.GetReturnValue ().Set (result);
2832
+ }
2802
2833
}
2803
2834
2804
2835
void SQLTagStore::Size (const FunctionCallbackInfo<Value>& info) {
@@ -2854,7 +2885,7 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
2854
2885
return BaseObjectPtr<StatementSync>();
2855
2886
}
2856
2887
Utf8Value part (isolate, str_val);
2857
- sql += * part;
2888
+ sql += part. ToStringView () ;
2858
2889
if (i < n_params) {
2859
2890
sql += " ?" ;
2860
2891
}
@@ -2872,7 +2903,7 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
2872
2903
if (stmt == nullptr ) {
2873
2904
sqlite3_stmt* s = nullptr ;
2874
2905
int r = sqlite3_prepare_v2 (
2875
- session->database_ ->connection_ , sql.c_str (), - 1 , &s, 0 );
2906
+ session->database_ ->connection_ , sql.data (), sql. size () , &s, 0 );
2876
2907
2877
2908
if (r != SQLITE_OK) {
2878
2909
THROW_ERR_SQLITE_ERROR (isolate, " Failed to prepare statement" );
0 commit comments