Skip to content

Commit

Permalink
src: declare process-related C++ methods in node_process.h
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
joyeecheung authored and BridgeAR committed Jan 17, 2019
1 parent 49ac968 commit 2ed3fa1
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 97 deletions.
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -450,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
1 change: 1 addition & 0 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 Down
1 change: 1 addition & 0 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
9 changes: 4 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "node_options-inl.h"
#include "node_perf.h"
#include "node_platform.h"
#include "node_process.h"
#include "node_revert.h"
#include "node_version.h"
#include "tracing/traced_value.h"
Expand Down Expand Up @@ -586,9 +587,9 @@ void Exit(const FunctionCallbackInfo<Value>& args) {
}

static Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
const char* warning,
const char* type = nullptr,
const char* code = nullptr) {
const char* warning,
const char* type = nullptr,
const char* code = nullptr) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

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

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

// Create binding loaders
std::vector<Local<String>> loaders_params = {
Expand Down
9 changes: 5 additions & 4 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "node_crypto.h"
#include "node.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_constants.h"
#include "node_crypto.h"
#include "node_crypto_bio.h"
#include "node_crypto_groups.h"
#include "node_crypto_clienthello-inl.h"
#include "node_mutex.h"
#include "node_crypto_groups.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_mutex.h"
#include "node_process.h"
#include "tls_wrap.h" // TLSWrap

#include "async_wrap-inl.h"
Expand Down
3 changes: 2 additions & 1 deletion src/node_env_var.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "node_internals.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"

#ifdef __APPLE__
#include <crt_externs.h>
Expand Down
4 changes: 3 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "node_file.h"
#include "aliased_buffer.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "node_process.h"
#include "node_stat_watcher.h"
#include "node_file.h"

#include "tracing/trace_event.h"

#include "req_wrap-inl.h"
Expand Down
31 changes: 0 additions & 31 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ void RegisterSignalHandler(int signal,
bool reset_handler = false);
#endif

v8::Local<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context,
v8::Isolate* isolate,
v8::Local<v8::Value> data);

std::string GetHumanReadableProcessName();
void GetHumanReadableProcessName(char (*name)[1024]);

Expand Down Expand Up @@ -180,16 +176,6 @@ namespace task_queue {
void PromiseRejectCallback(v8::PromiseRejectMessage message);
} // namespace task_queue

v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
const char* warning,
const char* deprecation_code);

v8::Local<v8::Object> CreateProcessObject(
Environment* env,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);

enum Endianness {
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
kBigEndian
Expand Down Expand Up @@ -371,23 +357,6 @@ void DisposePlatform();

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

void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);

void DebugPortGetter(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
void DebugPortSetter(v8::Local<v8::Name> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info);

void GetParentProcessId(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info);

void ProcessTitleGetter(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
void ProcessTitleSetter(v8::Local<v8::Name> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info);

#if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
#define NODE_IMPLEMENTS_POSIX_CREDENTIALS 1
#endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)
Expand Down
11 changes: 6 additions & 5 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "debug_utils.h"
#include "node_messaging.h"
#include "node_internals.h"
#include "async_wrap-inl.h"
#include "async_wrap.h"
#include "debug_utils.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "util.h"
#include "node_internals.h"
#include "node_process.h"
#include "util-inl.h"
#include "async_wrap.h"
#include "async_wrap-inl.h"
#include "util.h"

using v8::Array;
using v8::ArrayBuffer;
Expand Down
32 changes: 32 additions & 0 deletions src/node_process.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef SRC_NODE_PROCESS_H_
#define SRC_NODE_PROCESS_H_

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "v8.h"

namespace node {

v8::Local<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context,
v8::Isolate* isolate,
v8::Local<v8::Value> data);

// Most of the time, it's best to use `console.error` to write
// to the process.stderr stream. However, in some cases, such as
// when debugging the stream.Writable class or the process.nextTick
// function, it is useful to bypass JavaScript entirely.
void RawDebug(const v8::FunctionCallbackInfo<v8::Value>& args);

v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
const char* warning,
const char* deprecation_code);

v8::Local<v8::Object> CreateProcessObject(
Environment* env,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);

} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_NODE_PROCESS_H_
52 changes: 5 additions & 47 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "node.h"
#include "node_internals.h"
#include "node_errors.h"
#include "base_object.h"
#include "base_object-inl.h"
#include "base_object.h"
#include "env-inl.h"
#include "node.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_process.h"
#include "util-inl.h"
#include "uv.h"
#include "v8.h"
Expand Down Expand Up @@ -44,7 +45,6 @@ using v8::Local;
using v8::Name;
using v8::NewStringType;
using v8::Object;
using v8::PropertyCallbackInfo;
using v8::String;
using v8::Uint32;
using v8::Uint32Array;
Expand Down Expand Up @@ -197,10 +197,6 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
fields[3] = v8_heap_stats.external_memory();
}

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

void ProcessTitleGetter(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
char buffer[512];
uv_get_process_title(buffer, sizeof(buffer));
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer,
NewStringType::kNormal).ToLocalChecked());
}

void ProcessTitleSetter(Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info) {
node::Utf8Value title(info.GetIsolate(), value);
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
TRACE_STR_COPY(*title));
uv_set_process_title(*title);
}

void GetParentProcessId(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
info.GetReturnValue().Set(uv_os_getppid());
}

static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

void DebugPortGetter(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
int port = env->inspector_host_port()->port();
info.GetReturnValue().Set(port);
}


void DebugPortSetter(Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info) {
Environment* env = Environment::GetCurrent(info);
int32_t port = value->Int32Value(env->context()).FromMaybe(0);
env->inspector_host_port()->set_port(static_cast<int>(port));
}

#ifdef __POSIX__
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down
Loading

0 comments on commit 2ed3fa1

Please sign in to comment.