Skip to content

Commit 5a15f4b

Browse files
committed
src: move process object creation into node_process_object.cc
Changes `SetupProcessObject` to `CreateProessObject` which creates the process object from scratch and return it to `Environment::Start` to be stored in the Environment object. PR-URL: #25397 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 4c9ea8f commit 5a15f4b

File tree

6 files changed

+265
-240
lines changed

6 files changed

+265
-240
lines changed

node.gyp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@
370370
'src/node_perf.cc',
371371
'src/node_platform.cc',
372372
'src/node_postmortem_metadata.cc',
373-
'src/node_process.cc',
373+
'src/node_process_methods.cc',
374+
'src/node_process_object.cc',
374375
'src/node_serdes.cc',
375376
'src/node_stat_watcher.cc',
376377
'src/node_symbols.cc',

src/env.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ using v8::Context;
2222
using v8::EmbedderGraph;
2323
using v8::External;
2424
using v8::Function;
25-
using v8::FunctionTemplate;
2625
using v8::HandleScope;
2726
using v8::Integer;
2827
using v8::Isolate;
@@ -339,17 +338,9 @@ void Environment::Start(const std::vector<std::string>& args,
339338
StartProfilerIdleNotifier();
340339
}
341340

342-
auto process_template = FunctionTemplate::New(isolate());
343-
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate(), "process"));
344-
345-
auto process_object = process_template->GetFunction(context())
346-
.ToLocalChecked()
347-
->NewInstance(context())
348-
.ToLocalChecked();
341+
Local<Object> process_object = CreateProcessObject(this, args, exec_args);
349342
set_process_object(process_object);
350343

351-
SetupProcessObject(this, args, exec_args);
352-
353344
static uv_once_t init_once = UV_ONCE_INIT;
354345
uv_once(&init_once, InitThreadLocalOnce);
355346
uv_key_set(&thread_local_env, this);

src/node.cc

Lines changed: 0 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,12 @@ using v8::MaybeLocal;
124124
using v8::Message;
125125
using v8::MicrotasksPolicy;
126126
using v8::NewStringType;
127-
using v8::None;
128127
using v8::Nothing;
129128
using v8::Object;
130129
using v8::ObjectTemplate;
131130
using v8::Script;
132131
using v8::ScriptOrigin;
133132
using v8::SealHandleScope;
134-
using v8::SideEffectType;
135133
using v8::String;
136134
using v8::TracingController;
137135
using v8::Undefined;
@@ -686,230 +684,6 @@ static void OnMessage(Local<Message> message, Local<Value> error) {
686684
}
687685
}
688686

689-
void SetupProcessObject(Environment* env,
690-
const std::vector<std::string>& args,
691-
const std::vector<std::string>& exec_args) {
692-
Isolate* isolate = env->isolate();
693-
HandleScope scope(isolate);
694-
Local<Context> context = env->context();
695-
696-
Local<Object> process = env->process_object();
697-
698-
auto title_string = FIXED_ONE_BYTE_STRING(env->isolate(), "title");
699-
CHECK(process->SetAccessor(
700-
env->context(),
701-
title_string,
702-
ProcessTitleGetter,
703-
env->is_main_thread() ? ProcessTitleSetter : nullptr,
704-
env->as_external(),
705-
DEFAULT,
706-
None,
707-
SideEffectType::kHasNoSideEffect).FromJust());
708-
709-
// process.version
710-
READONLY_PROPERTY(process,
711-
"version",
712-
FIXED_ONE_BYTE_STRING(env->isolate(), NODE_VERSION));
713-
714-
// process.versions
715-
Local<Object> versions = Object::New(env->isolate());
716-
READONLY_PROPERTY(process, "versions", versions);
717-
718-
#define V(key) \
719-
if (!per_process::metadata.versions.key.empty()) { \
720-
READONLY_STRING_PROPERTY( \
721-
versions, #key, per_process::metadata.versions.key); \
722-
}
723-
NODE_VERSIONS_KEYS(V)
724-
#undef V
725-
726-
// process.arch
727-
READONLY_STRING_PROPERTY(process, "arch", per_process::metadata.arch);
728-
729-
// process.platform
730-
READONLY_STRING_PROPERTY(process, "platform", per_process::metadata.platform);
731-
732-
// process.release
733-
Local<Object> release = Object::New(env->isolate());
734-
READONLY_PROPERTY(process, "release", release);
735-
READONLY_STRING_PROPERTY(release, "name", per_process::metadata.release.name);
736-
#if NODE_VERSION_IS_LTS
737-
READONLY_STRING_PROPERTY(release, "lts", per_process::metadata.release.lts);
738-
#endif // NODE_VERSION_IS_LTS
739-
740-
#ifdef NODE_HAS_RELEASE_URLS
741-
READONLY_STRING_PROPERTY(
742-
release, "sourceUrl", per_process::metadata.release.source_url);
743-
READONLY_STRING_PROPERTY(
744-
release, "headersUrl", per_process::metadata.release.headers_url);
745-
#ifdef _WIN32
746-
READONLY_STRING_PROPERTY(
747-
release, "libUrl", per_process::metadata.release.lib_url);
748-
#endif // _WIN32
749-
#endif // NODE_HAS_RELEASE_URLS
750-
751-
// process.argv
752-
process->Set(env->context(),
753-
FIXED_ONE_BYTE_STRING(env->isolate(), "argv"),
754-
ToV8Value(env->context(), args).ToLocalChecked()).FromJust();
755-
756-
// process.execArgv
757-
process->Set(env->context(),
758-
FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
759-
ToV8Value(env->context(), exec_args)
760-
.ToLocalChecked()).FromJust();
761-
762-
// create process.env
763-
process
764-
->Set(env->context(),
765-
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
766-
CreateEnvVarProxy(context, isolate, env->as_external()))
767-
.FromJust();
768-
769-
READONLY_PROPERTY(process, "pid",
770-
Integer::New(env->isolate(), uv_os_getpid()));
771-
772-
CHECK(process->SetAccessor(env->context(),
773-
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
774-
GetParentProcessId).FromJust());
775-
776-
// -e, --eval
777-
// TODO(addaleax): Remove this.
778-
if (env->options()->has_eval_string) {
779-
READONLY_PROPERTY(process,
780-
"_eval",
781-
String::NewFromUtf8(
782-
env->isolate(),
783-
env->options()->eval_string.c_str(),
784-
NewStringType::kNormal).ToLocalChecked());
785-
}
786-
787-
// -p, --print
788-
// TODO(addaleax): Remove this.
789-
if (env->options()->print_eval) {
790-
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
791-
}
792-
793-
// -c, --check
794-
// TODO(addaleax): Remove this.
795-
if (env->options()->syntax_check_only) {
796-
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
797-
}
798-
799-
// -i, --interactive
800-
// TODO(addaleax): Remove this.
801-
if (env->options()->force_repl) {
802-
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
803-
}
804-
805-
// -r, --require
806-
// TODO(addaleax): Remove this.
807-
const std::vector<std::string>& preload_modules =
808-
env->options()->preload_modules;
809-
if (!preload_modules.empty()) {
810-
READONLY_PROPERTY(process,
811-
"_preload_modules",
812-
ToV8Value(env->context(), preload_modules)
813-
.ToLocalChecked());
814-
}
815-
816-
// --no-deprecation
817-
if (env->options()->no_deprecation) {
818-
READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
819-
}
820-
821-
// --no-warnings
822-
if (env->options()->no_warnings) {
823-
READONLY_PROPERTY(process, "noProcessWarnings", True(env->isolate()));
824-
}
825-
826-
// --trace-warnings
827-
if (env->options()->trace_warnings) {
828-
READONLY_PROPERTY(process, "traceProcessWarnings", True(env->isolate()));
829-
}
830-
831-
// --throw-deprecation
832-
if (env->options()->throw_deprecation) {
833-
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
834-
}
835-
836-
#ifdef NODE_NO_BROWSER_GLOBALS
837-
// configure --no-browser-globals
838-
READONLY_PROPERTY(process, "_noBrowserGlobals", True(env->isolate()));
839-
#endif // NODE_NO_BROWSER_GLOBALS
840-
841-
// --prof-process
842-
// TODO(addaleax): Remove this.
843-
if (env->options()->prof_process) {
844-
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
845-
}
846-
847-
// --trace-deprecation
848-
if (env->options()->trace_deprecation) {
849-
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
850-
}
851-
852-
// TODO(refack): move the following 4 to `node_config`
853-
// --inspect-brk
854-
if (env->options()->debug_options().wait_for_connect()) {
855-
READONLY_DONT_ENUM_PROPERTY(process,
856-
"_breakFirstLine", True(env->isolate()));
857-
}
858-
859-
if (env->options()->debug_options().break_node_first_line) {
860-
READONLY_DONT_ENUM_PROPERTY(process,
861-
"_breakNodeFirstLine", True(env->isolate()));
862-
}
863-
864-
// --inspect --debug-brk
865-
if (env->options()->debug_options().deprecated_invocation()) {
866-
READONLY_DONT_ENUM_PROPERTY(process,
867-
"_deprecatedDebugBrk", True(env->isolate()));
868-
}
869-
870-
// --debug or, --debug-brk without --inspect
871-
if (env->options()->debug_options().invalid_invocation()) {
872-
READONLY_DONT_ENUM_PROPERTY(process,
873-
"_invalidDebug", True(env->isolate()));
874-
}
875-
876-
// --security-revert flags
877-
#define V(code, _, __) \
878-
do { \
879-
if (IsReverted(SECURITY_REVERT_ ## code)) { \
880-
READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \
881-
} \
882-
} while (0);
883-
SECURITY_REVERSIONS(V)
884-
#undef V
885-
886-
{
887-
size_t exec_path_len = 2 * PATH_MAX;
888-
std::vector<char> exec_path(exec_path_len);
889-
Local<String> exec_path_value;
890-
if (uv_exepath(exec_path.data(), &exec_path_len) == 0) {
891-
exec_path_value = String::NewFromUtf8(env->isolate(),
892-
exec_path.data(),
893-
NewStringType::kInternalized,
894-
exec_path_len).ToLocalChecked();
895-
} else {
896-
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
897-
NewStringType::kInternalized).ToLocalChecked();
898-
}
899-
process->Set(env->context(),
900-
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
901-
exec_path_value).FromJust();
902-
}
903-
904-
auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
905-
CHECK(process->SetAccessor(env->context(),
906-
debug_port_string,
907-
DebugPortGetter,
908-
env->is_main_thread() ? DebugPortSetter : nullptr,
909-
env->as_external()).FromJust());
910-
}
911-
912-
913687
void SignalExit(int signo) {
914688
uv_tty_reset_mode();
915689
#ifdef __FreeBSD__

src/node_internals.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
185185
const char* warning,
186186
const char* deprecation_code);
187187

188-
void SetupProcessObject(Environment* env,
189-
const std::vector<std::string>& args,
190-
const std::vector<std::string>& exec_args);
188+
v8::Local<v8::Object> CreateProcessObject(
189+
Environment* env,
190+
const std::vector<std::string>& args,
191+
const std::vector<std::string>& exec_args);
191192

192193
enum Endianness {
193194
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
File renamed without changes.

0 commit comments

Comments
 (0)