Skip to content

Commit 2acb57b

Browse files
legendecastargos
authored andcommitted
src: mark fatal error functions as noreturn
OnFatalError and OOMErrorHandler will not return control flow to the calling function. node::FatalError is an alias of node::OnFatalError. Replace all the callsites with node::OnFatalError instead. PR-URL: #47695 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent f88132f commit 2acb57b

7 files changed

+14
-20
lines changed

src/api/environment.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
726726
}
727727
} else if (per_process::cli_options->disable_proto != "") {
728728
// Validated in ProcessGlobalArgs
729-
FatalError("InitializeContextRuntime()",
730-
"invalid --disable-proto mode");
729+
OnFatalError("InitializeContextRuntime()", "invalid --disable-proto mode");
731730
}
732731

733732
return Just(true);

src/inspector_agent.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace node {
3636
namespace inspector {
3737
namespace {
3838

39-
using node::FatalError;
39+
using node::OnFatalError;
4040

4141
using v8::Context;
4242
using v8::Function;
@@ -901,8 +901,8 @@ void Agent::ToggleAsyncHook(Isolate* isolate, Local<Function> fn) {
901901
USE(fn->Call(context, Undefined(isolate), 0, nullptr));
902902
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
903903
PrintCaughtException(isolate, context, try_catch);
904-
FatalError("\nnode::inspector::Agent::ToggleAsyncHook",
905-
"Cannot toggle Inspector's AsyncHook, please report this.");
904+
OnFatalError("\nnode::inspector::Agent::ToggleAsyncHook",
905+
"Cannot toggle Inspector's AsyncHook, please report this.");
906906
}
907907
}
908908

src/node.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);
722722
// a snapshot and have a main context that was read from that snapshot.
723723
NODE_EXTERN v8::Local<v8::Context> GetMainContext(Environment* env);
724724

725-
NODE_EXTERN void OnFatalError(const char* location, const char* message);
725+
[[noreturn]] NODE_EXTERN void OnFatalError(const char* location,
726+
const char* message);
726727
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
727728
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
728729
v8::Local<v8::String>);

src/node_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ NAPI_NO_RETURN void NAPI_CDECL napi_fatal_error(const char* location,
805805
message_string.assign(const_cast<char*>(message), strlen(message));
806806
}
807807

808-
node::FatalError(location_string.c_str(), message_string.c_str());
808+
node::OnFatalError(location_string.c_str(), message_string.c_str());
809809
}
810810

811811
napi_status NAPI_CDECL

src/node_errors.cc

+3-8
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,7 @@ static void ReportFatalException(Environment* env,
504504
fflush(stderr);
505505
}
506506

507-
[[noreturn]] void FatalError(const char* location, const char* message) {
508-
OnFatalError(location, message);
509-
// to suppress compiler warning
510-
ABORT();
511-
}
512-
513-
void OnFatalError(const char* location, const char* message) {
507+
[[noreturn]] void OnFatalError(const char* location, const char* message) {
514508
if (location) {
515509
FPrintF(stderr, "FATAL ERROR: %s %s\n", location, message);
516510
} else {
@@ -532,7 +526,8 @@ void OnFatalError(const char* location, const char* message) {
532526
ABORT();
533527
}
534528

535-
void OOMErrorHandler(const char* location, const v8::OOMDetails& details) {
529+
[[noreturn]] void OOMErrorHandler(const char* location,
530+
const v8::OOMDetails& details) {
536531
const char* message =
537532
details.is_heap_oom ? "Allocation failed - JavaScript heap out of memory"
538533
: "Allocation failed - process out of memory";

src/node_errors.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void AppendExceptionLine(Environment* env,
1919
v8::Local<v8::Message> message,
2020
enum ErrorHandlingMode mode);
2121

22-
[[noreturn]] void FatalError(const char* location, const char* message);
23-
void OnFatalError(const char* location, const char* message);
24-
void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
22+
[[noreturn]] void OnFatalError(const char* location, const char* message);
23+
[[noreturn]] void OOMErrorHandler(const char* location,
24+
const v8::OOMDetails& details);
2525

2626
// Helpers to construct errors similar to the ones provided by
2727
// lib/internal/errors.js.

src/node_watchdog.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms, bool* timed_out)
4545
int rc;
4646
rc = uv_loop_init(&loop_);
4747
if (rc != 0) {
48-
FatalError("node::Watchdog::Watchdog()",
49-
"Failed to initialize uv loop.");
48+
OnFatalError("node::Watchdog::Watchdog()", "Failed to initialize uv loop.");
5049
}
5150

5251
rc = uv_async_init(&loop_, &async_, [](uv_async_t* signal) {

0 commit comments

Comments
 (0)