-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node: extract node env initialization out of process initialization #980
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,83 @@ inline void NODE_SET_EXTERNAL(v8::Handle<v8::ObjectTemplate> target, | |
v8::DontDelete)); | ||
} | ||
|
||
enum NodeInstanceType { MAIN, WORKER }; | ||
|
||
class NodeInstanceData { | ||
public: | ||
NodeInstanceData(NodeInstanceType node_instance_type, | ||
uv_loop_t* event_loop, | ||
int argc, | ||
const char** argv, | ||
int exec_argc, | ||
const char** exec_argv, | ||
bool use_debug_agent_flag) | ||
: node_instance_type_(node_instance_type), | ||
exit_code_(1), | ||
event_loop_(event_loop), | ||
argc_(argc), | ||
argv_(argv), | ||
exec_argc_(exec_argc), | ||
exec_argv_(exec_argv), | ||
use_debug_agent_flag_(use_debug_agent_flag) { | ||
CHECK_NE(event_loop_, nullptr); | ||
} | ||
|
||
uv_loop_t* event_loop() const { | ||
return event_loop_; | ||
} | ||
|
||
int exit_code() { | ||
CHECK(is_main()); | ||
return exit_code_; | ||
} | ||
|
||
void set_exit_code(int exit_code) { | ||
CHECK(is_main()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, what is the reason to allow set_exit_code() only for the main thread? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well ultimately it will depend on how the Worker API will turn out and whether it's going to need the exit code, for now I just made it more restrictive in case it won't be needed. If it turns out it's going to be needed, it can always be loosened up after. |
||
exit_code_ = exit_code; | ||
} | ||
|
||
bool is_main() { | ||
return node_instance_type_ == MAIN; | ||
} | ||
|
||
bool is_worker() { | ||
return node_instance_type_ == WORKER; | ||
} | ||
|
||
int argc() { | ||
return argc_; | ||
} | ||
|
||
const char** argv() { | ||
return argv_; | ||
} | ||
|
||
int exec_argc() { | ||
return exec_argc_; | ||
} | ||
|
||
const char** exec_argv() { | ||
return exec_argv_; | ||
} | ||
|
||
bool use_debug_agent() { | ||
return is_main() && use_debug_agent_flag_; | ||
} | ||
|
||
private: | ||
const NodeInstanceType node_instance_type_; | ||
int exit_code_; | ||
uv_loop_t* const event_loop_; | ||
const int argc_; | ||
const char** argv_; | ||
const int exec_argc_; | ||
const char** exec_argv_; | ||
const bool use_debug_agent_flag_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(NodeInstanceData); | ||
}; | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_NODE_INTERNALS_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure you clean up node_isolate here as well.