Skip to content

Commit 2178f17

Browse files
joyeecheungdanielleadams
authored andcommitted
bootstrap: support more builtins in the embedded code cache
This patch: - Make NativeModuleLoader::LookupAndCompile() detect parameters based on module IDs. This allows us to compile more builtins when generating the embedded bootstrap, including - internal/per_context/* - internal/bootstrap/* - internal/main/* - Move pre_execution.js to lib/internal/process as it needs to be compiled as a regular built-in module, unlike other scripts in lib/internal/bootstrap - Move markBootstrapComplete() to the performance binding instead of making it a function-wrapper-based global to reduce number of special cases. PR-URL: #44018 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 6cfb1ac commit 2178f17

27 files changed

+156
-137
lines changed

lib/internal/bootstrap/loaders.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ class NativeModule {
326326
requireWithFallbackInDeps : nativeModuleRequire;
327327

328328
const fn = compileFunction(id);
329+
// Arguments must match the parameters specified in
330+
// NativeModuleLoader::LookupAndCompile().
329331
fn(this.exports, requireFn, this, process, internalBinding, primordials);
330332

331333
this.loaded = true;

lib/internal/bootstrap/node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// This file is expected not to perform any asynchronous operations itself
88
// when being executed - those should be done in either
9-
// `lib/internal/bootstrap/pre_execution.js` or in main scripts. The majority
9+
// `lib/internal/process/pre_execution.js` or in main scripts. The majority
1010
// of the code here focuses on setting up the global proxy and the process
1111
// object in a synchronous manner.
1212
// As special caution is given to the performance of the startup process,
@@ -28,7 +28,7 @@
2828
// Then, depending on how the Node.js instance is launched, one of the main
2929
// scripts in `lib/internal/main` will be selected by C++ to start the actual
3030
// execution. They may run additional setups exported by
31-
// `lib/internal/bootstrap/pre_execution.js` depending on the runtime states.
31+
// `lib/internal/process/pre_execution.js` depending on the runtime states.
3232

3333
'use strict';
3434

lib/internal/main/.eslintrc.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/internal/main/check_syntax.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
// instead of actually running the file.
55

66
const {
7-
prepareMainThreadExecution
8-
} = require('internal/bootstrap/pre_execution');
7+
prepareMainThreadExecution,
8+
markBootstrapComplete
9+
} = require('internal/process/pre_execution');
910

1011
const {
1112
readStdin

lib/internal/bootstrap/environment.js renamed to lib/internal/main/environment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// that depends on run time states.
55
// It is currently only intended for preparing contexts for embedders.
66

7-
/* global markBootstrapComplete */
87
const {
9-
prepareMainThreadExecution
10-
} = require('internal/bootstrap/pre_execution');
8+
prepareMainThreadExecution,
9+
markBootstrapComplete
10+
} = require('internal/process/pre_execution');
1111

1212
prepareMainThreadExecution();
1313
markBootstrapComplete();

lib/internal/main/eval_stdin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// Stdin is not a TTY, we will read it and execute it.
44

55
const {
6-
prepareMainThreadExecution
7-
} = require('internal/bootstrap/pre_execution');
6+
prepareMainThreadExecution,
7+
markBootstrapComplete
8+
} = require('internal/process/pre_execution');
89

910
const { getOptionValue } = require('internal/options');
1011

lib/internal/main/eval_string.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const {
88
} = primordials;
99

1010
const {
11-
prepareMainThreadExecution
12-
} = require('internal/bootstrap/pre_execution');
11+
prepareMainThreadExecution,
12+
markBootstrapComplete
13+
} = require('internal/process/pre_execution');
1314
const { evalModule, evalScript } = require('internal/process/execution');
1415
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
1516

lib/internal/main/inspect.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// `node inspect ...` or `node debug ...`
44

55
const {
6-
prepareMainThreadExecution
7-
} = require('internal/bootstrap/pre_execution');
6+
prepareMainThreadExecution,
7+
markBootstrapComplete
8+
} = require('internal/process/pre_execution');
89

910
prepareMainThreadExecution();
1011

lib/internal/main/mksnapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function requireForUserSnapshot(id) {
114114
function main() {
115115
const {
116116
prepareMainThreadExecution
117-
} = require('internal/bootstrap/pre_execution');
117+
} = require('internal/process/pre_execution');
118118

119119
prepareMainThreadExecution(true, false);
120120

lib/internal/main/print_help.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ const { types } = internalBinding('options');
2020
const hasCrypto = Boolean(process.versions.openssl);
2121

2222
const {
23-
prepareMainThreadExecution
24-
} = require('internal/bootstrap/pre_execution');
23+
prepareMainThreadExecution,
24+
markBootstrapComplete
25+
} = require('internal/process/pre_execution');
2526

2627
const typeLookup = [];
2728
for (const key of ObjectKeys(types))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy