Skip to content
Permalink
Browse files

src: split `LoadEnvironment()` at `startExecution()`

This makes it easier to cater to embedders which wish to skip
the `startExecution()` part.

PR-URL: #25320
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information...
addaleax authored and BridgeAR committed Jan 2, 2019
1 parent e8a6cc8 commit 6cdaf038ce7ac4acc0318ebf4e20bdaea73fa1af
@@ -319,7 +319,7 @@ function startup() {
} = perf.constants;
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);

startExecution();
return startExecution;
}

// There are various modes that Node can run in. The most common two
@@ -737,4 +737,4 @@ function checkScriptSyntax(source, filename) {
new vm.Script(source, { displayErrors: true, filename });
}

startup();
return startup();
@@ -633,6 +633,14 @@ inline void Environment::set_can_call_into_js(bool can_call_into_js) {
can_call_into_js_ = can_call_into_js;
}

inline bool Environment::has_run_bootstrapping_code() const {
return has_run_bootstrapping_code_;
}

inline void Environment::set_has_run_bootstrapping_code(bool value) {
has_run_bootstrapping_code_ = value;
}

inline bool Environment::is_main_thread() const {
return thread_id_ == 0;
}
@@ -369,6 +369,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
V(script_data_constructor_function, v8::Function) \
V(secure_context_constructor_template, v8::FunctionTemplate) \
V(shutdown_wrap_template, v8::ObjectTemplate) \
V(start_execution_function, v8::Function) \
V(tcp_constructor_template, v8::FunctionTemplate) \
V(tick_callback_function, v8::Function) \
V(timers_callback_function, v8::Function) \
@@ -751,6 +752,9 @@ class Environment {
inline bool can_call_into_js() const;
inline void set_can_call_into_js(bool can_call_into_js);

inline bool has_run_bootstrapping_code() const;
inline void set_has_run_bootstrapping_code(bool has_run_bootstrapping_code);

inline bool is_main_thread() const;
inline uint64_t thread_id() const;
inline void set_thread_id(uint64_t id);
@@ -976,6 +980,7 @@ class Environment {
std::unique_ptr<performance::performance_state> performance_state_;
std::unordered_map<std::string, uint64_t> performance_marks_;

bool has_run_bootstrapping_code_ = false;
bool can_call_into_js_ = true;
uint64_t thread_id_ = 0;
std::unordered_set<worker::Worker*> sub_worker_contexts_;
@@ -1079,6 +1079,14 @@ static MaybeLocal<Value> ExecuteBootstrapper(
}

void LoadEnvironment(Environment* env) {
RunBootstrapping(env);
StartExecution(env);
}

void RunBootstrapping(Environment* env) {
CHECK(!env->has_run_bootstrapping_code());
env->set_has_run_bootstrapping_code(true);

HandleScope handle_scope(env->isolate());
Isolate* isolate = env->isolate();
Local<Context> context = env->context();
@@ -1140,11 +1148,29 @@ void LoadEnvironment(Environment* env) {
loader_exports.ToLocalChecked(),
Boolean::New(isolate, env->is_main_thread())};

if (ExecuteBootstrapper(
Local<Value> start_execution;
if (!ExecuteBootstrapper(
env, "internal/bootstrap/node", &node_params, &node_args)
.IsEmpty()) {
.ToLocal(&start_execution)) {
return;
}

if (start_execution->IsFunction())
env->set_start_execution_function(start_execution.As<Function>());
}

void StartExecution(Environment* env) {
HandleScope handle_scope(env->isolate());
// We have to use Local<>::New because of the optimized way in which we access
// the object in the env->...() getters, which does not play well with
// resetting the handle while we're accessing the object through the Local<>.
Local<Function> start_execution =
Local<Function>::New(env->isolate(), env->start_execution_function());
env->set_start_execution_function(Local<Function>());

if (start_execution.IsEmpty()) return;
USE(start_execution->Call(
env->context(), Undefined(env->isolate()), 0, nullptr));
}

static void StartInspector(Environment* env, const char* path) {
@@ -397,6 +397,9 @@ bool SafeGetenv(const char* key, std::string* text);

void DefineZlibConstants(v8::Local<v8::Object> target);

void RunBootstrapping(Environment* env);
void StartExecution(Environment* env);

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -18,4 +18,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
at *
at *
at *
at *
@@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
@@ -11,8 +11,6 @@ SyntaxError: Strict mode code may not include a with statement
at evalScript (internal/process/execution.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*
42
42
[eval]:1
@@ -28,8 +26,6 @@ Error: hello
at evalScript (internal/process/execution.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*

[eval]:1
throw new Error("hello")
@@ -44,8 +40,6 @@ Error: hello
at evalScript (internal/process/execution.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*
100
[eval]:1
var x = 100; y = x;
@@ -60,8 +54,6 @@ ReferenceError: y is not defined
at evalScript (internal/process/execution.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*

[eval]:1
var ______________________________________________; throw 10
@@ -12,13 +12,10 @@ Error
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
Emitted 'error' event at:
at process.nextTick (*events_unhandled_error_nexttick.js:*:*)
at processTicksAndRejections (internal/process/next_tick.js:*:*)
at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:*:*)
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*
@@ -12,9 +12,8 @@ Error
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
Emitted 'error' event at:
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
[... lines matching original stack trace ...]
at startup (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
@@ -9,5 +9,3 @@ ReferenceError: undefined_reference_error_maker is not defined
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at executeUserCode (internal/bootstrap/node.js:*:*)
at startExecution (internal/bootstrap/node.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
at internal/bootstrap/node.js:*:*
@@ -15,9 +15,6 @@
at *
at *
at *
at *
at *
at *
(node:*) Error: This was rejected
at * (*test*message*unhandled_promise_trace_warnings.js:*)
at *
@@ -28,7 +25,6 @@
at *
at *
at *
at *
(node:*) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at *
at *
@@ -38,8 +34,6 @@
at *
at *
at *
at *
at *
(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
at handledRejection (internal/process/promises.js:*)
at promiseRejectHandler (internal/process/promises.js:*)
@@ -10,7 +10,6 @@
at *
at *
at *
at *
nested:
{ err:
Error: foo
@@ -23,7 +22,6 @@
at *
at *
at *
at *
at * } }
{
err: Error: foo
@@ -36,7 +34,6 @@
at *
at *
at *
at *
at *,
nested: {
err: Error: foo
@@ -50,7 +47,6 @@
at *
at *
at *
at *
}
}
{ Error: foo
@@ -64,5 +60,4 @@ bar
at *
at *
at *
at *
foo: 'bar' }

0 comments on commit 6cdaf03

Please sign in to comment.
You can’t perform that action at this time.