Skip to content

Commit

Permalink
src: make LoadEnvironment with string work with builtin modules path
Browse files Browse the repository at this point in the history
Fixes: #40605

PR-URL: #40607
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
targos committed Nov 8, 2021
1 parent bbc10f1 commit fb7c437
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/node_native_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ static std::string OnDiskFileName(const char* id) {
MaybeLocal<String> 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;
Expand All @@ -222,13 +232,6 @@ MaybeLocal<String> 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
}

Expand Down

0 comments on commit fb7c437

Please sign in to comment.