From bf4e51972afe0f81ed5da94aaaac0f9c4a10b779 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Thu, 2 Feb 2023 20:42:35 +0530 Subject: [PATCH] src: call IsSingleExecutable() before FindSingleExecutableCode() This also serves as a workaround for https://github.com/nodejs/postject/issues/70. Signed-off-by: Darshan Sen --- src/node.cc | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/node.cc b/src/node.cc index e260e3dcc56a90..1bbaf09616ba2f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -312,23 +312,25 @@ MaybeLocal StartExecution(Environment* env, StartExecutionCallback cb) { } #ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION - size_t single_executable_application_size = 0; - const char* single_executable_application_code = - FindSingleExecutableCode(&single_executable_application_size); - if (single_executable_application_code != nullptr) { - Local buffer = - Buffer::New( - env->isolate(), - const_cast(single_executable_application_code), - single_executable_application_size, - [](char* data, void* hint) {}, - nullptr) - .ToLocalChecked(); - env->process_object() - ->SetPrivate( - env->context(), env->single_executable_application_code(), buffer) - .Check(); - return StartExecution(env, "internal/main/single_executable_application"); + if (IsSingleExecutable()) { + size_t single_executable_application_size = 0; + const char* single_executable_application_code = + FindSingleExecutableCode(&single_executable_application_size); + if (single_executable_application_code != nullptr) { + Local buffer = + Buffer::New( + env->isolate(), + const_cast(single_executable_application_code), + single_executable_application_size, + [](char* data, void* hint) {}, + nullptr) + .ToLocalChecked(); + env->process_object() + ->SetPrivate( + env->context(), env->single_executable_application_code(), buffer) + .Check(); + return StartExecution(env, "internal/main/single_executable_application"); + } } #endif