GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
// Copyright Joyent, Inc. and other Node contributors. |
||
2 |
// |
||
3 |
// Permission is hereby granted, free of charge, to any person obtaining a |
||
4 |
// copy of this software and associated documentation files (the |
||
5 |
// "Software"), to deal in the Software without restriction, including |
||
6 |
// without limitation the rights to use, copy, modify, merge, publish, |
||
7 |
// distribute, sublicense, and/or sell copies of the Software, and to permit |
||
8 |
// persons to whom the Software is furnished to do so, subject to the |
||
9 |
// following conditions: |
||
10 |
// |
||
11 |
// The above copyright notice and this permission notice shall be included |
||
12 |
// in all copies or substantial portions of the Software. |
||
13 |
// |
||
14 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
15 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
16 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
||
17 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
||
18 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
19 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
20 |
// USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
21 |
|||
22 |
#ifndef SRC_ENV_INL_H_ |
||
23 |
#define SRC_ENV_INL_H_ |
||
24 |
|||
25 |
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
||
26 |
|||
27 |
#include "aliased_buffer.h" |
||
28 |
#include "callback_queue-inl.h" |
||
29 |
#include "env.h" |
||
30 |
#include "node.h" |
||
31 |
#include "node_context_data.h" |
||
32 |
#include "node_internals.h" |
||
33 |
#include "node_perf_common.h" |
||
34 |
#include "node_realm-inl.h" |
||
35 |
#include "util-inl.h" |
||
36 |
#include "uv.h" |
||
37 |
#include "v8.h" |
||
38 |
|||
39 |
#include <cstddef> |
||
40 |
#include <cstdint> |
||
41 |
|||
42 |
#include <utility> |
||
43 |
|||
44 |
namespace node { |
||
45 |
|||
46 |
115841 |
NoArrayBufferZeroFillScope::NoArrayBufferZeroFillScope( |
|
47 |
115841 |
IsolateData* isolate_data) |
|
48 |
115841 |
: node_allocator_(isolate_data->node_allocator()) { |
|
49 |
✓✗ | 115841 |
if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 0; |
50 |
115841 |
} |
|
51 |
|||
52 |
231682 |
NoArrayBufferZeroFillScope::~NoArrayBufferZeroFillScope() { |
|
53 |
✓✗ | 115841 |
if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 1; |
54 |
115841 |
} |
|
55 |
|||
56 |
25904 |
inline v8::Isolate* IsolateData::isolate() const { |
|
57 |
25904 |
return isolate_; |
|
58 |
} |
||
59 |
|||
60 |
1311500 |
inline uv_loop_t* IsolateData::event_loop() const { |
|
61 |
1311500 |
return event_loop_; |
|
62 |
} |
||
63 |
|||
64 |
122721 |
inline NodeArrayBufferAllocator* IsolateData::node_allocator() const { |
|
65 |
122721 |
return node_allocator_; |
|
66 |
} |
||
67 |
|||
68 |
86407 |
inline MultiIsolatePlatform* IsolateData::platform() const { |
|
69 |
86407 |
return platform_; |
|
70 |
} |
||
71 |
|||
72 |
736 |
inline void IsolateData::set_worker_context(worker::Worker* context) { |
|
73 |
✗✓ | 736 |
CHECK_NULL(worker_context_); // Should be set only once. |
74 |
736 |
worker_context_ = context; |
|
75 |
736 |
} |
|
76 |
|||
77 |
16531 |
inline worker::Worker* IsolateData::worker_context() const { |
|
78 |
16531 |
return worker_context_; |
|
79 |
} |
||
80 |
|||
81 |
214552 |
inline v8::Local<v8::String> IsolateData::async_wrap_provider(int index) const { |
|
82 |
429104 |
return async_wrap_providers_[index].Get(isolate_); |
|
83 |
} |
||
84 |
|||
85 |
2722613 |
inline AliasedUint32Array& AsyncHooks::fields() { |
|
86 |
2722613 |
return fields_; |
|
87 |
} |
||
88 |
|||
89 |
1678758 |
inline AliasedFloat64Array& AsyncHooks::async_id_fields() { |
|
90 |
1678758 |
return async_id_fields_; |
|
91 |
} |
||
92 |
|||
93 |
786 |
inline AliasedFloat64Array& AsyncHooks::async_ids_stack() { |
|
94 |
786 |
return async_ids_stack_; |
|
95 |
} |
||
96 |
|||
97 |
884972 |
v8::Local<v8::Array> AsyncHooks::js_execution_async_resources() { |
|
98 |
✓✓ | 1769944 |
if (UNLIKELY(js_execution_async_resources_.IsEmpty())) { |
99 |
1572 |
js_execution_async_resources_.Reset( |
|
100 |
1572 |
env()->isolate(), v8::Array::New(env()->isolate())); |
|
101 |
} |
||
102 |
884972 |
return PersistentToLocal::Strong(js_execution_async_resources_); |
|
103 |
} |
||
104 |
|||
105 |
2406 |
v8::Local<v8::Object> AsyncHooks::native_execution_async_resource(size_t i) { |
|
106 |
✗✓ | 2406 |
if (i >= native_execution_async_resources_.size()) return {}; |
107 |
2406 |
return native_execution_async_resources_[i]; |
|
108 |
} |
||
109 |
|||
110 |
214204 |
inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) { |
|
111 |
214204 |
return env()->isolate_data()->async_wrap_provider(idx); |
|
112 |
} |
||
113 |
|||
114 |
1 |
inline void AsyncHooks::no_force_checks() { |
|
115 |
1 |
fields_[kCheck] -= 1; |
|
116 |
1 |
} |
|
117 |
|||
118 |
484173 |
inline Environment* AsyncHooks::env() { |
|
119 |
484173 |
return Environment::ForAsyncHooks(this); |
|
120 |
} |
||
121 |
|||
122 |
484173 |
Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) { |
|
123 |
484173 |
return ContainerOf(&Environment::async_hooks_, hooks); |
|
124 |
} |
||
125 |
|||
126 |
842226 |
inline size_t Environment::async_callback_scope_depth() const { |
|
127 |
842226 |
return async_callback_scope_depth_; |
|
128 |
} |
||
129 |
|||
130 |
856428 |
inline void Environment::PushAsyncCallbackScope() { |
|
131 |
856428 |
async_callback_scope_depth_++; |
|
132 |
856428 |
} |
|
133 |
|||
134 |
855752 |
inline void Environment::PopAsyncCallbackScope() { |
|
135 |
855752 |
async_callback_scope_depth_--; |
|
136 |
855752 |
} |
|
137 |
|||
138 |
786 |
inline AliasedUint32Array& ImmediateInfo::fields() { |
|
139 |
786 |
return fields_; |
|
140 |
} |
||
141 |
|||
142 |
211897 |
inline uint32_t ImmediateInfo::count() const { |
|
143 |
211897 |
return fields_[kCount]; |
|
144 |
} |
||
145 |
|||
146 |
317958 |
inline uint32_t ImmediateInfo::ref_count() const { |
|
147 |
317958 |
return fields_[kRefCount]; |
|
148 |
} |
||
149 |
|||
150 |
56261 |
inline bool ImmediateInfo::has_outstanding() const { |
|
151 |
56261 |
return fields_[kHasOutstanding] == 1; |
|
152 |
} |
||
153 |
|||
154 |
33259 |
inline void ImmediateInfo::ref_count_inc(uint32_t increment) { |
|
155 |
33259 |
fields_[kRefCount] += increment; |
|
156 |
33259 |
} |
|
157 |
|||
158 |
229389 |
inline void ImmediateInfo::ref_count_dec(uint32_t decrement) { |
|
159 |
229389 |
fields_[kRefCount] -= decrement; |
|
160 |
229389 |
} |
|
161 |
|||
162 |
786 |
inline AliasedUint8Array& TickInfo::fields() { |
|
163 |
786 |
return fields_; |
|
164 |
} |
||
165 |
|||
166 |
1536703 |
inline bool TickInfo::has_tick_scheduled() const { |
|
167 |
1536703 |
return fields_[kHasTickScheduled] == 1; |
|
168 |
} |
||
169 |
|||
170 |
560297 |
inline bool TickInfo::has_rejection_to_warn() const { |
|
171 |
560297 |
return fields_[kHasRejectionToWarn] == 1; |
|
172 |
} |
||
173 |
|||
174 |
82036 |
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) { |
|
175 |
✓✓ | 82036 |
if (UNLIKELY(!isolate->InContext())) return nullptr; |
176 |
153468 |
v8::HandleScope handle_scope(isolate); |
|
177 |
76734 |
return GetCurrent(isolate->GetCurrentContext()); |
|
178 |
} |
||
179 |
|||
180 |
7914008 |
inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) { |
|
181 |
✓✓ | 7914008 |
if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) { |
182 |
13 |
return nullptr; |
|
183 |
} |
||
184 |
return static_cast<Environment*>( |
||
185 |
7913995 |
context->GetAlignedPointerFromEmbedderData( |
|
186 |
7913995 |
ContextEmbedderIndex::kEnvironment)); |
|
187 |
} |
||
188 |
|||
189 |
5991726 |
inline Environment* Environment::GetCurrent( |
|
190 |
const v8::FunctionCallbackInfo<v8::Value>& info) { |
||
191 |
5991726 |
return GetCurrent(info.GetIsolate()->GetCurrentContext()); |
|
192 |
} |
||
193 |
|||
194 |
template <typename T> |
||
195 |
1423591 |
inline Environment* Environment::GetCurrent( |
|
196 |
const v8::PropertyCallbackInfo<T>& info) { |
||
197 |
1423591 |
return GetCurrent(info.GetIsolate()->GetCurrentContext()); |
|
198 |
} |
||
199 |
|||
200 |
template <typename T, typename U> |
||
201 |
inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) { |
||
202 |
return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); |
||
203 |
} |
||
204 |
|||
205 |
template <typename T> |
||
206 |
1027642 |
inline T* Environment::GetBindingData( |
|
207 |
const v8::FunctionCallbackInfo<v8::Value>& info) { |
||
208 |
1027642 |
return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); |
|
209 |
} |
||
210 |
|||
211 |
template <typename T> |
||
212 |
1027644 |
inline T* Environment::GetBindingData(v8::Local<v8::Context> context) { |
|
213 |
1027644 |
BindingDataStore* map = static_cast<BindingDataStore*>( |
|
214 |
1027644 |
context->GetAlignedPointerFromEmbedderData( |
|
215 |
ContextEmbedderIndex::kBindingListIndex)); |
||
216 |
DCHECK_NOT_NULL(map); |
||
217 |
1027644 |
auto it = map->find(T::type_name); |
|
218 |
✗✓ | 1027644 |
if (UNLIKELY(it == map->end())) return nullptr; |
219 |
1027644 |
T* result = static_cast<T*>(it->second.get()); |
|
220 |
DCHECK_NOT_NULL(result); |
||
221 |
DCHECK_EQ(result->env(), GetCurrent(context)); |
||
222 |
1027644 |
return result; |
|
223 |
} |
||
224 |
|||
225 |
template <typename T> |
||
226 |
26514 |
inline T* Environment::AddBindingData( |
|
227 |
v8::Local<v8::Context> context, |
||
228 |
v8::Local<v8::Object> target) { |
||
229 |
DCHECK_EQ(GetCurrent(context), this); |
||
230 |
// This won't compile if T is not a BaseObject subclass. |
||
231 |
53028 |
BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target); |
|
232 |
26514 |
BindingDataStore* map = static_cast<BindingDataStore*>( |
|
233 |
26514 |
context->GetAlignedPointerFromEmbedderData( |
|
234 |
ContextEmbedderIndex::kBindingListIndex)); |
||
235 |
DCHECK_NOT_NULL(map); |
||
236 |
26514 |
auto result = map->emplace(T::type_name, item); |
|
237 |
✗✓ | 26514 |
CHECK(result.second); |
238 |
DCHECK_EQ(GetBindingData<T>(context), item.get()); |
||
239 |
53028 |
return item.get(); |
|
240 |
} |
||
241 |
|||
242 |
24515079 |
inline v8::Isolate* Environment::isolate() const { |
|
243 |
24515079 |
return isolate_; |
|
244 |
} |
||
245 |
|||
246 |
8395 |
inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { |
|
247 |
8395 |
return ContainerOf(&Environment::timer_handle_, handle); |
|
248 |
} |
||
249 |
|||
250 |
33259 |
inline uv_timer_t* Environment::timer_handle() { |
|
251 |
33259 |
return &timer_handle_; |
|
252 |
} |
||
253 |
|||
254 |
211898 |
inline Environment* Environment::from_immediate_check_handle( |
|
255 |
uv_check_t* handle) { |
||
256 |
211898 |
return ContainerOf(&Environment::immediate_check_handle_, handle); |
|
257 |
} |
||
258 |
|||
259 |
25180 |
inline uv_check_t* Environment::immediate_check_handle() { |
|
260 |
25180 |
return &immediate_check_handle_; |
|
261 |
} |
||
262 |
|||
263 |
258053 |
inline uv_idle_t* Environment::immediate_idle_handle() { |
|
264 |
258053 |
return &immediate_idle_handle_; |
|
265 |
} |
||
266 |
|||
267 |
37770 |
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, |
|
268 |
HandleCleanupCb cb, |
||
269 |
void* arg) { |
||
270 |
37770 |
handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg}); |
|
271 |
37770 |
} |
|
272 |
|||
273 |
template <typename T, typename OnCloseCallback> |
||
274 |
38737 |
inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) { |
|
275 |
38737 |
handle_cleanup_waiting_++; |
|
276 |
static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle"); |
||
277 |
static_assert(offsetof(T, data) == offsetof(uv_handle_t, data), |
||
278 |
"T is a libuv handle"); |
||
279 |
static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb), |
||
280 |
"T is a libuv handle"); |
||
281 |
struct CloseData { |
||
282 |
Environment* env; |
||
283 |
OnCloseCallback callback; |
||
284 |
void* original_data; |
||
285 |
}; |
||
286 |
38737 |
handle->data = new CloseData { this, callback, handle->data }; |
|
287 |
154948 |
uv_close(reinterpret_cast<uv_handle_t*>(handle), [](uv_handle_t* handle) { |
|
288 |
77474 |
std::unique_ptr<CloseData> data { static_cast<CloseData*>(handle->data) }; |
|
289 |
38737 |
data->env->handle_cleanup_waiting_--; |
|
290 |
38737 |
handle->data = data->original_data; |
|
291 |
38737 |
data->callback(reinterpret_cast<T*>(handle)); |
|
292 |
38737 |
}); |
|
293 |
38737 |
} |
|
294 |
|||
295 |
94877 |
void Environment::IncreaseWaitingRequestCounter() { |
|
296 |
94877 |
request_waiting_++; |
|
297 |
94877 |
} |
|
298 |
|||
299 |
94868 |
void Environment::DecreaseWaitingRequestCounter() { |
|
300 |
94868 |
request_waiting_--; |
|
301 |
✗✓ | 94868 |
CHECK_GE(request_waiting_, 0); |
302 |
94868 |
} |
|
303 |
|||
304 |
1305170 |
inline uv_loop_t* Environment::event_loop() const { |
|
305 |
1305170 |
return isolate_data()->event_loop(); |
|
306 |
} |
||
307 |
|||
308 |
#if HAVE_INSPECTOR |
||
309 |
71844 |
inline bool Environment::is_in_inspector_console_call() const { |
|
310 |
71844 |
return is_in_inspector_console_call_; |
|
311 |
} |
||
312 |
|||
313 |
143686 |
inline void Environment::set_is_in_inspector_console_call(bool value) { |
|
314 |
143686 |
is_in_inspector_console_call_ = value; |
|
315 |
143686 |
} |
|
316 |
#endif |
||
317 |
|||
318 |
6149345 |
inline AsyncHooks* Environment::async_hooks() { |
|
319 |
6149345 |
return &async_hooks_; |
|
320 |
} |
||
321 |
|||
322 |
849550 |
inline ImmediateInfo* Environment::immediate_info() { |
|
323 |
849550 |
return &immediate_info_; |
|
324 |
} |
||
325 |
|||
326 |
769175 |
inline TickInfo* Environment::tick_info() { |
|
327 |
769175 |
return &tick_info_; |
|
328 |
} |
||
329 |
|||
330 |
104612 |
inline uint64_t Environment::timer_base() const { |
|
331 |
104612 |
return timer_base_; |
|
332 |
} |
||
333 |
|||
334 |
1441855 |
inline std::shared_ptr<KVStore> Environment::env_vars() { |
|
335 |
1441855 |
return env_vars_; |
|
336 |
} |
||
337 |
|||
338 |
7054 |
inline void Environment::set_env_vars(std::shared_ptr<KVStore> env_vars) { |
|
339 |
7054 |
env_vars_ = env_vars; |
|
340 |
7054 |
} |
|
341 |
|||
342 |
22 |
inline bool Environment::printed_error() const { |
|
343 |
22 |
return printed_error_; |
|
344 |
} |
||
345 |
|||
346 |
22 |
inline void Environment::set_printed_error(bool value) { |
|
347 |
22 |
printed_error_ = value; |
|
348 |
22 |
} |
|
349 |
|||
350 |
11211 |
inline void Environment::set_trace_sync_io(bool value) { |
|
351 |
11211 |
trace_sync_io_ = value; |
|
352 |
11211 |
} |
|
353 |
|||
354 |
124 |
inline bool Environment::abort_on_uncaught_exception() const { |
|
355 |
124 |
return options_->abort_on_uncaught_exception; |
|
356 |
} |
||
357 |
|||
358 |
inline void Environment::set_force_context_aware(bool value) { |
||
359 |
options_->force_context_aware = value; |
||
360 |
} |
||
361 |
|||
362 |
44 |
inline bool Environment::force_context_aware() const { |
|
363 |
44 |
return options_->force_context_aware; |
|
364 |
} |
||
365 |
|||
366 |
11596 |
inline void Environment::set_exiting(bool value) { |
|
367 |
✓✓ | 11596 |
exiting_[0] = value ? 1 : 0; |
368 |
11596 |
} |
|
369 |
|||
370 |
786 |
inline AliasedUint32Array& Environment::exiting() { |
|
371 |
786 |
return exiting_; |
|
372 |
} |
||
373 |
|||
374 |
729 |
inline void Environment::set_abort_on_uncaught_exception(bool value) { |
|
375 |
729 |
options_->abort_on_uncaught_exception = value; |
|
376 |
729 |
} |
|
377 |
|||
378 |
816 |
inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() { |
|
379 |
816 |
return should_abort_on_uncaught_toggle_; |
|
380 |
} |
||
381 |
|||
382 |
310456 |
inline AliasedInt32Array& Environment::stream_base_state() { |
|
383 |
310456 |
return stream_base_state_; |
|
384 |
} |
||
385 |
|||
386 |
52274 |
inline uint32_t Environment::get_next_module_id() { |
|
387 |
52274 |
return module_id_counter_++; |
|
388 |
} |
||
389 |
6410 |
inline uint32_t Environment::get_next_script_id() { |
|
390 |
6410 |
return script_id_counter_++; |
|
391 |
} |
||
392 |
37188 |
inline uint32_t Environment::get_next_function_id() { |
|
393 |
37188 |
return function_id_counter_++; |
|
394 |
} |
||
395 |
|||
396 |
110450 |
ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( |
|
397 |
110450 |
Environment* env) |
|
398 |
110450 |
: env_(env) { |
|
399 |
110450 |
env_->PushShouldNotAbortOnUncaughtScope(); |
|
400 |
110450 |
} |
|
401 |
|||
402 |
220894 |
ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { |
|
403 |
110447 |
Close(); |
|
404 |
110447 |
} |
|
405 |
|||
406 |
110640 |
void ShouldNotAbortOnUncaughtScope::Close() { |
|
407 |
✓✓ | 110640 |
if (env_ != nullptr) { |
408 |
110447 |
env_->PopShouldNotAbortOnUncaughtScope(); |
|
409 |
110447 |
env_ = nullptr; |
|
410 |
} |
||
411 |
110640 |
} |
|
412 |
|||
413 |
110450 |
inline void Environment::PushShouldNotAbortOnUncaughtScope() { |
|
414 |
110450 |
should_not_abort_scope_counter_++; |
|
415 |
110450 |
} |
|
416 |
|||
417 |
110447 |
inline void Environment::PopShouldNotAbortOnUncaughtScope() { |
|
418 |
110447 |
should_not_abort_scope_counter_--; |
|
419 |
110447 |
} |
|
420 |
|||
421 |
1 |
inline bool Environment::inside_should_not_abort_on_uncaught_scope() const { |
|
422 |
1 |
return should_not_abort_scope_counter_ > 0; |
|
423 |
} |
||
424 |
|||
425 |
438321 |
inline std::vector<double>* Environment::destroy_async_id_list() { |
|
426 |
438321 |
return &destroy_async_id_list_; |
|
427 |
} |
||
428 |
|||
429 |
214759 |
inline double Environment::new_async_id() { |
|
430 |
214759 |
async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1; |
|
431 |
214759 |
return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter]; |
|
432 |
} |
||
433 |
|||
434 |
246484 |
inline double Environment::execution_async_id() { |
|
435 |
246484 |
return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId]; |
|
436 |
} |
||
437 |
|||
438 |
65298 |
inline double Environment::trigger_async_id() { |
|
439 |
65298 |
return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId]; |
|
440 |
} |
||
441 |
|||
442 |
214756 |
inline double Environment::get_default_trigger_async_id() { |
|
443 |
double default_trigger_async_id = |
||
444 |
214756 |
async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; |
|
445 |
// If defaultTriggerAsyncId isn't set, use the executionAsyncId |
||
446 |
✓✓ | 214756 |
if (default_trigger_async_id < 0) |
447 |
181107 |
default_trigger_async_id = execution_async_id(); |
|
448 |
214756 |
return default_trigger_async_id; |
|
449 |
} |
||
450 |
|||
451 |
80404 |
inline std::shared_ptr<EnvironmentOptions> Environment::options() { |
|
452 |
80404 |
return options_; |
|
453 |
} |
||
454 |
|||
455 |
17832 |
inline const std::vector<std::string>& Environment::argv() { |
|
456 |
17832 |
return argv_; |
|
457 |
} |
||
458 |
|||
459 |
6971 |
inline const std::vector<std::string>& Environment::exec_argv() { |
|
460 |
6971 |
return exec_argv_; |
|
461 |
} |
||
462 |
|||
463 |
12592 |
inline const std::string& Environment::exec_path() const { |
|
464 |
12592 |
return exec_path_; |
|
465 |
} |
||
466 |
|||
467 |
#if HAVE_INSPECTOR |
||
468 |
6291 |
inline void Environment::set_coverage_directory(const char* dir) { |
|
469 |
6291 |
coverage_directory_ = std::string(dir); |
|
470 |
6291 |
} |
|
471 |
|||
472 |
6316 |
inline void Environment::set_coverage_connection( |
|
473 |
std::unique_ptr<profiler::V8CoverageConnection> connection) { |
||
474 |
✗✓ | 6316 |
CHECK_NULL(coverage_connection_); |
475 |
6316 |
std::swap(coverage_connection_, connection); |
|
476 |
6316 |
} |
|
477 |
|||
478 |
18945 |
inline profiler::V8CoverageConnection* Environment::coverage_connection() { |
|
479 |
18945 |
return coverage_connection_.get(); |
|
480 |
} |
||
481 |
|||
482 |
6272 |
inline const std::string& Environment::coverage_directory() const { |
|
483 |
6272 |
return coverage_directory_; |
|
484 |
} |
||
485 |
|||
486 |
12 |
inline void Environment::set_cpu_profiler_connection( |
|
487 |
std::unique_ptr<profiler::V8CpuProfilerConnection> connection) { |
||
488 |
✗✓ | 12 |
CHECK_NULL(cpu_profiler_connection_); |
489 |
12 |
std::swap(cpu_profiler_connection_, connection); |
|
490 |
12 |
} |
|
491 |
|||
492 |
inline profiler::V8CpuProfilerConnection* |
||
493 |
6330 |
Environment::cpu_profiler_connection() { |
|
494 |
6330 |
return cpu_profiler_connection_.get(); |
|
495 |
} |
||
496 |
|||
497 |
12 |
inline void Environment::set_cpu_prof_interval(uint64_t interval) { |
|
498 |
12 |
cpu_prof_interval_ = interval; |
|
499 |
12 |
} |
|
500 |
|||
501 |
12 |
inline uint64_t Environment::cpu_prof_interval() const { |
|
502 |
12 |
return cpu_prof_interval_; |
|
503 |
} |
||
504 |
|||
505 |
12 |
inline void Environment::set_cpu_prof_name(const std::string& name) { |
|
506 |
12 |
cpu_prof_name_ = name; |
|
507 |
12 |
} |
|
508 |
|||
509 |
12 |
inline const std::string& Environment::cpu_prof_name() const { |
|
510 |
12 |
return cpu_prof_name_; |
|
511 |
} |
||
512 |
|||
513 |
12 |
inline void Environment::set_cpu_prof_dir(const std::string& dir) { |
|
514 |
12 |
cpu_prof_dir_ = dir; |
|
515 |
12 |
} |
|
516 |
|||
517 |
12 |
inline const std::string& Environment::cpu_prof_dir() const { |
|
518 |
12 |
return cpu_prof_dir_; |
|
519 |
} |
||
520 |
|||
521 |
12 |
inline void Environment::set_heap_profiler_connection( |
|
522 |
std::unique_ptr<profiler::V8HeapProfilerConnection> connection) { |
||
523 |
✗✓ | 12 |
CHECK_NULL(heap_profiler_connection_); |
524 |
12 |
std::swap(heap_profiler_connection_, connection); |
|
525 |
12 |
} |
|
526 |
|||
527 |
inline profiler::V8HeapProfilerConnection* |
||
528 |
6318 |
Environment::heap_profiler_connection() { |
|
529 |
6318 |
return heap_profiler_connection_.get(); |
|
530 |
} |
||
531 |
|||
532 |
12 |
inline void Environment::set_heap_prof_name(const std::string& name) { |
|
533 |
12 |
heap_prof_name_ = name; |
|
534 |
12 |
} |
|
535 |
|||
536 |
12 |
inline const std::string& Environment::heap_prof_name() const { |
|
537 |
12 |
return heap_prof_name_; |
|
538 |
} |
||
539 |
|||
540 |
12 |
inline void Environment::set_heap_prof_dir(const std::string& dir) { |
|
541 |
12 |
heap_prof_dir_ = dir; |
|
542 |
12 |
} |
|
543 |
|||
544 |
12 |
inline const std::string& Environment::heap_prof_dir() const { |
|
545 |
12 |
return heap_prof_dir_; |
|
546 |
} |
||
547 |
|||
548 |
12 |
inline void Environment::set_heap_prof_interval(uint64_t interval) { |
|
549 |
12 |
heap_prof_interval_ = interval; |
|
550 |
12 |
} |
|
551 |
|||
552 |
12 |
inline uint64_t Environment::heap_prof_interval() const { |
|
553 |
12 |
return heap_prof_interval_; |
|
554 |
} |
||
555 |
|||
556 |
#endif // HAVE_INSPECTOR |
||
557 |
|||
558 |
inline |
||
559 |
12899 |
std::shared_ptr<ExclusiveAccess<HostPort>> Environment::inspector_host_port() { |
|
560 |
12899 |
return inspector_host_port_; |
|
561 |
} |
||
562 |
|||
563 |
64402 |
inline std::shared_ptr<PerIsolateOptions> IsolateData::options() { |
|
564 |
64402 |
return options_; |
|
565 |
} |
||
566 |
|||
567 |
294 |
inline void IsolateData::set_options( |
|
568 |
std::shared_ptr<PerIsolateOptions> options) { |
||
569 |
294 |
options_ = std::move(options); |
|
570 |
294 |
} |
|
571 |
|||
572 |
template <typename Fn> |
||
573 |
58034 |
void Environment::SetImmediate(Fn&& cb, CallbackFlags::Flags flags) { |
|
574 |
116068 |
auto callback = native_immediates_.CreateCallback(std::move(cb), flags); |
|
575 |
58034 |
native_immediates_.Push(std::move(callback)); |
|
576 |
|||
577 |
✓✓✓✓ ✓✗✓✗ ✓✗✗✗ ✓✗✗✗ ✗✗✓✗ ✓✗✓✗ ✓✗ |
58034 |
if (flags & CallbackFlags::kRefed) { |
578 |
✓✓✓✓ ✓✓✓✓ ✗✓✗✗ ✓✗✗✗ ✗✗✓✗ ✓✓✓✓ ✓✓ |
33259 |
if (immediate_info()->ref_count() == 0) |
579 |
24936 |
ToggleImmediateRef(true); |
|
580 |
33259 |
immediate_info()->ref_count_inc(1); |
|
581 |
} |
||
582 |
58034 |
} |
|
583 |
|||
584 |
template <typename Fn> |
||
585 |
1363 |
void Environment::SetImmediateThreadsafe(Fn&& cb, CallbackFlags::Flags flags) { |
|
586 |
4089 |
auto callback = native_immediates_threadsafe_.CreateCallback( |
|
587 |
1363 |
std::move(cb), flags); |
|
588 |
{ |
||
589 |
2726 |
Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); |
|
590 |
1363 |
native_immediates_threadsafe_.Push(std::move(callback)); |
|
591 |
✓✓✓✗ |
1363 |
if (task_queues_async_initialized_) |
592 |
1354 |
uv_async_send(&task_queues_async_); |
|
593 |
} |
||
594 |
1363 |
} |
|
595 |
|||
596 |
template <typename Fn> |
||
597 |
10616 |
void Environment::RequestInterrupt(Fn&& cb) { |
|
598 |
31848 |
auto callback = native_immediates_interrupts_.CreateCallback( |
|
599 |
10616 |
std::move(cb), CallbackFlags::kRefed); |
|
600 |
{ |
||
601 |
21232 |
Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); |
|
602 |
10616 |
native_immediates_interrupts_.Push(std::move(callback)); |
|
603 |
✓✓ | 10616 |
if (task_queues_async_initialized_) |
604 |
4176 |
uv_async_send(&task_queues_async_); |
|
605 |
} |
||
606 |
10616 |
RequestInterruptFromV8(); |
|
607 |
10616 |
} |
|
608 |
|||
609 |
3574382 |
inline bool Environment::can_call_into_js() const { |
|
610 |
✓✓✓✓ |
3574382 |
return can_call_into_js_ && !is_stopping(); |
611 |
} |
||
612 |
|||
613 |
1761 |
inline void Environment::set_can_call_into_js(bool can_call_into_js) { |
|
614 |
1761 |
can_call_into_js_ = can_call_into_js; |
|
615 |
1761 |
} |
|
616 |
|||
617 |
1583969 |
inline bool Environment::has_run_bootstrapping_code() const { |
|
618 |
1583969 |
return principal_realm_->has_run_bootstrapping_code(); |
|
619 |
} |
||
620 |
|||
621 |
20 |
inline bool Environment::has_serialized_options() const { |
|
622 |
20 |
return has_serialized_options_; |
|
623 |
} |
||
624 |
|||
625 |
6951 |
inline void Environment::set_has_serialized_options(bool value) { |
|
626 |
6951 |
has_serialized_options_ = value; |
|
627 |
6951 |
} |
|
628 |
|||
629 |
9524 |
inline bool Environment::is_main_thread() const { |
|
630 |
9524 |
return worker_context() == nullptr; |
|
631 |
} |
||
632 |
|||
633 |
1159 |
inline bool Environment::no_native_addons() const { |
|
634 |
✓✓✓✓ |
2314 |
return (flags_ & EnvironmentFlags::kNoNativeAddons) || |
635 |
2314 |
!options_->allow_native_addons; |
|
636 |
} |
||
637 |
|||
638 |
6281 |
inline bool Environment::should_not_register_esm_loader() const { |
|
639 |
6281 |
return flags_ & EnvironmentFlags::kNoRegisterESMLoader; |
|
640 |
} |
||
641 |
|||
642 |
16433 |
inline bool Environment::owns_process_state() const { |
|
643 |
16433 |
return flags_ & EnvironmentFlags::kOwnsProcessState; |
|
644 |
} |
||
645 |
|||
646 |
6325 |
inline bool Environment::owns_inspector() const { |
|
647 |
6325 |
return flags_ & EnvironmentFlags::kOwnsInspector; |
|
648 |
} |
||
649 |
|||
650 |
17134 |
inline bool Environment::should_create_inspector() const { |
|
651 |
✓✓ | 34268 |
return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0 && |
652 |
✓✗✓✓ |
34246 |
!options_->test_runner && !options_->watch_mode; |
653 |
} |
||
654 |
|||
655 |
138039 |
inline bool Environment::tracks_unmanaged_fds() const { |
|
656 |
138039 |
return flags_ & EnvironmentFlags::kTrackUnmanagedFds; |
|
657 |
} |
||
658 |
|||
659 |
4008 |
inline bool Environment::hide_console_windows() const { |
|
660 |
4008 |
return flags_ & EnvironmentFlags::kHideConsoleWindows; |
|
661 |
} |
||
662 |
|||
663 |
7247 |
inline bool Environment::no_global_search_paths() const { |
|
664 |
✓✗✗✓ |
14494 |
return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) || |
665 |
14494 |
!options_->global_search_paths; |
|
666 |
} |
||
667 |
|||
668 |
1752 |
inline bool Environment::no_browser_globals() const { |
|
669 |
// configure --no-browser-globals |
||
670 |
#ifdef NODE_NO_BROWSER_GLOBALS |
||
671 |
return true; |
||
672 |
#else |
||
673 |
1752 |
return flags_ & EnvironmentFlags::kNoBrowserGlobals; |
|
674 |
#endif |
||
675 |
} |
||
676 |
|||
677 |
5 |
bool Environment::filehandle_close_warning() const { |
|
678 |
5 |
return emit_filehandle_warning_; |
|
679 |
} |
||
680 |
|||
681 |
4 |
void Environment::set_filehandle_close_warning(bool on) { |
|
682 |
4 |
emit_filehandle_warning_ = on; |
|
683 |
4 |
} |
|
684 |
|||
685 |
6115 |
void Environment::set_source_maps_enabled(bool on) { |
|
686 |
6115 |
source_maps_enabled_ = on; |
|
687 |
6115 |
} |
|
688 |
|||
689 |
2053 |
bool Environment::source_maps_enabled() const { |
|
690 |
2053 |
return source_maps_enabled_; |
|
691 |
} |
||
692 |
|||
693 |
7878 |
inline uint64_t Environment::thread_id() const { |
|
694 |
7878 |
return thread_id_; |
|
695 |
} |
||
696 |
|||
697 |
16531 |
inline worker::Worker* Environment::worker_context() const { |
|
698 |
16531 |
return isolate_data()->worker_context(); |
|
699 |
} |
||
700 |
|||
701 |
963 |
inline void Environment::add_sub_worker_context(worker::Worker* context) { |
|
702 |
963 |
sub_worker_contexts_.insert(context); |
|
703 |
963 |
} |
|
704 |
|||
705 |
991 |
inline void Environment::remove_sub_worker_context(worker::Worker* context) { |
|
706 |
991 |
sub_worker_contexts_.erase(context); |
|
707 |
991 |
} |
|
708 |
|||
709 |
template <typename Fn> |
||
710 |
29 |
inline void Environment::ForEachWorker(Fn&& iterator) { |
|
711 |
✓✓ | 29 |
for (worker::Worker* w : sub_worker_contexts_) iterator(w); |
712 |
29 |
} |
|
713 |
|||
714 |
5220549 |
inline bool Environment::is_stopping() const { |
|
715 |
5220549 |
return is_stopping_.load(); |
|
716 |
} |
||
717 |
|||
718 |
6026 |
inline void Environment::set_stopping(bool value) { |
|
719 |
6026 |
is_stopping_.store(value); |
|
720 |
6026 |
} |
|
721 |
|||
722 |
14 |
inline std::list<node_module>* Environment::extra_linked_bindings() { |
|
723 |
14 |
return &extra_linked_bindings_; |
|
724 |
} |
||
725 |
|||
726 |
10 |
inline node_module* Environment::extra_linked_bindings_head() { |
|
727 |
✓✓ | 19 |
return extra_linked_bindings_.size() > 0 ? |
728 |
19 |
&extra_linked_bindings_.front() : nullptr; |
|
729 |
} |
||
730 |
|||
731 |
9 |
inline node_module* Environment::extra_linked_bindings_tail() { |
|
732 |
✓✓ | 14 |
return extra_linked_bindings_.size() > 0 ? |
733 |
14 |
&extra_linked_bindings_.back() : nullptr; |
|
734 |
} |
||
735 |
|||
736 |
19 |
inline const Mutex& Environment::extra_linked_bindings_mutex() const { |
|
737 |
19 |
return extra_linked_bindings_mutex_; |
|
738 |
} |
||
739 |
|||
740 |
42972 |
inline performance::PerformanceState* Environment::performance_state() { |
|
741 |
42972 |
return performance_state_.get(); |
|
742 |
} |
||
743 |
|||
744 |
9291075 |
inline IsolateData* Environment::isolate_data() const { |
|
745 |
9291075 |
return isolate_data_; |
|
746 |
} |
||
747 |
|||
748 |
template <typename T> |
||
749 |
5266 |
inline void Environment::ForEachRealm(T&& iterator) const { |
|
750 |
// TODO(legendecas): iterate over more realms bound to the environment. |
||
751 |
5266 |
iterator(principal_realm()); |
|
752 |
5266 |
} |
|
753 |
|||
754 |
8 |
inline void Environment::ThrowError(const char* errmsg) { |
|
755 |
8 |
ThrowError(v8::Exception::Error, errmsg); |
|
756 |
8 |
} |
|
757 |
|||
758 |
inline void Environment::ThrowTypeError(const char* errmsg) { |
||
759 |
ThrowError(v8::Exception::TypeError, errmsg); |
||
760 |
} |
||
761 |
|||
762 |
inline void Environment::ThrowRangeError(const char* errmsg) { |
||
763 |
ThrowError(v8::Exception::RangeError, errmsg); |
||
764 |
} |
||
765 |
|||
766 |
8 |
inline void Environment::ThrowError( |
|
767 |
v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), |
||
768 |
const char* errmsg) { |
||
769 |
16 |
v8::HandleScope handle_scope(isolate()); |
|
770 |
8 |
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg))); |
|
771 |
8 |
} |
|
772 |
|||
773 |
11 |
inline void Environment::ThrowErrnoException(int errorno, |
|
774 |
const char* syscall, |
||
775 |
const char* message, |
||
776 |
const char* path) { |
||
777 |
11 |
isolate()->ThrowException( |
|
778 |
11 |
ErrnoException(isolate(), errorno, syscall, message, path)); |
|
779 |
11 |
} |
|
780 |
|||
781 |
15 |
inline void Environment::ThrowUVException(int errorno, |
|
782 |
const char* syscall, |
||
783 |
const char* message, |
||
784 |
const char* path, |
||
785 |
const char* dest) { |
||
786 |
15 |
isolate()->ThrowException( |
|
787 |
15 |
UVException(isolate(), errorno, syscall, message, path, dest)); |
|
788 |
15 |
} |
|
789 |
|||
790 |
54655 |
void Environment::AddCleanupHook(CleanupQueue::Callback fn, void* arg) { |
|
791 |
54655 |
cleanup_queue_.Add(fn, arg); |
|
792 |
54655 |
} |
|
793 |
|||
794 |
36186 |
void Environment::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) { |
|
795 |
36186 |
cleanup_queue_.Remove(fn, arg); |
|
796 |
36186 |
} |
|
797 |
|||
798 |
19 |
void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) { |
|
799 |
✗✓ | 19 |
CHECK(!main_utf16_); |
800 |
19 |
main_utf16_ = std::move(str); |
|
801 |
19 |
} |
|
802 |
|||
803 |
727 |
void Environment::set_process_exit_handler( |
|
804 |
std::function<void(Environment*, ExitCode)>&& handler) { |
||
805 |
727 |
process_exit_handler_ = std::move(handler); |
|
806 |
727 |
} |
|
807 |
|||
808 |
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
||
809 |
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
||
810 |
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
||
811 |
#define V(TypeName, PropertyName) \ |
||
812 |
inline \ |
||
813 |
v8::Local<TypeName> IsolateData::PropertyName() const { \ |
||
814 |
return PropertyName ## _ .Get(isolate_); \ |
||
815 |
} |
||
816 |
84402 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
|
817 |
1184156 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
|
818 |
12496910 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
|
819 |
#undef V |
||
820 |
#undef VS |
||
821 |
#undef VY |
||
822 |
#undef VP |
||
823 |
|||
824 |
#define V(PropertyName, TypeName) \ |
||
825 |
inline v8::Local<TypeName> IsolateData::PropertyName() const { \ |
||
826 |
return PropertyName##_.Get(isolate_); \ |
||
827 |
} \ |
||
828 |
inline void IsolateData::set_##PropertyName(v8::Local<TypeName> value) { \ |
||
829 |
PropertyName##_.Set(isolate_, value); \ |
||
830 |
} |
||
831 |
1070564 |
PER_ISOLATE_TEMPLATE_PROPERTIES(V) |
|
832 |
#undef V |
||
833 |
|||
834 |
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
||
835 |
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
||
836 |
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
||
837 |
#define V(TypeName, PropertyName) \ |
||
838 |
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
||
839 |
return isolate_data()->PropertyName(); \ |
||
840 |
} |
||
841 |
42201 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
|
842 |
591778 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
|
843 |
6241609 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
|
844 |
#undef V |
||
845 |
#undef VS |
||
846 |
#undef VY |
||
847 |
#undef VP |
||
848 |
|||
849 |
#define V(PropertyName, TypeName) \ |
||
850 |
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
||
851 |
return isolate_data()->PropertyName(); \ |
||
852 |
} \ |
||
853 |
inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \ |
||
854 |
DCHECK(isolate_data()->PropertyName().IsEmpty()); \ |
||
855 |
isolate_data()->set_##PropertyName(value); \ |
||
856 |
} |
||
857 |
441810 |
PER_ISOLATE_TEMPLATE_PROPERTIES(V) |
|
858 |
#undef V |
||
859 |
|||
860 |
#define V(PropertyName, TypeName) \ |
||
861 |
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
||
862 |
DCHECK_NOT_NULL(principal_realm_); \ |
||
863 |
return principal_realm_->PropertyName(); \ |
||
864 |
} \ |
||
865 |
inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \ |
||
866 |
DCHECK_NOT_NULL(principal_realm_); \ |
||
867 |
principal_realm_->set_##PropertyName(value); \ |
||
868 |
} |
||
869 |
5214481 |
PER_REALM_STRONG_PERSISTENT_VALUES(V) |
|
870 |
#undef V |
||
871 |
|||
872 |
9344149 |
v8::Local<v8::Context> Environment::context() const { |
|
873 |
9344149 |
return principal_realm()->context(); |
|
874 |
} |
||
875 |
|||
876 |
10818570 |
Realm* Environment::principal_realm() const { |
|
877 |
10818570 |
return principal_realm_.get(); |
|
878 |
} |
||
879 |
|||
880 |
1 |
inline void Environment::set_heap_snapshot_near_heap_limit(uint32_t limit) { |
|
881 |
1 |
heap_snapshot_near_heap_limit_ = limit; |
|
882 |
1 |
} |
|
883 |
|||
884 |
inline bool Environment::is_in_heapsnapshot_heap_limit_callback() const { |
||
885 |
return is_in_heapsnapshot_heap_limit_callback_; |
||
886 |
} |
||
887 |
|||
888 |
2 |
inline void Environment::AddHeapSnapshotNearHeapLimitCallback() { |
|
889 |
DCHECK(!heapsnapshot_near_heap_limit_callback_added_); |
||
890 |
2 |
heapsnapshot_near_heap_limit_callback_added_ = true; |
|
891 |
2 |
isolate_->AddNearHeapLimitCallback(Environment::NearHeapLimitCallback, this); |
|
892 |
2 |
} |
|
893 |
|||
894 |
2 |
inline void Environment::RemoveHeapSnapshotNearHeapLimitCallback( |
|
895 |
size_t heap_limit) { |
||
896 |
DCHECK(heapsnapshot_near_heap_limit_callback_added_); |
||
897 |
2 |
heapsnapshot_near_heap_limit_callback_added_ = false; |
|
898 |
2 |
isolate_->RemoveNearHeapLimitCallback(Environment::NearHeapLimitCallback, |
|
899 |
heap_limit); |
||
900 |
2 |
} |
|
901 |
|||
902 |
} // namespace node |
||
903 |
|||
904 |
// These two files depend on each other. Including base_object-inl.h after this |
||
905 |
// file is the easiest way to avoid issues with that circular dependency. |
||
906 |
#include "base_object-inl.h" |
||
907 |
|||
908 |
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
||
909 |
|||
910 |
#endif // SRC_ENV_INL_H_ |
Generated by: GCOVR (Version 4.2) |