Skip to content

Commit 8e6af9f

Browse files
legendecasMoLow
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: nodejs#47695 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent d3449ca commit 8e6af9f

7 files changed

+12
-19
lines changed

src/api/environment.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
661661
}
662662
} else if (per_process::cli_options->disable_proto != "") {
663663
// Validated in ProcessGlobalArgs
664-
FatalError("InitializeContextRuntime()",
665-
"invalid --disable-proto mode");
664+
OnFatalError("InitializeContextRuntime()", "invalid --disable-proto mode");
666665
}
667666

668667
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;
@@ -898,8 +898,8 @@ void Agent::ToggleAsyncHook(Isolate* isolate, Local<Function> fn) {
898898
USE(fn->Call(context, Undefined(isolate), 0, nullptr));
899899
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
900900
PrintCaughtException(isolate, context, try_catch);
901-
FatalError("\nnode::inspector::Agent::ToggleAsyncHook",
902-
"Cannot toggle Inspector's AsyncHook, please report this.");
901+
OnFatalError("\nnode::inspector::Agent::ToggleAsyncHook",
902+
"Cannot toggle Inspector's AsyncHook, please report this.");
903903
}
904904
}
905905

src/node.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
645645
NODE_EXTERN IsolateData* GetEnvironmentIsolateData(Environment* env);
646646
NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);
647647

648-
NODE_EXTERN void OnFatalError(const char* location, const char* message);
648+
[[noreturn]] NODE_EXTERN void OnFatalError(const char* location,
649+
const char* message);
649650
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
650651
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
651652
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,7 @@ static void ReportFatalException(Environment* env,
499499
fflush(stderr);
500500
}
501501

502-
[[noreturn]] void FatalError(const char* location, const char* message) {
503-
OnFatalError(location, message);
504-
// to suppress compiler warning
505-
ABORT();
506-
}
507-
508-
void OnFatalError(const char* location, const char* message) {
502+
[[noreturn]] void OnFatalError(const char* location, const char* message) {
509503
if (location) {
510504
FPrintF(stderr, "FATAL ERROR: %s %s\n", location, message);
511505
} else {
@@ -527,7 +521,7 @@ void OnFatalError(const char* location, const char* message) {
527521
ABORT();
528522
}
529523

530-
void OOMErrorHandler(const char* location, bool is_heap_oom) {
524+
[[noreturn]] void OOMErrorHandler(const char* location, bool is_heap_oom) {
531525
const char* message =
532526
is_heap_oom ? "Allocation failed - JavaScript heap out of memory"
533527
: "Allocation failed - process out of memory";

src/node_errors.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void AppendExceptionLine(Environment* env,
2020
enum ErrorHandlingMode mode);
2121

2222
[[noreturn]] void FatalError(const char* location, const char* message);
23-
void OnFatalError(const char* location, const char* message);
24-
void OOMErrorHandler(const char* location, bool is_heap_oom);
23+
[[noreturn]] void OnFatalError(const char* location, const char* message);
24+
[[noreturn]] void OOMErrorHandler(const char* location, bool is_heap_oom);
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)