Skip to content

Commit

Permalink
src: put bootstrappers in lib/internal/bootstrap/
Browse files Browse the repository at this point in the history
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
```

Backport-PR-URL: #19374
PR-URL: #19177
Refs: #19112
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Apr 4, 2018
1 parent ff7a116 commit ebdcf91
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const util = require('util');
const EventEmitter = require('events');
const errors = require('internal/errors');
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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
// 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:
//
Expand All @@ -29,7 +29,7 @@
// 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
// require('internal/bootstrap/loaders') even when this file is not written in
// CommonJS style.
//
// Other objects:
Expand Down Expand Up @@ -111,7 +111,7 @@
// 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';
const loaderId = 'internal/bootstrap/loaders';
NativeModule.require = function(id) {
if (id === loaderId) {
return loaderExports;
Expand Down Expand Up @@ -211,6 +211,6 @@
};

// This will be passed to the bootstrapNodeJSCore function in
// bootstrap_node.js.
// bootstrap/node.js.
return loaderExports;
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 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
// 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
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/loader/CreateDynamicModule.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/loader/DefaultResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/loader/ModuleJob.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/loader/ModuleWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// exposes ModuleWrap for testing

const { internalBinding } = require('internal/bootstrap_loaders');
const { internalBinding } = require('internal/bootstrap/loaders');
module.exports = internalBinding('module_wrap').ModuleWrap;
2 changes: 1 addition & 1 deletion lib/internal/loader/Translators.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/modules.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { internalBinding } = require('internal/bootstrap_loaders');
const { internalBinding } = require('internal/bootstrap/loaders');
const {
setImportModuleDynamicallyCallback
} = internalBinding('module_wrap');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/vm/Module.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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',
Expand Down
32 changes: 17 additions & 15 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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
Expand All @@ -263,7 +263,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;
Expand Down Expand Up @@ -3645,23 +3645,23 @@ static Local<Function> GetBootstrapper(Environment* env, Local<String> source,
// are not safe to ignore.
try_catch.SetVerbose(false);

// Execute the factory javascript file
Local<Value> factory_v = ExecuteString(env, source, script_name);
// Execute the bootstrapper javascript file
Local<Value> bootstrapper_v = ExecuteString(env, source, script_name);
if (try_catch.HasCaught()) {
ReportException(env, try_catch);
exit(10);
}

CHECK(factory_v->IsFunction());
Local<Function> factory = Local<Function>::Cast(factory_v);
CHECK(bootstrapper_v->IsFunction());
Local<Function> bootstrapper = Local<Function>::Cast(bootstrapper_v);

return scope.Escape(factory);
return scope.Escape(bootstrapper);
}

static bool ExecuteBootstrapper(Environment* env, Local<Function> factory,
static bool ExecuteBootstrapper(Environment* env, Local<Function> bootstrapper,
int argc, Local<Value> argv[],
Local<Value>* 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
Expand All @@ -3688,16 +3688,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<String> loaders_name =
FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/loaders.js");
Local<Function> loaders_bootstrapper =
GetBootstrapper(env, LoadersBootstrapperSource(env),
FIXED_ONE_BYTE_STRING(env->isolate(), "bootstrap_loaders.js"));
GetBootstrapper(env, LoadersBootstrapperSource(env), loaders_name);
Local<String> node_name =
FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/node.js");
Local<Function> 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<Object> global = env->context()->Global();
Expand Down
4 changes: 2 additions & 2 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,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.
Expand Down
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@ const Local<Value> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion test/message/core_line_numbers.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*)
4 changes: 2 additions & 2 deletions test/message/error_exit.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ AssertionError [ERR_ASSERTION]: 1 === 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:*:*)
24 changes: 12 additions & 12 deletions test/message/eval_messages.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ SyntaxError: Strict mode code may not include a with statement
at Object.runInThisContext (vm.js:*:*)
at Object.<anonymous> ([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
Expand All @@ -23,9 +23,9 @@ Error: hello
at Object.runInThisContext (vm.js:*:*)
at Object.<anonymous> ([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")
Expand All @@ -37,9 +37,9 @@ Error: hello
at Object.runInThisContext (vm.js:*:*)
at Object.<anonymous> ([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;
Expand All @@ -51,9 +51,9 @@ ReferenceError: y is not defined
at Object.runInThisContext (vm.js:*:*)
at Object.<anonymous> ([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
Expand Down
6 changes: 3 additions & 3 deletions test/message/events_unhandled_error_common_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> (*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:*:*)
8 changes: 4 additions & 4 deletions test/message/events_unhandled_error_nexttick.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*)
6 changes: 3 additions & 3 deletions test/message/events_unhandled_error_sameline.out
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> (*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:*:*)
4 changes: 2 additions & 2 deletions test/message/nexttick_throw.out
Original file line number Diff line number Diff line change
Expand Up @@ -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:*:*)
16 changes: 8 additions & 8 deletions test/message/stdin_messages.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ SyntaxError: Strict mode code may not include a with statement
at Object.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at evalScript (bootstrap_node.js:*:*)
at Socket.<anonymous> (bootstrap_node.js:*:*)
at evalScript (internal/bootstrap/node.js:*:*)
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
at Socket.emit (events.js:*:*)
at endReadableNT (_stream_readable.js:*:*)
at process._tickCallback (internal/process/next_tick.js:*:*)
Expand All @@ -25,8 +25,8 @@ Error: hello
at Object.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at evalScript (bootstrap_node.js:*:*)
at Socket.<anonymous> (bootstrap_node.js:*:*)
at evalScript (internal/bootstrap/node.js:*:*)
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
at Socket.emit (events.js:*:*)
at endReadableNT (_stream_readable.js:*:*)
at process._tickCallback (internal/process/next_tick.js:*:*)
Expand All @@ -40,8 +40,8 @@ Error: hello
at Object.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at evalScript (bootstrap_node.js:*:*)
at Socket.<anonymous> (bootstrap_node.js:*:*)
at evalScript (internal/bootstrap/node.js:*:*)
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
at Socket.emit (events.js:*:*)
at endReadableNT (_stream_readable.js:*:*)
at process._tickCallback (internal/process/next_tick.js:*:*)
Expand All @@ -56,8 +56,8 @@ ReferenceError: y is not defined
at Object.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at evalScript (bootstrap_node.js:*:*)
at Socket.<anonymous> (bootstrap_node.js:*:*)
at evalScript (internal/bootstrap/node.js:*:*)
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
at Socket.emit (events.js:*:*)
at endReadableNT (_stream_readable.js:*:*)
at process._tickCallback (internal/process/next_tick.js:*:*)
Expand Down
Loading

0 comments on commit ebdcf91

Please sign in to comment.