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 "env.h" |
||
29 |
#include "node.h" |
||
30 |
#include "util-inl.h" |
||
31 |
#include "uv.h" |
||
32 |
#include "v8.h" |
||
33 |
#include "node_perf_common.h" |
||
34 |
#include "node_context_data.h" |
||
35 |
|||
36 |
#include <cstddef> |
||
37 |
#include <cstdint> |
||
38 |
|||
39 |
#include <utility> |
||
40 |
|||
41 |
namespace node { |
||
42 |
|||
43 |
10914 |
inline v8::Isolate* IsolateData::isolate() const { |
|
44 |
10914 |
return isolate_; |
|
45 |
} |
||
46 |
|||
47 |
1581793 |
inline uv_loop_t* IsolateData::event_loop() const { |
|
48 |
1581793 |
return event_loop_; |
|
49 |
} |
||
50 |
|||
51 |
326390 |
inline bool IsolateData::uses_node_allocator() const { |
|
52 |
326390 |
return uses_node_allocator_; |
|
53 |
} |
||
54 |
|||
55 |
663115 |
inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const { |
|
56 |
663115 |
return allocator_; |
|
57 |
} |
||
58 |
|||
59 |
331987 |
inline NodeArrayBufferAllocator* IsolateData::node_allocator() const { |
|
60 |
331987 |
return node_allocator_; |
|
61 |
} |
||
62 |
|||
63 |
232227 |
inline MultiIsolatePlatform* IsolateData::platform() const { |
|
64 |
232227 |
return platform_; |
|
65 |
} |
||
66 |
|||
67 |
5107 |
inline AsyncHooks::AsyncHooks() |
|
68 |
: async_ids_stack_(env()->isolate(), 16 * 2), |
||
69 |
fields_(env()->isolate(), kFieldsCount), |
||
70 |
5107 |
async_id_fields_(env()->isolate(), kUidFieldsCount) { |
|
71 |
5107 |
v8::HandleScope handle_scope(env()->isolate()); |
|
72 |
|||
73 |
// Always perform async_hooks checks, not just when async_hooks is enabled. |
||
74 |
// TODO(AndreasMadsen): Consider removing this for LTS releases. |
||
75 |
// See discussion in https://github.com/nodejs/node/pull/15454 |
||
76 |
// When removing this, do it by reverting the commit. Otherwise the test |
||
77 |
// and flag changes won't be included. |
||
78 |
5107 |
fields_[kCheck] = 1; |
|
79 |
|||
80 |
// kDefaultTriggerAsyncId should be -1, this indicates that there is no |
||
81 |
// specified default value and it should fallback to the executionAsyncId. |
||
82 |
// 0 is not used as the magic value, because that indicates a missing context |
||
83 |
// which is different from a default context. |
||
84 |
5107 |
async_id_fields_[AsyncHooks::kDefaultTriggerAsyncId] = -1; |
|
85 |
|||
86 |
// kAsyncIdCounter should start at 1 because that'll be the id the execution |
||
87 |
// context during bootstrap (code that runs before entering uv_run()). |
||
88 |
5107 |
async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1; |
|
89 |
|||
90 |
// Create all the provider strings that will be passed to JS. Place them in |
||
91 |
// an array so the array index matches the PROVIDER id offset. This way the |
||
92 |
// strings can be retrieved quickly. |
||
93 |
#define V(Provider) \ |
||
94 |
providers_[AsyncWrap::PROVIDER_ ## Provider].Set( \ |
||
95 |
env()->isolate(), \ |
||
96 |
v8::String::NewFromOneByte( \ |
||
97 |
env()->isolate(), \ |
||
98 |
reinterpret_cast<const uint8_t*>(#Provider), \ |
||
99 |
v8::NewStringType::kInternalized, \ |
||
100 |
sizeof(#Provider) - 1).ToLocalChecked()); |
||
101 |
454523 |
NODE_ASYNC_PROVIDER_TYPES(V) |
|
102 |
#undef V |
||
103 |
5107 |
} |
|
104 |
4940241 |
inline AliasedUint32Array& AsyncHooks::fields() { |
|
105 |
4940241 |
return fields_; |
|
106 |
} |
||
107 |
|||
108 |
4579655 |
inline AliasedFloat64Array& AsyncHooks::async_id_fields() { |
|
109 |
4579655 |
return async_id_fields_; |
|
110 |
} |
||
111 |
|||
112 |
5103 |
inline AliasedFloat64Array& AsyncHooks::async_ids_stack() { |
|
113 |
5103 |
return async_ids_stack_; |
|
114 |
} |
||
115 |
|||
116 |
318950 |
inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) { |
|
117 |
637901 |
return providers_[idx].Get(env()->isolate()); |
|
118 |
} |
||
119 |
|||
120 |
1 |
inline void AsyncHooks::no_force_checks() { |
|
121 |
1 |
fields_[kCheck] -= 1; |
|
122 |
1 |
} |
|
123 |
|||
124 |
788822 |
inline Environment* AsyncHooks::env() { |
|
125 |
788822 |
return Environment::ForAsyncHooks(this); |
|
126 |
} |
||
127 |
|||
128 |
// Remember to keep this code aligned with pushAsyncIds() in JS. |
||
129 |
1192490 |
inline void AsyncHooks::push_async_ids(double async_id, |
|
130 |
double trigger_async_id) { |
||
131 |
// Since async_hooks is experimental, do only perform the check |
||
132 |
// when async_hooks is enabled. |
||
133 |
✓✗ | 1192490 |
if (fields_[kCheck] > 0) { |
134 |
✗✓ | 1192482 |
CHECK_GE(async_id, -1); |
135 |
✗✓ | 1192482 |
CHECK_GE(trigger_async_id, -1); |
136 |
} |
||
137 |
|||
138 |
1192480 |
uint32_t offset = fields_[kStackLength]; |
|
139 |
✓✓ | 1192465 |
if (offset * 2 >= async_ids_stack_.Length()) |
140 |
8 |
grow_async_ids_stack(); |
|
141 |
1192457 |
async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId]; |
|
142 |
1192482 |
async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId]; |
|
143 |
1192474 |
fields_[kStackLength] += 1; |
|
144 |
1192483 |
async_id_fields_[kExecutionAsyncId] = async_id; |
|
145 |
1192471 |
async_id_fields_[kTriggerAsyncId] = trigger_async_id; |
|
146 |
1192462 |
} |
|
147 |
|||
148 |
// Remember to keep this code aligned with popAsyncIds() in JS. |
||
149 |
1192150 |
inline bool AsyncHooks::pop_async_id(double async_id) { |
|
150 |
// In case of an exception then this may have already been reset, if the |
||
151 |
// stack was multiple MakeCallback()'s deep. |
||
152 |
✓✓ | 1192150 |
if (fields_[kStackLength] == 0) return false; |
153 |
|||
154 |
// Ask for the async_id to be restored as a check that the stack |
||
155 |
// hasn't been corrupted. |
||
156 |
// Since async_hooks is experimental, do only perform the check |
||
157 |
// when async_hooks is enabled. |
||
158 |
✓✓✓✓ ✓✓✓✗ ✓✓ |
1191532 |
if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) { |
159 |
fprintf(stderr, |
||
160 |
"Error: async hook stack has become corrupted (" |
||
161 |
"actual: %.f, expected: %.f)\n", |
||
162 |
async_id_fields_.GetValue(kExecutionAsyncId), |
||
163 |
4 |
async_id); |
|
164 |
4 |
DumpBacktrace(stderr); |
|
165 |
4 |
fflush(stderr); |
|
166 |
✓✗ | 4 |
if (!env()->abort_on_uncaught_exception()) |
167 |
4 |
exit(1); |
|
168 |
fprintf(stderr, "\n"); |
||
169 |
fflush(stderr); |
||
170 |
ABORT_NO_BACKTRACE(); |
||
171 |
} |
||
172 |
|||
173 |
1191526 |
uint32_t offset = fields_[kStackLength] - 1; |
|
174 |
1191530 |
async_id_fields_[kExecutionAsyncId] = async_ids_stack_[2 * offset]; |
|
175 |
1191523 |
async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1]; |
|
176 |
1191528 |
fields_[kStackLength] = offset; |
|
177 |
|||
178 |
1191522 |
return fields_[kStackLength] > 0; |
|
179 |
} |
||
180 |
|||
181 |
// Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js. |
||
182 |
32 |
inline void AsyncHooks::clear_async_id_stack() { |
|
183 |
32 |
async_id_fields_[kExecutionAsyncId] = 0; |
|
184 |
32 |
async_id_fields_[kTriggerAsyncId] = 0; |
|
185 |
32 |
fields_[kStackLength] = 0; |
|
186 |
32 |
} |
|
187 |
|||
188 |
// The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in |
||
189 |
// async_wrap-inl.h to avoid a circular dependency. |
||
190 |
|||
191 |
1122318 |
inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope( |
|
192 |
Environment* env, double default_trigger_async_id) |
||
193 |
1122318 |
: async_hooks_(env->async_hooks()) { |
|
194 |
✓✗ | 1122318 |
if (env->async_hooks()->fields()[AsyncHooks::kCheck] > 0) { |
195 |
✗✓ | 1122319 |
CHECK_GE(default_trigger_async_id, 0); |
196 |
} |
||
197 |
|||
198 |
2244638 |
old_default_trigger_async_id_ = |
|
199 |
2244638 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; |
|
200 |
2244638 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = |
|
201 |
1122319 |
default_trigger_async_id; |
|
202 |
1122319 |
} |
|
203 |
|||
204 |
1122318 |
inline AsyncHooks::DefaultTriggerAsyncIdScope ::~DefaultTriggerAsyncIdScope() { |
|
205 |
2244636 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = |
|
206 |
1122318 |
old_default_trigger_async_id_; |
|
207 |
1122318 |
} |
|
208 |
|||
209 |
|||
210 |
788822 |
Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) { |
|
211 |
788822 |
return ContainerOf(&Environment::async_hooks_, hooks); |
|
212 |
} |
||
213 |
|||
214 |
1446598 |
inline AsyncCallbackScope::AsyncCallbackScope(Environment* env) : env_(env) { |
|
215 |
1446598 |
env_->PushAsyncCallbackScope(); |
|
216 |
1446676 |
} |
|
217 |
|||
218 |
1446271 |
inline AsyncCallbackScope::~AsyncCallbackScope() { |
|
219 |
1446271 |
env_->PopAsyncCallbackScope(); |
|
220 |
1446272 |
} |
|
221 |
|||
222 |
1187312 |
inline size_t Environment::async_callback_scope_depth() const { |
|
223 |
1187312 |
return async_callback_scope_depth_; |
|
224 |
} |
||
225 |
|||
226 |
1446604 |
inline void Environment::PushAsyncCallbackScope() { |
|
227 |
1446604 |
async_callback_scope_depth_++; |
|
228 |
1446604 |
} |
|
229 |
|||
230 |
1446271 |
inline void Environment::PopAsyncCallbackScope() { |
|
231 |
1446271 |
async_callback_scope_depth_--; |
|
232 |
1446271 |
} |
|
233 |
|||
234 |
5107 |
inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate) |
|
235 |
5107 |
: fields_(isolate, kFieldsCount) {} |
|
236 |
|||
237 |
5103 |
inline AliasedUint32Array& ImmediateInfo::fields() { |
|
238 |
5103 |
return fields_; |
|
239 |
} |
||
240 |
|||
241 |
446309 |
inline uint32_t ImmediateInfo::count() const { |
|
242 |
446309 |
return fields_[kCount]; |
|
243 |
} |
||
244 |
|||
245 |
88717 |
inline uint32_t ImmediateInfo::ref_count() const { |
|
246 |
88717 |
return fields_[kRefCount]; |
|
247 |
} |
||
248 |
|||
249 |
56523 |
inline bool ImmediateInfo::has_outstanding() const { |
|
250 |
56523 |
return fields_[kHasOutstanding] == 1; |
|
251 |
} |
||
252 |
|||
253 |
54962 |
inline void ImmediateInfo::count_inc(uint32_t increment) { |
|
254 |
54962 |
fields_[kCount] += increment; |
|
255 |
54962 |
} |
|
256 |
|||
257 |
56010 |
inline void ImmediateInfo::count_dec(uint32_t decrement) { |
|
258 |
56010 |
fields_[kCount] -= decrement; |
|
259 |
56010 |
} |
|
260 |
|||
261 |
32715 |
inline void ImmediateInfo::ref_count_inc(uint32_t increment) { |
|
262 |
32715 |
fields_[kRefCount] += increment; |
|
263 |
32715 |
} |
|
264 |
|||
265 |
56010 |
inline void ImmediateInfo::ref_count_dec(uint32_t decrement) { |
|
266 |
56010 |
fields_[kRefCount] -= decrement; |
|
267 |
56010 |
} |
|
268 |
|||
269 |
5107 |
inline TickInfo::TickInfo(v8::Isolate* isolate) |
|
270 |
5107 |
: fields_(isolate, kFieldsCount) {} |
|
271 |
|||
272 |
5103 |
inline AliasedUint8Array& TickInfo::fields() { |
|
273 |
5103 |
return fields_; |
|
274 |
} |
||
275 |
|||
276 |
1794593 |
inline bool TickInfo::has_tick_scheduled() const { |
|
277 |
1794593 |
return fields_[kHasTickScheduled] == 1; |
|
278 |
} |
||
279 |
|||
280 |
301154 |
inline bool TickInfo::has_rejection_to_warn() const { |
|
281 |
301154 |
return fields_[kHasRejectionToWarn] == 1; |
|
282 |
} |
||
283 |
|||
284 |
5565 |
inline void Environment::AssignToContext(v8::Local<v8::Context> context, |
|
285 |
const ContextInfo& info) { |
||
286 |
context->SetAlignedPointerInEmbedderData( |
||
287 |
5565 |
ContextEmbedderIndex::kEnvironment, this); |
|
288 |
// Used by Environment::GetCurrent to know that we are on a node context. |
||
289 |
context->SetAlignedPointerInEmbedderData( |
||
290 |
11132 |
ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr); |
|
291 |
#if HAVE_INSPECTOR |
||
292 |
5566 |
inspector_agent()->ContextCreated(context, info); |
|
293 |
#endif // HAVE_INSPECTOR |
||
294 |
5566 |
} |
|
295 |
|||
296 |
1217124 |
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) { |
|
297 |
✓✓ | 1217124 |
if (UNLIKELY(!isolate->InContext())) return nullptr; |
298 |
1217159 |
v8::HandleScope handle_scope(isolate); |
|
299 |
1217178 |
return GetCurrent(isolate->GetCurrentContext()); |
|
300 |
} |
||
301 |
|||
302 |
1535012 |
inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) { |
|
303 |
✗✓ | 1535012 |
if (UNLIKELY(context.IsEmpty())) { |
304 |
return nullptr; |
||
305 |
} |
||
306 |
✓✓ | 1535012 |
if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <= |
307 |
ContextEmbedderIndex::kContextTag)) { |
||
308 |
1 |
return nullptr; |
|
309 |
} |
||
310 |
✗✓ | 3070054 |
if (UNLIKELY(context->GetAlignedPointerFromEmbedderData( |
311 |
ContextEmbedderIndex::kContextTag) != |
||
312 |
Environment::kNodeContextTagPtr)) { |
||
313 |
return nullptr; |
||
314 |
} |
||
315 |
return static_cast<Environment*>( |
||
316 |
context->GetAlignedPointerFromEmbedderData( |
||
317 |
3070054 |
ContextEmbedderIndex::kEnvironment)); |
|
318 |
} |
||
319 |
|||
320 |
9419509 |
inline Environment* Environment::GetCurrent( |
|
321 |
const v8::FunctionCallbackInfo<v8::Value>& info) { |
||
322 |
9419509 |
return GetFromCallbackData(info.Data()); |
|
323 |
} |
||
324 |
|||
325 |
template <typename T> |
||
326 |
2433228 |
inline Environment* Environment::GetCurrent( |
|
327 |
const v8::PropertyCallbackInfo<T>& info) { |
||
328 |
2433228 |
return GetFromCallbackData(info.Data()); |
|
329 |
} |
||
330 |
|||
331 |
11852737 |
inline Environment* Environment::GetFromCallbackData(v8::Local<v8::Value> val) { |
|
332 |
DCHECK(val->IsObject()); |
||
333 |
11852737 |
v8::Local<v8::Object> obj = val.As<v8::Object>(); |
|
334 |
DCHECK_GE(obj->InternalFieldCount(), 1); |
||
335 |
Environment* env = |
||
336 |
23705474 |
static_cast<Environment*>(obj->GetAlignedPointerFromInternalField(0)); |
|
337 |
DCHECK(env->as_callback_data_template()->HasInstance(obj)); |
||
338 |
11852737 |
return env; |
|
339 |
} |
||
340 |
|||
341 |
7 |
inline Environment* Environment::GetThreadLocalEnv() { |
|
342 |
7 |
return static_cast<Environment*>(uv_key_get(&thread_local_env)); |
|
343 |
} |
||
344 |
|||
345 |
217 |
inline bool Environment::profiler_idle_notifier_started() const { |
|
346 |
217 |
return profiler_idle_notifier_started_; |
|
347 |
} |
||
348 |
|||
349 |
68921080 |
inline v8::Isolate* Environment::isolate() const { |
|
350 |
68921080 |
return isolate_; |
|
351 |
} |
||
352 |
|||
353 |
5330 |
inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { |
|
354 |
5330 |
return ContainerOf(&Environment::timer_handle_, handle); |
|
355 |
} |
||
356 |
|||
357 |
23049 |
inline uv_timer_t* Environment::timer_handle() { |
|
358 |
23049 |
return &timer_handle_; |
|
359 |
} |
||
360 |
|||
361 |
446308 |
inline Environment* Environment::from_immediate_check_handle( |
|
362 |
uv_check_t* handle) { |
||
363 |
446308 |
return ContainerOf(&Environment::immediate_check_handle_, handle); |
|
364 |
} |
||
365 |
|||
366 |
20426 |
inline uv_check_t* Environment::immediate_check_handle() { |
|
367 |
20426 |
return &immediate_check_handle_; |
|
368 |
} |
||
369 |
|||
370 |
91229 |
inline uv_idle_t* Environment::immediate_idle_handle() { |
|
371 |
91229 |
return &immediate_idle_handle_; |
|
372 |
} |
||
373 |
|||
374 |
25535 |
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, |
|
375 |
HandleCleanupCb cb, |
||
376 |
void* arg) { |
||
377 |
25535 |
handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg}); |
|
378 |
25535 |
} |
|
379 |
|||
380 |
template <typename T, typename OnCloseCallback> |
||
381 |
28573 |
inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) { |
|
382 |
28573 |
handle_cleanup_waiting_++; |
|
383 |
static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle"); |
||
384 |
static_assert(offsetof(T, data) == offsetof(uv_handle_t, data), |
||
385 |
"T is a libuv handle"); |
||
386 |
static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb), |
||
387 |
"T is a libuv handle"); |
||
388 |
struct CloseData { |
||
389 |
Environment* env; |
||
390 |
OnCloseCallback callback; |
||
391 |
void* original_data; |
||
392 |
}; |
||
393 |
28573 |
handle->data = new CloseData { this, callback, handle->data }; |
|
394 |
114242 |
uv_close(reinterpret_cast<uv_handle_t*>(handle), [](uv_handle_t* handle) { |
|
395 |
28548 |
std::unique_ptr<CloseData> data { static_cast<CloseData*>(handle->data) }; |
|
396 |
28548 |
data->env->handle_cleanup_waiting_--; |
|
397 |
28548 |
handle->data = data->original_data; |
|
398 |
28548 |
data->callback(reinterpret_cast<T*>(handle)); |
|
399 |
85694 |
}); |
|
400 |
28573 |
} |
|
401 |
|||
402 |
120813 |
void Environment::IncreaseWaitingRequestCounter() { |
|
403 |
120813 |
request_waiting_++; |
|
404 |
120813 |
} |
|
405 |
|||
406 |
120747 |
void Environment::DecreaseWaitingRequestCounter() { |
|
407 |
120747 |
request_waiting_--; |
|
408 |
✗✓ | 120747 |
CHECK_GE(request_waiting_, 0); |
409 |
120747 |
} |
|
410 |
|||
411 |
1576685 |
inline uv_loop_t* Environment::event_loop() const { |
|
412 |
1576685 |
return isolate_data()->event_loop(); |
|
413 |
} |
||
414 |
|||
415 |
151 |
inline void Environment::TryLoadAddon( |
|
416 |
const char* filename, |
||
417 |
int flags, |
||
418 |
const std::function<bool(binding::DLib*)>& was_loaded) { |
||
419 |
151 |
loaded_addons_.emplace_back(filename, flags); |
|
420 |
✓✓ | 151 |
if (!was_loaded(&loaded_addons_.back())) { |
421 |
7 |
loaded_addons_.pop_back(); |
|
422 |
} |
||
423 |
151 |
} |
|
424 |
|||
425 |
#if HAVE_INSPECTOR |
||
426 |
227574 |
inline bool Environment::is_in_inspector_console_call() const { |
|
427 |
227574 |
return is_in_inspector_console_call_; |
|
428 |
} |
||
429 |
|||
430 |
455146 |
inline void Environment::set_is_in_inspector_console_call(bool value) { |
|
431 |
455146 |
is_in_inspector_console_call_ = value; |
|
432 |
455146 |
} |
|
433 |
#endif |
||
434 |
|||
435 |
9983338 |
inline AsyncHooks* Environment::async_hooks() { |
|
436 |
9983338 |
return &async_hooks_; |
|
437 |
} |
||
438 |
|||
439 |
796348 |
inline ImmediateInfo* Environment::immediate_info() { |
|
440 |
796348 |
return &immediate_info_; |
|
441 |
} |
||
442 |
|||
443 |
902408 |
inline TickInfo* Environment::tick_info() { |
|
444 |
902408 |
return &tick_info_; |
|
445 |
} |
||
446 |
|||
447 |
508250 |
inline uint64_t Environment::timer_base() const { |
|
448 |
508250 |
return timer_base_; |
|
449 |
} |
||
450 |
|||
451 |
2447827 |
inline std::shared_ptr<KVStore> Environment::env_vars() { |
|
452 |
2447827 |
return env_vars_; |
|
453 |
} |
||
454 |
|||
455 |
5315 |
inline void Environment::set_env_vars(std::shared_ptr<KVStore> env_vars) { |
|
456 |
5315 |
env_vars_ = env_vars; |
|
457 |
5316 |
} |
|
458 |
|||
459 |
11 |
inline bool Environment::printed_error() const { |
|
460 |
11 |
return printed_error_; |
|
461 |
} |
||
462 |
|||
463 |
11 |
inline void Environment::set_printed_error(bool value) { |
|
464 |
11 |
printed_error_ = value; |
|
465 |
11 |
} |
|
466 |
|||
467 |
9136 |
inline void Environment::set_trace_sync_io(bool value) { |
|
468 |
9136 |
trace_sync_io_ = value; |
|
469 |
9136 |
} |
|
470 |
|||
471 |
30 |
inline bool Environment::abort_on_uncaught_exception() const { |
|
472 |
30 |
return options_->abort_on_uncaught_exception; |
|
473 |
} |
||
474 |
|||
475 |
208 |
inline void Environment::set_abort_on_uncaught_exception(bool value) { |
|
476 |
208 |
options_->abort_on_uncaught_exception = value; |
|
477 |
209 |
} |
|
478 |
|||
479 |
5134 |
inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() { |
|
480 |
5134 |
return should_abort_on_uncaught_toggle_; |
|
481 |
} |
||
482 |
|||
483 |
2508793 |
inline AliasedInt32Array& Environment::stream_base_state() { |
|
484 |
2508793 |
return stream_base_state_; |
|
485 |
} |
||
486 |
|||
487 |
429 |
inline uint32_t Environment::get_next_module_id() { |
|
488 |
429 |
return module_id_counter_++; |
|
489 |
} |
||
490 |
1961 |
inline uint32_t Environment::get_next_script_id() { |
|
491 |
1961 |
return script_id_counter_++; |
|
492 |
} |
||
493 |
39903 |
inline uint32_t Environment::get_next_function_id() { |
|
494 |
39903 |
return function_id_counter_++; |
|
495 |
} |
||
496 |
|||
497 |
2536 |
ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( |
|
498 |
Environment* env) |
||
499 |
2536 |
: env_(env) { |
|
500 |
2536 |
env_->PushShouldNotAbortOnUncaughtScope(); |
|
501 |
2536 |
} |
|
502 |
|||
503 |
2535 |
ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { |
|
504 |
2535 |
Close(); |
|
505 |
2535 |
} |
|
506 |
|||
507 |
2736 |
void ShouldNotAbortOnUncaughtScope::Close() { |
|
508 |
✓✓ | 2736 |
if (env_ != nullptr) { |
509 |
2535 |
env_->PopShouldNotAbortOnUncaughtScope(); |
|
510 |
2535 |
env_ = nullptr; |
|
511 |
} |
||
512 |
2736 |
} |
|
513 |
|||
514 |
2536 |
inline void Environment::PushShouldNotAbortOnUncaughtScope() { |
|
515 |
2536 |
should_not_abort_scope_counter_++; |
|
516 |
2536 |
} |
|
517 |
|||
518 |
2535 |
inline void Environment::PopShouldNotAbortOnUncaughtScope() { |
|
519 |
2535 |
should_not_abort_scope_counter_--; |
|
520 |
2535 |
} |
|
521 |
|||
522 |
1 |
inline bool Environment::inside_should_not_abort_on_uncaught_scope() const { |
|
523 |
1 |
return should_not_abort_scope_counter_ > 0; |
|
524 |
} |
||
525 |
|||
526 |
191376 |
inline std::vector<double>* Environment::destroy_async_id_list() { |
|
527 |
191376 |
return &destroy_async_id_list_; |
|
528 |
} |
||
529 |
|||
530 |
319513 |
inline double Environment::new_async_id() { |
|
531 |
319513 |
async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1; |
|
532 |
319514 |
return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter]; |
|
533 |
} |
||
534 |
|||
535 |
211592 |
inline double Environment::execution_async_id() { |
|
536 |
211592 |
return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId]; |
|
537 |
} |
||
538 |
|||
539 |
37467 |
inline double Environment::trigger_async_id() { |
|
540 |
37467 |
return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId]; |
|
541 |
} |
||
542 |
|||
543 |
319511 |
inline double Environment::get_default_trigger_async_id() { |
|
544 |
double default_trigger_async_id = |
||
545 |
319511 |
async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; |
|
546 |
// If defaultTriggerAsyncId isn't set, use the executionAsyncId |
||
547 |
✓✓ | 319510 |
if (default_trigger_async_id < 0) |
548 |
173625 |
default_trigger_async_id = execution_async_id(); |
|
549 |
319511 |
return default_trigger_async_id; |
|
550 |
} |
||
551 |
|||
552 |
68 |
inline double* Environment::heap_statistics_buffer() const { |
|
553 |
✗✓ | 68 |
CHECK_NOT_NULL(heap_statistics_buffer_); |
554 |
68 |
return heap_statistics_buffer_; |
|
555 |
} |
||
556 |
|||
557 |
66 |
inline void Environment::set_heap_statistics_buffer(double* pointer) { |
|
558 |
✗✓ | 66 |
CHECK_NULL(heap_statistics_buffer_); // Should be set only once. |
559 |
66 |
heap_statistics_buffer_ = pointer; |
|
560 |
66 |
} |
|
561 |
|||
562 |
67 |
inline double* Environment::heap_space_statistics_buffer() const { |
|
563 |
✗✓ | 67 |
CHECK_NOT_NULL(heap_space_statistics_buffer_); |
564 |
67 |
return heap_space_statistics_buffer_; |
|
565 |
} |
||
566 |
|||
567 |
66 |
inline void Environment::set_heap_space_statistics_buffer(double* pointer) { |
|
568 |
✗✓ | 66 |
CHECK_NULL(heap_space_statistics_buffer_); // Should be set only once. |
569 |
66 |
heap_space_statistics_buffer_ = pointer; |
|
570 |
66 |
} |
|
571 |
|||
572 |
67 |
inline double* Environment::heap_code_statistics_buffer() const { |
|
573 |
✗✓ | 67 |
CHECK_NOT_NULL(heap_code_statistics_buffer_); |
574 |
67 |
return heap_code_statistics_buffer_; |
|
575 |
} |
||
576 |
|||
577 |
66 |
inline void Environment::set_heap_code_statistics_buffer(double* pointer) { |
|
578 |
✗✓ | 66 |
CHECK_NULL(heap_code_statistics_buffer_); // Should be set only once. |
579 |
66 |
heap_code_statistics_buffer_ = pointer; |
|
580 |
66 |
} |
|
581 |
|||
582 |
406135 |
inline char* Environment::http_parser_buffer() const { |
|
583 |
406135 |
return http_parser_buffer_; |
|
584 |
} |
||
585 |
|||
586 |
294 |
inline void Environment::set_http_parser_buffer(char* buffer) { |
|
587 |
✗✓ | 294 |
CHECK_NULL(http_parser_buffer_); // Should be set only once. |
588 |
294 |
http_parser_buffer_ = buffer; |
|
589 |
294 |
} |
|
590 |
|||
591 |
135374 |
inline bool Environment::http_parser_buffer_in_use() const { |
|
592 |
135374 |
return http_parser_buffer_in_use_; |
|
593 |
} |
||
594 |
|||
595 |
270744 |
inline void Environment::set_http_parser_buffer_in_use(bool in_use) { |
|
596 |
270744 |
http_parser_buffer_in_use_ = in_use; |
|
597 |
270744 |
} |
|
598 |
|||
599 |
1711 |
inline http2::Http2State* Environment::http2_state() const { |
|
600 |
1711 |
return http2_state_.get(); |
|
601 |
} |
||
602 |
|||
603 |
232 |
inline void Environment::set_http2_state( |
|
604 |
std::unique_ptr<http2::Http2State> buffer) { |
||
605 |
✗✓ | 232 |
CHECK(!http2_state_); // Should be set only once. |
606 |
232 |
http2_state_ = std::move(buffer); |
|
607 |
232 |
} |
|
608 |
|||
609 |
1229902 |
bool Environment::debug_enabled(DebugCategory category) const { |
|
610 |
DCHECK_GE(static_cast<int>(category), 0); |
||
611 |
DCHECK_LT(static_cast<int>(category), |
||
612 |
static_cast<int>(DebugCategory::CATEGORY_COUNT)); |
||
613 |
1229902 |
return debug_enabled_[static_cast<int>(category)]; |
|
614 |
} |
||
615 |
|||
616 |
22 |
void Environment::set_debug_enabled(DebugCategory category, bool enabled) { |
|
617 |
DCHECK_GE(static_cast<int>(category), 0); |
||
618 |
DCHECK_LT(static_cast<int>(category), |
||
619 |
static_cast<int>(DebugCategory::CATEGORY_COUNT)); |
||
620 |
22 |
debug_enabled_[static_cast<int>(category)] = enabled; |
|
621 |
22 |
} |
|
622 |
|||
623 |
207247 |
inline AliasedFloat64Array* Environment::fs_stats_field_array() { |
|
624 |
207247 |
return &fs_stats_field_array_; |
|
625 |
} |
||
626 |
|||
627 |
5113 |
inline AliasedBigUint64Array* Environment::fs_stats_field_bigint_array() { |
|
628 |
5113 |
return &fs_stats_field_bigint_array_; |
|
629 |
} |
||
630 |
|||
631 |
inline std::vector<std::unique_ptr<fs::FileHandleReadWrap>>& |
||
632 |
442 |
Environment::file_handle_read_wrap_freelist() { |
|
633 |
442 |
return file_handle_read_wrap_freelist_; |
|
634 |
} |
||
635 |
|||
636 |
53150 |
inline std::shared_ptr<EnvironmentOptions> Environment::options() { |
|
637 |
53150 |
return options_; |
|
638 |
} |
||
639 |
|||
640 |
14755 |
inline const std::vector<std::string>& Environment::argv() { |
|
641 |
14755 |
return argv_; |
|
642 |
} |
||
643 |
|||
644 |
5311 |
inline const std::vector<std::string>& Environment::exec_argv() { |
|
645 |
5311 |
return exec_argv_; |
|
646 |
} |
||
647 |
|||
648 |
10206 |
inline const std::string& Environment::exec_path() const { |
|
649 |
10206 |
return exec_path_; |
|
650 |
} |
||
651 |
|||
652 |
#if HAVE_INSPECTOR |
||
653 |
5097 |
inline void Environment::set_coverage_directory(const char* dir) { |
|
654 |
5097 |
coverage_directory_ = std::string(dir); |
|
655 |
5097 |
} |
|
656 |
|||
657 |
5096 |
inline void Environment::set_coverage_connection( |
|
658 |
std::unique_ptr<profiler::V8CoverageConnection> connection) { |
||
659 |
✗✓ | 5096 |
CHECK_NULL(coverage_connection_); |
660 |
5096 |
std::swap(coverage_connection_, connection); |
|
661 |
5096 |
} |
|
662 |
|||
663 |
15373 |
inline profiler::V8CoverageConnection* Environment::coverage_connection() { |
|
664 |
15373 |
return coverage_connection_.get(); |
|
665 |
} |
||
666 |
|||
667 |
5058 |
inline const std::string& Environment::coverage_directory() const { |
|
668 |
5058 |
return coverage_directory_; |
|
669 |
} |
||
670 |
|||
671 |
10 |
inline void Environment::set_cpu_profiler_connection( |
|
672 |
std::unique_ptr<profiler::V8CpuProfilerConnection> connection) { |
||
673 |
✗✓ | 10 |
CHECK_NULL(cpu_profiler_connection_); |
674 |
10 |
std::swap(cpu_profiler_connection_, connection); |
|
675 |
10 |
} |
|
676 |
|||
677 |
inline profiler::V8CpuProfilerConnection* |
||
678 |
5201 |
Environment::cpu_profiler_connection() { |
|
679 |
5201 |
return cpu_profiler_connection_.get(); |
|
680 |
} |
||
681 |
|||
682 |
10 |
inline void Environment::set_cpu_prof_interval(uint64_t interval) { |
|
683 |
10 |
cpu_prof_interval_ = interval; |
|
684 |
10 |
} |
|
685 |
|||
686 |
10 |
inline uint64_t Environment::cpu_prof_interval() const { |
|
687 |
10 |
return cpu_prof_interval_; |
|
688 |
} |
||
689 |
|||
690 |
10 |
inline void Environment::set_cpu_prof_name(const std::string& name) { |
|
691 |
10 |
cpu_prof_name_ = name; |
|
692 |
10 |
} |
|
693 |
|||
694 |
10 |
inline const std::string& Environment::cpu_prof_name() const { |
|
695 |
10 |
return cpu_prof_name_; |
|
696 |
} |
||
697 |
|||
698 |
10 |
inline void Environment::set_cpu_prof_dir(const std::string& dir) { |
|
699 |
10 |
cpu_prof_dir_ = dir; |
|
700 |
10 |
} |
|
701 |
|||
702 |
10 |
inline const std::string& Environment::cpu_prof_dir() const { |
|
703 |
10 |
return cpu_prof_dir_; |
|
704 |
} |
||
705 |
|||
706 |
10 |
inline void Environment::set_heap_profiler_connection( |
|
707 |
std::unique_ptr<profiler::V8HeapProfilerConnection> connection) { |
||
708 |
✗✓ | 10 |
CHECK_NULL(heap_profiler_connection_); |
709 |
10 |
std::swap(heap_profiler_connection_, connection); |
|
710 |
10 |
} |
|
711 |
|||
712 |
inline profiler::V8HeapProfilerConnection* |
||
713 |
5191 |
Environment::heap_profiler_connection() { |
|
714 |
5191 |
return heap_profiler_connection_.get(); |
|
715 |
} |
||
716 |
|||
717 |
10 |
inline void Environment::set_heap_prof_name(const std::string& name) { |
|
718 |
10 |
heap_prof_name_ = name; |
|
719 |
10 |
} |
|
720 |
|||
721 |
10 |
inline const std::string& Environment::heap_prof_name() const { |
|
722 |
10 |
return heap_prof_name_; |
|
723 |
} |
||
724 |
|||
725 |
10 |
inline void Environment::set_heap_prof_dir(const std::string& dir) { |
|
726 |
10 |
heap_prof_dir_ = dir; |
|
727 |
10 |
} |
|
728 |
|||
729 |
10 |
inline const std::string& Environment::heap_prof_dir() const { |
|
730 |
10 |
return heap_prof_dir_; |
|
731 |
} |
||
732 |
|||
733 |
10 |
inline void Environment::set_heap_prof_interval(uint64_t interval) { |
|
734 |
10 |
heap_prof_interval_ = interval; |
|
735 |
10 |
} |
|
736 |
|||
737 |
10 |
inline uint64_t Environment::heap_prof_interval() const { |
|
738 |
10 |
return heap_prof_interval_; |
|
739 |
} |
||
740 |
|||
741 |
#endif // HAVE_INSPECTOR |
||
742 |
|||
743 |
10297 |
inline std::shared_ptr<HostPort> Environment::inspector_host_port() { |
|
744 |
10297 |
return inspector_host_port_; |
|
745 |
} |
||
746 |
|||
747 |
16560 |
inline std::shared_ptr<PerIsolateOptions> IsolateData::options() { |
|
748 |
16560 |
return options_; |
|
749 |
} |
||
750 |
|||
751 |
9 |
inline void IsolateData::set_options( |
|
752 |
std::shared_ptr<PerIsolateOptions> options) { |
||
753 |
9 |
options_ = std::move(options); |
|
754 |
9 |
} |
|
755 |
|||
756 |
template <typename Fn> |
||
757 |
54962 |
void Environment::CreateImmediate(Fn&& cb, |
|
758 |
v8::Local<v8::Object> keep_alive, |
||
759 |
bool ref) { |
||
760 |
auto callback = std::make_unique<NativeImmediateCallbackImpl<Fn>>( |
||
761 |
54962 |
std::move(cb), |
|
762 |
v8::Global<v8::Object>(isolate(), keep_alive), |
||
763 |
164886 |
ref); |
|
764 |
54962 |
NativeImmediateCallback* prev_tail = native_immediate_callbacks_tail_; |
|
765 |
|||
766 |
54962 |
native_immediate_callbacks_tail_ = callback.get(); |
|
767 |
✓✓✓✓ ✓✓✓✓ ✓✗ |
54962 |
if (prev_tail != nullptr) |
768 |
6143 |
prev_tail->set_next(std::move(callback)); |
|
769 |
else |
||
770 |
48819 |
native_immediate_callbacks_head_ = std::move(callback); |
|
771 |
|||
772 |
54962 |
immediate_info()->count_inc(1); |
|
773 |
54962 |
} |
|
774 |
|||
775 |
template <typename Fn> |
||
776 |
32715 |
void Environment::SetImmediate(Fn&& cb, v8::Local<v8::Object> keep_alive) { |
|
777 |
32715 |
CreateImmediate(std::move(cb), keep_alive, true); |
|
778 |
|||
779 |
✓✓✓✓ ✓✓✓✓ ✗✓ |
32715 |
if (immediate_info()->ref_count() == 0) |
780 |
23903 |
ToggleImmediateRef(true); |
|
781 |
32715 |
immediate_info()->ref_count_inc(1); |
|
782 |
32715 |
} |
|
783 |
|||
784 |
template <typename Fn> |
||
785 |
22247 |
void Environment::SetUnrefImmediate(Fn&& cb, v8::Local<v8::Object> keep_alive) { |
|
786 |
22247 |
CreateImmediate(std::move(cb), keep_alive, false); |
|
787 |
22247 |
} |
|
788 |
|||
789 |
54962 |
Environment::NativeImmediateCallback::NativeImmediateCallback(bool refed) |
|
790 |
54962 |
: refed_(refed) {} |
|
791 |
|||
792 |
54774 |
bool Environment::NativeImmediateCallback::is_refed() const { |
|
793 |
54774 |
return refed_; |
|
794 |
} |
||
795 |
|||
796 |
std::unique_ptr<Environment::NativeImmediateCallback> |
||
797 |
54773 |
Environment::NativeImmediateCallback::get_next() { |
|
798 |
54773 |
return std::move(next_); |
|
799 |
} |
||
800 |
|||
801 |
6143 |
void Environment::NativeImmediateCallback::set_next( |
|
802 |
std::unique_ptr<NativeImmediateCallback> next) { |
||
803 |
6143 |
next_ = std::move(next); |
|
804 |
6143 |
} |
|
805 |
|||
806 |
template <typename Fn> |
||
807 |
54962 |
Environment::NativeImmediateCallbackImpl<Fn>::NativeImmediateCallbackImpl( |
|
808 |
Fn&& callback, v8::Global<v8::Object>&& keep_alive, bool refed) |
||
809 |
: NativeImmediateCallback(refed), |
||
810 |
54962 |
callback_(std::move(callback)), |
|
811 |
164886 |
keep_alive_(std::move(keep_alive)) {} |
|
812 |
|||
813 |
template <typename Fn> |
||
814 |
54774 |
void Environment::NativeImmediateCallbackImpl<Fn>::Call(Environment* env) { |
|
815 |
54774 |
callback_(env); |
|
816 |
54773 |
} |
|
817 |
|||
818 |
4117148 |
inline bool Environment::can_call_into_js() const { |
|
819 |
✓✓✓✗ |
4117148 |
return can_call_into_js_ && !is_stopping(); |
820 |
} |
||
821 |
|||
822 |
4763 |
inline void Environment::set_can_call_into_js(bool can_call_into_js) { |
|
823 |
4763 |
can_call_into_js_ = can_call_into_js; |
|
824 |
4763 |
} |
|
825 |
|||
826 |
20762 |
inline bool Environment::has_run_bootstrapping_code() const { |
|
827 |
20762 |
return has_run_bootstrapping_code_; |
|
828 |
} |
||
829 |
|||
830 |
5103 |
inline void Environment::set_has_run_bootstrapping_code(bool value) { |
|
831 |
5103 |
has_run_bootstrapping_code_ = value; |
|
832 |
5103 |
} |
|
833 |
|||
834 |
16 |
inline bool Environment::has_serialized_options() const { |
|
835 |
16 |
return has_serialized_options_; |
|
836 |
} |
||
837 |
|||
838 |
5103 |
inline void Environment::set_has_serialized_options(bool value) { |
|
839 |
5103 |
has_serialized_options_ = value; |
|
840 |
5103 |
} |
|
841 |
|||
842 |
24953 |
inline bool Environment::is_main_thread() const { |
|
843 |
24953 |
return flags_ & kIsMainThread; |
|
844 |
} |
||
845 |
|||
846 |
29648 |
inline bool Environment::owns_process_state() const { |
|
847 |
29648 |
return flags_ & kOwnsProcessState; |
|
848 |
} |
||
849 |
|||
850 |
5106 |
inline bool Environment::owns_inspector() const { |
|
851 |
5106 |
return flags_ & kOwnsInspector; |
|
852 |
} |
||
853 |
|||
854 |
8889 |
inline uint64_t Environment::thread_id() const { |
|
855 |
8889 |
return thread_id_; |
|
856 |
} |
||
857 |
|||
858 |
106 |
inline worker::Worker* Environment::worker_context() const { |
|
859 |
106 |
return worker_context_; |
|
860 |
} |
||
861 |
|||
862 |
208 |
inline void Environment::set_worker_context(worker::Worker* context) { |
|
863 |
✗✓ | 208 |
CHECK_NULL(worker_context_); // Should be set only once. |
864 |
208 |
worker_context_ = context; |
|
865 |
208 |
} |
|
866 |
|||
867 |
216 |
inline void Environment::add_sub_worker_context(worker::Worker* context) { |
|
868 |
216 |
sub_worker_contexts_.insert(context); |
|
869 |
216 |
} |
|
870 |
|||
871 |
239 |
inline void Environment::remove_sub_worker_context(worker::Worker* context) { |
|
872 |
239 |
sub_worker_contexts_.erase(context); |
|
873 |
239 |
} |
|
874 |
|||
875 |
4115657 |
inline bool Environment::is_stopping() const { |
|
876 |
4115657 |
return thread_stopper_.is_stopped(); |
|
877 |
} |
||
878 |
|||
879 |
40207 |
inline performance::performance_state* Environment::performance_state() { |
|
880 |
40207 |
return performance_state_.get(); |
|
881 |
} |
||
882 |
|||
883 |
inline std::unordered_map<std::string, uint64_t>* |
||
884 |
43 |
Environment::performance_marks() { |
|
885 |
43 |
return &performance_marks_; |
|
886 |
} |
||
887 |
|||
888 |
6774528 |
inline IsolateData* Environment::isolate_data() const { |
|
889 |
6774528 |
return isolate_data_; |
|
890 |
} |
||
891 |
|||
892 |
510587 |
inline char* Environment::AllocateUnchecked(size_t size) { |
|
893 |
return static_cast<char*>( |
||
894 |
510587 |
isolate_data()->allocator()->AllocateUninitialized(size)); |
|
895 |
} |
||
896 |
|||
897 |
491409 |
inline char* Environment::Allocate(size_t size) { |
|
898 |
491409 |
char* ret = AllocateUnchecked(size); |
|
899 |
✗✓ | 491409 |
CHECK_NE(ret, nullptr); |
900 |
491409 |
return ret; |
|
901 |
} |
||
902 |
|||
903 |
1280311 |
inline void Environment::Free(char* data, size_t size) { |
|
904 |
✓✓ | 1280311 |
if (data != nullptr) |
905 |
152528 |
isolate_data()->allocator()->Free(data, size); |
|
906 |
1280311 |
} |
|
907 |
|||
908 |
510587 |
inline AllocatedBuffer Environment::AllocateManaged(size_t size, bool checked) { |
|
909 |
✓✓ | 510587 |
char* data = checked ? Allocate(size) : AllocateUnchecked(size); |
910 |
✗✓ | 510587 |
if (data == nullptr) size = 0; |
911 |
510587 |
return AllocatedBuffer(this, uv_buf_init(data, size)); |
|
912 |
} |
||
913 |
|||
914 |
914052 |
inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf) |
|
915 |
914052 |
: env_(env), buffer_(buf) {} |
|
916 |
|||
917 |
351718 |
inline void AllocatedBuffer::Resize(size_t len) { |
|
918 |
// The `len` check is to make sure we don't end up with `nullptr` as our base. |
||
919 |
char* new_data = env_->Reallocate(buffer_.base, buffer_.len, |
||
920 |
✓✓ | 351718 |
len > 0 ? len : 1); |
921 |
✗✓ | 351718 |
CHECK_NOT_NULL(new_data); |
922 |
351718 |
buffer_ = uv_buf_init(new_data, len); |
|
923 |
351718 |
} |
|
924 |
|||
925 |
2177549 |
inline uv_buf_t AllocatedBuffer::release() { |
|
926 |
2177549 |
uv_buf_t ret = buffer_; |
|
927 |
2177549 |
buffer_ = uv_buf_init(nullptr, 0); |
|
928 |
2177549 |
return ret; |
|
929 |
} |
||
930 |
|||
931 |
775073 |
inline char* AllocatedBuffer::data() { |
|
932 |
775073 |
return buffer_.base; |
|
933 |
} |
||
934 |
|||
935 |
inline const char* AllocatedBuffer::data() const { |
||
936 |
return buffer_.base; |
||
937 |
} |
||
938 |
|||
939 |
868904 |
inline size_t AllocatedBuffer::size() const { |
|
940 |
868904 |
return buffer_.len; |
|
941 |
} |
||
942 |
|||
943 |
164153 |
inline AllocatedBuffer::AllocatedBuffer(Environment* env) |
|
944 |
164153 |
: env_(env), buffer_(uv_buf_init(nullptr, 0)) {} |
|
945 |
|||
946 |
828 |
inline AllocatedBuffer::AllocatedBuffer(AllocatedBuffer&& other) |
|
947 |
828 |
: AllocatedBuffer() { |
|
948 |
828 |
*this = std::move(other); |
|
949 |
828 |
} |
|
950 |
|||
951 |
172282 |
inline AllocatedBuffer& AllocatedBuffer::operator=(AllocatedBuffer&& other) { |
|
952 |
172282 |
clear(); |
|
953 |
172282 |
env_ = other.env_; |
|
954 |
172282 |
buffer_ = other.release(); |
|
955 |
172282 |
return *this; |
|
956 |
} |
||
957 |
|||
958 |
1078049 |
inline AllocatedBuffer::~AllocatedBuffer() { |
|
959 |
1078049 |
clear(); |
|
960 |
1078049 |
} |
|
961 |
|||
962 |
1280311 |
inline void AllocatedBuffer::clear() { |
|
963 |
1280311 |
uv_buf_t buf = release(); |
|
964 |
1280311 |
env_->Free(buf.base, buf.len); |
|
965 |
1280311 |
} |
|
966 |
|||
967 |
// It's a bit awkward to define this Buffer::New() overload here, but it |
||
968 |
// avoids a circular dependency with node_internals.h. |
||
969 |
namespace Buffer { |
||
970 |
v8::MaybeLocal<v8::Object> New(Environment* env, |
||
971 |
char* data, |
||
972 |
size_t length, |
||
973 |
bool uses_malloc); |
||
974 |
} |
||
975 |
|||
976 |
46658 |
inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer() { |
|
977 |
✗✓ | 46658 |
CHECK_NOT_NULL(env_); |
978 |
46658 |
v8::MaybeLocal<v8::Object> obj = Buffer::New(env_, data(), size(), false); |
|
979 |
✓✗ | 46658 |
if (!obj.IsEmpty()) release(); |
980 |
46658 |
return obj; |
|
981 |
} |
||
982 |
|||
983 |
317461 |
inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer() { |
|
984 |
✗✓ | 317461 |
CHECK_NOT_NULL(env_); |
985 |
317461 |
uv_buf_t buf = release(); |
|
986 |
return v8::ArrayBuffer::New(env_->isolate(), |
||
987 |
buf.base, |
||
988 |
buf.len, |
||
989 |
317461 |
v8::ArrayBufferCreationMode::kInternalized); |
|
990 |
} |
||
991 |
|||
992 |
697 |
inline void Environment::ThrowError(const char* errmsg) { |
|
993 |
697 |
ThrowError(v8::Exception::Error, errmsg); |
|
994 |
697 |
} |
|
995 |
|||
996 |
2 |
inline void Environment::ThrowTypeError(const char* errmsg) { |
|
997 |
2 |
ThrowError(v8::Exception::TypeError, errmsg); |
|
998 |
2 |
} |
|
999 |
|||
1000 |
inline void Environment::ThrowRangeError(const char* errmsg) { |
||
1001 |
ThrowError(v8::Exception::RangeError, errmsg); |
||
1002 |
} |
||
1003 |
|||
1004 |
699 |
inline void Environment::ThrowError( |
|
1005 |
v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), |
||
1006 |
const char* errmsg) { |
||
1007 |
699 |
v8::HandleScope handle_scope(isolate()); |
|
1008 |
699 |
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg))); |
|
1009 |
699 |
} |
|
1010 |
|||
1011 |
3 |
inline void Environment::ThrowErrnoException(int errorno, |
|
1012 |
const char* syscall, |
||
1013 |
const char* message, |
||
1014 |
const char* path) { |
||
1015 |
isolate()->ThrowException( |
||
1016 |
3 |
ErrnoException(isolate(), errorno, syscall, message, path)); |
|
1017 |
3 |
} |
|
1018 |
|||
1019 |
13 |
inline void Environment::ThrowUVException(int errorno, |
|
1020 |
const char* syscall, |
||
1021 |
const char* message, |
||
1022 |
const char* path, |
||
1023 |
const char* dest) { |
||
1024 |
isolate()->ThrowException( |
||
1025 |
13 |
UVException(isolate(), errorno, syscall, message, path, dest)); |
|
1026 |
13 |
} |
|
1027 |
|||
1028 |
inline v8::Local<v8::FunctionTemplate> |
||
1029 |
1894253 |
Environment::NewFunctionTemplate(v8::FunctionCallback callback, |
|
1030 |
v8::Local<v8::Signature> signature, |
||
1031 |
v8::ConstructorBehavior behavior, |
||
1032 |
v8::SideEffectType side_effect_type) { |
||
1033 |
1894253 |
v8::Local<v8::Object> external = as_callback_data(); |
|
1034 |
return v8::FunctionTemplate::New(isolate(), callback, external, |
||
1035 |
1894256 |
signature, 0, behavior, side_effect_type); |
|
1036 |
} |
||
1037 |
|||
1038 |
776247 |
inline void Environment::SetMethod(v8::Local<v8::Object> that, |
|
1039 |
const char* name, |
||
1040 |
v8::FunctionCallback callback) { |
||
1041 |
776247 |
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
|
1042 |
v8::Local<v8::Function> function = |
||
1043 |
NewFunctionTemplate(callback, v8::Local<v8::Signature>(), |
||
1044 |
v8::ConstructorBehavior::kThrow, |
||
1045 |
776247 |
v8::SideEffectType::kHasSideEffect) |
|
1046 |
2328742 |
->GetFunction(context) |
|
1047 |
1552495 |
.ToLocalChecked(); |
|
1048 |
// kInternalized strings are created in the old space. |
||
1049 |
776247 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
|
1050 |
v8::Local<v8::String> name_string = |
||
1051 |
1552495 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
|
1052 |
1552495 |
that->Set(context, name_string, function).Check(); |
|
1053 |
776247 |
function->SetName(name_string); // NODE_SET_METHOD() compatibility. |
|
1054 |
776248 |
} |
|
1055 |
|||
1056 |
340024 |
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that, |
|
1057 |
const char* name, |
||
1058 |
v8::FunctionCallback callback) { |
||
1059 |
340024 |
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
|
1060 |
v8::Local<v8::Function> function = |
||
1061 |
NewFunctionTemplate(callback, v8::Local<v8::Signature>(), |
||
1062 |
v8::ConstructorBehavior::kThrow, |
||
1063 |
340024 |
v8::SideEffectType::kHasNoSideEffect) |
|
1064 |
1020072 |
->GetFunction(context) |
|
1065 |
680048 |
.ToLocalChecked(); |
|
1066 |
// kInternalized strings are created in the old space. |
||
1067 |
340024 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
|
1068 |
v8::Local<v8::String> name_string = |
||
1069 |
680046 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
|
1070 |
680046 |
that->Set(context, name_string, function).Check(); |
|
1071 |
340024 |
function->SetName(name_string); // NODE_SET_METHOD() compatibility. |
|
1072 |
340023 |
} |
|
1073 |
|||
1074 |
530241 |
inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that, |
|
1075 |
const char* name, |
||
1076 |
v8::FunctionCallback callback) { |
||
1077 |
530241 |
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that); |
|
1078 |
v8::Local<v8::FunctionTemplate> t = |
||
1079 |
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, |
||
1080 |
530241 |
v8::SideEffectType::kHasSideEffect); |
|
1081 |
// kInternalized strings are created in the old space. |
||
1082 |
530240 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
|
1083 |
v8::Local<v8::String> name_string = |
||
1084 |
1060481 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
|
1085 |
1060481 |
that->PrototypeTemplate()->Set(name_string, t); |
|
1086 |
530240 |
t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. |
|
1087 |
530241 |
} |
|
1088 |
|||
1089 |
49250 |
inline void Environment::SetProtoMethodNoSideEffect( |
|
1090 |
v8::Local<v8::FunctionTemplate> that, |
||
1091 |
const char* name, |
||
1092 |
v8::FunctionCallback callback) { |
||
1093 |
49250 |
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that); |
|
1094 |
v8::Local<v8::FunctionTemplate> t = |
||
1095 |
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, |
||
1096 |
49250 |
v8::SideEffectType::kHasNoSideEffect); |
|
1097 |
// kInternalized strings are created in the old space. |
||
1098 |
49250 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
|
1099 |
v8::Local<v8::String> name_string = |
||
1100 |
98500 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
|
1101 |
98500 |
that->PrototypeTemplate()->Set(name_string, t); |
|
1102 |
49250 |
t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. |
|
1103 |
49250 |
} |
|
1104 |
|||
1105 |
733617 |
void Environment::AddCleanupHook(void (*fn)(void*), void* arg) { |
|
1106 |
auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback { |
||
1107 |
fn, arg, cleanup_hook_counter_++ |
||
1108 |
733617 |
}); |
|
1109 |
// Make sure there was no existing element with these values. |
||
1110 |
✗✓ | 733619 |
CHECK_EQ(insertion_info.second, true); |
1111 |
733619 |
} |
|
1112 |
|||
1113 |
730865 |
void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) { |
|
1114 |
730865 |
CleanupHookCallback search { fn, arg, 0 }; |
|
1115 |
730865 |
cleanup_hooks_.erase(search); |
|
1116 |
730867 |
} |
|
1117 |
|||
1118 |
1603355 |
size_t CleanupHookCallback::Hash::operator()( |
|
1119 |
const CleanupHookCallback& cb) const { |
||
1120 |
1603355 |
return std::hash<void*>()(cb.arg_); |
|
1121 |
} |
||
1122 |
|||
1123 |
799678 |
bool CleanupHookCallback::Equal::operator()( |
|
1124 |
const CleanupHookCallback& a, const CleanupHookCallback& b) const { |
||
1125 |
✓✗✓✗ |
799678 |
return a.fn_ == b.fn_ && a.arg_ == b.arg_; |
1126 |
} |
||
1127 |
|||
1128 |
349 |
BaseObject* CleanupHookCallback::GetBaseObject() const { |
|
1129 |
✓✓ | 349 |
if (fn_ == BaseObject::DeleteMe) |
1130 |
348 |
return static_cast<BaseObject*>(arg_); |
|
1131 |
else |
||
1132 |
1 |
return nullptr; |
|
1133 |
} |
||
1134 |
|||
1135 |
template <typename T> |
||
1136 |
void Environment::ForEachBaseObject(T&& iterator) { |
||
1137 |
for (const auto& hook : cleanup_hooks_) { |
||
1138 |
BaseObject* obj = hook.GetBaseObject(); |
||
1139 |
if (obj != nullptr) |
||
1140 |
iterator(obj); |
||
1141 |
} |
||
1142 |
} |
||
1143 |
|||
1144 |
4115660 |
bool AsyncRequest::is_stopped() const { |
|
1145 |
4115660 |
return stopped_.load(); |
|
1146 |
} |
||
1147 |
|||
1148 |
5594 |
void AsyncRequest::set_stopped(bool flag) { |
|
1149 |
5594 |
stopped_.store(flag); |
|
1150 |
5595 |
} |
|
1151 |
|||
1152 |
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
||
1153 |
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
||
1154 |
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
||
1155 |
#define V(TypeName, PropertyName) \ |
||
1156 |
inline \ |
||
1157 |
v8::Local<TypeName> IsolateData::PropertyName(v8::Isolate* isolate) const { \ |
||
1158 |
/* Strings are immutable so casting away const-ness here is okay. */ \ |
||
1159 |
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate); \ |
||
1160 |
} |
||
1161 |
21116 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
|
1162 |
727052 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
|
1163 |
6314000 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
|
1164 |
#undef V |
||
1165 |
#undef VS |
||
1166 |
#undef VY |
||
1167 |
#undef VP |
||
1168 |
|||
1169 |
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
||
1170 |
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
||
1171 |
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
||
1172 |
#define V(TypeName, PropertyName) \ |
||
1173 |
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
||
1174 |
return isolate_data()->PropertyName(isolate()); \ |
||
1175 |
} |
||
1176 |
10558 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
|
1177 |
363337 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
|
1178 |
3146228 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
|
1179 |
#undef V |
||
1180 |
#undef VS |
||
1181 |
#undef VY |
||
1182 |
#undef VP |
||
1183 |
|||
1184 |
#define V(PropertyName, TypeName) \ |
||
1185 |
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
||
1186 |
return PersistentToLocal::Strong(PropertyName ## _); \ |
||
1187 |
} \ |
||
1188 |
inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) { \ |
||
1189 |
PropertyName ## _.Reset(isolate(), value); \ |
||
1190 |
} |
||
1191 |
545282 |
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V) |
|
1192 |
7888000 |
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V) |
|
1193 |
#undef V |
||
1194 |
|||
1195 |
18382887 |
inline v8::Local<v8::Context> Environment::context() const { |
|
1196 |
18382887 |
return PersistentToLocal::Strong(context_); |
|
1197 |
} |
||
1198 |
} // namespace node |
||
1199 |
|||
1200 |
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
||
1201 |
|||
1202 |
#endif // SRC_ENV_INL_H_ |
Generated by: GCOVR (Version 3.4) |