From 795c8a4df40ba1ca835f45d59f1ec9e27fd5a5b4 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 19 Jul 2024 15:01:14 -0700 Subject: [PATCH] src: switch from ToLocalChecked to ToLocal in node_webstorage --- src/node_webstorage.cc | 98 +++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 29 deletions(-) diff --git a/src/node_webstorage.cc b/src/node_webstorage.cc index 6c3e19db1dbffc..c087bd381c9840 100644 --- a/src/node_webstorage.cc +++ b/src/node_webstorage.cc @@ -239,16 +239,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()); @@ -298,12 +301,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); } @@ -313,7 +318,7 @@ Local Storage::Load(Local key) { Local Storage::LoadKey(const int index) { if (!Open()) { - return Local(); + return {}; } static constexpr std::string_view sql = @@ -330,12 +335,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); } @@ -411,10 +418,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) { @@ -615,33 +620,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) {