@@ -239,16 +239,19 @@ Local<Array> Storage::Enumerate() {
239239 CHECK_ERROR_OR_THROW (env (), r, SQLITE_OK, Local<Array>());
240240 auto stmt = stmt_unique_ptr (s);
241241 std::vector<Local<Value>> values;
242+ Local<Value> value;
242243 while ((r = sqlite3_step (stmt.get ())) == SQLITE_ROW) {
243244 CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
244245 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);
252255 }
253256 CHECK_ERROR_OR_THROW (env (), r, SQLITE_DONE, Local<Array>());
254257 return Array::New (env ()->isolate (), values.data (), values.size ());
@@ -298,12 +301,14 @@ Local<Value> Storage::Load(Local<Name> key) {
298301 if (r == SQLITE_ROW) {
299302 CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
300303 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+ }
307312 } else if (r != SQLITE_DONE) {
308313 THROW_SQLITE_ERROR (env (), r);
309314 }
@@ -313,7 +318,7 @@ Local<Value> Storage::Load(Local<Name> key) {
313318
314319Local<Value> Storage::LoadKey (const int index) {
315320 if (!Open ()) {
316- return Local<Value>() ;
321+ return {} ;
317322 }
318323
319324 static constexpr std::string_view sql =
@@ -330,12 +335,14 @@ Local<Value> Storage::LoadKey(const int index) {
330335 if (r == SQLITE_ROW) {
331336 CHECK (sqlite3_column_type (stmt.get (), 0 ) == SQLITE_BLOB);
332337 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+ }
339346 } else if (r != SQLITE_DONE) {
340347 THROW_SQLITE_ERROR (env (), r);
341348 }
@@ -411,10 +418,8 @@ bool Storage::Store(Local<Name> key, Local<Value> value) {
411418 return true ;
412419}
413420
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);
418423}
419424
420425static void Clear (const FunctionCallbackInfo<Value>& info) {
@@ -615,33 +620,68 @@ static Intercepted StorageDefiner(Local<Name> property,
615620static Intercepted IndexedGetter (uint32_t index,
616621 const PropertyCallbackInfo<Value>& info) {
617622 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);
619631}
620632
621633static Intercepted IndexedSetter (uint32_t index,
622634 Local<Value> value,
623635 const PropertyCallbackInfo<void >& info) {
624636 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);
626645}
627646
628647static Intercepted IndexedQuery (uint32_t index,
629648 const PropertyCallbackInfo<Integer>& info) {
630649 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);
632658}
633659
634660static Intercepted IndexedDeleter (uint32_t index,
635661 const PropertyCallbackInfo<Boolean>& info) {
636662 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);
638671}
639672
640673static Intercepted IndexedDefiner (uint32_t index,
641674 const PropertyDescriptor& desc,
642675 const PropertyCallbackInfo<void >& info) {
643676 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);
645685}
646686
647687static void StorageLengthGetter (const FunctionCallbackInfo<Value>& info) {
0 commit comments