summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-31 23:18:08 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-11 20:11:55 +0800
commit7824280b5827e1aaba067088b195328185525b21 (patch)
tree7c1971d1ee5ac4a6f02b38e8fb6bfebf5a02c250 /src
parent5a15f4bdfa060082757062dc5f39519d93e7b8fb (diff)
downloadandroid-node-v8-7824280b5827e1aaba067088b195328185525b21.tar.gz
android-node-v8-7824280b5827e1aaba067088b195328185525b21.tar.bz2
android-node-v8-7824280b5827e1aaba067088b195328185525b21.zip
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: https://github.com/nodejs/node/pull/25397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src')
-rw-r--r--src/env.cc1
-rw-r--r--src/inspector_agent.cc1
-rw-r--r--src/node.cc9
-rw-r--r--src/node_crypto.cc9
-rw-r--r--src/node_env_var.cc3
-rw-r--r--src/node_file.cc4
-rw-r--r--src/node_internals.h31
-rw-r--r--src/node_messaging.cc11
-rw-r--r--src/node_process.h32
-rw-r--r--src/node_process_methods.cc52
-rw-r--r--src/node_process_object.cc55
-rw-r--r--src/signal_wrap.cc1
-rw-r--r--src/uv.cc3
13 files changed, 115 insertions, 97 deletions
diff --git a/src/env.cc b/src/env.cc
index 19cc16fcfa..d2d5d5bf35 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -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"
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 8710b85690..d9a252bbe8 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -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"
diff --git a/src/node.cc b/src/node.cc
index 59c13aba32..b82da9c9b5 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -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"
@@ -582,9 +583,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());
@@ -742,12 +743,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 = {
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 75a687801f..296b15de5b 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -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"
diff --git a/src/node_env_var.cc b/src/node_env_var.cc
index 8cbfa22973..d1ebb064e2 100644
--- a/src/node_env_var.cc
+++ b/src/node_env_var.cc
@@ -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>
diff --git a/src/node_file.cc b/src/node_file.cc
index b66c0fe6d2..8757f6bf0d 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -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"
diff --git a/src/node_internals.h b/src/node_internals.h
index a192c519a3..0b0c97f8c8 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -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]);
@@ -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
@@ -697,23 +683,6 @@ static inline const char* errno_string(int errorno) {
// 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__)
diff --git a/src/node_messaging.cc b/src/node_messaging.cc
index 6036648dd4..a538839bcc 100644
--- a/src/node_messaging.cc
+++ b/src/node_messaging.cc
@@ -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;
diff --git a/src/node_process.h b/src/node_process.h
new file mode 100644
index 0000000000..35667ca1b9
--- /dev/null
+++ b/src/node_process.h
@@ -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_
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc
index 69f08a219b..c9abe19b7e 100644
--- a/src/node_process_methods.cc
+++ b/src/node_process_methods.cc
@@ -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"
@@ -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;
@@ -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");
@@ -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);
@@ -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);
diff --git a/src/node_process_object.cc b/src/node_process_object.cc
index 07f28653de..980b5002b6 100644
--- a/src/node_process_object.cc
+++ b/src/node_process_object.cc
@@ -4,6 +4,7 @@
#include "node_internals.h"
#include "node_options-inl.h"
#include "node_metadata.h"
+#include "node_process.h"
#include "node_revert.h"
#include "util-inl.h"
@@ -18,13 +19,53 @@ using v8::Integer;
using v8::Isolate;
using v8::Just;
using v8::Local;
+using v8::Name;
using v8::NewStringType;
using v8::None;
using v8::Object;
+using v8::PropertyCallbackInfo;
using v8::SideEffectType;
using v8::String;
using v8::Value;
+static 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());
+}
+
+static 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);
+}
+
+static 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);
+}
+
+static 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));
+}
+
+static void GetParentProcessId(Local<Name> property,
+ const PropertyCallbackInfo<Value>& info) {
+ info.GetReturnValue().Set(uv_os_getppid());
+}
+
Local<Object> CreateProcessObject(Environment* env,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args) {
@@ -39,6 +80,7 @@ Local<Object> CreateProcessObject(Environment* env,
->NewInstance(context)
.ToLocalChecked();
+ // process.title
auto title_string = FIXED_ONE_BYTE_STRING(env->isolate(), "title");
CHECK(process->SetAccessor(
env->context(),
@@ -103,7 +145,7 @@ Local<Object> CreateProcessObject(Environment* env,
ToV8Value(env->context(), exec_args)
.ToLocalChecked()).FromJust();
- // create process.env
+ // process.env
process
->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
@@ -117,6 +159,9 @@ Local<Object> CreateProcessObject(Environment* env,
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
GetParentProcessId).FromJust());
+ // TODO(joyeecheung): the following process properties that are set using
+ // parsed CLI flags should be migrated to `internal/options` in JS land.
+
// -e, --eval
// TODO(addaleax): Remove this.
if (env->options()->has_eval_string) {
@@ -193,13 +238,13 @@ Local<Object> CreateProcessObject(Environment* env,
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
}
- // TODO(refack): move the following 4 to `node_config`
// --inspect-brk
if (env->options()->debug_options().wait_for_connect()) {
READONLY_DONT_ENUM_PROPERTY(process,
"_breakFirstLine", True(env->isolate()));
}
+ // --inspect-brk-node
if (env->options()->debug_options().break_node_first_line) {
READONLY_DONT_ENUM_PROPERTY(process,
"_breakNodeFirstLine", True(env->isolate()));
@@ -227,6 +272,7 @@ Local<Object> CreateProcessObject(Environment* env,
SECURITY_REVERSIONS(V)
#undef V
+ // process.execPath
{
size_t exec_path_len = 2 * PATH_MAX;
std::vector<char> exec_path(exec_path_len);
@@ -245,6 +291,7 @@ Local<Object> CreateProcessObject(Environment* env,
exec_path_value).FromJust();
}
+ // process.debugPort
auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
CHECK(process->SetAccessor(env->context(),
debug_port_string,
@@ -252,6 +299,10 @@ Local<Object> CreateProcessObject(Environment* env,
env->is_main_thread() ? DebugPortSetter : nullptr,
env->as_external()).FromJust());
+ // process._rawDebug: may be overwritten later in JS land, but should be
+ // availbale from the begining for debugging purposes
+ env->SetMethod(process, "_rawDebug", RawDebug);
+
return scope.Escape(process);
}
diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc
index 93f86f5d79..ca08342ec6 100644
--- a/src/signal_wrap.cc
+++ b/src/signal_wrap.cc
@@ -22,6 +22,7 @@
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "handle_wrap.h"
+#include "node_process.h"
#include "util-inl.h"
#include "v8.h"
diff --git a/src/uv.cc b/src/uv.cc
index a7d0b1012c..5422b0d240 100644
--- a/src/uv.cc
+++ b/src/uv.cc
@@ -20,9 +20,10 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "uv.h"
+#include "env-inl.h"
#include "node.h"
#include "node_internals.h"
-#include "env-inl.h"
+#include "node_process.h"
namespace node {