-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
src: reorganize process object creation, property implementation and events in C++ land #25397
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60d3a5e
src: move process object creation into node_process_object.cc
joyeecheung a28145b
src: declare process-related C++ methods in node_process.h
joyeecheung 5e1b8a2
process: move C++ process events into node_process_events.cc
joyeecheung ff4e9de
fixup! src: move process object creation into node_process_object.cc
joyeecheung cc8d7e3
fixup! src: declare process-related C++ methods in node_process.h
joyeecheung cdd42e7
fixup! src: move process object creation into node_process_object.cc
joyeecheung b05ae4e
fixup! process: move C++ process events into node_process_events.cc
joyeecheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
process: move C++ process events into node_process_events.cc
Move the C++ `process.emit` and `process.emitWarning` methods from `node.cc` into into `node_process_events.cc`, and reuse the implementation in other places that need to do `process.emit` in C++.
- Loading branch information
commit 5e1b8a27eb3f9d20405b098f3f2a0f4bcfdee3ee
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #include <stdarg.h> | ||
|
|
||
| #include "env.h" | ||
| #include "node_internals.h" | ||
| #include "node_process.h" | ||
|
|
||
| namespace node { | ||
| using v8::Context; | ||
| using v8::Function; | ||
| using v8::HandleScope; | ||
| using v8::Isolate; | ||
| using v8::Just; | ||
| using v8::Local; | ||
| using v8::Maybe; | ||
| using v8::MaybeLocal; | ||
| using v8::NewStringType; | ||
| using v8::Nothing; | ||
| using v8::Object; | ||
| using v8::String; | ||
| using v8::Value; | ||
|
|
||
| MaybeLocal<Value> ProcessEmit(Environment* env, | ||
| const char* event, | ||
| Local<Value> message) { | ||
| // Send message to enable debug in cluster workers | ||
| Local<Object> process = env->process_object(); | ||
| Isolate* isolate = env->isolate(); | ||
| Local<Value> argv[] = {OneByteString(isolate, event), message}; | ||
|
|
||
| return MakeCallback(isolate, process, "emit", arraysize(argv), argv, {0, 0}); | ||
| } | ||
|
|
||
| Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | ||
| const char* warning, | ||
| const char* type, | ||
| const char* code) { | ||
| HandleScope handle_scope(env->isolate()); | ||
| Context::Scope context_scope(env->context()); | ||
|
|
||
| Local<Object> process = env->process_object(); | ||
| Local<Value> emit_warning; | ||
| if (!process->Get(env->context(), env->emit_warning_string()) | ||
| .ToLocal(&emit_warning)) { | ||
| return Nothing<bool>(); | ||
| } | ||
|
|
||
| if (!emit_warning->IsFunction()) return Just(false); | ||
|
|
||
| int argc = 0; | ||
| Local<Value> args[3]; // warning, type, code | ||
|
|
||
| // The caller has to be able to handle a failure anyway, so we might as well | ||
| // do proper error checking for string creation. | ||
| if (!String::NewFromUtf8(env->isolate(), warning, NewStringType::kNormal) | ||
| .ToLocal(&args[argc++])) { | ||
| return Nothing<bool>(); | ||
| } | ||
| if (type != nullptr) { | ||
| if (!String::NewFromOneByte(env->isolate(), | ||
| reinterpret_cast<const uint8_t*>(type), | ||
| NewStringType::kNormal) | ||
| .ToLocal(&args[argc++])) { | ||
| return Nothing<bool>(); | ||
| } | ||
| if (code != nullptr && | ||
| !String::NewFromOneByte(env->isolate(), | ||
| reinterpret_cast<const uint8_t*>(code), | ||
| NewStringType::kNormal) | ||
| .ToLocal(&args[argc++])) { | ||
| return Nothing<bool>(); | ||
| } | ||
| } | ||
|
|
||
| // MakeCallback() unneeded because emitWarning is internal code, it calls | ||
| // process.emit('warning', ...), but does so on the nextTick. | ||
| if (emit_warning.As<Function>() | ||
| ->Call(env->context(), process, argc, args) | ||
| .IsEmpty()) { | ||
| return Nothing<bool>(); | ||
| } | ||
| return Just(true); | ||
| } | ||
|
|
||
| // Call process.emitWarning(str), fmt is a snprintf() format string | ||
| Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...) { | ||
| char warning[1024]; | ||
| va_list ap; | ||
|
|
||
| va_start(ap, fmt); | ||
| vsnprintf(warning, sizeof(warning), fmt, ap); | ||
| va_end(ap); | ||
|
|
||
| return ProcessEmitWarningGeneric(env, warning); | ||
| } | ||
|
|
||
| Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | ||
| const char* warning, | ||
| const char* deprecation_code) { | ||
| return ProcessEmitWarningGeneric( | ||
| env, warning, "DeprecationWarning", deprecation_code); | ||
| } | ||
|
|
||
| } // namespace node |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This sounds like something we might want to migrate off
process.emit(), right?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.
@addaleax yeah, this looks like the only place where
internalMessageis emitted, maybe the C++ side can call a method passed from JS side somehow instead ..