diff --git a/src/node_webstorage.cc b/src/node_webstorage.cc index 7c759e94cfb938..15d142e3d8f6e6 100644 --- a/src/node_webstorage.cc +++ b/src/node_webstorage.cc @@ -249,16 +249,19 @@ Local Storage::Enumerate() { CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Local()); auto stmt = stmt_unique_ptr(s); std::vector> values; + Local value; while ((r = sqlite3_step(stmt.get())) == SQLITE_ROW) { CHECK(sqlite3_column_type(stmt.get(), 0) == SQLITE_BLOB); auto size = sqlite3_column_bytes(stmt.get(), 0) / sizeof(uint16_t); - values.emplace_back( - String::NewFromTwoByte(env()->isolate(), - reinterpret_cast( - sqlite3_column_blob(stmt.get(), 0)), - v8::NewStringType::kNormal, - size) - .ToLocalChecked()); + if (!String::NewFromTwoByte(env()->isolate(), + reinterpret_cast( + sqlite3_column_blob(stmt.get(), 0)), + v8::NewStringType::kNormal, + size) + .ToLocal(&value)) { + return Local(); + } + values.emplace_back(value); } CHECK_ERROR_OR_THROW(env(), r, SQLITE_DONE, Local()); return Array::New(env()->isolate(), values.data(), values.size()); @@ -308,12 +311,14 @@ Local Storage::Load(Local key) { if (r == SQLITE_ROW) { CHECK(sqlite3_column_type(stmt.get(), 0) == SQLITE_BLOB); auto size = sqlite3_column_bytes(stmt.get(), 0) / sizeof(uint16_t); - value = String::NewFromTwoByte(env()->isolate(), - reinterpret_cast( - sqlite3_column_blob(stmt.get(), 0)), - v8::NewStringType::kNormal, - size) - .ToLocalChecked(); + if (!String::NewFromTwoByte(env()->isolate(), + reinterpret_cast( + sqlite3_column_blob(stmt.get(), 0)), + v8::NewStringType::kNormal, + size) + .ToLocal(&value)) { + return {}; + } } else if (r != SQLITE_DONE) { THROW_SQLITE_ERROR(env(), r); } @@ -323,7 +328,7 @@ Local Storage::Load(Local key) { Local Storage::LoadKey(const int index) { if (!Open()) { - return Local(); + return {}; } static constexpr std::string_view sql = @@ -340,12 +345,14 @@ Local Storage::LoadKey(const int index) { if (r == SQLITE_ROW) { CHECK(sqlite3_column_type(stmt.get(), 0) == SQLITE_BLOB); auto size = sqlite3_column_bytes(stmt.get(), 0) / sizeof(uint16_t); - value = String::NewFromTwoByte(env()->isolate(), - reinterpret_cast( - sqlite3_column_blob(stmt.get(), 0)), - v8::NewStringType::kNormal, - size) - .ToLocalChecked(); + if (!String::NewFromTwoByte(env()->isolate(), + reinterpret_cast( + sqlite3_column_blob(stmt.get(), 0)), + v8::NewStringType::kNormal, + size) + .ToLocal(&value)) { + return {}; + } } else if (r != SQLITE_DONE) { THROW_SQLITE_ERROR(env(), r); } @@ -421,10 +428,8 @@ bool Storage::Store(Local key, Local value) { return true; } -static Local Uint32ToName(Local context, uint32_t index) { - return Uint32::New(context->GetIsolate(), index) - ->ToString(context) - .ToLocalChecked(); +static MaybeLocal Uint32ToName(Local context, uint32_t index) { + return Uint32::New(context->GetIsolate(), index)->ToString(context); } static void Clear(const FunctionCallbackInfo& info) { @@ -625,33 +630,68 @@ static Intercepted StorageDefiner(Local property, static Intercepted IndexedGetter(uint32_t index, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); - return StorageGetter(Uint32ToName(env->context(), index), info); + Local name; + if (!Uint32ToName(env->context(), index).ToLocal(&name)) { + // There was an error converting the index to a name. + // We aren't going to return a result but let's indicate + // that we intercepted the operation. + return Intercepted::kYes; + } + return StorageGetter(name, info); } static Intercepted IndexedSetter(uint32_t index, Local value, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); - return StorageSetter(Uint32ToName(env->context(), index), value, info); + Local name; + if (!Uint32ToName(env->context(), index).ToLocal(&name)) { + // There was an error converting the index to a name. + // We aren't going to return a result but let's indicate + // that we intercepted the operation. + return Intercepted::kYes; + } + return StorageSetter(name, value, info); } static Intercepted IndexedQuery(uint32_t index, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); - return StorageQuery(Uint32ToName(env->context(), index), info); + Local name; + if (!Uint32ToName(env->context(), index).ToLocal(&name)) { + // There was an error converting the index to a name. + // We aren't going to return a result but let's indicate + // that we intercepted the operation. + return Intercepted::kYes; + } + return StorageQuery(name, info); } static Intercepted IndexedDeleter(uint32_t index, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); - return StorageDeleter(Uint32ToName(env->context(), index), info); + Local name; + if (!Uint32ToName(env->context(), index).ToLocal(&name)) { + // There was an error converting the index to a name. + // We aren't going to return a result but let's indicate + // that we intercepted the operation. + return Intercepted::kYes; + } + return StorageDeleter(name, info); } static Intercepted IndexedDefiner(uint32_t index, const PropertyDescriptor& desc, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); - return StorageDefiner(Uint32ToName(env->context(), index), desc, info); + Local name; + if (!Uint32ToName(env->context(), index).ToLocal(&name)) { + // There was an error converting the index to a name. + // We aren't going to return a result but let's indicate + // that we intercepted the operation. + return Intercepted::kYes; + } + return StorageDefiner(name, desc, info); } static void StorageLengthGetter(const FunctionCallbackInfo& info) {