GeezerVison is showing github.com — src: split `LoadEnvironment()` at `startExecution()` · nodejs/node@21096f9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -319,7 +319,7 @@ function startup() { | 319 | 319 | } = perf.constants; | 320 | 320 | perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); | 321 | 321 |
| 322 | | - startExecution(); | | 322 | + return startExecution; | 323 | 323 | } | 324 | 324 |
| 325 | 325 | // There are various modes that Node can run in. The most common two | @@ -737,4 +737,4 @@ function checkScriptSyntax(source, filename) { | 737 | 737 | new vm.Script(source, { displayErrors: true, filename }); | 738 | 738 | } | 739 | 739 |
| 740 | | -startup(); | | 740 | +return startup(); |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -633,6 +633,14 @@ inline void Environment::set_can_call_into_js(bool can_call_into_js) { | 633 | 633 | can_call_into_js_ = can_call_into_js; | 634 | 634 | } | 635 | 635 |
| | 636 | +inline bool Environment::has_run_bootstrapping_code() const { | | 637 | + return has_run_bootstrapping_code_; | | 638 | +} | | 639 | + | | 640 | +inline void Environment::set_has_run_bootstrapping_code(bool value) { | | 641 | + has_run_bootstrapping_code_ = value; | | 642 | +} | | 643 | + | 636 | 644 | inline bool Environment::is_main_thread() const { | 637 | 645 | return thread_id_ == 0; | 638 | 646 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -369,6 +369,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; | 369 | 369 | V(script_data_constructor_function, v8::Function) \ | 370 | 370 | V(secure_context_constructor_template, v8::FunctionTemplate) \ | 371 | 371 | V(shutdown_wrap_template, v8::ObjectTemplate) \ | | 372 | + V(start_execution_function, v8::Function) \ | 372 | 373 | V(tcp_constructor_template, v8::FunctionTemplate) \ | 373 | 374 | V(tick_callback_function, v8::Function) \ | 374 | 375 | V(timers_callback_function, v8::Function) \ | @@ -751,6 +752,9 @@ class Environment { | 751 | 752 | inline bool can_call_into_js() const; | 752 | 753 | inline void set_can_call_into_js(bool can_call_into_js); | 753 | 754 |
| | 755 | + inline bool has_run_bootstrapping_code() const; | | 756 | + inline void set_has_run_bootstrapping_code(bool has_run_bootstrapping_code); | | 757 | + | 754 | 758 | inline bool is_main_thread() const; | 755 | 759 | inline uint64_t thread_id() const; | 756 | 760 | inline void set_thread_id(uint64_t id); | @@ -976,6 +980,7 @@ class Environment { | 976 | 980 | std::unique_ptr<performance::performance_state> performance_state_; | 977 | 981 | std::unordered_map<std::string, uint64_t> performance_marks_; | 978 | 982 |
| | 983 | + bool has_run_bootstrapping_code_ = false; | 979 | 984 | bool can_call_into_js_ = true; | 980 | 985 | uint64_t thread_id_ = 0; | 981 | 986 | std::unordered_set<worker::Worker*> sub_worker_contexts_; | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +28-2Lines changed: 28 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1079,6 +1079,14 @@ static MaybeLocal<Value> ExecuteBootstrapper( | 1079 | 1079 | } | 1080 | 1080 |
| 1081 | 1081 | void LoadEnvironment(Environment* env) { | | 1082 | + RunBootstrapping(env); | | 1083 | + StartExecution(env); | | 1084 | +} | | 1085 | + | | 1086 | +void RunBootstrapping(Environment* env) { | | 1087 | + CHECK(!env->has_run_bootstrapping_code()); | | 1088 | + env->set_has_run_bootstrapping_code(true); | | 1089 | + | 1082 | 1090 | HandleScope handle_scope(env->isolate()); | 1083 | 1091 | Isolate* isolate = env->isolate(); | 1084 | 1092 | Local<Context> context = env->context(); | @@ -1140,11 +1148,29 @@ void LoadEnvironment(Environment* env) { | 1140 | 1148 | loader_exports.ToLocalChecked(), | 1141 | 1149 | Boolean::New(isolate, env->is_main_thread())}; | 1142 | 1150 |
| 1143 | | - if (ExecuteBootstrapper( | | 1151 | + Local<Value> start_execution; | | 1152 | + if (!ExecuteBootstrapper( | 1144 | 1153 | env, "internal/bootstrap/node", &node_params, &node_args) | 1145 | | - .IsEmpty()) { | | 1154 | + .ToLocal(&start_execution)) { | 1146 | 1155 | return; | 1147 | 1156 | } | | 1157 | + | | 1158 | + if (start_execution->IsFunction()) | | 1159 | + env->set_start_execution_function(start_execution.As<Function>()); | | 1160 | +} | | 1161 | + | | 1162 | +void StartExecution(Environment* env) { | | 1163 | + HandleScope handle_scope(env->isolate()); | | 1164 | + // We have to use Local<>::New because of the optimized way in which we access | | 1165 | + // the object in the env->...() getters, which does not play well with | | 1166 | + // resetting the handle while we're accessing the object through the Local<>. | | 1167 | + Local<Function> start_execution = | | 1168 | + Local<Function>::New(env->isolate(), env->start_execution_function()); | | 1169 | + env->set_start_execution_function(Local<Function>()); | | 1170 | + | | 1171 | + if (start_execution.IsEmpty()) return; | | 1172 | + USE(start_execution->Call( | | 1173 | + env->context(), Undefined(env->isolate()), 0, nullptr)); | 1148 | 1174 | } | 1149 | 1175 |
| 1150 | 1176 | static void StartInspector(Environment* env, const char* path) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -397,6 +397,9 @@ bool SafeGetenv(const char* key, std::string* text); | 397 | 397 |
| 398 | 398 | void DefineZlibConstants(v8::Local<v8::Object> target); | 399 | 399 |
| | 400 | +void RunBootstrapping(Environment* env); | | 401 | +void StartExecution(Environment* env); | | 402 | + | 400 | 403 | } // namespace node | 401 | 404 |
| 402 | 405 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
Collapse file Copy file name to clipboardExpand all lines: test/message/assert_throws_stack.out -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,4 +18,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: | 18 | 18 | at * | 19 | 19 | at * | 20 | 20 | at * | 21 | | - at * |
Collapse file Copy file name to clipboardExpand all lines: test/message/error_exit.out -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | 16 | 16 | at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) | 17 | 17 | at executeUserCode (internal/bootstrap/node.js:*:*) | 18 | 18 | at startExecution (internal/bootstrap/node.js:*:*) | 19 | | - at startup (internal/bootstrap/node.js:*:*) |
Collapse file Copy file name to clipboardExpand all lines: test/message/eval_messages.out -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,8 +11,6 @@ SyntaxError: Strict mode code may not include a with statement | 11 | 11 | at evalScript (internal/process/execution.js:*:*) | 12 | 12 | at executeUserCode (internal/bootstrap/node.js:*:*) | 13 | 13 | at startExecution (internal/bootstrap/node.js:*:*) | 14 | | - at startup (internal/bootstrap/node.js:*:*) | 15 | | - at internal/bootstrap/node.js:*:* | 16 | 14 | 42 | 17 | 15 | 42 | 18 | 16 | [eval]:1 | @@ -28,8 +26,6 @@ Error: hello | 28 | 26 | at evalScript (internal/process/execution.js:*:*) | 29 | 27 | at executeUserCode (internal/bootstrap/node.js:*:*) | 30 | 28 | at startExecution (internal/bootstrap/node.js:*:*) | 31 | | - at startup (internal/bootstrap/node.js:*:*) | 32 | | - at internal/bootstrap/node.js:*:* | 33 | 29 |
| 34 | 30 | [eval]:1 | 35 | 31 | throw new Error("hello") | @@ -44,8 +40,6 @@ Error: hello | 44 | 40 | at evalScript (internal/process/execution.js:*:*) | 45 | 41 | at executeUserCode (internal/bootstrap/node.js:*:*) | 46 | 42 | at startExecution (internal/bootstrap/node.js:*:*) | 47 | | - at startup (internal/bootstrap/node.js:*:*) | 48 | | - at internal/bootstrap/node.js:*:* | 49 | 43 | 100 | 50 | 44 | [eval]:1 | 51 | 45 | var x = 100; y = x; | @@ -60,8 +54,6 @@ ReferenceError: y is not defined | 60 | 54 | at evalScript (internal/process/execution.js:*:*) | 61 | 55 | at executeUserCode (internal/bootstrap/node.js:*:*) | 62 | 56 | at startExecution (internal/bootstrap/node.js:*:*) | 63 | | - at startup (internal/bootstrap/node.js:*:*) | 64 | | - at internal/bootstrap/node.js:*:* | 65 | 57 |
| 66 | 58 | [eval]:1 | 67 | 59 | var ______________________________________________; throw 10 | |
Collapse file Copy file name to clipboardExpand all lines: test/message/events_unhandled_error_nexttick.out -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,13 +12,10 @@ Error | 12 | 12 | at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) | 13 | 13 | at executeUserCode (internal/bootstrap/node.js:*:*) | 14 | 14 | at startExecution (internal/bootstrap/node.js:*:*) | 15 | | - at startup (internal/bootstrap/node.js:*:*) | 16 | 15 | Emitted 'error' event at: | 17 | 16 | at process.nextTick (*events_unhandled_error_nexttick.js:*:*) | 18 | 17 | at processTicksAndRejections (internal/process/next_tick.js:*:*) | 19 | 18 | at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:*:*) | 20 | 19 | at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) | 21 | 20 | at executeUserCode (internal/bootstrap/node.js:*:*) | 22 | 21 | at startExecution (internal/bootstrap/node.js:*:*) | 23 | | - at startup (internal/bootstrap/node.js:*:*) | 24 | | - at internal/bootstrap/node.js:*:* |
Collapse file Copy file name to clipboardExpand all lines: test/message/events_unhandled_error_sameline.out +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | at Function.Module.runMain (internal/modules/cjs/loader.js:*:*) | 13 | 13 | at executeUserCode (internal/bootstrap/node.js:*:*) | 14 | 14 | at startExecution (internal/bootstrap/node.js:*:*) | 15 | | - at startup (internal/bootstrap/node.js:*:*) | 16 | 15 | Emitted 'error' event at: | 17 | 16 | at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*) | 18 | 17 | at Module._compile (internal/modules/cjs/loader.js:*:*) | 19 | 18 | [... lines matching original stack trace ...] | 20 | | - at startup (internal/bootstrap/node.js:*:*) | | 19 | + at startExecution (internal/bootstrap/node.js:*:*) |
|