GeezerVison is showing github.com — src: fixup errorhandling more in various places · nodejs/node@99ed503
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/encoding.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,7 +144,7 @@ MaybeLocal<Value> TryEncode(Isolate* isolate, | 144 | 144 | } | 145 | 145 |
| 146 | 146 | 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); | 148 | 148 | } | 149 | 149 |
| 150 | 150 | Local<Value> Encode(Isolate* isolate, | |
Collapse file Copy file name to clipboardExpand all lines: src/api/environment.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -539,8 +539,11 @@ MaybeLocal<Value> LoadEnvironment(Environment* env, | 539 | 539 | return LoadEnvironment( | 540 | 540 | env, | 541 | 541 | [&](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 | + } | 544 | 547 | return info.run_cjs->Call( | 545 | 548 | env->context(), Null(env->isolate()), 1, &main_script); | 546 | 549 | }, | |
Collapse file Copy file name to clipboardExpand all lines: src/js_stream.cc +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -117,10 +117,13 @@ int JSStream::DoWrite(WriteWrap* w, | 117 | 117 | HandleScope scope(env()->isolate()); | 118 | 118 | Context::Scope context_scope(env()->context()); | 119 | 119 |
| | 120 | + int value_int = UV_EPROTO; | | 121 | + | 120 | 122 | MaybeStackBuffer<Local<Value>, 16> bufs_arr(count); | 121 | 123 | 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 | + } | 124 | 127 | } | 125 | 128 |
| 126 | 129 | Local<Value> argv[] = { | @@ -130,7 +133,6 @@ int JSStream::DoWrite(WriteWrap* w, | 130 | 133 |
| 131 | 134 | TryCatchScope try_catch(env()); | 132 | 135 | Local<Value> value; | 133 | | - int value_int = UV_EPROTO; | 134 | 136 | if (!MakeCallback(env()->onwrite_string(), | 135 | 137 | arraysize(argv), | 136 | 138 | argv).ToLocal(&value) || | |
Collapse file Copy file name to clipboardExpand all lines: src/js_udp_wrap.cc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,8 +99,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs, | 99 | 99 |
| 100 | 100 | MaybeStackBuffer<Local<Value>, 16> buffers(nbufs); | 101 | 101 | 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 | + } | 104 | 105 | total_len += bufs[i].len; | 105 | 106 | } | 106 | 107 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_contextify.cc +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1363,7 +1363,12 @@ bool ContextifyScript::EvalMachine(Local<Context> context, | 1363 | 1363 | return false; | 1364 | 1364 | } | 1365 | 1365 |
| 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); | 1367 | 1372 | return true; | 1368 | 1373 | } | 1369 | 1374 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_http_common.h +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -414,8 +414,11 @@ class NgRcBufPointer : public MemoryRetainer { | 414 | 414 | const char* header_name = reinterpret_cast<const char*>(ptr.data()); | 415 | 415 | v8::Eternal<v8::String>& eternal = static_str_map[header_name]; | 416 | 416 | 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 | + } | 419 | 422 | eternal.Set(env->isolate(), str); | 420 | 423 | return str; | 421 | 424 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/pipe_wrap.cc +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,10 +53,12 @@ MaybeLocal<Object> PipeWrap::Instantiate(Environment* env, | 53 | 53 | EscapableHandleScope handle_scope(env->isolate()); | 54 | 54 | AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); | 55 | 55 | 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 | + } | 60 | 62 | Local<Value> type_value = Int32::New(env->isolate(), type); | 61 | 63 | return handle_scope.EscapeMaybe( | 62 | 64 | constructor->NewInstance(env->context(), 1, &type_value)); | |
Collapse file Copy file name to clipboardExpand all lines: src/tcp_wrap.cc +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,10 +59,12 @@ MaybeLocal<Object> TCPWrap::Instantiate(Environment* env, | 59 | 59 | EscapableHandleScope handle_scope(env->isolate()); | 60 | 60 | AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); | 61 | 61 | 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 | + } | 66 | 68 | Local<Value> type_value = Int32::New(env->isolate(), type); | 67 | 69 | return handle_scope.EscapeMaybe( | 68 | 70 | constructor->NewInstance(env->context(), 1, &type_value)); | |
Collapse file Copy file name to clipboardExpand all lines: src/util.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -811,8 +811,11 @@ v8::Maybe<int32_t> GetValidatedFd(Environment* env, | 811 | 811 | const bool is_out_of_range = fd < 0 || fd > INT32_MAX; | 812 | 812 |
| 813 | 813 | 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); | 816 | 819 | if (is_out_of_range && !std::isinf(fd)) { | 817 | 820 | THROW_ERR_OUT_OF_RANGE(env, | 818 | 821 | "The value of \"fd\" is out of range. " | |
|