diff --git a/src/node_builtins.cc b/src/node_builtins.cc index be960df02223ad..82d9d6cd2e99b9 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -10,8 +10,10 @@ namespace node { namespace builtins { +using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; +using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::IntegrityLevel; @@ -19,6 +21,7 @@ using v8::Isolate; using v8::Local; using v8::MaybeLocal; using v8::Name; +using v8::NewStringType; using v8::None; using v8::Object; using v8::ObjectTemplate; @@ -28,6 +31,7 @@ using v8::ScriptOrigin; using v8::Set; using v8::SideEffectType; using v8::String; +using v8::TryCatch; using v8::Undefined; using v8::Value; @@ -201,11 +205,11 @@ MaybeLocal BuiltinLoader::LoadBuiltinSource(Isolate* isolate, uv_strerror(r), filename); Local message = OneByteString(isolate, buf); - isolate->ThrowException(v8::Exception::Error(message)); + isolate->ThrowException(Exception::Error(message)); return MaybeLocal(); } return String::NewFromUtf8( - isolate, contents.c_str(), v8::NewStringType::kNormal, contents.length()); + isolate, contents.c_str(), NewStringType::kNormal, contents.length()); #endif // NODE_BUILTIN_MODULES_PATH } @@ -529,7 +533,7 @@ bool BuiltinLoader::CompileAllBuiltinsAndCopyCodeCache( to_eager_compile_.emplace(id); } - v8::TryCatch bootstrapCatch(context->GetIsolate()); + TryCatch bootstrapCatch(context->GetIsolate()); auto fn = LookupAndCompile(context, id.data(), nullptr); if (bootstrapCatch.HasCaught()) { per_process::Debug(DebugCategory::CODE_CACHE, @@ -582,18 +586,15 @@ void BuiltinLoader::GetBuiltinCategories( Local can_be_required_js; if (!ToV8Value(context, builtin_categories.cannot_be_required) - .ToLocal(&cannot_be_required_js)) - return; - if (result + .ToLocal(&cannot_be_required_js) || + result ->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cannotBeRequired"), cannot_be_required_js) - .IsNothing()) - return; - if (!ToV8Value(context, builtin_categories.can_be_required) - .ToLocal(&can_be_required_js)) - return; - if (result + .IsNothing() || + !ToV8Value(context, builtin_categories.can_be_required) + .ToLocal(&can_be_required_js) || + result ->Set(context, FIXED_ONE_BYTE_STRING(isolate, "canBeRequired"), can_be_required_js) @@ -613,34 +614,22 @@ void BuiltinLoader::GetCacheUsage(const FunctionCallbackInfo& args) { Local builtins_without_cache_js; Local builtins_in_snapshot_js; if (!ToV8Value(context, realm->builtins_with_cache) - .ToLocal(&builtins_with_cache_js)) { - return; - } - if (result + .ToLocal(&builtins_with_cache_js) || + result ->Set(context, FIXED_ONE_BYTE_STRING(isolate, "compiledWithCache"), builtins_with_cache_js) - .IsNothing()) { - return; - } - - if (!ToV8Value(context, realm->builtins_without_cache) - .ToLocal(&builtins_without_cache_js)) { - return; - } - if (result + .IsNothing() || + !ToV8Value(context, realm->builtins_without_cache) + .ToLocal(&builtins_without_cache_js) || + result ->Set(context, FIXED_ONE_BYTE_STRING(isolate, "compiledWithoutCache"), builtins_without_cache_js) - .IsNothing()) { - return; - } - - if (!ToV8Value(context, realm->builtins_in_snapshot) - .ToLocal(&builtins_in_snapshot_js)) { - return; - } - if (result + .IsNothing() || + !ToV8Value(context, realm->builtins_in_snapshot) + .ToLocal(&builtins_in_snapshot_js) || + result ->Set(context, FIXED_ONE_BYTE_STRING(isolate, "compiledInSnapshot"), builtins_in_snapshot_js) @@ -657,8 +646,10 @@ void BuiltinLoader::BuiltinIdsGetter(Local property, Isolate* isolate = env->isolate(); auto ids = env->builtin_loader()->GetBuiltinIds(); - info.GetReturnValue().Set( - ToV8Value(isolate->GetCurrentContext(), ids).ToLocalChecked()); + Local ret; + if (ToV8Value(isolate->GetCurrentContext(), ids).ToLocal(&ret)) { + info.GetReturnValue().Set(ret); + } } void BuiltinLoader::ConfigStringGetter( @@ -694,7 +685,7 @@ void BuiltinLoader::CompileFunction(const FunctionCallbackInfo& args) { void BuiltinLoader::HasCachedBuiltins(const FunctionCallbackInfo& args) { auto instance = Environment::GetCurrent(args)->builtin_loader(); RwLock::ScopedReadLock lock(instance->code_cache_->mutex); - args.GetReturnValue().Set(v8::Boolean::New( + args.GetReturnValue().Set(Boolean::New( args.GetIsolate(), instance->code_cache_->has_code_cache)); } diff --git a/src/node_http2.cc b/src/node_http2.cc index 38b3046861e805..af7698797278e4 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2928,9 +2928,11 @@ void Http2Session::UpdateChunksSent(const FunctionCallbackInfo& args) { uint32_t length = session->chunks_sent_since_last_write_; - session->object()->Set(env->context(), - env->chunks_sent_since_last_write_string(), - Integer::NewFromUnsigned(isolate, length)).Check(); + if (session->object()->Set(env->context(), + env->chunks_sent_since_last_write_string(), + Integer::NewFromUnsigned(isolate, length)).IsNothing()) { + return; + } args.GetReturnValue().Set(length); } @@ -3109,11 +3111,13 @@ void Http2Session::AltSvc(const FunctionCallbackInfo& args) { int32_t id = args[0]->Int32Value(env->context()).ToChecked(); // origin and value are both required to be ASCII, handle them as such. - Local origin_str = args[1]->ToString(env->context()).ToLocalChecked(); - Local value_str = args[2]->ToString(env->context()).ToLocalChecked(); + Local origin_str; + Local value_str; - if (origin_str.IsEmpty() || value_str.IsEmpty()) + if (!args[1]->ToString(env->context()).ToLocal(&origin_str) || + !args[2]->ToString(env->context()).ToLocal(&value_str)) { return; + } size_t origin_len = origin_str->Length(); size_t value_len = value_str->Length(); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 6ea4aa826e1c30..acebdd952eb943 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -736,12 +736,13 @@ class Parser : public AsyncWrap, public StreamListener { Parser* parser; ASSIGN_OR_RETURN_UNWRAP(&parser, args.This()); - Local ret = Buffer::Copy( + Local ret; + if (Buffer::Copy( parser->env(), parser->current_buffer_data_, - parser->current_buffer_len_).ToLocalChecked(); - - args.GetReturnValue().Set(ret); + parser->current_buffer_len_).ToLocal(&ret)) { + args.GetReturnValue().Set(ret); + } } static void Duration(const FunctionCallbackInfo& args) {