Skip to content

Commit 2ed3fa1

Browse files
joyeecheungBridgeAR
authored andcommitted
src: declare process-related C++ methods in node_process.h
Instead of in node_internals.h. Also move process property accessors that are not reused into node_process_object.cc and make them static. PR-URL: #25397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 49ac968 commit 2ed3fa1

14 files changed

+116
-97
lines changed

node.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@
450450
'src/node_perf_common.h',
451451
'src/node_persistent.h',
452452
'src/node_platform.h',
453+
'src/node_process.h',
453454
'src/node_revert.h',
454455
'src/node_root_certs.h',
455456
'src/node_stat_watcher.h',

src/env.cc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "node_native_module.h"
88
#include "node_options-inl.h"
99
#include "node_platform.h"
10+
#include "node_process.h"
1011
#include "node_worker.h"
1112
#include "tracing/agent.h"
1213
#include "tracing/traced_value.h"

src/inspector_agent.cc

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "node/inspector/protocol/Protocol.h"
1010
#include "node_errors.h"
1111
#include "node_internals.h"
12+
#include "node_process.h"
1213
#include "node_url.h"
1314
#include "v8-inspector.h"
1415
#include "v8-platform.h"

src/node.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "node_options-inl.h"
3131
#include "node_perf.h"
3232
#include "node_platform.h"
33+
#include "node_process.h"
3334
#include "node_revert.h"
3435
#include "node_version.h"
3536
#include "tracing/traced_value.h"
@@ -586,9 +587,9 @@ void Exit(const FunctionCallbackInfo<Value>& args) {
586587
}
587588

588589
static Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
589-
const char* warning,
590-
const char* type = nullptr,
591-
const char* code = nullptr) {
590+
const char* warning,
591+
const char* type = nullptr,
592+
const char* code = nullptr) {
592593
HandleScope handle_scope(env->isolate());
593594
Context::Scope context_scope(env->context());
594595

@@ -746,12 +747,10 @@ void RunBootstrapping(Environment* env) {
746747

747748
// Setting global properties for the bootstrappers to use:
748749
// - global
749-
// - process._rawDebug
750750
// Expose the global object as a property on itself
751751
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
752752
global->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global)
753753
.FromJust();
754-
env->SetMethod(process, "_rawDebug", RawDebug);
755754

756755
// Create binding loaders
757756
std::vector<Local<String>> loaders_params = {

src/node_crypto.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
#include "node_crypto.h"
2223
#include "node.h"
2324
#include "node_buffer.h"
24-
#include "node_errors.h"
2525
#include "node_constants.h"
26-
#include "node_crypto.h"
2726
#include "node_crypto_bio.h"
28-
#include "node_crypto_groups.h"
2927
#include "node_crypto_clienthello-inl.h"
30-
#include "node_mutex.h"
28+
#include "node_crypto_groups.h"
29+
#include "node_errors.h"
3130
#include "node_internals.h"
31+
#include "node_mutex.h"
32+
#include "node_process.h"
3233
#include "tls_wrap.h" // TLSWrap
3334

3435
#include "async_wrap-inl.h"

src/node_env_var.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include "node_internals.h"
21
#include "node_errors.h"
2+
#include "node_internals.h"
3+
#include "node_process.h"
34

45
#ifdef __APPLE__
56
#include <crt_externs.h>

src/node_file.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
#include "node_file.h"
2223
#include "aliased_buffer.h"
2324
#include "node_buffer.h"
2425
#include "node_internals.h"
26+
#include "node_process.h"
2527
#include "node_stat_watcher.h"
26-
#include "node_file.h"
28+
2729
#include "tracing/trace_event.h"
2830

2931
#include "req_wrap-inl.h"

src/node_internals.h

-31
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ void RegisterSignalHandler(int signal,
123123
bool reset_handler = false);
124124
#endif
125125

126-
v8::Local<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context,
127-
v8::Isolate* isolate,
128-
v8::Local<v8::Value> data);
129-
130126
std::string GetHumanReadableProcessName();
131127
void GetHumanReadableProcessName(char (*name)[1024]);
132128

@@ -180,16 +176,6 @@ namespace task_queue {
180176
void PromiseRejectCallback(v8::PromiseRejectMessage message);
181177
} // namespace task_queue
182178

183-
v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
184-
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
185-
const char* warning,
186-
const char* deprecation_code);
187-
188-
v8::Local<v8::Object> CreateProcessObject(
189-
Environment* env,
190-
const std::vector<std::string>& args,
191-
const std::vector<std::string>& exec_args);
192-
193179
enum Endianness {
194180
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
195181
kBigEndian
@@ -371,23 +357,6 @@ void DisposePlatform();
371357

372358
// Functions defined in node.cc that are exposed via the bootstrapper object
373359

374-
void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);
375-
376-
void DebugPortGetter(v8::Local<v8::Name> property,
377-
const v8::PropertyCallbackInfo<v8::Value>& info);
378-
void DebugPortSetter(v8::Local<v8::Name> property,
379-
v8::Local<v8::Value> value,
380-
const v8::PropertyCallbackInfo<void>& info);
381-
382-
void GetParentProcessId(v8::Local<v8::Name> property,
383-
const v8::PropertyCallbackInfo<v8::Value>& info);
384-
385-
void ProcessTitleGetter(v8::Local<v8::Name> property,
386-
const v8::PropertyCallbackInfo<v8::Value>& info);
387-
void ProcessTitleSetter(v8::Local<v8::Name> property,
388-
v8::Local<v8::Value> value,
389-
const v8::PropertyCallbackInfo<void>& info);
390-
391360
#if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
392361
#define NODE_IMPLEMENTS_POSIX_CREDENTIALS 1
393362
#endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)

src/node_messaging.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#include "debug_utils.h"
21
#include "node_messaging.h"
3-
#include "node_internals.h"
2+
#include "async_wrap-inl.h"
3+
#include "async_wrap.h"
4+
#include "debug_utils.h"
45
#include "node_buffer.h"
56
#include "node_errors.h"
6-
#include "util.h"
7+
#include "node_internals.h"
8+
#include "node_process.h"
79
#include "util-inl.h"
8-
#include "async_wrap.h"
9-
#include "async_wrap-inl.h"
10+
#include "util.h"
1011

1112
using v8::Array;
1213
using v8::ArrayBuffer;

src/node_process.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef SRC_NODE_PROCESS_H_
2+
#define SRC_NODE_PROCESS_H_
3+
4+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5+
6+
#include "v8.h"
7+
8+
namespace node {
9+
10+
v8::Local<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context,
11+
v8::Isolate* isolate,
12+
v8::Local<v8::Value> data);
13+
14+
// Most of the time, it's best to use `console.error` to write
15+
// to the process.stderr stream. However, in some cases, such as
16+
// when debugging the stream.Writable class or the process.nextTick
17+
// function, it is useful to bypass JavaScript entirely.
18+
void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);
19+
20+
v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
21+
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
22+
const char* warning,
23+
const char* deprecation_code);
24+
25+
v8::Local<v8::Object> CreateProcessObject(
26+
Environment* env,
27+
const std::vector<std::string>& args,
28+
const std::vector<std::string>& exec_args);
29+
30+
} // namespace node
31+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
32+
#endif // SRC_NODE_PROCESS_H_

src/node_process_methods.cc

+5-47
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include "node.h"
2-
#include "node_internals.h"
3-
#include "node_errors.h"
4-
#include "base_object.h"
51
#include "base_object-inl.h"
2+
#include "base_object.h"
63
#include "env-inl.h"
4+
#include "node.h"
5+
#include "node_errors.h"
6+
#include "node_internals.h"
7+
#include "node_process.h"
78
#include "util-inl.h"
89
#include "uv.h"
910
#include "v8.h"
@@ -44,7 +45,6 @@ using v8::Local;
4445
using v8::Name;
4546
using v8::NewStringType;
4647
using v8::Object;
47-
using v8::PropertyCallbackInfo;
4848
using v8::String;
4949
using v8::Uint32;
5050
using v8::Uint32Array;
@@ -197,10 +197,6 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
197197
fields[3] = v8_heap_stats.external_memory();
198198
}
199199

200-
// Most of the time, it's best to use `console.error` to write
201-
// to the process.stderr stream. However, in some cases, such as
202-
// when debugging the stream.Writable class or the process.nextTick
203-
// function, it is useful to bypass JavaScript entirely.
204200
void RawDebug(const FunctionCallbackInfo<Value>& args) {
205201
CHECK(args.Length() == 1 && args[0]->IsString() &&
206202
"must be called with a single string");
@@ -246,28 +242,6 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
246242
args.GetReturnValue().Set(uptime / 1000);
247243
}
248244

249-
void ProcessTitleGetter(Local<Name> property,
250-
const PropertyCallbackInfo<Value>& info) {
251-
char buffer[512];
252-
uv_get_process_title(buffer, sizeof(buffer));
253-
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer,
254-
NewStringType::kNormal).ToLocalChecked());
255-
}
256-
257-
void ProcessTitleSetter(Local<Name> property,
258-
Local<Value> value,
259-
const PropertyCallbackInfo<void>& info) {
260-
node::Utf8Value title(info.GetIsolate(), value);
261-
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
262-
TRACE_STR_COPY(*title));
263-
uv_set_process_title(*title);
264-
}
265-
266-
void GetParentProcessId(Local<Name> property,
267-
const PropertyCallbackInfo<Value>& info) {
268-
info.GetReturnValue().Set(uv_os_getppid());
269-
}
270-
271245
static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
272246
Environment* env = Environment::GetCurrent(args);
273247

@@ -297,22 +271,6 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
297271
Array::New(env->isolate(), handle_v.data(), handle_v.size()));
298272
}
299273

300-
void DebugPortGetter(Local<Name> property,
301-
const PropertyCallbackInfo<Value>& info) {
302-
Environment* env = Environment::GetCurrent(info);
303-
int port = env->inspector_host_port()->port();
304-
info.GetReturnValue().Set(port);
305-
}
306-
307-
308-
void DebugPortSetter(Local<Name> property,
309-
Local<Value> value,
310-
const PropertyCallbackInfo<void>& info) {
311-
Environment* env = Environment::GetCurrent(info);
312-
int32_t port = value->Int32Value(env->context()).FromMaybe(0);
313-
env->inspector_host_port()->set_port(static_cast<int>(port));
314-
}
315-
316274
#ifdef __POSIX__
317275
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
318276
Environment* env = Environment::GetCurrent(args);

0 commit comments

Comments
 (0)