Skip to content
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

src: reorganize process object creation, property implementation and events in C++ land #25397

Closed
wants to merge 7 commits into from
5 changes: 4 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@
'src/node_perf.cc',
'src/node_platform.cc',
'src/node_postmortem_metadata.cc',
'src/node_process.cc',
'src/node_process_events.cc',
'src/node_process_methods.cc',
'src/node_process_object.cc',
'src/node_serdes.cc',
'src/node_stat_watcher.cc',
'src/node_symbols.cc',
Expand Down Expand Up @@ -448,6 +450,7 @@
'src/node_perf_common.h',
'src/node_persistent.h',
'src/node_platform.h',
'src/node_process.h',
'src/node_revert.h',
'src/node_root_certs.h',
'src/node_stat_watcher.h',
Expand Down
12 changes: 2 additions & 10 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "node_native_module.h"
#include "node_options-inl.h"
#include "node_platform.h"
#include "node_process.h"
#include "node_worker.h"
#include "tracing/agent.h"
#include "tracing/traced_value.h"
Expand All @@ -22,7 +23,6 @@ using v8::Context;
using v8::EmbedderGraph;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
Expand Down Expand Up @@ -339,17 +339,9 @@ void Environment::Start(const std::vector<std::string>& args,
StartProfilerIdleNotifier();
}

auto process_template = FunctionTemplate::New(isolate());
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process"));

auto process_object = process_template->GetFunction(context())
.ToLocalChecked()
->NewInstance(context())
.ToLocalChecked();
Local<Object> process_object = CreateProcessObject(this, args, exec_args);
set_process_object(process_object);

SetupProcessObject(this, args, exec_args);

static uv_once_t init_once = UV_ONCE_INIT;
uv_once(&init_once, InitThreadLocalOnce);
uv_key_set(&thread_local_env, this);
Expand Down
18 changes: 3 additions & 15 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "node/inspector/protocol/Protocol.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "node_url.h"
#include "v8-inspector.h"
#include "v8-platform.h"
Expand Down Expand Up @@ -369,26 +370,13 @@ class SameThreadInspectorSession : public InspectorSession {
void NotifyClusterWorkersDebugEnabled(Environment* env) {
Isolate* isolate = env->isolate();
HandleScope handle_scope(isolate);
auto context = env->context();
Local<Context> context = env->context();

// Send message to enable debug in cluster workers
Local<Object> process_object = env->process_object();
Local<Value> emit_fn =
process_object->Get(context, FIXED_ONE_BYTE_STRING(isolate, "emit"))
.ToLocalChecked();
// In case the thread started early during the startup
if (!emit_fn->IsFunction())
return;

Local<Object> message = Object::New(isolate);
message->Set(context, FIXED_ONE_BYTE_STRING(isolate, "cmd"),
FIXED_ONE_BYTE_STRING(isolate, "NODE_DEBUG_ENABLED")).FromJust();
Local<Value> argv[] = {
FIXED_ONE_BYTE_STRING(isolate, "internalMessage"),
message
};
MakeCallback(env->isolate(), process_object, emit_fn.As<Function>(),
arraysize(argv), argv, {0, 0});
ProcessEmit(env, "internalMessage", message);
Copy link
Member

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?

Copy link
Member Author

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 internalMessage is emitted, maybe the C++ side can call a method passed from JS side somehow instead ..

}

#ifdef _WIN32
Expand Down
Loading