From 8484b40b3d38e18c524b7dd560c16ab30c94e427 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 6 Mar 2018 22:42:32 +0800 Subject: src: put bootstrappers in lib/internal/bootstrap/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create `lib/internal/bootstrap/` and put bootstrappers there: Before: ``` lib/internal ├── ... ├── bootstrap_loaders.js └── bootstrap_node.js ``` After: ``` lib/internal ├── ... └── bootstrap ├── loaders.js └── node.js ``` PR-URL: https://github.com/nodejs/node/pull/19177 Refs: https://github.com/nodejs/node/pull/19112 Reviewed-By: Gus Caplan Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum --- lib/assert.js | 2 +- lib/buffer.js | 2 +- lib/domain.js | 2 +- lib/internal/bootstrap/loaders.js | 229 +++++++++ lib/internal/bootstrap/node.js | 563 +++++++++++++++++++++ lib/internal/bootstrap_loaders.js | 229 --------- lib/internal/bootstrap_node.js | 563 --------------------- lib/internal/encoding.js | 2 +- lib/internal/http2/core.js | 2 +- lib/internal/loader/CreateDynamicModule.js | 2 +- lib/internal/loader/DefaultResolve.js | 2 +- lib/internal/loader/ModuleJob.js | 2 +- lib/internal/loader/Translators.js | 2 +- lib/internal/process/modules.js | 2 +- lib/internal/test/binding.js | 2 +- lib/internal/util/comparisons.js | 2 +- lib/internal/vm/Module.js | 2 +- lib/module.js | 2 +- lib/string_decoder.js | 2 +- lib/util.js | 2 +- node.gyp | 4 +- src/node.cc | 34 +- src/node_internals.h | 4 +- src/node_url.cc | 2 +- test/message/core_line_numbers.out | 2 +- test/message/error_exit.out | 4 +- test/message/eval_messages.out | 24 +- .../events_unhandled_error_common_trace.out | 6 +- test/message/events_unhandled_error_nexttick.out | 8 +- test/message/events_unhandled_error_sameline.out | 6 +- test/message/nexttick_throw.out | 4 +- test/message/stdin_messages.out | 16 +- test/parallel/test-loaders-hidden-from-users.js | 6 +- test/sequential/test-inspector-overwrite-config.js | 3 +- 34 files changed, 871 insertions(+), 868 deletions(-) create mode 100644 lib/internal/bootstrap/loaders.js create mode 100644 lib/internal/bootstrap/node.js delete mode 100644 lib/internal/bootstrap_loaders.js delete mode 100644 lib/internal/bootstrap_node.js diff --git a/lib/assert.js b/lib/assert.js index b0d0d9ab4c..797252afc0 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -36,7 +36,7 @@ const { openSync, closeSync, readSync } = require('fs'); const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn'); const { inspect } = require('util'); const { EOL } = require('os'); -const { NativeModule } = require('internal/bootstrap_loaders'); +const { NativeModule } = require('internal/bootstrap/loaders'); // Escape control characters but not \n and \t to keep the line breaks and // indentation intact. diff --git a/lib/buffer.js b/lib/buffer.js index 7703d2a129..b369d27a1e 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -41,7 +41,7 @@ const { // that test/parallel/test-buffer-bindingobj-no-zerofill.js is written. let isAnyArrayBuffer; try { - const { internalBinding } = require('internal/bootstrap_loaders'); + const { internalBinding } = require('internal/bootstrap/loaders'); isAnyArrayBuffer = internalBinding('types').isAnyArrayBuffer; } catch (e) { isAnyArrayBuffer = require('util').types.isAnyArrayBuffer; diff --git a/lib/domain.js b/lib/domain.js index e2cc38a1f9..170f291727 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -34,7 +34,7 @@ const { ERR_UNHANDLED_ERROR } = require('internal/errors').codes; const { createHook } = require('async_hooks'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); // overwrite process.domain with a getter/setter that will allow for more // effective optimizations diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js new file mode 100644 index 0000000000..601c54a0cd --- /dev/null +++ b/lib/internal/bootstrap/loaders.js @@ -0,0 +1,229 @@ +// This file creates the internal module & binding loaders used by built-in +// modules. In contrast, user land modules are loaded using +// lib/module.js (CommonJS Modules) or lib/internal/loader/* (ES Modules). +// +// This file is compiled and run by node.cc before bootstrap/node.js +// was called, therefore the loaders are bootstraped before we start to +// actually bootstrap Node.js. It creates the following objects: +// +// C++ binding loaders: +// - process.binding(): the legacy C++ binding loader, accessible from user land +// because it is an object attached to the global process object. +// These C++ bindings are created using NODE_BUILTIN_MODULE_CONTEXT_AWARE() +// and have their nm_flags set to NM_F_BUILTIN. We do not make any guarantees +// about the stability of these bindings, but still have to take care of +// compatibility issues caused by them from time to time. +// - process._linkedBinding(): intended to be used by embedders to add +// additional C++ bindings in their applications. These C++ bindings +// can be created using NODE_MODULE_CONTEXT_AWARE_CPP() with the flag +// NM_F_LINKED. +// - internalBinding(): the private internal C++ binding loader, inaccessible +// from user land because they are only available from NativeModule.require() +// These C++ bindings are created using NODE_MODULE_CONTEXT_AWARE_INTERNAL() +// and have their nm_flags set to NM_F_INTERNAL. +// +// Internal JavaScript module loader: +// - NativeModule: a minimal module system used to load the JavaScript core +// modules found in lib/**/*.js and deps/**/*.js. All core modules are +// compiled into the node binary via node_javascript.cc generated by js2c.py, +// so they can be loaded faster without the cost of I/O. This class makes the +// lib/internal/*, deps/internal/* modules and internalBinding() available by +// default to core modules, and lets the core modules require itself via +// require('internal/bootstrap/loaders') even when this file is not written in +// CommonJS style. +// +// Other objects: +// - process.moduleLoadList: an array recording the bindings and the modules +// loaded in the process and the order in which they are loaded. + +'use strict'; + +(function bootstrapInternalLoaders(process, getBinding, getLinkedBinding, + getInternalBinding) { + + // Set up process.moduleLoadList + const moduleLoadList = []; + Object.defineProperty(process, 'moduleLoadList', { + value: moduleLoadList, + configurable: true, + enumerable: true, + writable: false + }); + + // Set up process.binding() and process._linkedBinding() + { + const bindingObj = Object.create(null); + + process.binding = function binding(module) { + module = String(module); + let mod = bindingObj[module]; + if (typeof mod !== 'object') { + mod = bindingObj[module] = getBinding(module); + moduleLoadList.push(`Binding ${module}`); + } + return mod; + }; + + process._linkedBinding = function _linkedBinding(module) { + module = String(module); + let mod = bindingObj[module]; + if (typeof mod !== 'object') + mod = bindingObj[module] = getLinkedBinding(module); + return mod; + }; + } + + // Set up internalBinding() in the closure + let internalBinding; + { + const bindingObj = Object.create(null); + internalBinding = function internalBinding(module) { + let mod = bindingObj[module]; + if (typeof mod !== 'object') { + mod = bindingObj[module] = getInternalBinding(module); + moduleLoadList.push(`Internal Binding ${module}`); + } + return mod; + }; + } + + // Minimal sandbox helper + const ContextifyScript = process.binding('contextify').ContextifyScript; + function runInThisContext(code, options) { + const script = new ContextifyScript(code, options); + return script.runInThisContext(); + } + + // Set up NativeModule + function NativeModule(id) { + this.filename = `${id}.js`; + this.id = id; + this.exports = {}; + this.loaded = false; + this.loading = false; + } + + NativeModule._source = getBinding('natives'); + NativeModule._cache = {}; + + const config = getBinding('config'); + + // Think of this as module.exports in this file even though it is not + // written in CommonJS style. + const loaderExports = { internalBinding, NativeModule }; + const loaderId = 'internal/bootstrap/loaders'; + NativeModule.require = function(id) { + if (id === loaderId) { + return loaderExports; + } + + const cached = NativeModule.getCached(id); + if (cached && (cached.loaded || cached.loading)) { + return cached.exports; + } + + if (!NativeModule.exists(id)) { + // Model the error off the internal/errors.js model, but + // do not use that module given that it could actually be + // the one causing the error if there's a bug in Node.js + const err = new Error(`No such built-in module: ${id}`); + err.code = 'ERR_UNKNOWN_BUILTIN_MODULE'; + err.name = 'Error [ERR_UNKNOWN_BUILTIN_MODULE]'; + throw err; + } + + moduleLoadList.push(`NativeModule ${id}`); + + const nativeModule = new NativeModule(id); + + nativeModule.cache(); + nativeModule.compile(); + + return nativeModule.exports; + }; + + NativeModule.requireForDeps = function(id) { + if (!NativeModule.exists(id) || + // TODO(TimothyGu): remove when DEP0084 reaches end of life. + id.startsWith('node-inspect/') || + id.startsWith('v8/')) { + id = `internal/deps/${id}`; + } + return NativeModule.require(id); + }; + + NativeModule.getCached = function(id) { + return NativeModule._cache[id]; + }; + + NativeModule.exists = function(id) { + return NativeModule._source.hasOwnProperty(id); + }; + + if (config.exposeInternals) { + NativeModule.nonInternalExists = function(id) { + // Do not expose this to user land even with --expose-internals + if (id === loaderId) { + return false; + } + return NativeModule.exists(id); + }; + + NativeModule.isInternal = function(id) { + // Do not expose this to user land even with --expose-internals + return id === loaderId; + }; + } else { + NativeModule.nonInternalExists = function(id) { + return NativeModule.exists(id) && !NativeModule.isInternal(id); + }; + + NativeModule.isInternal = function(id) { + return id.startsWith('internal/'); + }; + } + + NativeModule.getSource = function(id) { + return NativeModule._source[id]; + }; + + NativeModule.wrap = function(script) { + return NativeModule.wrapper[0] + script + NativeModule.wrapper[1]; + }; + + NativeModule.wrapper = [ + '(function (exports, require, module, process) {', + '\n});' + ]; + + NativeModule.prototype.compile = function() { + let source = NativeModule.getSource(this.id); + source = NativeModule.wrap(source); + + this.loading = true; + + try { + const fn = runInThisContext(source, { + filename: this.filename, + lineOffset: 0, + displayErrors: true + }); + const requireFn = this.id.startsWith('internal/deps/') ? + NativeModule.requireForDeps : + NativeModule.require; + fn(this.exports, requireFn, this, process); + + this.loaded = true; + } finally { + this.loading = false; + } + }; + + NativeModule.prototype.cache = function() { + NativeModule._cache[this.id] = this; + }; + + // This will be passed to the bootstrapNodeJSCore function in + // bootstrap/node.js. + return loaderExports; +}); diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js new file mode 100644 index 0000000000..67ec63eb01 --- /dev/null +++ b/lib/internal/bootstrap/node.js @@ -0,0 +1,563 @@ +// Hello, and welcome to hacking node.js! +// +// This file is invoked by node::LoadEnvironment in src/node.cc, and is +// responsible for bootstrapping the node.js core. As special caution is given +// to the performance of the startup process, many dependencies are invoked +// lazily. +// +// Before this file is run, lib/internal/bootstrap/loaders.js gets run first +// to bootstrap the internal binding and module loaders, including +// process.binding(), process._linkedBinding(), internalBinding() and +// NativeModule. And then { internalBinding, NativeModule } will be passed +// into this bootstrapper to bootstrap Node.js core. + +'use strict'; + +(function bootstrapNodeJSCore(process, { internalBinding, NativeModule }) { + const exceptionHandlerState = { captureFn: null }; + + function startup() { + const EventEmitter = NativeModule.require('events'); + + const origProcProto = Object.getPrototypeOf(process); + Object.setPrototypeOf(origProcProto, EventEmitter.prototype); + + EventEmitter.call(process); + + setupProcessObject(); + + // do this good and early, since it handles errors. + setupProcessFatal(); + + setupV8(); + setupProcessICUVersions(); + + setupGlobalVariables(); + + const _process = NativeModule.require('internal/process'); + _process.setupConfig(NativeModule._source); + _process.setupSignalHandlers(); + _process.setupUncaughtExceptionCapture(exceptionHandlerState); + NativeModule.require('internal/process/warning').setup(); + NativeModule.require('internal/process/next_tick').setup(); + NativeModule.require('internal/process/stdio').setup(); + + const perf = process.binding('performance'); + const { + NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, + NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START, + NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END, + NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START, + NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END, + NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START, + NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END, + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START, + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END + } = perf.constants; + + _process.setup_hrtime(); + _process.setup_performance(); + _process.setup_cpuUsage(); + _process.setupMemoryUsage(); + _process.setupKillAndExit(); + if (global.__coverage__) + NativeModule.require('internal/process/write-coverage').setup(); + + NativeModule.require('internal/trace_events_async_hooks').setup(); + NativeModule.require('internal/inspector_async_hook').setup(); + + _process.setupChannel(); + _process.setupRawDebug(); + + const browserGlobals = !process._noBrowserGlobals; + if (browserGlobals) { + setupGlobalTimeouts(); + setupGlobalConsole(); + setupGlobalURL(); + } + + // Ensure setURLConstructor() is called before the native + // URL::ToObject() method is used. + NativeModule.require('internal/url'); + + // On OpenBSD process.execPath will be relative unless we + // get the full path before process.execPath is used. + if (process.platform === 'openbsd') { + const { realpathSync } = NativeModule.require('fs'); + process.execPath = realpathSync.native(process.execPath); + } + + Object.defineProperty(process, 'argv0', { + enumerable: true, + configurable: false, + value: process.argv[0] + }); + process.argv[0] = process.execPath; + + // Handle `--debug*` deprecation and invalidation + if (process._invalidDebug) { + process.emitWarning( + '`node --debug` and `node --debug-brk` are invalid. ' + + 'Please use `node --inspect` or `node --inspect-brk` instead.', + 'DeprecationWarning', 'DEP0062', startup, true); + process.exit(9); + } else if (process._deprecatedDebugBrk) { + process.emitWarning( + '`node --inspect --debug-brk` is deprecated. ' + + 'Please use `node --inspect-brk` instead.', + 'DeprecationWarning', 'DEP0062', startup, true); + } + + if (process.binding('config').experimentalModules) { + process.emitWarning( + 'The ESM module loader is experimental.', + 'ExperimentalWarning', undefined); + NativeModule.require('internal/process/modules').setup(); + } + + { + // Install legacy getters on the `util` binding for typechecking. + // TODO(addaleax): Turn into a full runtime deprecation. + const { pendingDeprecation } = process.binding('config'); + const { deprecate } = NativeModule.require('internal/util'); + const utilBinding = process.binding('util'); + const types = internalBinding('types'); + for (const name of [ + 'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction', + 'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator', + 'isNativeError', 'isPromise', 'isRegExp', 'isSet', 'isSetIterator', + 'isTypedArray', 'isUint8Array', 'isAnyArrayBuffer' + ]) { + utilBinding[name] = pendingDeprecation ? + deprecate(types[name], + 'Accessing native typechecking bindings of Node ' + + 'directly is deprecated. ' + + `Please use \`util.types.${name}\` instead.`, + 'DEP0103') : + types[name]; + } + } + + // There are various modes that Node can run in. The most common two + // are running from a script and running the REPL - but there are a few + // others like the debugger or running --eval arguments. Here we decide + // which mode we run in. + + if (NativeModule.exists('_third_party_main')) { + // To allow people to extend Node in different ways, this hook allows + // one to drop a file lib/_third_party_main.js into the build + // directory which will be executed instead of Node's normal loading. + process.nextTick(function() { + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START); + NativeModule.require('_third_party_main'); + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END); + }); + + } else if (process.argv[1] === 'inspect' || process.argv[1] === 'debug') { + if (process.argv[1] === 'debug') { + process.emitWarning( + '`node debug` is deprecated. Please use `node inspect` instead.', + 'DeprecationWarning', 'DEP0068'); + } + + // Start the debugger agent + process.nextTick(function() { + NativeModule.require('internal/deps/node-inspect/lib/_inspect').start(); + }); + + } else if (process.profProcess) { + NativeModule.require('internal/v8_prof_processor'); + + } else { + // There is user code to be run + + // If this is a worker in cluster mode, start up the communication + // channel. This needs to be done before any user code gets executed + // (including preload modules). + if (process.argv[1] && process.env.NODE_UNIQUE_ID) { + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START); + const cluster = NativeModule.require('cluster'); + cluster._setupWorker(); + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END); + // Make sure it's not accidentally inherited by child processes. + delete process.env.NODE_UNIQUE_ID; + } + + if (process._eval != null && !process._forceRepl) { + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); + // User passed '-e' or '--eval' arguments to Node without '-i' or + // '--interactive' + + perf.markMilestone( + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); + preloadModules(); + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); + + const internalModule = NativeModule.require('internal/module'); + internalModule.addBuiltinLibsToObject(global); + evalScript('[eval]'); + } else if (process.argv[1] && process.argv[1] !== '-') { + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); + // make process.argv[1] into a full path + const path = NativeModule.require('path'); + process.argv[1] = path.resolve(process.argv[1]); + + const Module = NativeModule.require('module'); + + // check if user passed `-c` or `--check` arguments to Node. + if (process._syntax_check_only != null) { + const fs = NativeModule.require('fs'); + // read the source + const filename = Module._resolveFilename(process.argv[1]); + const source = fs.readFileSync(filename, 'utf-8'); + checkScriptSyntax(source, filename); + process.exit(0); + } + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); + perf.markMilestone( + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); + preloadModules(); + perf.markMilestone( + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); + Module.runMain(); + } else { + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); + perf.markMilestone( + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); + preloadModules(); + perf.markMilestone( + NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); + // If -i or --interactive were passed, or stdin is a TTY. + if (process._forceRepl || NativeModule.require('tty').isatty(0)) { + // REPL + const cliRepl = NativeModule.require('internal/repl'); + cliRepl.createInternalRepl(process.env, function(err, repl) { + if (err) { + throw err; + } + repl.on('exit', function() { + if (repl._flushing) { + repl.pause(); + return repl.once('flushHistory', function() { + process.exit(); + }); + } + process.exit(); + }); + }); + + if (process._eval != null) { + // User passed '-e' or '--eval' + evalScript('[eval]'); + } + } else { + // Read all of stdin - execute it. + process.stdin.setEncoding('utf8'); + + let code = ''; + process.stdin.on('data', function(d) { + code += d; + }); + + process.stdin.on('end', function() { + if (process._syntax_check_only != null) { + checkScriptSyntax(code, '[stdin]'); + } else { + process._eval = code; + evalScript('[stdin]'); + } + }); + } + } + } + perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); + } + + function setupProcessObject() { + process._setupProcessObject(pushValueToArray); + + function pushValueToArray() { + for (var i = 0; i < arguments.length; i++) + this.push(arguments[i]); + } + } + + function setupGlobalVariables() { + Object.defineProperty(global, Symbol.toStringTag, { + value: 'global', + writable: false, + enumerable: false, + configurable: true + }); + global.process = process; + const util = NativeModule.require('util'); + + function makeGetter(name) { + return util.deprecate(function() { + return this; + }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); + } + + function makeSetter(name) { + return util.deprecate(function(value) { + Object.defineProperty(this, name, { + configurable: true, + writable: true, + enumerable: true, + value: value + }); + }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); + } + + Object.defineProperties(global, { + GLOBAL: { + configurable: true, + get: makeGetter('GLOBAL'), + set: makeSetter('GLOBAL') + }, + root: { + configurable: true, + get: makeGetter('root'), + set: makeSetter('root') + } + }); + + // This, as side effect, removes `setupBufferJS` from the buffer binding, + // and exposes it on `internal/buffer`. + NativeModule.require('internal/buffer'); + + global.Buffer = NativeModule.require('buffer').Buffer; + process.domain = null; + process._exiting = false; + } + + function setupGlobalTimeouts() { + const timers = NativeModule.require('timers'); + global.clearImmediate = timers.clearImmediate; + global.clearInterval = timers.clearInterval; + global.clearTimeout = timers.clearTimeout; + global.setImmediate = timers.setImmediate; + global.setInterval = timers.setInterval; + global.setTimeout = timers.setTimeout; + } + + function setupGlobalConsole() { + const originalConsole = global.console; + const Module = NativeModule.require('module'); + // Setup Node.js global.console + const wrappedConsole = NativeModule.require('console'); + Object.defineProperty(global, 'console', { + configurable: true, + enumerable: false, + value: wrappedConsole + }); + setupInspector(originalConsole, wrappedConsole, Module); + } + + function setupGlobalURL() { + const { URL, URLSearchParams } = NativeModule.require('internal/url'); + Object.defineProperties(global, { + URL: { + value: URL, + writable: true, + configurable: true, + enumerable: false + }, + URLSearchParams: { + value: URLSearchParams, + writable: true, + configurable: true, + enumerable: false + } + }); + } + + function setupInspector(originalConsole, wrappedConsole, Module) { + if (!process.config.variables.v8_enable_inspector) { + return; + } + const { addCommandLineAPI, consoleCall } = process.binding('inspector'); + // Setup inspector command line API + const { makeRequireFunction } = NativeModule.require('internal/module'); + const path = NativeModule.require('path'); + const cwd = tryGetCwd(path); + + const consoleAPIModule = new Module(''); + consoleAPIModule.paths = + Module._nodeModulePaths(cwd).concat(Module.globalPaths); + addCommandLineAPI('require', makeRequireFunction(consoleAPIModule)); + const config = {}; + for (const key of Object.keys(wrappedConsole)) { + if (!originalConsole.hasOwnProperty(key)) + continue; + // If global console has the same method as inspector console, + // then wrap these two methods into one. Native wrapper will preserve + // the original stack. + wrappedConsole[key] = consoleCall.bind(wrappedConsole, + originalConsole[key], + wrappedConsole[key], + config); + } + for (const key of Object.keys(originalConsole)) { + if (wrappedConsole.hasOwnProperty(key)) + continue; + wrappedConsole[key] = originalConsole[key]; + } + } + + function noop() {} + + function setupProcessFatal() { + const { + executionAsyncId, + clearDefaultTriggerAsyncId, + clearAsyncIdStack, + hasAsyncIdStack, + afterHooksExist, + emitAfter + } = NativeModule.require('internal/async_hooks'); + + process._fatalException = function(er) { + // It's possible that defaultTriggerAsyncId was set for a constructor + // call that threw and was never cleared. So clear it now. + clearDefaultTriggerAsyncId(); + + if (exceptionHandlerState.captureFn !== null) { + exceptionHandlerState.captureFn(er); + } else if (!process.emit('uncaughtException', er)) { + // If someone handled it, then great. otherwise, die in C++ land + // since that means that we'll exit the process, emit the 'exit' event + try { + if (!process._exiting) { + process._exiting = true; + process.emit('exit', 1); + } + } catch (er) { + // nothing to be done about it at this point. + } + try { + const { kExpandStackSymbol } = NativeModule.require('internal/util'); + if (typeof er[kExpandStackSymbol] === 'function') + er[kExpandStackSymbol](); + } catch (er) {} + return false; + } + + // If we handled an error, then make sure any ticks get processed + // by ensuring that the next Immediate cycle isn't empty + NativeModule.require('timers').setImmediate(noop); + + // Emit the after() hooks now that the exception has been handled. + if (afterHooksExist()) { + do { + emitAfter(executionAsyncId()); + } while (hasAsyncIdStack()); + // Or completely empty the id stack. + } else { + clearAsyncIdStack(); + } + + return true; + }; + } + + function setupV8() { + // Warm up the map and set iterator preview functions. V8 compiles + // functions lazily (unless --nolazy is set) so we need to do this + // before we turn off --allow_natives_syntax again. + const v8 = NativeModule.require('internal/v8'); + v8.previewMapIterator(new Map().entries(), 1); + v8.previewSetIterator(new Set().entries(), 1); + // Disable --allow_natives_syntax again unless it was explicitly + // specified on the command line. + const re = /^--allow[-_]natives[-_]syntax$/; + if (!process.execArgv.some((s) => re.test(s))) + process.binding('v8').setFlagsFromString('--noallow_natives_syntax'); + } + + function setupProcessICUVersions() { + const icu = process.binding('config').hasIntl ? + process.binding('icu') : undefined; + if (!icu) return; // no Intl/ICU: nothing to add here. + // With no argument, getVersion() returns a comma separated list + // of possible types. + const versionTypes = icu.getVersion().split(','); + + for (var n = 0; n < versionTypes.length; n++) { + const name = versionTypes[n]; + const version = icu.getVersion(name); + Object.defineProperty(process.versions, name, { + writable: false, + enumerable: true, + value: version + }); + } + } + + function tryGetCwd(path) { + try { + return process.cwd(); + } catch (ex) { + // getcwd(3) can fail if the current working directory has been deleted. + // Fall back to the directory name of the (absolute) executable path. + // It's not really correct but what are the alternatives? + return path.dirname(process.execPath); + } + } + + function wrapForBreakOnFirstLine(source) { + if (!process._breakFirstLine) + return source; + const fn = `function() {\n\n${source};\n\n}`; + return `process.binding('inspector').callAndPauseOnStart(${fn}, {})`; + } + + function evalScript(name) { + const Module = NativeModule.require('module'); + const path = NativeModule.require('path'); + const cwd = tryGetCwd(path); + + const module = new Module(name); + module.filename = path.join(cwd, name); + module.paths = Module._nodeModulePaths(cwd); + const body = wrapForBreakOnFirstLine(process._eval); + const script = `global.__filename = ${JSON.stringify(name)};\n` + + 'global.exports = exports;\n' + + 'global.module = module;\n' + + 'global.__dirname = __dirname;\n' + + 'global.require = require;\n' + + 'return require("vm").runInThisContext(' + + `${JSON.stringify(body)}, { filename: ` + + `${JSON.stringify(name)}, displayErrors: true });\n`; + const result = module._compile(script, `${name}-wrapper`); + if (process._print_eval) console.log(result); + // Handle any nextTicks added in the first tick of the program. + process._tickCallback(); + } + + // Load preload modules + function preloadModules() { + if (process._preload_modules) { + NativeModule.require('module')._preloadModules(process._preload_modules); + } + } + + function checkScriptSyntax(source, filename) { + const Module = NativeModule.require('module'); + const vm = NativeModule.require('vm'); + const internalModule = NativeModule.require('internal/module'); + + // remove Shebang + source = internalModule.stripShebang(source); + // remove BOM + source = internalModule.stripBOM(source); + // wrap it + source = Module.wrap(source); + // compile the script, this will throw if it fails + new vm.Script(source, { displayErrors: true, filename }); + } + + startup(); +}); diff --git a/lib/internal/bootstrap_loaders.js b/lib/internal/bootstrap_loaders.js deleted file mode 100644 index e409438dfc..0000000000 --- a/lib/internal/bootstrap_loaders.js +++ /dev/null @@ -1,229 +0,0 @@ -// This file creates the internal module & binding loaders used by built-in -// modules. In contrast, user land modules are loaded using -// lib/module.js (CommonJS Modules) or lib/internal/loader/* (ES Modules). -// -// This file is compiled and run by node.cc before bootstrap_node.js -// was called, therefore the loaders are bootstraped before we start to -// actually bootstrap Node.js. It creates the following objects: -// -// C++ binding loaders: -// - process.binding(): the legacy C++ binding loader, accessible from user land -// because it is an object attached to the global process object. -// These C++ bindings are created using NODE_BUILTIN_MODULE_CONTEXT_AWARE() -// and have their nm_flags set to NM_F_BUILTIN. We do not make any guarantees -// about the stability of these bindings, but still have to take care of -// compatibility issues caused by them from time to time. -// - process._linkedBinding(): intended to be used by embedders to add -// additional C++ bindings in their applications. These C++ bindings -// can be created using NODE_MODULE_CONTEXT_AWARE_CPP() with the flag -// NM_F_LINKED. -// - internalBinding(): the private internal C++ binding loader, inaccessible -// from user land because they are only available from NativeModule.require() -// These C++ bindings are created using NODE_MODULE_CONTEXT_AWARE_INTERNAL() -// and have their nm_flags set to NM_F_INTERNAL. -// -// Internal JavaScript module loader: -// - NativeModule: a minimal module system used to load the JavaScript core -// modules found in lib/**/*.js and deps/**/*.js. All core modules are -// compiled into the node binary via node_javascript.cc generated by js2c.py, -// so they can be loaded faster without the cost of I/O. This class makes the -// lib/internal/*, deps/internal/* modules and internalBinding() available by -// default to core modules, and lets the core modules require itself via -// require('internal/bootstrap_loaders') even when this file is not written in -// CommonJS style. -// -// Other objects: -// - process.moduleLoadList: an array recording the bindings and the modules -// loaded in the process and the order in which they are loaded. - -'use strict'; - -(function bootstrapInternalLoaders(process, getBinding, getLinkedBinding, - getInternalBinding) { - - // Set up process.moduleLoadList - const moduleLoadList = []; - Object.defineProperty(process, 'moduleLoadList', { - value: moduleLoadList, - configurable: true, - enumerable: true, - writable: false - }); - - // Set up process.binding() and process._linkedBinding() - { - const bindingObj = Object.create(null); - - process.binding = function binding(module) { - module = String(module); - let mod = bindingObj[module]; - if (typeof mod !== 'object') { - mod = bindingObj[module] = getBinding(module); - moduleLoadList.push(`Binding ${module}`); - } - return mod; - }; - - process._linkedBinding = function _linkedBinding(module) { - module = String(module); - let mod = bindingObj[module]; - if (typeof mod !== 'object') - mod = bindingObj[module] = getLinkedBinding(module); - return mod; - }; - } - - // Set up internalBinding() in the closure - let internalBinding; - { - const bindingObj = Object.create(null); - internalBinding = function internalBinding(module) { - let mod = bindingObj[module]; - if (typeof mod !== 'object') { - mod = bindingObj[module] = getInternalBinding(module); - moduleLoadList.push(`Internal Binding ${module}`); - } - return mod; - }; - } - - // Minimal sandbox helper - const ContextifyScript = process.binding('contextify').ContextifyScript; - function runInThisContext(code, options) { - const script = new ContextifyScript(code, options); - return script.runInThisContext(); - } - - // Set up NativeModule - function NativeModule(id) { - this.filename = `${id}.js`; - this.id = id; - this.exports = {}; - this.loaded = false; - this.loading = false; - } - - NativeModule._source = getBinding('natives'); - NativeModule._cache = {}; - - const config = getBinding('config'); - - // Think of this as module.exports in this file even though it is not - // written in CommonJS style. - const loaderExports = { internalBinding, NativeModule }; - const loaderId = 'internal/bootstrap_loaders'; - NativeModule.require = function(id) { - if (id === loaderId) { - return loaderExports; - } - - const cached = NativeModule.getCached(id); - if (cached && (cached.loaded || cached.loading)) { - return cached.exports; - } - - if (!NativeModule.exists(id)) { - // Model the error off the internal/errors.js model, but - // do not use that module given that it could actually be - // the one causing the error if there's a bug in Node.js - const err = new Error(`No such built-in module: ${id}`); - err.code = 'ERR_UNKNOWN_BUILTIN_MODULE'; - err.name = 'Error [ERR_UNKNOWN_BUILTIN_MODULE]'; - throw err; - } - - moduleLoadList.push(`NativeModule ${id}`); - - const nativeModule = new NativeModule(id); - - nativeModule.cache(); - nativeModule.compile(); - - return nativeModule.exports; - }; - - NativeModule.requireForDeps = function(id) { - if (!NativeModule.exists(id) || - // TODO(TimothyGu): remove when DEP0084 reaches end of life. - id.startsWith('node-inspect/') || - id.startsWith('v8/')) { - id = `internal/deps/${id}`; - } - return NativeModule.require(id); - }; - - NativeModule.getCached = function(id) { - return NativeModule._cache[id]; - }; - - NativeModule.exists = function(id) { - return NativeModule._source.hasOwnProperty(id); - }; - - if (config.exposeInternals) { - NativeModule.nonInternalExists = function(id) { - // Do not expose this to user land even with --expose-internals - if (id === loaderId) { - return false; - } - return NativeModule.exists(id); - }; - - NativeModule.isInternal = function(id) { - // Do not expose this to user land even with --expose-internals - return id === loaderId; - }; - } else { - NativeModule.nonInternalExists = function(id) { - return NativeModule.exists(id) && !NativeModule.isInternal(id); - }; - - NativeModule.isInternal = function(id) { - return id.startsWith('internal/'); - }; - } - - NativeModule.getSource = function(id) { - return NativeModule._source[id]; - }; - - NativeModule.wrap = function(script) { - return NativeModule.wrapper[0] + script + NativeModule.wrapper[1]; - }; - - NativeModule.wrapper = [ - '(function (exports, require, module, process) {', - '\n});' - ]; - - NativeModule.prototype.compile = function() { - let source = NativeModule.getSource(this.id); - source = NativeModule.wrap(source); - - this.loading = true; - - try { - const fn = runInThisContext(source, { - filename: this.filename, - lineOffset: 0, - displayErrors: true - }); - const requireFn = this.id.startsWith('internal/deps/') ? - NativeModule.requireForDeps : - NativeModule.require; - fn(this.exports, requireFn, this, process); - - this.loaded = true; - } finally { - this.loading = false; - } - }; - - NativeModule.prototype.cache = function() { - NativeModule._cache[this.id] = this; - }; - - // This will be passed to the bootstrapNodeJSCore function in - // bootstrap_node.js. - return loaderExports; -}); diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js deleted file mode 100644 index 6cdbebc0c1..0000000000 --- a/lib/internal/bootstrap_node.js +++ /dev/null @@ -1,563 +0,0 @@ -// Hello, and welcome to hacking node.js! -// -// This file is invoked by node::LoadEnvironment in src/node.cc, and is -// responsible for bootstrapping the node.js core. As special caution is given -// to the performance of the startup process, many dependencies are invoked -// lazily. -// -// Before this file is run, lib/internal/bootstrap_loaders.js gets run first -// to bootstrap the internal binding and module loaders, including -// process.binding(), process._linkedBinding(), internalBinding() and -// NativeModule. And then { internalBinding, NativeModule } will be passed -// into this bootstrapper to bootstrap Node.js core. - -'use strict'; - -(function bootstrapNodeJSCore(process, { internalBinding, NativeModule }) { - const exceptionHandlerState = { captureFn: null }; - - function startup() { - const EventEmitter = NativeModule.require('events'); - - const origProcProto = Object.getPrototypeOf(process); - Object.setPrototypeOf(origProcProto, EventEmitter.prototype); - - EventEmitter.call(process); - - setupProcessObject(); - - // do this good and early, since it handles errors. - setupProcessFatal(); - - setupV8(); - setupProcessICUVersions(); - - setupGlobalVariables(); - - const _process = NativeModule.require('internal/process'); - _process.setupConfig(NativeModule._source); - _process.setupSignalHandlers(); - _process.setupUncaughtExceptionCapture(exceptionHandlerState); - NativeModule.require('internal/process/warning').setup(); - NativeModule.require('internal/process/next_tick').setup(); - NativeModule.require('internal/process/stdio').setup(); - - const perf = process.binding('performance'); - const { - NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, - NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START, - NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END, - NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START, - NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END, - NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START, - NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END, - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START, - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END - } = perf.constants; - - _process.setup_hrtime(); - _process.setup_performance(); - _process.setup_cpuUsage(); - _process.setupMemoryUsage(); - _process.setupKillAndExit(); - if (global.__coverage__) - NativeModule.require('internal/process/write-coverage').setup(); - - NativeModule.require('internal/trace_events_async_hooks').setup(); - NativeModule.require('internal/inspector_async_hook').setup(); - - _process.setupChannel(); - _process.setupRawDebug(); - - const browserGlobals = !process._noBrowserGlobals; - if (browserGlobals) { - setupGlobalTimeouts(); - setupGlobalConsole(); - setupGlobalURL(); - } - - // Ensure setURLConstructor() is called before the native - // URL::ToObject() method is used. - NativeModule.require('internal/url'); - - // On OpenBSD process.execPath will be relative unless we - // get the full path before process.execPath is used. - if (process.platform === 'openbsd') { - const { realpathSync } = NativeModule.require('fs'); - process.execPath = realpathSync.native(process.execPath); - } - - Object.defineProperty(process, 'argv0', { - enumerable: true, - configurable: false, - value: process.argv[0] - }); - process.argv[0] = process.execPath; - - // Handle `--debug*` deprecation and invalidation - if (process._invalidDebug) { - process.emitWarning( - '`node --debug` and `node --debug-brk` are invalid. ' + - 'Please use `node --inspect` or `node --inspect-brk` instead.', - 'DeprecationWarning', 'DEP0062', startup, true); - process.exit(9); - } else if (process._deprecatedDebugBrk) { - process.emitWarning( - '`node --inspect --debug-brk` is deprecated. ' + - 'Please use `node --inspect-brk` instead.', - 'DeprecationWarning', 'DEP0062', startup, true); - } - - if (process.binding('config').experimentalModules) { - process.emitWarning( - 'The ESM module loader is experimental.', - 'ExperimentalWarning', undefined); - NativeModule.require('internal/process/modules').setup(); - } - - { - // Install legacy getters on the `util` binding for typechecking. - // TODO(addaleax): Turn into a full runtime deprecation. - const { pendingDeprecation } = process.binding('config'); - const { deprecate } = NativeModule.require('internal/util'); - const utilBinding = process.binding('util'); - const types = internalBinding('types'); - for (const name of [ - 'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction', - 'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator', - 'isNativeError', 'isPromise', 'isRegExp', 'isSet', 'isSetIterator', - 'isTypedArray', 'isUint8Array', 'isAnyArrayBuffer' - ]) { - utilBinding[name] = pendingDeprecation ? - deprecate(types[name], - 'Accessing native typechecking bindings of Node ' + - 'directly is deprecated. ' + - `Please use \`util.types.${name}\` instead.`, - 'DEP0103') : - types[name]; - } - } - - // There are various modes that Node can run in. The most common two - // are running from a script and running the REPL - but there are a few - // others like the debugger or running --eval arguments. Here we decide - // which mode we run in. - - if (NativeModule.exists('_third_party_main')) { - // To allow people to extend Node in different ways, this hook allows - // one to drop a file lib/_third_party_main.js into the build - // directory which will be executed instead of Node's normal loading. - process.nextTick(function() { - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START); - NativeModule.require('_third_party_main'); - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END); - }); - - } else if (process.argv[1] === 'inspect' || process.argv[1] === 'debug') { - if (process.argv[1] === 'debug') { - process.emitWarning( - '`node debug` is deprecated. Please use `node inspect` instead.', - 'DeprecationWarning', 'DEP0068'); - } - - // Start the debugger agent - process.nextTick(function() { - NativeModule.require('internal/deps/node-inspect/lib/_inspect').start(); - }); - - } else if (process.profProcess) { - NativeModule.require('internal/v8_prof_processor'); - - } else { - // There is user code to be run - - // If this is a worker in cluster mode, start up the communication - // channel. This needs to be done before any user code gets executed - // (including preload modules). - if (process.argv[1] && process.env.NODE_UNIQUE_ID) { - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START); - const cluster = NativeModule.require('cluster'); - cluster._setupWorker(); - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END); - // Make sure it's not accidentally inherited by child processes. - delete process.env.NODE_UNIQUE_ID; - } - - if (process._eval != null && !process._forceRepl) { - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); - // User passed '-e' or '--eval' arguments to Node without '-i' or - // '--interactive' - - perf.markMilestone( - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); - preloadModules(); - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); - - const internalModule = NativeModule.require('internal/module'); - internalModule.addBuiltinLibsToObject(global); - evalScript('[eval]'); - } else if (process.argv[1] && process.argv[1] !== '-') { - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); - // make process.argv[1] into a full path - const path = NativeModule.require('path'); - process.argv[1] = path.resolve(process.argv[1]); - - const Module = NativeModule.require('module'); - - // check if user passed `-c` or `--check` arguments to Node. - if (process._syntax_check_only != null) { - const fs = NativeModule.require('fs'); - // read the source - const filename = Module._resolveFilename(process.argv[1]); - const source = fs.readFileSync(filename, 'utf-8'); - checkScriptSyntax(source, filename); - process.exit(0); - } - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); - perf.markMilestone( - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); - preloadModules(); - perf.markMilestone( - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); - Module.runMain(); - } else { - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START); - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END); - perf.markMilestone( - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START); - preloadModules(); - perf.markMilestone( - NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END); - // If -i or --interactive were passed, or stdin is a TTY. - if (process._forceRepl || NativeModule.require('tty').isatty(0)) { - // REPL - const cliRepl = NativeModule.require('internal/repl'); - cliRepl.createInternalRepl(process.env, function(err, repl) { - if (err) { - throw err; - } - repl.on('exit', function() { - if (repl._flushing) { - repl.pause(); - return repl.once('flushHistory', function() { - process.exit(); - }); - } - process.exit(); - }); - }); - - if (process._eval != null) { - // User passed '-e' or '--eval' - evalScript('[eval]'); - } - } else { - // Read all of stdin - execute it. - process.stdin.setEncoding('utf8'); - - let code = ''; - process.stdin.on('data', function(d) { - code += d; - }); - - process.stdin.on('end', function() { - if (process._syntax_check_only != null) { - checkScriptSyntax(code, '[stdin]'); - } else { - process._eval = code; - evalScript('[stdin]'); - } - }); - } - } - } - perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); - } - - function setupProcessObject() { - process._setupProcessObject(pushValueToArray); - - function pushValueToArray() { - for (var i = 0; i < arguments.length; i++) - this.push(arguments[i]); - } - } - - function setupGlobalVariables() { - Object.defineProperty(global, Symbol.toStringTag, { - value: 'global', - writable: false, - enumerable: false, - configurable: true - }); - global.process = process; - const util = NativeModule.require('util'); - - function makeGetter(name) { - return util.deprecate(function() { - return this; - }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); - } - - function makeSetter(name) { - return util.deprecate(function(value) { - Object.defineProperty(this, name, { - configurable: true, - writable: true, - enumerable: true, - value: value - }); - }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); - } - - Object.defineProperties(global, { - GLOBAL: { - configurable: true, - get: makeGetter('GLOBAL'), - set: makeSetter('GLOBAL') - }, - root: { - configurable: true, - get: makeGetter('root'), - set: makeSetter('root') - } - }); - - // This, as side effect, removes `setupBufferJS` from the buffer binding, - // and exposes it on `internal/buffer`. - NativeModule.require('internal/buffer'); - - global.Buffer = NativeModule.require('buffer').Buffer; - process.domain = null; - process._exiting = false; - } - - function setupGlobalTimeouts() { - const timers = NativeModule.require('timers'); - global.clearImmediate = timers.clearImmediate; - global.clearInterval = timers.clearInterval; - global.clearTimeout = timers.clearTimeout; - global.setImmediate = timers.setImmediate; - global.setInterval = timers.setInterval; - global.setTimeout = timers.setTimeout; - } - - function setupGlobalConsole() { - const originalConsole = global.console; - const Module = NativeModule.require('module'); - // Setup Node.js global.console - const wrappedConsole = NativeModule.require('console'); - Object.defineProperty(global, 'console', { - configurable: true, - enumerable: false, - value: wrappedConsole - }); - setupInspector(originalConsole, wrappedConsole, Module); - } - - function setupGlobalURL() { - const { URL, URLSearchParams } = NativeModule.require('internal/url'); - Object.defineProperties(global, { - URL: { - value: URL, - writable: true, - configurable: true, - enumerable: false - }, - URLSearchParams: { - value: URLSearchParams, - writable: true, - configurable: true, - enumerable: false - } - }); - } - - function setupInspector(originalConsole, wrappedConsole, Module) { - if (!process.config.variables.v8_enable_inspector) { - return; - } - const { addCommandLineAPI, consoleCall } = process.binding('inspector'); - // Setup inspector command line API - const { makeRequireFunction } = NativeModule.require('internal/module'); - const path = NativeModule.require('path'); - const cwd = tryGetCwd(path); - - const consoleAPIModule = new Module(''); - consoleAPIModule.paths = - Module._nodeModulePaths(cwd).concat(Module.globalPaths); - addCommandLineAPI('require', makeRequireFunction(consoleAPIModule)); - const config = {}; - for (const key of Object.keys(wrappedConsole)) { - if (!originalConsole.hasOwnProperty(key)) - continue; - // If global console has the same method as inspector console, - // then wrap these two methods into one. Native wrapper will preserve - // the original stack. - wrappedConsole[key] = consoleCall.bind(wrappedConsole, - originalConsole[key], - wrappedConsole[key], - config); - } - for (const key of Object.keys(originalConsole)) { - if (wrappedConsole.hasOwnProperty(key)) - continue; - wrappedConsole[key] = originalConsole[key]; - } - } - - function noop() {} - - function setupProcessFatal() { - const { - executionAsyncId, - clearDefaultTriggerAsyncId, - clearAsyncIdStack, - hasAsyncIdStack, - afterHooksExist, - emitAfter - } = NativeModule.require('internal/async_hooks'); - - process._fatalException = function(er) { - // It's possible that defaultTriggerAsyncId was set for a constructor - // call that threw and was never cleared. So clear it now. - clearDefaultTriggerAsyncId(); - - if (exceptionHandlerState.captureFn !== null) { - exceptionHandlerState.captureFn(er); - } else if (!process.emit('uncaughtException', er)) { - // If someone handled it, then great. otherwise, die in C++ land - // since that means that we'll exit the process, emit the 'exit' event - try { - if (!process._exiting) { - process._exiting = true; - process.emit('exit', 1); - } - } catch (er) { - // nothing to be done about it at this point. - } - try { - const { kExpandStackSymbol } = NativeModule.require('internal/util'); - if (typeof er[kExpandStackSymbol] === 'function') - er[kExpandStackSymbol](); - } catch (er) {} - return false; - } - - // If we handled an error, then make sure any ticks get processed - // by ensuring that the next Immediate cycle isn't empty - NativeModule.require('timers').setImmediate(noop); - - // Emit the after() hooks now that the exception has been handled. - if (afterHooksExist()) { - do { - emitAfter(executionAsyncId()); - } while (hasAsyncIdStack()); - // Or completely empty the id stack. - } else { - clearAsyncIdStack(); - } - - return true; - }; - } - - function setupV8() { - // Warm up the map and set iterator preview functions. V8 compiles - // functions lazily (unless --nolazy is set) so we need to do this - // before we turn off --allow_natives_syntax again. - const v8 = NativeModule.require('internal/v8'); - v8.previewMapIterator(new Map().entries(), 1); - v8.previewSetIterator(new Set().entries(), 1); - // Disable --allow_natives_syntax again unless it was explicitly - // specified on the command line. - const re = /^--allow[-_]natives[-_]syntax$/; - if (!process.execArgv.some((s) => re.test(s))) - process.binding('v8').setFlagsFromString('--noallow_natives_syntax'); - } - - function setupProcessICUVersions() { - const icu = process.binding('config').hasIntl ? - process.binding('icu') : undefined; - if (!icu) return; // no Intl/ICU: nothing to add here. - // With no argument, getVersion() returns a comma separated list - // of possible types. - const versionTypes = icu.getVersion().split(','); - - for (var n = 0; n < versionTypes.length; n++) { - const name = versionTypes[n]; - const version = icu.getVersion(name); - Object.defineProperty(process.versions, name, { - writable: false, - enumerable: true, - value: version - }); - } - } - - function tryGetCwd(path) { - try { - return process.cwd(); - } catch (ex) { - // getcwd(3) can fail if the current working directory has been deleted. - // Fall back to the directory name of the (absolute) executable path. - // It's not really correct but what are the alternatives? - return path.dirname(process.execPath); - } - } - - function wrapForBreakOnFirstLine(source) { - if (!process._breakFirstLine) - return source; - const fn = `function() {\n\n${source};\n\n}`; - return `process.binding('inspector').callAndPauseOnStart(${fn}, {})`; - } - - function evalScript(name) { - const Module = NativeModule.require('module'); - const path = NativeModule.require('path'); - const cwd = tryGetCwd(path); - - const module = new Module(name); - module.filename = path.join(cwd, name); - module.paths = Module._nodeModulePaths(cwd); - const body = wrapForBreakOnFirstLine(process._eval); - const script = `global.__filename = ${JSON.stringify(name)};\n` + - 'global.exports = exports;\n' + - 'global.module = module;\n' + - 'global.__dirname = __dirname;\n' + - 'global.require = require;\n' + - 'return require("vm").runInThisContext(' + - `${JSON.stringify(body)}, { filename: ` + - `${JSON.stringify(name)}, displayErrors: true });\n`; - const result = module._compile(script, `${name}-wrapper`); - if (process._print_eval) console.log(result); - // Handle any nextTicks added in the first tick of the program. - process._tickCallback(); - } - - // Load preload modules - function preloadModules() { - if (process._preload_modules) { - NativeModule.require('module')._preloadModules(process._preload_modules); - } - } - - function checkScriptSyntax(source, filename) { - const Module = NativeModule.require('module'); - const vm = NativeModule.require('vm'); - const internalModule = NativeModule.require('internal/module'); - - // remove Shebang - source = internalModule.stripShebang(source); - // remove BOM - source = internalModule.stripBOM(source); - // wrap it - source = Module.wrap(source); - // compile the script, this will throw if it fails - new vm.Script(source, { displayErrors: true, filename }); - } - - startup(); -}); diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 1846fc5527..9cd47f861f 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -23,7 +23,7 @@ const { const { isArrayBufferView } = require('internal/util/types'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { isArrayBuffer } = internalBinding('types'); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 7137e527df..9315474364 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -4,7 +4,7 @@ require('internal/util').assertCrypto(); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { async_id_symbol } = require('internal/async_hooks').symbols; const { UV_EOF } = process.binding('uv'); const http = require('http'); diff --git a/lib/internal/loader/CreateDynamicModule.js b/lib/internal/loader/CreateDynamicModule.js index 8c28917138..7e9777af51 100644 --- a/lib/internal/loader/CreateDynamicModule.js +++ b/lib/internal/loader/CreateDynamicModule.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const debug = require('util').debuglog('esm'); const ArrayJoin = Function.call.bind(Array.prototype.join); diff --git a/lib/internal/loader/DefaultResolve.js b/lib/internal/loader/DefaultResolve.js index f99e0c98b9..a012314d2a 100644 --- a/lib/internal/loader/DefaultResolve.js +++ b/lib/internal/loader/DefaultResolve.js @@ -3,7 +3,7 @@ const { URL } = require('url'); const CJSmodule = require('module'); const internalFS = require('internal/fs'); -const { NativeModule, internalBinding } = require('internal/bootstrap_loaders'); +const { NativeModule, internalBinding } = require('internal/bootstrap/loaders'); const { extname } = require('path'); const { realpathSync } = require('fs'); const preserveSymlinks = !!process.binding('config').preserveSymlinks; diff --git a/lib/internal/loader/ModuleJob.js b/lib/internal/loader/ModuleJob.js index 162b0504d3..d948252829 100644 --- a/lib/internal/loader/ModuleJob.js +++ b/lib/internal/loader/ModuleJob.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const { SafeSet, SafePromise } = require('internal/safe_globals'); const { decorateErrorStack } = require('internal/util'); diff --git a/lib/internal/loader/Translators.js b/lib/internal/loader/Translators.js index 74dd435827..8796b4ddfd 100644 --- a/lib/internal/loader/Translators.js +++ b/lib/internal/loader/Translators.js @@ -1,6 +1,6 @@ 'use strict'; -const { NativeModule, internalBinding } = require('internal/bootstrap_loaders'); +const { NativeModule, internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const internalCJSModule = require('internal/module'); const CJSModule = require('module'); diff --git a/lib/internal/process/modules.js b/lib/internal/process/modules.js index 1592761f54..ca2a9dde5d 100644 --- a/lib/internal/process/modules.js +++ b/lib/internal/process/modules.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { setImportModuleDynamicallyCallback, setInitializeImportMetaObjectCallback diff --git a/lib/internal/test/binding.js b/lib/internal/test/binding.js index aae89ce7a0..f9f018a782 100644 --- a/lib/internal/test/binding.js +++ b/lib/internal/test/binding.js @@ -8,7 +8,7 @@ process.emitWarning( // These exports should be scoped as specifically as possible // to avoid exposing APIs because even with that warning and // this file being internal people will still try to abuse it. -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); module.exports = { ModuleWrap: internalBinding('module_wrap').ModuleWrap, }; diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index c1c4d7a712..119fb66611 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -2,7 +2,7 @@ const { compare } = process.binding('buffer'); const { isArrayBufferView } = require('internal/util/types'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { isDate, isMap, isRegExp, isSet } = internalBinding('types'); function objectToString(o) { diff --git a/lib/internal/vm/Module.js b/lib/internal/vm/Module.js index 6d8f7f76d8..feb4bb190f 100644 --- a/lib/internal/vm/Module.js +++ b/lib/internal/vm/Module.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { emitExperimentalWarning } = require('internal/util'); const { URL } = require('internal/url'); const { kParsingContext, isContext } = process.binding('contextify'); diff --git a/lib/module.js b/lib/module.js index 6d4e3dbfcf..0b94cb84c6 100644 --- a/lib/module.js +++ b/lib/module.js @@ -21,7 +21,7 @@ 'use strict'; -const { NativeModule } = require('internal/bootstrap_loaders'); +const { NativeModule } = require('internal/bootstrap/loaders'); const util = require('util'); const { decorateErrorStack } = require('internal/util'); const { getURLFromFilePath } = require('internal/url'); diff --git a/lib/string_decoder.js b/lib/string_decoder.js index 4cb50ca97b..a6ae64c062 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -22,7 +22,7 @@ 'use strict'; const { Buffer } = require('buffer'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { kIncompleteCharactersStart, kIncompleteCharactersEnd, diff --git a/lib/util.js b/lib/util.js index 95bf17519b..b64d103cb3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -39,7 +39,7 @@ const { kRejected, } = process.binding('util'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const types = internalBinding('types'); Object.assign(types, require('internal/util/types')); const { diff --git a/node.gyp b/node.gyp index 1b047fe9ac..06f0a3b57c 100644 --- a/node.gyp +++ b/node.gyp @@ -24,8 +24,8 @@ 'node_lib_target_name%': 'node_lib', 'node_intermediate_lib_type%': 'static_library', 'library_files': [ - 'lib/internal/bootstrap_loaders.js', - 'lib/internal/bootstrap_node.js', + 'lib/internal/bootstrap/loaders.js', + 'lib/internal/bootstrap/node.js', 'lib/async_hooks.js', 'lib/assert.js', 'lib/buffer.js', diff --git a/src/node.cc b/src/node.cc index ede8314924..33065cd504 100644 --- a/src/node.cc +++ b/src/node.cc @@ -246,7 +246,7 @@ bool config_experimental_vm_modules = false; // Set in node.cc by ParseArgs when --loader is used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js std::string config_userland_loader; // NOLINT(runtime/string) // Set by ParseArgs when --pending-deprecation or NODE_PENDING_DEPRECATION @@ -259,7 +259,7 @@ std::string config_warning_file; // NOLINT(runtime/string) // Set in node.cc by ParseArgs when --expose-internals or --expose_internals is // used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js bool config_expose_internals = false; bool v8_initialized = false; @@ -3319,23 +3319,23 @@ static Local GetBootstrapper(Environment* env, Local source, // are not safe to ignore. try_catch.SetVerbose(false); - // Execute the factory javascript file - Local factory_v = ExecuteString(env, source, script_name); + // Execute the bootstrapper javascript file + Local bootstrapper_v = ExecuteString(env, source, script_name); if (try_catch.HasCaught()) { ReportException(env, try_catch); exit(10); } - CHECK(factory_v->IsFunction()); - Local factory = Local::Cast(factory_v); + CHECK(bootstrapper_v->IsFunction()); + Local bootstrapper = Local::Cast(bootstrapper_v); - return scope.Escape(factory); + return scope.Escape(bootstrapper); } -static bool ExecuteBootstrapper(Environment* env, Local factory, +static bool ExecuteBootstrapper(Environment* env, Local bootstrapper, int argc, Local argv[], Local* out) { - bool ret = factory->Call( + bool ret = bootstrapper->Call( env->context(), Null(env->isolate()), argc, argv).ToLocal(out); // If there was an error during bootstrap then it was either handled by the @@ -3362,16 +3362,18 @@ void LoadEnvironment(Environment* env) { // are not safe to ignore. try_catch.SetVerbose(false); - // The factory scripts are lib/internal/bootstrap_loaders.js and - // lib/internal/bootstrap_node.js, each included as a static C string + // The bootstrapper scripts are lib/internal/bootstrap/loaders.js and + // lib/internal/bootstrap/node.js, each included as a static C string // defined in node_javascript.h, generated in node_javascript.cc by // node_js2c. + Local loaders_name = + FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/loaders.js"); Local loaders_bootstrapper = - GetBootstrapper(env, LoadersBootstrapperSource(env), - FIXED_ONE_BYTE_STRING(env->isolate(), "bootstrap_loaders.js")); + GetBootstrapper(env, LoadersBootstrapperSource(env), loaders_name); + Local node_name = + FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/node.js"); Local node_bootstrapper = - GetBootstrapper(env, NodeBootstrapperSource(env), - FIXED_ONE_BYTE_STRING(env->isolate(), "bootstrap_node.js")); + GetBootstrapper(env, NodeBootstrapperSource(env), node_name); // Add a reference to the global object Local global = env->context()->Global(); @@ -4285,7 +4287,7 @@ void Init(int* argc, #endif // Needed for access to V8 intrinsics. Disabled again during bootstrapping, - // see lib/internal/bootstrap_node.js. + // see lib/internal/bootstrap/node.js. const char allow_natives_syntax[] = "--allow_natives_syntax"; V8::SetFlagsFromString(allow_natives_syntax, sizeof(allow_natives_syntax) - 1); diff --git a/src/node_internals.h b/src/node_internals.h index 79c2ce5532..909d5e1790 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -183,13 +183,13 @@ extern bool config_experimental_vm_modules; // Set in node.cc by ParseArgs when --loader is used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js extern std::string config_userland_loader; // Set in node.cc by ParseArgs when --expose-internals or --expose_internals is // used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js extern bool config_expose_internals; // Set in node.cc by ParseArgs when --redirect-warnings= is used. diff --git a/src/node_url.cc b/src/node_url.cc index cac2831af6..6b56628d75 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -2275,7 +2275,7 @@ const Local URL::ToObject(Environment* env) const { // The SetURLConstructor method must have been called already to // set the constructor function used below. SetURLConstructor is // called automatically when the internal/url.js module is loaded - // during the internal/bootstrap_node.js processing. + // during the internal/bootstrap/node.js processing. ret = env->url_constructor_function() ->Call(env->context(), undef, arraysize(argv), argv); } diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 1049fdc3e9..5658a5a59e 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -12,4 +12,4 @@ RangeError: Invalid input at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) diff --git a/test/message/error_exit.out b/test/message/error_exit.out index eab43959b6..2cbc4ad4fd 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -11,5 +11,5 @@ AssertionError [ERR_ASSERTION]: 1 strictEqual 2 at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/eval_messages.out b/test/message/eval_messages.out index 7dbf9e950c..84772ffa48 100644 --- a/test/message/eval_messages.out +++ b/test/message/eval_messages.out @@ -8,9 +8,9 @@ SyntaxError: Strict mode code may not include a with statement at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) 42 42 [eval]:1 @@ -23,9 +23,9 @@ Error: hello at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) [eval]:1 throw new Error("hello") @@ -37,9 +37,9 @@ Error: hello at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) 100 [eval]:1 var x = 100; y = x; @@ -51,9 +51,9 @@ ReferenceError: y is not defined at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) [eval]:1 var ______________________________________________; throw 10 diff --git a/test/message/events_unhandled_error_common_trace.out b/test/message/events_unhandled_error_common_trace.out index 1535573470..003446edaa 100644 --- a/test/message/events_unhandled_error_common_trace.out +++ b/test/message/events_unhandled_error_common_trace.out @@ -12,11 +12,11 @@ Error: foo:bar at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) Emitted 'error' event at: at quux (*events_unhandled_error_common_trace.js:*:*) at Object. (*events_unhandled_error_common_trace.js:*:*) at Module._compile (module.js:*:*) [... lines matching original stack trace ...] - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/events_unhandled_error_nexttick.out b/test/message/events_unhandled_error_nexttick.out index c578f55f90..5912f9fd38 100644 --- a/test/message/events_unhandled_error_nexttick.out +++ b/test/message/events_unhandled_error_nexttick.out @@ -10,11 +10,11 @@ Error at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) Emitted 'error' event at: at process.nextTick (*events_unhandled_error_nexttick.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/events_unhandled_error_sameline.out b/test/message/events_unhandled_error_sameline.out index d8441c44d4..dcbb45afbd 100644 --- a/test/message/events_unhandled_error_sameline.out +++ b/test/message/events_unhandled_error_sameline.out @@ -10,10 +10,10 @@ Error at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) Emitted 'error' event at: at Object. (*events_unhandled_error_sameline.js:*:*) at Module._compile (module.js:*:*) [... lines matching original stack trace ...] - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/nexttick_throw.out b/test/message/nexttick_throw.out index 41412b95f6..798b208d7d 100644 --- a/test/message/nexttick_throw.out +++ b/test/message/nexttick_throw.out @@ -6,5 +6,5 @@ ReferenceError: undefined_reference_error_maker is not defined at *test*message*nexttick_throw.js:*:* at process._tickCallback (internal/process/next_tick.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out index d2192050dd..c6c37a5be4 100644 --- a/test/message/stdin_messages.out +++ b/test/message/stdin_messages.out @@ -8,8 +8,8 @@ SyntaxError: Strict mode code may not include a with statement at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -25,8 +25,8 @@ Error: hello at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -40,8 +40,8 @@ Error: hello at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -56,8 +56,8 @@ ReferenceError: y is not defined at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) diff --git a/test/parallel/test-loaders-hidden-from-users.js b/test/parallel/test-loaders-hidden-from-users.js index b3e6622c8c..0d752f5718 100644 --- a/test/parallel/test-loaders-hidden-from-users.js +++ b/test/parallel/test-loaders-hidden-from-users.js @@ -6,16 +6,16 @@ const common = require('../common'); common.expectsError( () => { - require('internal/bootstrap_loaders'); + require('internal/bootstrap/loaders'); }, { code: 'MODULE_NOT_FOUND', - message: 'Cannot find module \'internal/bootstrap_loaders\'' + message: 'Cannot find module \'internal/bootstrap/loaders\'' } ); common.expectsError( () => { - const source = 'module.exports = require("internal/bootstrap_loaders")'; + const source = 'module.exports = require("internal/bootstrap/loaders")'; process.binding('natives').owo = source; require('owo'); }, { diff --git a/test/sequential/test-inspector-overwrite-config.js b/test/sequential/test-inspector-overwrite-config.js index 2a00b1e079..8b641a0048 100644 --- a/test/sequential/test-inspector-overwrite-config.js +++ b/test/sequential/test-inspector-overwrite-config.js @@ -2,7 +2,8 @@ 'use strict'; // This test ensures that overwriting a process configuration -// value does not affect code in bootstrap_node.js. Specifically this tests +// value does not affect code in lib/internal/bootstrap/node.js. +// Specifically this tests // that the inspector console functions are bound even though // overwrite-config-preload-module.js overwrote the process.config variable. -- cgit v1.2.3