Skip to content

Commit 99ed503

Browse files
jasnellRafaelGSS
authored andcommitted
src: fixup errorhandling more in various places
PR-URL: #57852 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent f2fd19e commit 99ed503

File tree

9 files changed

+42
-21
lines changed

9 files changed

+42
-21
lines changed

src/api/encoding.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ MaybeLocal<Value> TryEncode(Isolate* isolate,
144144
}
145145

146146
MaybeLocal<Value> TryEncode(Isolate* isolate, const uint16_t* buf, size_t len) {
147-
return StringBytes::Encode(isolate, buf, len).ToLocalChecked();
147+
return StringBytes::Encode(isolate, buf, len);
148148
}
149149

150150
Local<Value> Encode(Isolate* isolate,

src/api/environment.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,11 @@ MaybeLocal<Value> LoadEnvironment(Environment* env,
539539
return LoadEnvironment(
540540
env,
541541
[&](const StartExecutionCallbackInfo& info) -> MaybeLocal<Value> {
542-
Local<Value> main_script =
543-
ToV8Value(env->context(), main_script_source_utf8).ToLocalChecked();
542+
Local<Value> main_script;
543+
if (!ToV8Value(env->context(), main_script_source_utf8)
544+
.ToLocal(&main_script)) {
545+
return {};
546+
}
544547
return info.run_cjs->Call(
545548
env->context(), Null(env->isolate()), 1, &main_script);
546549
},

src/js_stream.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,13 @@ int JSStream::DoWrite(WriteWrap* w,
117117
HandleScope scope(env()->isolate());
118118
Context::Scope context_scope(env()->context());
119119

120+
int value_int = UV_EPROTO;
121+
120122
MaybeStackBuffer<Local<Value>, 16> bufs_arr(count);
121123
for (size_t i = 0; i < count; i++) {
122-
bufs_arr[i] =
123-
Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
124+
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) {
125+
return value_int;
126+
}
124127
}
125128

126129
Local<Value> argv[] = {
@@ -130,7 +133,6 @@ int JSStream::DoWrite(WriteWrap* w,
130133

131134
TryCatchScope try_catch(env());
132135
Local<Value> value;
133-
int value_int = UV_EPROTO;
134136
if (!MakeCallback(env()->onwrite_string(),
135137
arraysize(argv),
136138
argv).ToLocal(&value) ||

src/js_udp_wrap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs,
9999

100100
MaybeStackBuffer<Local<Value>, 16> buffers(nbufs);
101101
for (size_t i = 0; i < nbufs; i++) {
102-
buffers[i] = Buffer::Copy(env(), bufs[i].base, bufs[i].len)
103-
.ToLocalChecked();
102+
if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) {
103+
return value_int;
104+
}
104105
total_len += bufs[i].len;
105106
}
106107

src/node_contextify.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,12 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
13631363
return false;
13641364
}
13651365

1366-
args.GetReturnValue().Set(result.ToLocalChecked());
1366+
// We checked for res being empty previously so this is a bit redundant
1367+
// but still safer than using ToLocalChecked.
1368+
Local<Value> res;
1369+
if (!result.ToLocal(&res)) return false;
1370+
1371+
args.GetReturnValue().Set(res);
13671372
return true;
13681373
}
13691374

src/node_http_common.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,11 @@ class NgRcBufPointer : public MemoryRetainer {
414414
const char* header_name = reinterpret_cast<const char*>(ptr.data());
415415
v8::Eternal<v8::String>& eternal = static_str_map[header_name];
416416
if (eternal.IsEmpty()) {
417-
v8::Local<v8::String> str =
418-
GetInternalizedString(env, ptr).ToLocalChecked();
417+
v8::Local<v8::String> str;
418+
if (!GetInternalizedString(env, ptr).ToLocal(&str)) {
419+
ptr.reset();
420+
return {};
421+
}
419422
eternal.Set(env->isolate(), str);
420423
return str;
421424
}

src/pipe_wrap.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
5353
EscapableHandleScope handle_scope(env->isolate());
5454
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
5555
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
56-
Local<Function> constructor = env->pipe_constructor_template()
57-
->GetFunction(env->context())
58-
.ToLocalChecked();
59-
CHECK_EQ(false, constructor.IsEmpty());
56+
Local<Function> constructor;
57+
if (!env->pipe_constructor_template()
58+
->GetFunction(env->context())
59+
.ToLocal(&constructor)) {
60+
return {};
61+
}
6062
Local<Value> type_value = Int32::New(env->isolate(), type);
6163
return handle_scope.EscapeMaybe(
6264
constructor->NewInstance(env->context(), 1, &type_value));

src/tcp_wrap.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ MaybeLocal<Object> TCPWrap::Instantiate(Environment* env,
5959
EscapableHandleScope handle_scope(env->isolate());
6060
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
6161
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
62-
Local<Function> constructor = env->tcp_constructor_template()
63-
->GetFunction(env->context())
64-
.ToLocalChecked();
65-
CHECK_EQ(constructor.IsEmpty(), false);
62+
Local<Function> constructor;
63+
if (!env->tcp_constructor_template()
64+
->GetFunction(env->context())
65+
.ToLocal(&constructor)) {
66+
return {};
67+
}
6668
Local<Value> type_value = Int32::New(env->isolate(), type);
6769
return handle_scope.EscapeMaybe(
6870
constructor->NewInstance(env->context(), 1, &type_value));

src/util.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,11 @@ v8::Maybe<int32_t> GetValidatedFd(Environment* env,
811811
const bool is_out_of_range = fd < 0 || fd > INT32_MAX;
812812

813813
if (is_out_of_range || !IsSafeJsInt(input)) {
814-
Utf8Value utf8_value(
815-
env->isolate(), input->ToDetailString(env->context()).ToLocalChecked());
814+
Local<String> str;
815+
if (!input->ToDetailString(env->context()).ToLocal(&str)) {
816+
return v8::Nothing<int32_t>();
817+
}
818+
Utf8Value utf8_value(env->isolate(), str);
816819
if (is_out_of_range && !std::isinf(fd)) {
817820
THROW_ERR_OUT_OF_RANGE(env,
818821
"The value of \"fd\" is out of range. "

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy