Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 21096f9

Browse filesBrowse files
committed
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>
1 parent 9c5db93 commit 21096f9
Copy full SHA for 21096f9
Expand file treeCollapse file tree

13 files changed

+47
-32
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/node.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function startup() {
319319
} = perf.constants;
320320
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
321321

322-
startExecution();
322+
return startExecution;
323323
}
324324

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

740-
startup();
740+
return startup();
Collapse file

‎src/env-inl.h‎

Copy file name to clipboardExpand all lines: src/env-inl.h
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ inline void Environment::set_can_call_into_js(bool can_call_into_js) {
633633
can_call_into_js_ = can_call_into_js;
634634
}
635635

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+
636644
inline bool Environment::is_main_thread() const {
637645
return thread_id_ == 0;
638646
}
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
369369
V(script_data_constructor_function, v8::Function) \
370370
V(secure_context_constructor_template, v8::FunctionTemplate) \
371371
V(shutdown_wrap_template, v8::ObjectTemplate) \
372+
V(start_execution_function, v8::Function) \
372373
V(tcp_constructor_template, v8::FunctionTemplate) \
373374
V(tick_callback_function, v8::Function) \
374375
V(timers_callback_function, v8::Function) \
@@ -751,6 +752,9 @@ class Environment {
751752
inline bool can_call_into_js() const;
752753
inline void set_can_call_into_js(bool can_call_into_js);
753754

755+
inline bool has_run_bootstrapping_code() const;
756+
inline void set_has_run_bootstrapping_code(bool has_run_bootstrapping_code);
757+
754758
inline bool is_main_thread() const;
755759
inline uint64_t thread_id() const;
756760
inline void set_thread_id(uint64_t id);
@@ -976,6 +980,7 @@ class Environment {
976980
std::unique_ptr<performance::performance_state> performance_state_;
977981
std::unordered_map<std::string, uint64_t> performance_marks_;
978982

983+
bool has_run_bootstrapping_code_ = false;
979984
bool can_call_into_js_ = true;
980985
uint64_t thread_id_ = 0;
981986
std::unordered_set<worker::Worker*> sub_worker_contexts_;
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+28-2Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,14 @@ static MaybeLocal<Value> ExecuteBootstrapper(
10791079
}
10801080

10811081
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+
10821090
HandleScope handle_scope(env->isolate());
10831091
Isolate* isolate = env->isolate();
10841092
Local<Context> context = env->context();
@@ -1140,11 +1148,29 @@ void LoadEnvironment(Environment* env) {
11401148
loader_exports.ToLocalChecked(),
11411149
Boolean::New(isolate, env->is_main_thread())};
11421150

1143-
if (ExecuteBootstrapper(
1151+
Local<Value> start_execution;
1152+
if (!ExecuteBootstrapper(
11441153
env, "internal/bootstrap/node", &node_params, &node_args)
1145-
.IsEmpty()) {
1154+
.ToLocal(&start_execution)) {
11461155
return;
11471156
}
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));
11481174
}
11491175

11501176
static void StartInspector(Environment* env, const char* path) {
Collapse file

‎src/node_internals.h‎

Copy file name to clipboardExpand all lines: src/node_internals.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ bool SafeGetenv(const char* key, std::string* text);
397397

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

400+
void RunBootstrapping(Environment* env);
401+
void StartExecution(Environment* env);
402+
400403
} // namespace node
401404

402405
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Collapse file

‎test/message/assert_throws_stack.out‎

Copy file name to clipboardExpand all lines: test/message/assert_throws_stack.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
1818
at *
1919
at *
2020
at *
21-
at *
Collapse file

‎test/message/error_exit.out‎

Copy file name to clipboardExpand all lines: test/message/error_exit.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1616
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1717
at executeUserCode (internal/bootstrap/node.js:*:*)
1818
at startExecution (internal/bootstrap/node.js:*:*)
19-
at startup (internal/bootstrap/node.js:*:*)
Collapse file

‎test/message/eval_messages.out‎

Copy file name to clipboardExpand all lines: test/message/eval_messages.out
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ SyntaxError: Strict mode code may not include a with statement
1111
at evalScript (internal/process/execution.js:*:*)
1212
at executeUserCode (internal/bootstrap/node.js:*:*)
1313
at startExecution (internal/bootstrap/node.js:*:*)
14-
at startup (internal/bootstrap/node.js:*:*)
15-
at internal/bootstrap/node.js:*:*
1614
42
1715
42
1816
[eval]:1
@@ -28,8 +26,6 @@ Error: hello
2826
at evalScript (internal/process/execution.js:*:*)
2927
at executeUserCode (internal/bootstrap/node.js:*:*)
3028
at startExecution (internal/bootstrap/node.js:*:*)
31-
at startup (internal/bootstrap/node.js:*:*)
32-
at internal/bootstrap/node.js:*:*
3329

3430
[eval]:1
3531
throw new Error("hello")
@@ -44,8 +40,6 @@ Error: hello
4440
at evalScript (internal/process/execution.js:*:*)
4541
at executeUserCode (internal/bootstrap/node.js:*:*)
4642
at startExecution (internal/bootstrap/node.js:*:*)
47-
at startup (internal/bootstrap/node.js:*:*)
48-
at internal/bootstrap/node.js:*:*
4943
100
5044
[eval]:1
5145
var x = 100; y = x;
@@ -60,8 +54,6 @@ ReferenceError: y is not defined
6054
at evalScript (internal/process/execution.js:*:*)
6155
at executeUserCode (internal/bootstrap/node.js:*:*)
6256
at startExecution (internal/bootstrap/node.js:*:*)
63-
at startup (internal/bootstrap/node.js:*:*)
64-
at internal/bootstrap/node.js:*:*
6557

6658
[eval]:1
6759
var ______________________________________________; throw 10
Collapse file

‎test/message/events_unhandled_error_nexttick.out‎

Copy file name to clipboardExpand all lines: test/message/events_unhandled_error_nexttick.out
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ Error
1212
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1313
at executeUserCode (internal/bootstrap/node.js:*:*)
1414
at startExecution (internal/bootstrap/node.js:*:*)
15-
at startup (internal/bootstrap/node.js:*:*)
1615
Emitted 'error' event at:
1716
at process.nextTick (*events_unhandled_error_nexttick.js:*:*)
1817
at processTicksAndRejections (internal/process/next_tick.js:*:*)
1918
at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:*:*)
2019
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
2120
at executeUserCode (internal/bootstrap/node.js:*:*)
2221
at startExecution (internal/bootstrap/node.js:*:*)
23-
at startup (internal/bootstrap/node.js:*:*)
24-
at internal/bootstrap/node.js:*:*
Collapse file

‎test/message/events_unhandled_error_sameline.out‎

Copy file name to clipboardExpand all lines: test/message/events_unhandled_error_sameline.out
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ Error
1212
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
1313
at executeUserCode (internal/bootstrap/node.js:*:*)
1414
at startExecution (internal/bootstrap/node.js:*:*)
15-
at startup (internal/bootstrap/node.js:*:*)
1615
Emitted 'error' event at:
1716
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
1817
at Module._compile (internal/modules/cjs/loader.js:*:*)
1918
[... lines matching original stack trace ...]
20-
at startup (internal/bootstrap/node.js:*:*)
19+
at startExecution (internal/bootstrap/node.js:*:*)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.