src: fixup errorhandling more in various places
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run

PR-URL: https://github.com/nodejs/node/pull/57852
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
James M Snell 2025-04-20 20:01:30 -07:00 committed by GitHub
parent 422529a2e3
commit e773e09c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 42 additions and 21 deletions

View File

@ -144,7 +144,7 @@ MaybeLocal<Value> TryEncode(Isolate* isolate,
}
MaybeLocal<Value> TryEncode(Isolate* isolate, const uint16_t* buf, size_t len) {
return StringBytes::Encode(isolate, buf, len).ToLocalChecked();
return StringBytes::Encode(isolate, buf, len);
}
Local<Value> Encode(Isolate* isolate,

View File

@ -539,8 +539,11 @@ MaybeLocal<Value> LoadEnvironment(Environment* env,
return LoadEnvironment(
env,
[&](const StartExecutionCallbackInfo& info) -> MaybeLocal<Value> {
Local<Value> main_script =
ToV8Value(env->context(), main_script_source_utf8).ToLocalChecked();
Local<Value> main_script;
if (!ToV8Value(env->context(), main_script_source_utf8)
.ToLocal(&main_script)) {
return {};
}
return info.run_cjs->Call(
env->context(), Null(env->isolate()), 1, &main_script);
},

View File

@ -117,10 +117,13 @@ int JSStream::DoWrite(WriteWrap* w,
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
int value_int = UV_EPROTO;
MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
for (size_t i = 0; i < count; i++) {
bufs_arr[i] =
Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
return value_int;
}
}
Local<Value> argv[] = {
@ -130,7 +133,6 @@ int JSStream::DoWrite(WriteWrap* w,
TryCatchScope try_catch(env());
Local<Value> value;
int value_int = UV_EPROTO;
if (!MakeCallback(env()->onwrite_string(),
arraysize(argv),
argv).ToLocal(&value) ||

View File

@ -99,8 +99,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
for (size_t i = 0; i < nbufs; i++) {
buffers[i] = Buffer::Copy(env(), bufs[i].base, bufs[i].len)
.ToLocalChecked();
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
return value_int;
}
total_len += bufs[i].len;
}

View File

@ -1363,7 +1363,12 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
return false;
}
args.GetReturnValue().Set(result.ToLocalChecked());
// We checked for res being empty previously so this is a bit redundant
// but still safer than using ToLocalChecked.
Local<Value> res;
if (!result.ToLocal(&res)) return false;
args.GetReturnValue().Set(res);
return true;
}

View File

@ -414,8 +414,11 @@ class NgRcBufPointer : public MemoryRetainer {
const char* header_name = reinterpret_cast<const char*>(ptr.data());
v8::Eternal<v8::String>& eternal = static_str_map[header_name];
if (eternal.IsEmpty()) {
v8::Local<v8::String> str =
GetInternalizedString(env, ptr).ToLocalChecked();
v8::Local<v8::String> str;
if (!GetInternalizedString(env, ptr).ToLocal(&str)) {
ptr.reset();
return {};
}
eternal.Set(env->isolate(), str);
return str;
}

View File

@ -53,10 +53,12 @@ MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
EscapableHandleScope handle_scope(env->isolate());
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
Local<Function> constructor = env->pipe_constructor_template()
->GetFunction(env->context())
.ToLocalChecked();
CHECK_EQ(false, constructor.IsEmpty());
Local<Function> constructor;
if (!env->pipe_constructor_template()
->GetFunction(env->context())
.ToLocal(&constructor)) {
return {};
}
Local<Value> type_value = Int32::New(env->isolate(), type);
return handle_scope.EscapeMaybe(
constructor->NewInstance(env->context(), 1, &type_value));

View File

@ -59,10 +59,12 @@ MaybeLocal<Object> TCPWrap::Instantiate(Environment* env,
EscapableHandleScope handle_scope(env->isolate());
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
Local<Function> constructor = env->tcp_constructor_template()
->GetFunction(env->context())
.ToLocalChecked();
CHECK_EQ(constructor.IsEmpty(), false);
Local<Function> constructor;
if (!env->tcp_constructor_template()
->GetFunction(env->context())
.ToLocal(&constructor)) {
return {};
}
Local<Value> type_value = Int32::New(env->isolate(), type);
return handle_scope.EscapeMaybe(
constructor->NewInstance(env->context(), 1, &type_value));

View File

@ -811,8 +811,11 @@ v8::Maybe<int32_t> GetValidatedFd(Environment* env,
const bool is_out_of_range = fd < 0 || fd > INT32_MAX;
if (is_out_of_range || !IsSafeJsInt(input)) {
Utf8Value utf8_value(
env->isolate(), input->ToDetailString(env->context()).ToLocalChecked());
Local<String> str;
if (!input->ToDetailString(env->context()).ToLocal(&str)) {
return v8::Nothing<int32_t>();
}
Utf8Value utf8_value(env->isolate(), str);
if (is_out_of_range && !std::isinf(fd)) {
THROW_ERR_OUT_OF_RANGE(env,
"The value of \"fd\" is out of range. "