mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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>
This commit is contained in:
1 parent
49ac9688f3
commit
2ed3fa187e
14 files changed
+116
-97
No files matched your search
@@ -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',
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+4
-5
@@ -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"
|
||||
@@ -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());
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
+5
-4
@@ -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"
|
||||
|
||||
+2
-1
@@ -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>
|
||||
|
||||
+3
-1
@@ -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"
|
||||
|
||||
@@ -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
|
||||
@@ -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__)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in new issue
Block a user