src: split LoadEnvironment() at startExecution()

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

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2019-01-02 22:14:23 +01:00
parent 728505acd5
commit f6a1d88c5d
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
13 changed files with 47 additions and 32 deletions

View File

@ -303,7 +303,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
@ -729,4 +729,4 @@ function checkScriptSyntax(source, filename) {
new vm.Script(source, { displayErrors: true, filename });
}
startup();
return startup();

View File

@ -637,6 +637,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;
}

View File

@ -371,6 +371,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) \
@ -755,6 +756,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);
@ -980,6 +984,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_;

View File

@ -1085,6 +1085,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();
@ -1146,11 +1154,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) {

View File

@ -724,6 +724,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

View File

@ -18,4 +18,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
at *
at *
at *
at *

View File

@ -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:*:*)

View File

@ -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

View File

@ -12,7 +12,6 @@ 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 internalTickCallback (internal/process/next_tick.js:*:*)
@ -20,5 +19,3 @@ Emitted 'error' event at:
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:*:*

View File

@ -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:*:*)

View File

@ -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:*:*

View File

@ -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:*)

View File

@ -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' }