From da118db366dff1f4df324e242510d9ed3c84937b 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 1/3] src: make LoadEnvironment with string work with builtin modules path Fixes: https://github.com/nodejs/node/issues/40605 --- 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..458f932b101877 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 } From e40fd65216b3c36609697441c613ec142c7e3660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 26 Oct 2021 13:03:16 +0200 Subject: [PATCH 2/3] test: skip macos sandbox test with builtin modules path Refs: https://github.com/nodejs/node/issues/40605 --- test/parallel/test-macos-app-sandbox.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-macos-app-sandbox.js b/test/parallel/test-macos-app-sandbox.js index b6743e8ba50da4..7de50d4b4a2507 100644 --- a/test/parallel/test-macos-app-sandbox.js +++ b/test/parallel/test-macos-app-sandbox.js @@ -2,6 +2,8 @@ const common = require('../common'); if (process.platform !== 'darwin') common.skip('App Sandbox is only available on Darwin'); +if (process.config.variables.node_builtin_modules_path) + common.skip('App Sandbox cannot load modules from outside the sandbox'); const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); From c80b1bf4f822cd17d23a3b84915e7d74c9c42396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 26 Oct 2021 13:08:01 +0200 Subject: [PATCH 3/3] fixup! src: make LoadEnvironment with string work with builtin modules path --- src/node_native_module.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_native_module.cc b/src/node_native_module.cc index 458f932b101877..006a30903184d7 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -207,7 +207,7 @@ 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) { + 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())) {