summaryrefslogtreecommitdiff
path: root/src/env.h
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-01-15 23:12:21 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-30 21:03:17 +0800
commit6967f91368cbb9cad3877ee59874cc83ccef4653 (patch)
tree2a7bae3359725c21df01aa31f266d6c79a2b7d35 /src/env.h
parentfeebdc5bc5a44779069a2269f4d3f15d4e36a277 (diff)
downloadandroid-node-v8-6967f91368cbb9cad3877ee59874cc83ccef4653.tar.gz
android-node-v8-6967f91368cbb9cad3877ee59874cc83ccef4653.tar.bz2
android-node-v8-6967f91368cbb9cad3877ee59874cc83ccef4653.zip
process: split execution into main scripts
This patch splits the execution mode selection from the environment setup in `lib/internal/bootstrap/node.js`, and split the entry point of different execution mode into main scripts under `lib/internal/main`: - `check_syntax.js`: used when `-c`/`--check` which only checks the syntax of the input instead of executing it. - `eval_stdin.js`: used when `-e` is passed without value and stdin is not a TTY (e.g. something is piped). - `eval_string`: used when `-e` is passed along with a string argument - `inspect.js`: for `node inspect`/`node debug` - `print_bash_completion.js`: for `--completion-bash` - `print_help.js`: for `--help` - `prof_process.js`: for `--prof-process` - `repl.js`: for the REPL - `run_main_module.js`: used when a main module is passed - `run_third_party_main.js`: for the legacy `_third_party_main.js` support - `worker_thread.js`: for workers This makes the entry points easier to navigate and paves the way for customized v8 snapshots (that do not need to deserialize execution mode setup) and better embedder APIs. As an example, after this patch, for the most common case where Node.js executes a user module as an entry point, it essentially goes through: - `lib/internal/per_context.js` to setup the v8 Context (which is also run when setting up contexts for the `vm` module) - `lib/internal/bootstrap/loaders.js` to set up internal binding and builtin module loaders (that are separate from the loaders accessible in the user land). - `lib/internal/bootstrap/node.js`: to set up the rest of the environment, including various globals and the process object - `lib/internal/main/run_main_module.js`: which is selected from C++ to prepare execution of the user module. This patch also removes `NativeModuleLoader::CompileAndCall` and exposes `NativeModuleLoader::LookupAndCompile` directly so that we can handle syntax errors and runtime errors of bootstrap scripts differently. PR-URL: https://github.com/nodejs/node/pull/25667 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/env.h')
-rw-r--r--src/env.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/env.h b/src/env.h
index 2fab688fc8..139694104e 100644
--- a/src/env.h
+++ b/src/env.h
@@ -315,7 +315,7 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
V(write_host_object_string, "_writeHostObject") \
V(write_queue_size_string, "writeQueueSize") \
V(x_forwarded_string, "x-forwarded-for") \
- V(zero_return_string, "ZERO_RETURN") \
+ V(zero_return_string, "ZERO_RETURN")
#define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) \
V(as_external, v8::External) \
@@ -355,11 +355,13 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
V(http2session_on_stream_trailers_function, v8::Function) \
V(http2settings_constructor_template, v8::ObjectTemplate) \
V(http2stream_constructor_template, v8::ObjectTemplate) \
+ V(internal_binding_loader, v8::Function) \
V(immediate_callback_function, v8::Function) \
V(inspector_console_extension_installer, v8::Function) \
V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \
V(message_port, v8::Object) \
V(message_port_constructor_template, v8::FunctionTemplate) \
+ V(native_module_require, v8::Function) \
V(performance_entry_callback, v8::Function) \
V(performance_entry_template, v8::Function) \
V(pipe_constructor_template, v8::FunctionTemplate) \
@@ -371,7 +373,6 @@ 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) \
@@ -611,7 +612,7 @@ class Environment {
~Environment();
void Start(bool start_profiler_idle_notifier);
- v8::MaybeLocal<v8::Object> CreateProcessObject(
+ v8::MaybeLocal<v8::Object> ProcessCliArgs(
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);
@@ -928,6 +929,24 @@ class Environment {
inline std::shared_ptr<EnvironmentOptions> options();
inline std::shared_ptr<HostPort> inspector_host_port();
+ enum class ExecutionMode {
+ kDefault,
+ kInspect, // node inspect
+ kDebug, // node debug
+ kPrintHelp, // node --help
+ kPrintBashCompletion, // node --completion-bash
+ kProfProcess, // node --prof-process
+ kEvalString, // node --eval without --interactive
+ kCheckSyntax, // node --check (incompatible with --eval)
+ kRepl,
+ kEvalStdin,
+ kRunMainModule
+ };
+
+ inline ExecutionMode execution_mode() { return execution_mode_; }
+
+ inline void set_execution_mode(ExecutionMode mode) { execution_mode_ = mode; }
+
private:
inline void CreateImmediate(native_immediate_callback cb,
void* data,
@@ -937,6 +956,7 @@ class Environment {
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
const char* errmsg);
+ ExecutionMode execution_mode_ = ExecutionMode::kDefault;
std::list<binding::DLib> loaded_addons_;
v8::Isolate* const isolate_;
IsolateData* const isolate_data_;