GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_process_object.cc Lines: 64 70 91.4 %
Date: 2020-08-17 22:13:26 Branches: 31 56 55.4 %

Line Branch Exec Source
1
#include "env-inl.h"
2
#include "node_external_reference.h"
3
#include "node_internals.h"
4
#include "node_metadata.h"
5
#include "node_options-inl.h"
6
#include "node_process.h"
7
#include "node_revert.h"
8
#include "util-inl.h"
9
10
#include <climits>  // PATH_MAX
11
12
namespace node {
13
using v8::Context;
14
using v8::DEFAULT;
15
using v8::EscapableHandleScope;
16
using v8::Function;
17
using v8::FunctionCallbackInfo;
18
using v8::FunctionTemplate;
19
using v8::Integer;
20
using v8::Isolate;
21
using v8::Local;
22
using v8::MaybeLocal;
23
using v8::Name;
24
using v8::NewStringType;
25
using v8::None;
26
using v8::Object;
27
using v8::PropertyCallbackInfo;
28
using v8::SideEffectType;
29
using v8::String;
30
using v8::Value;
31
32
24
static void ProcessTitleGetter(Local<Name> property,
33
                               const PropertyCallbackInfo<Value>& info) {
34
48
  std::string title = GetProcessTitle("node");
35
48
  info.GetReturnValue().Set(
36
48
      String::NewFromUtf8(info.GetIsolate(), title.data(),
37
48
                          NewStringType::kNormal, title.size())
38
      .ToLocalChecked());
39
24
}
40
41
95
static void ProcessTitleSetter(Local<Name> property,
42
                               Local<Value> value,
43
                               const PropertyCallbackInfo<void>& info) {
44
190
  node::Utf8Value title(info.GetIsolate(), value);
45

191
  TRACE_EVENT_METADATA1(
46
      "__metadata", "process_name", "name", TRACE_STR_COPY(*title));
47
95
  uv_set_process_title(*title);
48
95
}
49
50
101
static void DebugPortGetter(Local<Name> property,
51
                            const PropertyCallbackInfo<Value>& info) {
52
101
  Environment* env = Environment::GetCurrent(info);
53
202
  ExclusiveAccess<HostPort>::Scoped host_port(env->inspector_host_port());
54
101
  int port = host_port->port();
55
202
  info.GetReturnValue().Set(port);
56
101
}
57
58
static void DebugPortSetter(Local<Name> property,
59
                            Local<Value> value,
60
                            const PropertyCallbackInfo<void>& info) {
61
  Environment* env = Environment::GetCurrent(info);
62
  int32_t port = value->Int32Value(env->context()).FromMaybe(0);
63
  ExclusiveAccess<HostPort>::Scoped host_port(env->inspector_host_port());
64
  host_port->set_port(static_cast<int>(port));
65
}
66
67
18
static void GetParentProcessId(Local<Name> property,
68
                               const PropertyCallbackInfo<Value>& info) {
69
54
  info.GetReturnValue().Set(uv_os_getppid());
70
18
}
71
72
387
MaybeLocal<Object> CreateProcessObject(Environment* env) {
73
387
  Isolate* isolate = env->isolate();
74
387
  EscapableHandleScope scope(isolate);
75
388
  Local<Context> context = env->context();
76
77
388
  Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
78
776
  process_template->SetClassName(env->process_string());
79
  Local<Function> process_ctor;
80
  Local<Object> process;
81

1552
  if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
82
1164
      !process_ctor->NewInstance(context).ToLocal(&process)) {
83
    return MaybeLocal<Object>();
84
  }
85
86
  // process.version
87
1552
  READONLY_PROPERTY(process,
88
                    "version",
89
                    FIXED_ONE_BYTE_STRING(env->isolate(), NODE_VERSION));
90
91
  // process.versions
92
388
  Local<Object> versions = Object::New(env->isolate());
93
1164
  READONLY_PROPERTY(process, "versions", versions);
94
95
#define V(key)                                                                 \
96
  if (!per_process::metadata.versions.key.empty()) {                           \
97
    READONLY_STRING_PROPERTY(                                                  \
98
        versions, #key, per_process::metadata.versions.key);                   \
99
  }
100







17848
  NODE_VERSIONS_KEYS(V)
101
#undef V
102
103
  // process.arch
104
1552
  READONLY_STRING_PROPERTY(process, "arch", per_process::metadata.arch);
105
106
  // process.platform
107
1552
  READONLY_STRING_PROPERTY(process, "platform", per_process::metadata.platform);
108
109
  // process.release
110
388
  Local<Object> release = Object::New(env->isolate());
111
1164
  READONLY_PROPERTY(process, "release", release);
112
1552
  READONLY_STRING_PROPERTY(release, "name", per_process::metadata.release.name);
113
#if NODE_VERSION_IS_LTS
114
  READONLY_STRING_PROPERTY(release, "lts", per_process::metadata.release.lts);
115
#endif  // NODE_VERSION_IS_LTS
116
117
#ifdef NODE_HAS_RELEASE_URLS
118
  READONLY_STRING_PROPERTY(
119
      release, "sourceUrl", per_process::metadata.release.source_url);
120
  READONLY_STRING_PROPERTY(
121
      release, "headersUrl", per_process::metadata.release.headers_url);
122
#ifdef _WIN32
123
  READONLY_STRING_PROPERTY(
124
      release, "libUrl", per_process::metadata.release.lib_url);
125
#endif  // _WIN32
126
#endif  // NODE_HAS_RELEASE_URLS
127
128
  // process._rawDebug: may be overwritten later in JS land, but should be
129
  // available from the beginning for debugging purposes
130
388
  env->SetMethod(process, "_rawDebug", RawDebug);
131
132
388
  return scope.Escape(process);
133
}
134
135
4750
void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
136
4750
  Isolate* isolate = args.GetIsolate();
137
4750
  Local<Context> context = isolate->GetCurrentContext();
138
4750
  Environment* env = Environment::GetCurrent(context);
139
9500
  CHECK(args[0]->IsObject());
140
9500
  Local<Object> process = args[0].As<Object>();
141
142
  // process.title
143

14250
  CHECK(process
144
            ->SetAccessor(
145
                context,
146
                FIXED_ONE_BYTE_STRING(isolate, "title"),
147
                ProcessTitleGetter,
148
                env->owns_process_state() ? ProcessTitleSetter : nullptr,
149
                Local<Value>(),
150
                DEFAULT,
151
                None,
152
                SideEffectType::kHasNoSideEffect)
153
            .FromJust());
154
155
  // process.argv
156
9500
  process->Set(context,
157
               FIXED_ONE_BYTE_STRING(isolate, "argv"),
158
19000
               ToV8Value(context, env->argv()).ToLocalChecked()).Check();
159
160
  // process.execArgv
161
9500
  process->Set(context,
162
               FIXED_ONE_BYTE_STRING(isolate, "execArgv"),
163
9500
               ToV8Value(context, env->exec_argv())
164
14250
                   .ToLocalChecked()).Check();
165
166
19000
  READONLY_PROPERTY(process, "pid",
167
                    Integer::New(isolate, uv_os_getpid()));
168
169
14250
  CHECK(process->SetAccessor(context,
170
                             FIXED_ONE_BYTE_STRING(isolate, "ppid"),
171
                             GetParentProcessId).FromJust());
172
173
  // --security-revert flags
174
#define V(code, _, __)                                                        \
175
  do {                                                                        \
176
    if (IsReverted(SECURITY_REVERT_ ## code)) {                               \
177
      READONLY_PROPERTY(process, "REVERT_" #code, True(isolate));             \
178
    }                                                                         \
179
  } while (0);
180
  SECURITY_REVERSIONS(V)
181
#undef V
182
183
  // process.execPath
184
  process
185
9500
      ->Set(context,
186
            FIXED_ONE_BYTE_STRING(isolate, "execPath"),
187
9500
            String::NewFromUtf8(isolate,
188
4750
                                env->exec_path().c_str(),
189
                                NewStringType::kInternalized,
190
9500
                                env->exec_path().size())
191
14250
                .ToLocalChecked())
192
      .Check();
193
194
  // process.debugPort
195

14250
  CHECK(process
196
            ->SetAccessor(context,
197
                          FIXED_ONE_BYTE_STRING(isolate, "debugPort"),
198
                          DebugPortGetter,
199
                          env->owns_process_state() ? DebugPortSetter : nullptr,
200
                          Local<Value>())
201
            .FromJust());
202
4750
}
203
204
4390
void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) {
205
4390
  registry->Register(RawDebug);
206
4390
}
207
208
}  // namespace node
209
210

17770
NODE_MODULE_EXTERNAL_REFERENCE(process_object,
211
                               node::RegisterProcessExternalReferences)