summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/bootstrap/loaders.js2
-rw-r--r--lib/internal/bootstrap/node.js4
-rw-r--r--lib/internal/main/.eslintrc.yaml2
-rw-r--r--lib/internal/main/check_syntax.js5
-rw-r--r--lib/internal/main/environment.js (renamed from lib/internal/bootstrap/environment.js)6
-rw-r--r--lib/internal/main/eval_stdin.js5
-rw-r--r--lib/internal/main/eval_string.js5
-rw-r--r--lib/internal/main/inspect.js5
-rw-r--r--lib/internal/main/mksnapshot.js2
-rw-r--r--lib/internal/main/print_help.js5
-rw-r--r--lib/internal/main/prof_process.js5
-rw-r--r--lib/internal/main/repl.js5
-rw-r--r--lib/internal/main/run_main_module.js5
-rw-r--r--lib/internal/main/test_runner.js3
-rw-r--r--lib/internal/main/worker_thread.js5
-rw-r--r--lib/internal/process/pre_execution.js (renamed from lib/internal/bootstrap/pre_execution.js)7
-rw-r--r--lib/internal/v8/startup_snapshot.js6
-rw-r--r--lib/internal/wasm_web_api.js2
-rw-r--r--src/api/environment.cc15
-rw-r--r--src/node.cc68
-rw-r--r--src/node_internals.h1
-rw-r--r--src/node_native_module.cc91
-rw-r--r--src/node_native_module.h8
-rw-r--r--src/node_perf.cc8
-rw-r--r--src/node_snapshotable.cc5
-rw-r--r--test/parallel/test-bootstrap-modules.js2
-rw-r--r--test/parallel/test-code-cache.js16
27 files changed, 156 insertions, 137 deletions
diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js
index 41162fabcb..4c7a9acef2 100644
--- a/lib/internal/bootstrap/loaders.js
+++ b/lib/internal/bootstrap/loaders.js
@@ -326,6 +326,8 @@ class NativeModule {
requireWithFallbackInDeps : nativeModuleRequire;
const fn = compileFunction(id);
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
fn(this.exports, requireFn, this, process, internalBinding, primordials);
this.loaded = true;
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index df2afb84b5..14eb4bbcca 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -6,7 +6,7 @@
//
// This file is expected not to perform any asynchronous operations itself
// when being executed - those should be done in either
-// `lib/internal/bootstrap/pre_execution.js` or in main scripts. The majority
+// `lib/internal/process/pre_execution.js` or in main scripts. The majority
// of the code here focuses on setting up the global proxy and the process
// object in a synchronous manner.
// As special caution is given to the performance of the startup process,
@@ -28,7 +28,7 @@
// Then, depending on how the Node.js instance is launched, one of the main
// scripts in `lib/internal/main` will be selected by C++ to start the actual
// execution. They may run additional setups exported by
-// `lib/internal/bootstrap/pre_execution.js` depending on the runtime states.
+// `lib/internal/process/pre_execution.js` depending on the runtime states.
'use strict';
diff --git a/lib/internal/main/.eslintrc.yaml b/lib/internal/main/.eslintrc.yaml
deleted file mode 100644
index dfb7507778..0000000000
--- a/lib/internal/main/.eslintrc.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-globals:
- markBootstrapComplete: true
diff --git a/lib/internal/main/check_syntax.js b/lib/internal/main/check_syntax.js
index cf6f15290d..65f578be50 100644
--- a/lib/internal/main/check_syntax.js
+++ b/lib/internal/main/check_syntax.js
@@ -5,8 +5,9 @@
const { getOptionValue } = require('internal/options');
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const {
readStdin
diff --git a/lib/internal/bootstrap/environment.js b/lib/internal/main/environment.js
index 79a67dae37..0be982bfb6 100644
--- a/lib/internal/bootstrap/environment.js
+++ b/lib/internal/main/environment.js
@@ -4,10 +4,10 @@
// that depends on run time states.
// It is currently only intended for preparing contexts for embedders.
-/* global markBootstrapComplete */
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
prepareMainThreadExecution();
markBootstrapComplete();
diff --git a/lib/internal/main/eval_stdin.js b/lib/internal/main/eval_stdin.js
index 056d394b12..0a6d990601 100644
--- a/lib/internal/main/eval_stdin.js
+++ b/lib/internal/main/eval_stdin.js
@@ -3,8 +3,9 @@
// Stdin is not a TTY, we will read it and execute it.
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const { getOptionValue } = require('internal/options');
diff --git a/lib/internal/main/eval_string.js b/lib/internal/main/eval_string.js
index 64a01fee5e..e7baef4526 100644
--- a/lib/internal/main/eval_string.js
+++ b/lib/internal/main/eval_string.js
@@ -8,8 +8,9 @@ const {
} = primordials;
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const { evalModule, evalScript } = require('internal/process/execution');
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
diff --git a/lib/internal/main/inspect.js b/lib/internal/main/inspect.js
index b3b26ecaa9..6c4cc7cc36 100644
--- a/lib/internal/main/inspect.js
+++ b/lib/internal/main/inspect.js
@@ -3,8 +3,9 @@
// `node inspect ...` or `node debug ...`
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
prepareMainThreadExecution();
diff --git a/lib/internal/main/mksnapshot.js b/lib/internal/main/mksnapshot.js
index 616a436e0a..fdf0e02120 100644
--- a/lib/internal/main/mksnapshot.js
+++ b/lib/internal/main/mksnapshot.js
@@ -114,7 +114,7 @@ function requireForUserSnapshot(id) {
function main() {
const {
prepareMainThreadExecution
- } = require('internal/bootstrap/pre_execution');
+ } = require('internal/process/pre_execution');
prepareMainThreadExecution(true, false);
diff --git a/lib/internal/main/print_help.js b/lib/internal/main/print_help.js
index f8fc5a6075..bfef215ace 100644
--- a/lib/internal/main/print_help.js
+++ b/lib/internal/main/print_help.js
@@ -20,8 +20,9 @@ const { types } = internalBinding('options');
const hasCrypto = Boolean(process.versions.openssl);
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const typeLookup = [];
for (const key of ObjectKeys(types))
diff --git a/lib/internal/main/prof_process.js b/lib/internal/main/prof_process.js
index bd835bfe63..3d56e3ec57 100644
--- a/lib/internal/main/prof_process.js
+++ b/lib/internal/main/prof_process.js
@@ -1,8 +1,9 @@
'use strict';
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
prepareMainThreadExecution();
markBootstrapComplete();
diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js
index a8356687cc..7da68dc05e 100644
--- a/lib/internal/main/repl.js
+++ b/lib/internal/main/repl.js
@@ -4,8 +4,9 @@
// the main module is not specified and stdin is a TTY.
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const esmLoader = require('internal/process/esm_loader');
const {
diff --git a/lib/internal/main/run_main_module.js b/lib/internal/main/run_main_module.js
index ca5d1122c5..1c2d421fc0 100644
--- a/lib/internal/main/run_main_module.js
+++ b/lib/internal/main/run_main_module.js
@@ -1,8 +1,9 @@
'use strict';
const {
- prepareMainThreadExecution
-} = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
prepareMainThreadExecution(true);
diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js
index c1066cfca3..d28311f3ab 100644
--- a/lib/internal/main/test_runner.js
+++ b/lib/internal/main/test_runner.js
@@ -12,7 +12,8 @@ const {
} = primordials;
const {
prepareMainThreadExecution,
-} = require('internal/bootstrap/pre_execution');
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const { spawn } = require('child_process');
const { readdirSync, statSync } = require('fs');
const console = require('internal/console/global');
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js
index 8d5bc45edd..01f711aab2 100644
--- a/lib/internal/main/worker_thread.js
+++ b/lib/internal/main/worker_thread.js
@@ -30,8 +30,9 @@ const {
initializeReport,
initializeSourceMapsHandlers,
loadPreloadModules,
- setupTraceCategoryState
-} = require('internal/bootstrap/pre_execution');
+ setupTraceCategoryState,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
const {
threadId,
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/process/pre_execution.js
index 9e407dd29b..923311d7ac 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/process/pre_execution.js
@@ -596,6 +596,10 @@ function loadPreloadModules() {
}
}
+function markBootstrapComplete() {
+ internalBinding('performance').markBootstrapComplete();
+}
+
module.exports = {
refreshRuntimeOptions,
patchProcessObject,
@@ -616,5 +620,6 @@ module.exports = {
setupInspectorHooks,
initializeReport,
initializeCJSLoader,
- initializeWASI
+ initializeWASI,
+ markBootstrapComplete
};
diff --git a/lib/internal/v8/startup_snapshot.js b/lib/internal/v8/startup_snapshot.js
index 6a6a6c47e8..86bee87495 100644
--- a/lib/internal/v8/startup_snapshot.js
+++ b/lib/internal/v8/startup_snapshot.js
@@ -12,7 +12,6 @@ const {
setSerializeCallback,
setDeserializeCallback,
setDeserializeMainFunction: _setDeserializeMainFunction,
- markBootstrapComplete
} = internalBinding('mksnapshot');
function isBuildingSnapshot() {
@@ -87,8 +86,9 @@ function setDeserializeMainFunction(callback, data) {
_setDeserializeMainFunction(function deserializeMain() {
const {
- prepareMainThreadExecution
- } = require('internal/bootstrap/pre_execution');
+ prepareMainThreadExecution,
+ markBootstrapComplete
+ } = require('internal/process/pre_execution');
// This should be in sync with run_main_module.js until we make that
// a built-in main function.
diff --git a/lib/internal/wasm_web_api.js b/lib/internal/wasm_web_api.js
index 084a223806..8b28b5e1fb 100644
--- a/lib/internal/wasm_web_api.js
+++ b/lib/internal/wasm_web_api.js
@@ -15,7 +15,7 @@ function lazyUndici() {
// This is essentially an implementation of a v8::WasmStreamingCallback, except
// that it is implemented in JavaScript because the fetch() implementation is
-// difficult to use from C++. See lib/internal/bootstrap/pre_execution.js and
+// difficult to use from C++. See lib/internal/process/pre_execution.js and
// src/node_wasm_web_api.cc that interact with this function.
function wasmStreamingCallback(streamState, source) {
(async () => {
diff --git a/src/api/environment.cc b/src/api/environment.cc
index 3257f160bd..acf59f7154 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -452,13 +452,12 @@ MaybeLocal<Value> LoadEnvironment(
native_module::NativeModuleLoader::Add(
name.c_str(), UnionBytes(**main_utf16, main_utf16->length()));
env->set_main_utf16(std::move(main_utf16));
- std::vector<Local<String>> params = {
- env->process_string(),
- env->require_string()};
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
std::vector<Local<Value>> args = {
env->process_object(),
env->native_module_require()};
- return ExecuteBootstrapper(env, name.c_str(), &params, &args);
+ return ExecuteBootstrapper(env, name.c_str(), &args);
});
}
@@ -683,8 +682,6 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
Local<String> primordials_string =
FIXED_ONE_BYTE_STRING(isolate, "primordials");
- Local<String> global_string = FIXED_ONE_BYTE_STRING(isolate, "global");
- Local<String> exports_string = FIXED_ONE_BYTE_STRING(isolate, "exports");
// Create primordials first and make it available to per-context scripts.
Local<Object> primordials = Object::New(isolate);
@@ -700,12 +697,12 @@ Maybe<bool> InitializePrimordials(Local<Context> context) {
nullptr};
for (const char** module = context_files; *module != nullptr; module++) {
- std::vector<Local<String>> parameters = {
- global_string, exports_string, primordials_string};
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
Local<Value> arguments[] = {context->Global(), exports, primordials};
MaybeLocal<Function> maybe_fn =
native_module::NativeModuleLoader::LookupAndCompile(
- context, *module, &parameters, nullptr);
+ context, *module, nullptr);
Local<Function> fn;
if (!maybe_fn.ToLocal(&fn)) {
return Nothing<bool>();
diff --git a/src/node.cc b/src/node.cc
index 395ff47feb..f1cd377488 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -125,7 +125,6 @@ using native_module::NativeModuleLoader;
using v8::EscapableHandleScope;
using v8::Function;
-using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
@@ -170,11 +169,10 @@ void SignalExit(int signo, siginfo_t* info, void* ucontext) {
MaybeLocal<Value> ExecuteBootstrapper(Environment* env,
const char* id,
- std::vector<Local<String>>* parameters,
std::vector<Local<Value>>* arguments) {
EscapableHandleScope scope(env->isolate());
MaybeLocal<Function> maybe_fn =
- NativeModuleLoader::LookupAndCompile(env->context(), id, parameters, env);
+ NativeModuleLoader::LookupAndCompile(env->context(), id, env);
Local<Function> fn;
if (!maybe_fn.ToLocal(&fn)) {
@@ -293,12 +291,8 @@ void Environment::InitializeDiagnostics() {
MaybeLocal<Value> Environment::BootstrapInternalLoaders() {
EscapableHandleScope scope(isolate_);
- // Create binding loaders
- std::vector<Local<String>> loaders_params = {
- process_string(),
- FIXED_ONE_BYTE_STRING(isolate_, "getLinkedBinding"),
- FIXED_ONE_BYTE_STRING(isolate_, "getInternalBinding"),
- primordials_string()};
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
std::vector<Local<Value>> loaders_args = {
process_object(),
NewFunctionTemplate(isolate_, binding::GetLinkedBinding)
@@ -311,8 +305,7 @@ MaybeLocal<Value> Environment::BootstrapInternalLoaders() {
// Bootstrap internal loaders
Local<Value> loader_exports;
- if (!ExecuteBootstrapper(
- this, "internal/bootstrap/loaders", &loaders_params, &loaders_args)
+ if (!ExecuteBootstrapper(this, "internal/bootstrap/loaders", &loaders_args)
.ToLocal(&loader_exports)) {
return MaybeLocal<Value>();
}
@@ -334,28 +327,25 @@ MaybeLocal<Value> Environment::BootstrapInternalLoaders() {
MaybeLocal<Value> Environment::BootstrapNode() {
EscapableHandleScope scope(isolate_);
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
// process, require, internalBinding, primordials
- std::vector<Local<String>> node_params = {
- process_string(),
- require_string(),
- internal_binding_string(),
- primordials_string()};
std::vector<Local<Value>> node_args = {
process_object(),
native_module_require(),
internal_binding_loader(),
primordials()};
- MaybeLocal<Value> result = ExecuteBootstrapper(
- this, "internal/bootstrap/node", &node_params, &node_args);
+ MaybeLocal<Value> result =
+ ExecuteBootstrapper(this, "internal/bootstrap/node", &node_args);
if (result.IsEmpty()) {
return MaybeLocal<Value>();
}
if (!no_browser_globals()) {
- result = ExecuteBootstrapper(
- this, "internal/bootstrap/browser", &node_params, &node_args);
+ result =
+ ExecuteBootstrapper(this, "internal/bootstrap/browser", &node_args);
if (result.IsEmpty()) {
return MaybeLocal<Value>();
@@ -366,8 +356,7 @@ MaybeLocal<Value> Environment::BootstrapNode() {
auto thread_switch_id =
is_main_thread() ? "internal/bootstrap/switches/is_main_thread"
: "internal/bootstrap/switches/is_not_main_thread";
- result =
- ExecuteBootstrapper(this, thread_switch_id, &node_params, &node_args);
+ result = ExecuteBootstrapper(this, thread_switch_id, &node_args);
if (result.IsEmpty()) {
return MaybeLocal<Value>();
@@ -377,8 +366,7 @@ MaybeLocal<Value> Environment::BootstrapNode() {
owns_process_state()
? "internal/bootstrap/switches/does_own_process_state"
: "internal/bootstrap/switches/does_not_own_process_state";
- result = ExecuteBootstrapper(
- this, process_state_switch_id, &node_params, &node_args);
+ result = ExecuteBootstrapper(this, process_state_switch_id, &node_args);
if (result.IsEmpty()) {
return MaybeLocal<Value>();
@@ -420,35 +408,20 @@ MaybeLocal<Value> Environment::RunBootstrapping() {
return scope.Escape(result);
}
-void MarkBootstrapComplete(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args);
- env->performance_state()->Mark(
- performance::NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
-}
-
static
MaybeLocal<Value> StartExecution(Environment* env, const char* main_script_id) {
EscapableHandleScope scope(env->isolate());
CHECK_NOT_NULL(main_script_id);
- std::vector<Local<String>> parameters = {
- env->process_string(),
- env->require_string(),
- env->internal_binding_string(),
- env->primordials_string(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "markBootstrapComplete")};
-
- std::vector<Local<Value>> arguments = {
- env->process_object(),
- env->native_module_require(),
- env->internal_binding_loader(),
- env->primordials(),
- NewFunctionTemplate(env->isolate(), MarkBootstrapComplete)
- ->GetFunction(env->context())
- .ToLocalChecked()};
+ // Arguments must match the parameters specified in
+ // NativeModuleLoader::LookupAndCompile().
+ std::vector<Local<Value>> arguments = {env->process_object(),
+ env->native_module_require(),
+ env->internal_binding_loader(),
+ env->primordials()};
return scope.EscapeMaybe(
- ExecuteBootstrapper(env, main_script_id, &parameters, &arguments));
+ ExecuteBootstrapper(env, main_script_id, &arguments));
}
MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
@@ -461,8 +434,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
if (cb != nullptr) {
EscapableHandleScope scope(env->isolate());
- if (StartExecution(env, "internal/bootstrap/environment").IsEmpty())
- return {};
+ if (StartExecution(env, "internal/main/environment").IsEmpty()) return {};
StartExecutionCallbackInfo info = {
env->process_object(),
diff --git a/src/node_internals.h b/src/node_internals.h
index 3684bddb5a..890d77f79a 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -308,7 +308,6 @@ v8::MaybeLocal<v8::Object> GetPerContextExports(v8::Local<v8::Context> context);
v8::MaybeLocal<v8::Value> ExecuteBootstrapper(
Environment* env,
const char* id,
- std::vector<v8::Local<v8::String>>* parameters,
std::vector<v8::Local<v8::Value>>* arguments);
void MarkBootstrapComplete(const v8::FunctionCallbackInfo<v8::Value>& args);
diff --git a/src/node_native_module.cc b/src/node_native_module.cc
index 7a515cc1ef..ffd406625d 100644
--- a/src/node_native_module.cc
+++ b/src/node_native_module.cc
@@ -184,21 +184,6 @@ ScriptCompiler::CachedData* NativeModuleLoader::GetCodeCache(
return it->second.get();
}
-MaybeLocal<Function> NativeModuleLoader::CompileAsModule(
- Local<Context> context,
- const char* id,
- NativeModuleLoader::Result* result) {
- Isolate* isolate = context->GetIsolate();
- std::vector<Local<String>> parameters = {
- FIXED_ONE_BYTE_STRING(isolate, "exports"),
- FIXED_ONE_BYTE_STRING(isolate, "require"),
- FIXED_ONE_BYTE_STRING(isolate, "module"),
- FIXED_ONE_BYTE_STRING(isolate, "process"),
- FIXED_ONE_BYTE_STRING(isolate, "internalBinding"),
- FIXED_ONE_BYTE_STRING(isolate, "primordials")};
- return LookupAndCompileInternal(context, id, &parameters, result);
-}
-
#ifdef NODE_BUILTIN_MODULES_PATH
static std::string OnDiskFileName(const char* id) {
std::string filename = NODE_BUILTIN_MODULES_PATH;
@@ -360,29 +345,84 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompileInternal(
MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
Local<Context> context,
const char* id,
- std::vector<Local<String>>* parameters,
Environment* optional_env) {
Result result;
- MaybeLocal<Function> maybe =
- GetInstance()->LookupAndCompileInternal(context, id, parameters, &result);
+ std::vector<Local<String>> parameters;
+ Isolate* isolate = context->GetIsolate();
+ // Detects parameters of the scripts based on module ids.
+ // internal/bootstrap/loaders: process, getLinkedBinding,
+ // getInternalBinding, primordials
+ if (strcmp(id, "internal/bootstrap/loaders") == 0) {
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "process"),
+ FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
+ FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
+ FIXED_ONE_BYTE_STRING(isolate, "primordials"),
+ };
+ } else if (strncmp(id,
+ "internal/per_context/",
+ strlen("internal/per_context/")) == 0) {
+ // internal/per_context/*: global, exports, primordials
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "global"),
+ FIXED_ONE_BYTE_STRING(isolate, "exports"),
+ FIXED_ONE_BYTE_STRING(isolate, "primordials"),
+ };
+ } else if (strncmp(id, "internal/main/", strlen("internal/main/")) == 0) {
+ // internal/main/*: process, require, internalBinding, primordials
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "process"),
+ FIXED_ONE_BYTE_STRING(isolate, "require"),
+ FIXED_ONE_BYTE_STRING(isolate, "internalBinding"),
+ FIXED_ONE_BYTE_STRING(isolate, "primordials"),
+ };
+ } else if (strncmp(id, "embedder_main_", strlen("embedder_main_")) == 0) {
+ // Synthetic embedder main scripts from LoadEnvironment(): process, require
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "process"),
+ FIXED_ONE_BYTE_STRING(isolate, "require"),
+ };
+ } else if (strncmp(id,
+ "internal/bootstrap/",
+ strlen("internal/bootstrap/")) == 0) {
+ // internal/bootstrap/*: process, require, internalBinding, primordials
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "process"),
+ FIXED_ONE_BYTE_STRING(isolate, "require"),
+ FIXED_ONE_BYTE_STRING(isolate, "internalBinding"),
+ FIXED_ONE_BYTE_STRING(isolate, "primordials"),
+ };
+ } else {
+ // others: exports, require, module, process, internalBinding, primordials
+ parameters = {
+ FIXED_ONE_BYTE_STRING(isolate, "exports"),
+ FIXED_ONE_BYTE_STRING(isolate, "require"),
+ FIXED_ONE_BYTE_STRING(isolate, "module"),
+ FIXED_ONE_BYTE_STRING(isolate, "process"),
+ FIXED_ONE_BYTE_STRING(isolate, "internalBinding"),
+ FIXED_ONE_BYTE_STRING(isolate, "primordials"),
+ };
+ }
+
+ MaybeLocal<Function> maybe = GetInstance()->LookupAndCompileInternal(
+ context, id, &parameters, &result);
if (optional_env != nullptr) {
RecordResult(id, result, optional_env);
}
return maybe;
}
-bool NativeModuleLoader::CompileAllModules(Local<Context> context) {
+bool NativeModuleLoader::CompileAllBuiltins(Local<Context> context) {
NativeModuleLoader* loader = GetInstance();
std::vector<std::string> ids = loader->GetModuleIds();
bool all_succeeded = true;
+ std::string v8_tools_prefix = "internal/deps/v8/tools/";
for (const auto& id : ids) {
- // TODO(joyeecheung): compile non-module scripts here too.
- if (!loader->CanBeRequired(id.c_str())) {
+ if (id.compare(0, v8_tools_prefix.size(), v8_tools_prefix) == 0) {
continue;
}
v8::TryCatch bootstrapCatch(context->GetIsolate());
- Result result;
- USE(loader->CompileAsModule(context, id.c_str(), &result));
+ USE(loader->LookupAndCompile(context, id.c_str(), nullptr));
if (bootstrapCatch.HasCaught()) {
per_process::Debug(DebugCategory::CODE_CACHE,
"Failed to compile code cache for %s\n",
@@ -538,16 +578,15 @@ void NativeModuleLoader::RecordResult(const char* id,
env->native_modules_without_cache.insert(id);
}
}
+
void NativeModuleLoader::CompileFunction(
const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsString());
node::Utf8Value id_v(env->isolate(), args[0].As<String>());
const char* id = *id_v;
- NativeModuleLoader::Result result;
MaybeLocal<Function> maybe =
- GetInstance()->CompileAsModule(env->context(), id, &result);
- RecordResult(id, result, env);
+ GetInstance()->LookupAndCompile(env->context(), id, env);
Local<Function> fn;
if (maybe.ToLocal(&fn)) {
args.GetReturnValue().Set(fn);
diff --git a/src/node_native_module.h b/src/node_native_module.h
index 3c797a5d35..5357a1272d 100644
--- a/src/node_native_module.h
+++ b/src/node_native_module.h
@@ -45,10 +45,11 @@ class NODE_EXTERN_PRIVATE NativeModuleLoader {
v8::Local<v8::Context> context,
void* priv);
+ // The parameters used to compile the scripts are detected based on
+ // the pattern of the id.
static v8::MaybeLocal<v8::Function> LookupAndCompile(
v8::Local<v8::Context> context,
const char* id,
- std::vector<v8::Local<v8::String>>* parameters,
Environment* optional_env);
static v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context);
@@ -57,7 +58,7 @@ class NODE_EXTERN_PRIVATE NativeModuleLoader {
static bool Exists(const char* id);
static bool Add(const char* id, const UnionBytes& source);
- static bool CompileAllModules(v8::Local<v8::Context> context);
+ static bool CompileAllBuiltins(v8::Local<v8::Context> context);
static void RefreshCodeCache(const std::vector<CodeCacheInfo>& in);
static void CopyCodeCache(std::vector<CodeCacheInfo>* out);
@@ -100,9 +101,6 @@ class NODE_EXTERN_PRIVATE NativeModuleLoader {
const char* id,
std::vector<v8::Local<v8::String>>* parameters,
Result* result);
- v8::MaybeLocal<v8::Function> CompileAsModule(v8::Local<v8::Context> context,
- const char* id,
- Result* result);
static void RecordResult(const char* id,
NativeModuleLoader::Result result,
diff --git a/src/node_perf.cc b/src/node_perf.cc
index cf48b471a6..cdd609b0a2 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -267,6 +267,12 @@ void GetTimeOriginTimeStamp(const FunctionCallbackInfo<Value>& args) {
args.GetIsolate(), env->time_origin_timestamp() / MICROS_PER_MILLIS));
}
+void MarkBootstrapComplete(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ env->performance_state()->Mark(
+ performance::NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
+}
+
void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
@@ -306,6 +312,7 @@ void Initialize(Local<Object> target,
SetMethod(context, target, "getTimeOrigin", GetTimeOrigin);
SetMethod(context, target, "getTimeOriginTimestamp", GetTimeOriginTimeStamp);
SetMethod(context, target, "createELDHistogram", CreateELDHistogram);
+ SetMethod(context, target, "markBootstrapComplete", MarkBootstrapComplete);
Local<Object> constants = Object::New(isolate);
@@ -360,6 +367,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(GetTimeOrigin);
registry->Register(GetTimeOriginTimeStamp);
registry->Register(CreateELDHistogram);
+ registry->Register(MarkBootstrapComplete);
HistogramBase::RegisterExternalReferences(registry);
IntervalHistogram::RegisterExternalReferences(registry);
}
diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc
index 0fb298814f..e11087f496 100644
--- a/src/node_snapshotable.cc
+++ b/src/node_snapshotable.cc
@@ -986,7 +986,8 @@ int SnapshotBuilder::Generate(SnapshotData* out,
#ifdef NODE_USE_NODE_CODE_CACHE
// Regenerate all the code cache.
- if (!native_module::NativeModuleLoader::CompileAllModules(main_context)) {
+ if (!native_module::NativeModuleLoader::CompileAllBuiltins(
+ main_context)) {
return UNCAUGHT_EXCEPTION_ERROR;
}
native_module::NativeModuleLoader::CopyCodeCache(&(out->code_cache));
@@ -1220,7 +1221,6 @@ void Initialize(Local<Object> target,
Local<Context> context,
void* priv) {
SetMethod(context, target, "compileSerializeMain", CompileSerializeMain);
- SetMethod(context, target, "markBootstrapComplete", MarkBootstrapComplete);
SetMethod(context, target, "setSerializeCallback", SetSerializeCallback);
SetMethod(context, target, "setDeserializeCallback", SetDeserializeCallback);
SetMethod(context,
@@ -1231,7 +1231,6 @@ void Initialize(Local<Object> target,
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(CompileSerializeMain);
- registry->Register(MarkBootstrapComplete);
registry->Register(SetSerializeCallback);
registry->Register(SetDeserializeCallback);
registry->Register(SetDeserializeMainFunction);
diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js
index 374fb3eed6..ebec2dc20a 100644
--- a/test/parallel/test-bootstrap-modules.js
+++ b/test/parallel/test-bootstrap-modules.js
@@ -52,7 +52,6 @@ const expectedModules = new Set([
'NativeModule internal/assert',
'NativeModule internal/async_hooks',
'NativeModule internal/blocklist',
- 'NativeModule internal/bootstrap/pre_execution',
'NativeModule internal/buffer',
'NativeModule internal/console/constructor',
'NativeModule internal/console/global',
@@ -105,6 +104,7 @@ const expectedModules = new Set([
'NativeModule internal/process/esm_loader',
'NativeModule internal/process/execution',
'NativeModule internal/process/per_thread',
+ 'NativeModule internal/process/pre_execution',
'NativeModule internal/process/promises',
'NativeModule internal/process/report',
'NativeModule internal/process/signal',
diff --git a/test/parallel/test-code-cache.js b/test/parallel/test-code-cache.js
index 00deafd6d4..44fe98238a 100644
--- a/test/parallel/test-code-cache.js
+++ b/test/parallel/test-code-cache.js
@@ -12,7 +12,7 @@ const {
} = require('internal/test/binding');
const {
getCacheUsage,
- moduleCategories: { canBeRequired, cannotBeRequired }
+ moduleCategories: { canBeRequired }
} = internalBinding('native_module');
for (const key of canBeRequired) {
@@ -54,20 +54,12 @@ if (!process.features.cached_builtins) {
} else { // Native compiled
assert(process.config.variables.node_use_node_code_cache);
- if (!isMainThread) {
- for (const key of [ 'internal/bootstrap/pre_execution' ]) {
- canBeRequired.add(key);
- cannotBeRequired.delete(key);
- }
- }
-
const wrong = [];
for (const key of loadedModules) {
- if (cannotBeRequired.has(key) && !compiledWithoutCache.has(key)) {
- wrong.push(`"${key}" should've been compiled **without** code cache`);
+ if (key.startsWith('internal/deps/v8/tools')) {
+ continue;
}
- if (canBeRequired.has(key) &&
- !compiledWithCache.has(key) &&
+ if (!compiledWithCache.has(key) &&
compiledInSnapshot.indexOf(key) === -1) {
wrong.push(`"${key}" should've been compiled **with** code cache`);
}