From bc0eb0a3ea30feed9d14954d2f37fb2bb518e0e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 26 Oct 2021 13:02:14 +0200 Subject: [PATCH] src: make LoadEnvironment with string work with builtin modules path Fixes: https://github.com/nodejs/node/issues/40605 PR-URL: https://github.com/nodejs/node/pull/40607 Reviewed-By: Geoffrey Booth Reviewed-By: Anna Henningsen --- src/node_native_module.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/node_native_module.cc b/src/node_native_module.cc index c4fd96c75c1862..006a30903184d7 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -207,6 +207,16 @@ static std::string OnDiskFileName(const char* id) { MaybeLocal NativeModuleLoader::LoadBuiltinModuleSource(Isolate* isolate, const char* id) { #ifdef NODE_BUILTIN_MODULES_PATH + if (strncmp(id, "embedder_main_", strlen("embedder_main_")) == 0) { +#endif // NODE_BUILTIN_MODULES_PATH + const auto source_it = source_.find(id); + if (UNLIKELY(source_it == source_.end())) { + fprintf(stderr, "Cannot find native builtin: \"%s\".\n", id); + ABORT(); + } + return source_it->second.ToStringChecked(isolate); +#ifdef NODE_BUILTIN_MODULES_PATH + } std::string filename = OnDiskFileName(id); std::string contents; @@ -222,13 +232,6 @@ MaybeLocal NativeModuleLoader::LoadBuiltinModuleSource(Isolate* isolate, } return String::NewFromUtf8( isolate, contents.c_str(), v8::NewStringType::kNormal, contents.length()); -#else - const auto source_it = source_.find(id); - if (UNLIKELY(source_it == source_.end())) { - fprintf(stderr, "Cannot find native builtin: \"%s\".\n", id); - ABORT(); - } - return source_it->second.ToStringChecked(isolate); #endif // NODE_BUILTIN_MODULES_PATH }