@@ -239,16 +239,19 @@ Local<Array> Storage::Enumerate() {
239
239
CHECK_ERROR_OR_THROW (env (), r, SQLITE_OK, Local<Array>());
240
240
auto stmt = stmt_unique_ptr (s);
241
241
std::vector<Local<Value>> values;
242
+ Local<Value> value;
242
243
while ((r = sqlite3_step (stmt.get ())) == SQLITE_ROW) {
243
244
CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
244
245
auto size = sqlite3_column_bytes (stmt.get (), 0 ) / sizeof (uint16_t );
245
- values.emplace_back (
246
- String::NewFromTwoByte (env ()->isolate (),
247
- reinterpret_cast <const uint16_t *>(
248
- sqlite3_column_blob (stmt.get (), 0 )),
249
- v8::NewStringType::kNormal ,
250
- size)
251
- .ToLocalChecked ());
246
+ if (!String::NewFromTwoByte (env ()->isolate (),
247
+ reinterpret_cast <const uint16_t *>(
248
+ sqlite3_column_blob (stmt.get (), 0 )),
249
+ v8::NewStringType::kNormal ,
250
+ size)
251
+ .ToLocal (&value)) {
252
+ return Local<Array>();
253
+ }
254
+ values.emplace_back (value);
252
255
}
253
256
CHECK_ERROR_OR_THROW (env (), r, SQLITE_DONE, Local<Array>());
254
257
return Array::New (env ()->isolate (), values.data (), values.size ());
@@ -298,12 +301,14 @@ Local<Value> Storage::Load(Local<Name> key) {
298
301
if (r == SQLITE_ROW) {
299
302
CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
300
303
auto size = sqlite3_column_bytes (stmt.get (), 0 ) / sizeof (uint16_t );
301
- value = String::NewFromTwoByte (env ()->isolate (),
302
- reinterpret_cast <const uint16_t *>(
303
- sqlite3_column_blob (stmt.get (), 0 )),
304
- v8::NewStringType::kNormal ,
305
- size)
306
- .ToLocalChecked ();
304
+ if (!String::NewFromTwoByte (env ()->isolate (),
305
+ reinterpret_cast <const uint16_t *>(
306
+ sqlite3_column_blob (stmt.get (), 0 )),
307
+ v8::NewStringType::kNormal ,
308
+ size)
309
+ .ToLocal (&value)) {
310
+ return {};
311
+ }
307
312
} else if (r != SQLITE_DONE) {
308
313
THROW_SQLITE_ERROR (env (), r);
309
314
}
@@ -313,7 +318,7 @@ Local<Value> Storage::Load(Local<Name> key) {
313
318
314
319
Local<Value> Storage::LoadKey (const int index) {
315
320
if (!Open ()) {
316
- return Local<Value>() ;
321
+ return {} ;
317
322
}
318
323
319
324
static constexpr std::string_view sql =
@@ -330,12 +335,14 @@ Local<Value> Storage::LoadKey(const int index) {
330
335
if (r == SQLITE_ROW) {
331
336
CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
332
337
auto size = sqlite3_column_bytes (stmt.get (), 0 ) / sizeof (uint16_t );
333
- value = String::NewFromTwoByte (env ()->isolate (),
334
- reinterpret_cast <const uint16_t *>(
335
- sqlite3_column_blob (stmt.get (), 0 )),
336
- v8::NewStringType::kNormal ,
337
- size)
338
- .ToLocalChecked ();
338
+ if (!String::NewFromTwoByte (env ()->isolate (),
339
+ reinterpret_cast <const uint16_t *>(
340
+ sqlite3_column_blob (stmt.get (), 0 )),
341
+ v8::NewStringType::kNormal ,
342
+ size)
343
+ .ToLocal (&value)) {
344
+ return {};
345
+ }
339
346
} else if (r != SQLITE_DONE) {
340
347
THROW_SQLITE_ERROR (env (), r);
341
348
}
@@ -411,10 +418,8 @@ bool Storage::Store(Local<Name> key, Local<Value> value) {
411
418
return true ;
412
419
}
413
420
414
- static Local<Name> Uint32ToName (Local<Context> context, uint32_t index) {
415
- return Uint32::New (context->GetIsolate (), index )
416
- ->ToString (context)
417
- .ToLocalChecked ();
421
+ static MaybeLocal<String> Uint32ToName (Local<Context> context, uint32_t index) {
422
+ return Uint32::New (context->GetIsolate (), index )->ToString (context);
418
423
}
419
424
420
425
static void Clear (const FunctionCallbackInfo<Value>& info) {
@@ -615,33 +620,68 @@ static Intercepted StorageDefiner(Local<Name> property,
615
620
static Intercepted IndexedGetter (uint32_t index,
616
621
const PropertyCallbackInfo<Value>& info) {
617
622
Environment* env = Environment::GetCurrent (info);
618
- return StorageGetter (Uint32ToName (env->context (), index ), info);
623
+ Local<Name> name;
624
+ if (!Uint32ToName (env->context (), index ).ToLocal (&name)) {
625
+ // There was an error converting the index to a name.
626
+ // We aren't going to return a result but let's indicate
627
+ // that we intercepted the operation.
628
+ return Intercepted::kYes ;
629
+ }
630
+ return StorageGetter (name, info);
619
631
}
620
632
621
633
static Intercepted IndexedSetter (uint32_t index,
622
634
Local<Value> value,
623
635
const PropertyCallbackInfo<void >& info) {
624
636
Environment* env = Environment::GetCurrent (info);
625
- return StorageSetter (Uint32ToName (env->context (), index ), value, info);
637
+ Local<Name> name;
638
+ if (!Uint32ToName (env->context (), index ).ToLocal (&name)) {
639
+ // There was an error converting the index to a name.
640
+ // We aren't going to return a result but let's indicate
641
+ // that we intercepted the operation.
642
+ return Intercepted::kYes ;
643
+ }
644
+ return StorageSetter (name, value, info);
626
645
}
627
646
628
647
static Intercepted IndexedQuery (uint32_t index,
629
648
const PropertyCallbackInfo<Integer>& info) {
630
649
Environment* env = Environment::GetCurrent (info);
631
- return StorageQuery (Uint32ToName (env->context (), index ), info);
650
+ Local<Name> name;
651
+ if (!Uint32ToName (env->context (), index ).ToLocal (&name)) {
652
+ // There was an error converting the index to a name.
653
+ // We aren't going to return a result but let's indicate
654
+ // that we intercepted the operation.
655
+ return Intercepted::kYes ;
656
+ }
657
+ return StorageQuery (name, info);
632
658
}
633
659
634
660
static Intercepted IndexedDeleter (uint32_t index,
635
661
const PropertyCallbackInfo<Boolean >& info) {
636
662
Environment* env = Environment::GetCurrent (info);
637
- return StorageDeleter (Uint32ToName (env->context (), index ), info);
663
+ Local<Name> name;
664
+ if (!Uint32ToName (env->context (), index ).ToLocal (&name)) {
665
+ // There was an error converting the index to a name.
666
+ // We aren't going to return a result but let's indicate
667
+ // that we intercepted the operation.
668
+ return Intercepted::kYes ;
669
+ }
670
+ return StorageDeleter (name, info);
638
671
}
639
672
640
673
static Intercepted IndexedDefiner (uint32_t index,
641
674
const PropertyDescriptor& desc,
642
675
const PropertyCallbackInfo<void >& info) {
643
676
Environment* env = Environment::GetCurrent (info);
644
- return StorageDefiner (Uint32ToName (env->context (), index ), desc, info);
677
+ Local<Name> name;
678
+ if (!Uint32ToName (env->context (), index ).ToLocal (&name)) {
679
+ // There was an error converting the index to a name.
680
+ // We aren't going to return a result but let's indicate
681
+ // that we intercepted the operation.
682
+ return Intercepted::kYes ;
683
+ }
684
+ return StorageDefiner (name, desc, info);
645
685
}
646
686
647
687
static void StorageLengthGetter (const FunctionCallbackInfo<Value>& info) {
0 commit comments