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 "util-inl.h" |
35 |
|
|
#include "uv.h" |
36 |
|
|
#include "v8-fast-api-calls.h" |
37 |
|
|
#include "v8.h" |
38 |
|
|
|
39 |
|
|
#include <cstddef> |
40 |
|
|
#include <cstdint> |
41 |
|
|
|
42 |
|
|
#include <utility> |
43 |
|
|
|
44 |
|
|
namespace node { |
45 |
|
|
|
46 |
|
116864 |
NoArrayBufferZeroFillScope::NoArrayBufferZeroFillScope( |
47 |
|
116864 |
IsolateData* isolate_data) |
48 |
|
116864 |
: node_allocator_(isolate_data->node_allocator()) { |
49 |
✓✗ |
116864 |
if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 0; |
50 |
|
116864 |
} |
51 |
|
|
|
52 |
|
233728 |
NoArrayBufferZeroFillScope::~NoArrayBufferZeroFillScope() { |
53 |
✓✗ |
116864 |
if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 1; |
54 |
|
116864 |
} |
55 |
|
|
|
56 |
|
|
inline v8::Isolate* IsolateData::isolate() const { |
57 |
|
|
return isolate_; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
1266356 |
inline uv_loop_t* IsolateData::event_loop() const { |
61 |
|
1266356 |
return event_loop_; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
123938 |
inline NodeArrayBufferAllocator* IsolateData::node_allocator() const { |
65 |
|
123938 |
return node_allocator_; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
58926 |
inline MultiIsolatePlatform* IsolateData::platform() const { |
69 |
|
58926 |
return platform_; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
1246 |
inline void IsolateData::set_worker_context(worker::Worker* context) { |
73 |
✗✓ |
1246 |
CHECK_NULL(worker_context_); // Should be set only once. |
74 |
|
1246 |
worker_context_ = context; |
75 |
|
1246 |
} |
76 |
|
|
|
77 |
|
20130 |
inline worker::Worker* IsolateData::worker_context() const { |
78 |
|
20130 |
return worker_context_; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
217226 |
inline v8::Local<v8::String> IsolateData::async_wrap_provider(int index) const { |
82 |
|
217226 |
return async_wrap_providers_[index].Get(isolate_); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
2639024 |
inline AliasedUint32Array& AsyncHooks::fields() { |
86 |
|
2639024 |
return fields_; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
1699475 |
inline AliasedFloat64Array& AsyncHooks::async_id_fields() { |
90 |
|
1699475 |
return async_id_fields_; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
1292 |
inline AliasedFloat64Array& AsyncHooks::async_ids_stack() { |
94 |
|
1292 |
return async_ids_stack_; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
832364 |
v8::Local<v8::Array> AsyncHooks::js_execution_async_resources() { |
98 |
✓✓ |
832364 |
if (UNLIKELY(js_execution_async_resources_.IsEmpty())) { |
99 |
|
1292 |
js_execution_async_resources_.Reset( |
100 |
|
2584 |
env()->isolate(), v8::Array::New(env()->isolate())); |
101 |
|
|
} |
102 |
|
832364 |
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 |
|
15378 |
inline void AsyncHooks::SetJSPromiseHooks(v8::Local<v8::Function> init, |
111 |
|
|
v8::Local<v8::Function> before, |
112 |
|
|
v8::Local<v8::Function> after, |
113 |
|
|
v8::Local<v8::Function> resolve) { |
114 |
|
15378 |
js_promise_hooks_[0].Reset(env()->isolate(), init); |
115 |
|
15378 |
js_promise_hooks_[1].Reset(env()->isolate(), before); |
116 |
|
15378 |
js_promise_hooks_[2].Reset(env()->isolate(), after); |
117 |
|
15378 |
js_promise_hooks_[3].Reset(env()->isolate(), resolve); |
118 |
✓✓ |
31098 |
for (auto it = contexts_.begin(); it != contexts_.end(); it++) { |
119 |
✗✓ |
15720 |
if (it->IsEmpty()) { |
120 |
|
|
contexts_.erase(it--); |
121 |
|
|
continue; |
122 |
|
|
} |
123 |
|
31440 |
PersistentToLocal::Weak(env()->isolate(), *it) |
124 |
|
15720 |
->SetPromiseHooks(init, before, after, resolve); |
125 |
|
|
} |
126 |
|
15378 |
} |
127 |
|
|
|
128 |
|
216878 |
inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) { |
129 |
|
216878 |
return env()->isolate_data()->async_wrap_provider(idx); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
1 |
inline void AsyncHooks::no_force_checks() { |
133 |
|
1 |
fields_[kCheck] -= 1; |
134 |
|
1 |
} |
135 |
|
|
|
136 |
|
446695 |
inline Environment* AsyncHooks::env() { |
137 |
|
446695 |
return Environment::ForAsyncHooks(this); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
// Remember to keep this code aligned with pushAsyncContext() in JS. |
141 |
|
798787 |
inline void AsyncHooks::push_async_context(double async_id, |
142 |
|
|
double trigger_async_id, |
143 |
|
|
v8::Local<v8::Object> resource) { |
144 |
|
|
// Since async_hooks is experimental, do only perform the check |
145 |
|
|
// when async_hooks is enabled. |
146 |
✓✓ |
798787 |
if (fields_[kCheck] > 0) { |
147 |
✗✓ |
798783 |
CHECK_GE(async_id, -1); |
148 |
✗✓ |
798783 |
CHECK_GE(trigger_async_id, -1); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
798787 |
uint32_t offset = fields_[kStackLength]; |
152 |
✓✓ |
798787 |
if (offset * 2 >= async_ids_stack_.Length()) |
153 |
|
4 |
grow_async_ids_stack(); |
154 |
|
798787 |
async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId]; |
155 |
|
798787 |
async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId]; |
156 |
|
798787 |
fields_[kStackLength] += 1; |
157 |
|
798787 |
async_id_fields_[kExecutionAsyncId] = async_id; |
158 |
|
798787 |
async_id_fields_[kTriggerAsyncId] = trigger_async_id; |
159 |
|
|
|
160 |
|
|
#ifdef DEBUG |
161 |
|
|
for (uint32_t i = offset; i < native_execution_async_resources_.size(); i++) |
162 |
|
|
CHECK(native_execution_async_resources_[i].IsEmpty()); |
163 |
|
|
#endif |
164 |
|
|
|
165 |
|
|
// When this call comes from JS (as a way of increasing the stack size), |
166 |
|
|
// `resource` will be empty, because JS caches these values anyway. |
167 |
✓✓ |
798787 |
if (!resource.IsEmpty()) { |
168 |
|
798783 |
native_execution_async_resources_.resize(offset + 1); |
169 |
|
|
// Caveat: This is a v8::Local<> assignment, we do not keep a v8::Global<>! |
170 |
|
798783 |
native_execution_async_resources_[offset] = resource; |
171 |
|
|
} |
172 |
|
798787 |
} |
173 |
|
|
|
174 |
|
|
// Remember to keep this code aligned with popAsyncContext() in JS. |
175 |
|
798392 |
inline bool AsyncHooks::pop_async_context(double async_id) { |
176 |
|
|
// In case of an exception then this may have already been reset, if the |
177 |
|
|
// stack was multiple MakeCallback()'s deep. |
178 |
✓✓ |
798392 |
if (UNLIKELY(fields_[kStackLength] == 0)) return false; |
179 |
|
|
|
180 |
|
|
// Ask for the async_id to be restored as a check that the stack |
181 |
|
|
// hasn't been corrupted. |
182 |
|
1594668 |
if (UNLIKELY(fields_[kCheck] > 0 && |
183 |
✓✓✓✓ ✓✓ |
1594668 |
async_id_fields_[kExecutionAsyncId] != async_id)) { |
184 |
|
4 |
FailWithCorruptedAsyncStack(async_id); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
797332 |
uint32_t offset = fields_[kStackLength] - 1; |
188 |
|
797332 |
async_id_fields_[kExecutionAsyncId] = async_ids_stack_[2 * offset]; |
189 |
|
797332 |
async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1]; |
190 |
|
797332 |
fields_[kStackLength] = offset; |
191 |
|
|
|
192 |
|
1594664 |
if (LIKELY(offset < native_execution_async_resources_.size() && |
193 |
✓✗✓✗ ✓✗ |
1594664 |
!native_execution_async_resources_[offset].IsEmpty())) { |
194 |
|
|
#ifdef DEBUG |
195 |
|
|
for (uint32_t i = offset + 1; |
196 |
|
|
i < native_execution_async_resources_.size(); |
197 |
|
|
i++) { |
198 |
|
|
CHECK(native_execution_async_resources_[i].IsEmpty()); |
199 |
|
|
} |
200 |
|
|
#endif |
201 |
|
797332 |
native_execution_async_resources_.resize(offset); |
202 |
|
797332 |
if (native_execution_async_resources_.size() < |
203 |
✓✓✗✓ ✗✓ |
1028745 |
native_execution_async_resources_.capacity() / 2 && |
204 |
|
231413 |
native_execution_async_resources_.size() > 16) { |
205 |
|
|
native_execution_async_resources_.shrink_to_fit(); |
206 |
|
|
} |
207 |
|
|
} |
208 |
|
|
|
209 |
✓✓ |
1594664 |
if (UNLIKELY(js_execution_async_resources()->Length() > offset)) { |
210 |
|
33740 |
v8::HandleScope handle_scope(env()->isolate()); |
211 |
|
67480 |
USE(js_execution_async_resources()->Set( |
212 |
|
|
env()->context(), |
213 |
|
|
env()->length_string(), |
214 |
|
134960 |
v8::Integer::NewFromUnsigned(env()->isolate(), offset))); |
215 |
|
|
} |
216 |
|
|
|
217 |
|
797332 |
return fields_[kStackLength] > 0; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
3314 |
void AsyncHooks::clear_async_id_stack() { |
221 |
|
3314 |
v8::Isolate* isolate = env()->isolate(); |
222 |
|
3314 |
v8::HandleScope handle_scope(isolate); |
223 |
✓✓ |
3314 |
if (!js_execution_async_resources_.IsEmpty()) { |
224 |
|
4044 |
USE(PersistentToLocal::Strong(js_execution_async_resources_)->Set( |
225 |
|
|
env()->context(), |
226 |
|
|
env()->length_string(), |
227 |
|
8088 |
v8::Integer::NewFromUnsigned(isolate, 0))); |
228 |
|
|
} |
229 |
|
3314 |
native_execution_async_resources_.clear(); |
230 |
|
3314 |
native_execution_async_resources_.shrink_to_fit(); |
231 |
|
|
|
232 |
|
3314 |
async_id_fields_[kExecutionAsyncId] = 0; |
233 |
|
3314 |
async_id_fields_[kTriggerAsyncId] = 0; |
234 |
|
3314 |
fields_[kStackLength] = 0; |
235 |
|
3314 |
} |
236 |
|
|
|
237 |
|
7152 |
inline void AsyncHooks::AddContext(v8::Local<v8::Context> ctx) { |
238 |
|
28198 |
ctx->SetPromiseHooks( |
239 |
✓✓ |
7152 |
js_promise_hooks_[0].IsEmpty() ? |
240 |
|
7152 |
v8::Local<v8::Function>() : |
241 |
|
205 |
PersistentToLocal::Strong(js_promise_hooks_[0]), |
242 |
✓✓ |
7152 |
js_promise_hooks_[1].IsEmpty() ? |
243 |
|
7152 |
v8::Local<v8::Function>() : |
244 |
|
205 |
PersistentToLocal::Strong(js_promise_hooks_[1]), |
245 |
✓✓ |
7152 |
js_promise_hooks_[2].IsEmpty() ? |
246 |
|
7152 |
v8::Local<v8::Function>() : |
247 |
|
205 |
PersistentToLocal::Strong(js_promise_hooks_[2]), |
248 |
✓✗ |
7152 |
js_promise_hooks_[3].IsEmpty() ? |
249 |
|
7152 |
v8::Local<v8::Function>() : |
250 |
|
|
PersistentToLocal::Strong(js_promise_hooks_[3])); |
251 |
|
|
|
252 |
|
7152 |
size_t id = contexts_.size(); |
253 |
|
7152 |
contexts_.resize(id + 1); |
254 |
|
7152 |
contexts_[id].Reset(env()->isolate(), ctx); |
255 |
|
7152 |
contexts_[id].SetWeak(); |
256 |
|
7152 |
} |
257 |
|
|
|
258 |
|
513 |
inline void AsyncHooks::RemoveContext(v8::Local<v8::Context> ctx) { |
259 |
|
513 |
v8::Isolate* isolate = env()->isolate(); |
260 |
|
1026 |
v8::HandleScope handle_scope(isolate); |
261 |
|
513 |
contexts_.erase(std::remove_if(contexts_.begin(), |
262 |
|
|
contexts_.end(), |
263 |
|
4835 |
[&](auto&& el) { return el.IsEmpty(); }), |
264 |
|
1026 |
contexts_.end()); |
265 |
✓✓ |
4772 |
for (auto it = contexts_.begin(); it != contexts_.end(); it++) { |
266 |
|
|
v8::Local<v8::Context> saved_context = |
267 |
|
4259 |
PersistentToLocal::Weak(isolate, *it); |
268 |
✗✓ |
4259 |
if (saved_context == ctx) { |
269 |
|
|
it->Reset(); |
270 |
|
|
contexts_.erase(it); |
271 |
|
|
break; |
272 |
|
|
} |
273 |
|
|
} |
274 |
|
513 |
} |
275 |
|
|
|
276 |
|
|
// The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in |
277 |
|
|
// async_wrap-inl.h to avoid a circular dependency. |
278 |
|
|
|
279 |
|
245315 |
inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope( |
280 |
|
245315 |
Environment* env, double default_trigger_async_id) |
281 |
|
245315 |
: async_hooks_(env->async_hooks()) { |
282 |
✓✗ |
245315 |
if (env->async_hooks()->fields()[AsyncHooks::kCheck] > 0) { |
283 |
✗✓ |
245315 |
CHECK_GE(default_trigger_async_id, 0); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
245315 |
old_default_trigger_async_id_ = |
287 |
|
245315 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; |
288 |
|
245315 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = |
289 |
|
245315 |
default_trigger_async_id; |
290 |
|
245315 |
} |
291 |
|
|
|
292 |
|
490628 |
inline AsyncHooks::DefaultTriggerAsyncIdScope ::~DefaultTriggerAsyncIdScope() { |
293 |
|
245314 |
async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = |
294 |
|
245314 |
old_default_trigger_async_id_; |
295 |
|
245314 |
} |
296 |
|
|
|
297 |
|
446695 |
Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) { |
298 |
|
446695 |
return ContainerOf(&Environment::async_hooks_, hooks); |
299 |
|
|
} |
300 |
|
|
|
301 |
|
798610 |
inline size_t Environment::async_callback_scope_depth() const { |
302 |
|
798610 |
return async_callback_scope_depth_; |
303 |
|
|
} |
304 |
|
|
|
305 |
|
815934 |
inline void Environment::PushAsyncCallbackScope() { |
306 |
|
815934 |
async_callback_scope_depth_++; |
307 |
|
815934 |
} |
308 |
|
|
|
309 |
|
815413 |
inline void Environment::PopAsyncCallbackScope() { |
310 |
|
815413 |
async_callback_scope_depth_--; |
311 |
|
815413 |
} |
312 |
|
|
|
313 |
|
1292 |
inline AliasedUint32Array& ImmediateInfo::fields() { |
314 |
|
1292 |
return fields_; |
315 |
|
|
} |
316 |
|
|
|
317 |
|
191015 |
inline uint32_t ImmediateInfo::count() const { |
318 |
|
191015 |
return fields_[kCount]; |
319 |
|
|
} |
320 |
|
|
|
321 |
|
292398 |
inline uint32_t ImmediateInfo::ref_count() const { |
322 |
|
292398 |
return fields_[kRefCount]; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
47734 |
inline bool ImmediateInfo::has_outstanding() const { |
326 |
|
47734 |
return fields_[kHasOutstanding] == 1; |
327 |
|
|
} |
328 |
|
|
|
329 |
|
34703 |
inline void ImmediateInfo::ref_count_inc(uint32_t increment) { |
330 |
|
34703 |
fields_[kRefCount] += increment; |
331 |
|
34703 |
} |
332 |
|
|
|
333 |
|
210912 |
inline void ImmediateInfo::ref_count_dec(uint32_t decrement) { |
334 |
|
210912 |
fields_[kRefCount] -= decrement; |
335 |
|
210912 |
} |
336 |
|
|
|
337 |
|
1292 |
inline AliasedUint8Array& TickInfo::fields() { |
338 |
|
1292 |
return fields_; |
339 |
|
|
} |
340 |
|
|
|
341 |
|
1440334 |
inline bool TickInfo::has_tick_scheduled() const { |
342 |
|
1440334 |
return fields_[kHasTickScheduled] == 1; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
528203 |
inline bool TickInfo::has_rejection_to_warn() const { |
346 |
|
528203 |
return fields_[kHasRejectionToWarn] == 1; |
347 |
|
|
} |
348 |
|
|
|
349 |
|
7152 |
inline void Environment::AssignToContext(v8::Local<v8::Context> context, |
350 |
|
|
const ContextInfo& info) { |
351 |
|
7152 |
context->SetAlignedPointerInEmbedderData( |
352 |
|
|
ContextEmbedderIndex::kEnvironment, this); |
353 |
|
|
// Used by Environment::GetCurrent to know that we are on a node context. |
354 |
|
7152 |
context->SetAlignedPointerInEmbedderData( |
355 |
|
|
ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr); |
356 |
|
|
// Used to retrieve bindings |
357 |
|
14304 |
context->SetAlignedPointerInEmbedderData( |
358 |
|
7152 |
ContextEmbedderIndex::kBindingListIndex, &(this->bindings_)); |
359 |
|
|
|
360 |
|
|
#if HAVE_INSPECTOR |
361 |
|
7152 |
inspector_agent()->ContextCreated(context, info); |
362 |
|
|
#endif // HAVE_INSPECTOR |
363 |
|
|
|
364 |
|
7152 |
this->async_hooks()->AddContext(context); |
365 |
|
7152 |
} |
366 |
|
|
|
367 |
|
59446 |
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) { |
368 |
✓✓ |
59446 |
if (UNLIKELY(!isolate->InContext())) return nullptr; |
369 |
|
114910 |
v8::HandleScope handle_scope(isolate); |
370 |
|
57455 |
return GetCurrent(isolate->GetCurrentContext()); |
371 |
|
|
} |
372 |
|
|
|
373 |
|
7652579 |
inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) { |
374 |
✓✓ |
7652579 |
if (UNLIKELY(context.IsEmpty())) { |
375 |
|
1 |
return nullptr; |
376 |
|
|
} |
377 |
|
7652578 |
if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <= |
378 |
✓✓ |
7652578 |
ContextEmbedderIndex::kContextTag)) { |
379 |
|
11 |
return nullptr; |
380 |
|
|
} |
381 |
|
7652567 |
if (UNLIKELY(context->GetAlignedPointerFromEmbedderData( |
382 |
|
|
ContextEmbedderIndex::kContextTag) != |
383 |
✗✓ |
7652567 |
Environment::kNodeContextTagPtr)) { |
384 |
|
|
return nullptr; |
385 |
|
|
} |
386 |
|
|
return static_cast<Environment*>( |
387 |
|
7652567 |
context->GetAlignedPointerFromEmbedderData( |
388 |
|
7652567 |
ContextEmbedderIndex::kEnvironment)); |
389 |
|
|
} |
390 |
|
|
|
391 |
|
5760194 |
inline Environment* Environment::GetCurrent( |
392 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& info) { |
393 |
|
5760194 |
return GetCurrent(info.GetIsolate()->GetCurrentContext()); |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
template <typename T> |
397 |
|
2762554 |
inline Environment* Environment::GetCurrent( |
398 |
|
|
const v8::PropertyCallbackInfo<T>& info) { |
399 |
|
2762554 |
return GetCurrent(info.GetIsolate()->GetCurrentContext()); |
400 |
|
|
} |
401 |
|
|
|
402 |
|
|
template <typename T, typename U> |
403 |
|
|
inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) { |
404 |
|
|
return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
template <typename T> |
408 |
|
998240 |
inline T* Environment::GetBindingData( |
409 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& info) { |
410 |
|
998240 |
return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
template <typename T> |
414 |
|
998242 |
inline T* Environment::GetBindingData(v8::Local<v8::Context> context) { |
415 |
|
|
BindingDataStore* map = static_cast<BindingDataStore*>( |
416 |
|
998242 |
context->GetAlignedPointerFromEmbedderData( |
417 |
|
|
ContextEmbedderIndex::kBindingListIndex)); |
418 |
|
|
DCHECK_NOT_NULL(map); |
419 |
|
998242 |
auto it = map->find(T::type_name); |
420 |
✗✓ |
998242 |
if (UNLIKELY(it == map->end())) return nullptr; |
421 |
|
998242 |
T* result = static_cast<T*>(it->second.get()); |
422 |
|
|
DCHECK_NOT_NULL(result); |
423 |
|
|
DCHECK_EQ(result->env(), GetCurrent(context)); |
424 |
|
998242 |
return result; |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
template <typename T> |
428 |
|
27637 |
inline T* Environment::AddBindingData( |
429 |
|
|
v8::Local<v8::Context> context, |
430 |
|
|
v8::Local<v8::Object> target) { |
431 |
|
|
DCHECK_EQ(GetCurrent(context), this); |
432 |
|
|
// This won't compile if T is not a BaseObject subclass. |
433 |
|
55274 |
BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target); |
434 |
|
|
BindingDataStore* map = static_cast<BindingDataStore*>( |
435 |
|
27637 |
context->GetAlignedPointerFromEmbedderData( |
436 |
|
|
ContextEmbedderIndex::kBindingListIndex)); |
437 |
|
|
DCHECK_NOT_NULL(map); |
438 |
|
27637 |
auto result = map->emplace(T::type_name, item); |
439 |
✗✓ |
27637 |
CHECK(result.second); |
440 |
|
|
DCHECK_EQ(GetBindingData<T>(context), item.get()); |
441 |
|
27637 |
return item.get(); |
442 |
|
|
} |
443 |
|
|
|
444 |
|
30350781 |
inline v8::Isolate* Environment::isolate() const { |
445 |
|
30350781 |
return isolate_; |
446 |
|
|
} |
447 |
|
|
|
448 |
|
7673 |
inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { |
449 |
|
7673 |
return ContainerOf(&Environment::timer_handle_, handle); |
450 |
|
|
} |
451 |
|
|
|
452 |
|
32966 |
inline uv_timer_t* Environment::timer_handle() { |
453 |
|
32966 |
return &timer_handle_; |
454 |
|
|
} |
455 |
|
|
|
456 |
|
191015 |
inline Environment* Environment::from_immediate_check_handle( |
457 |
|
|
uv_check_t* handle) { |
458 |
|
191015 |
return ContainerOf(&Environment::immediate_check_handle_, handle); |
459 |
|
|
} |
460 |
|
|
|
461 |
|
25972 |
inline uv_check_t* Environment::immediate_check_handle() { |
462 |
|
25972 |
return &immediate_check_handle_; |
463 |
|
|
} |
464 |
|
|
|
465 |
|
239436 |
inline uv_idle_t* Environment::immediate_idle_handle() { |
466 |
|
239436 |
return &immediate_idle_handle_; |
467 |
|
|
} |
468 |
|
|
|
469 |
|
38958 |
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, |
470 |
|
|
HandleCleanupCb cb, |
471 |
|
|
void* arg) { |
472 |
|
38958 |
handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg}); |
473 |
|
38958 |
} |
474 |
|
|
|
475 |
|
|
template <typename T, typename OnCloseCallback> |
476 |
|
40773 |
inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) { |
477 |
|
40617 |
handle_cleanup_waiting_++; |
478 |
|
|
static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle"); |
479 |
|
|
static_assert(offsetof(T, data) == offsetof(uv_handle_t, data), |
480 |
|
|
"T is a libuv handle"); |
481 |
|
|
static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb), |
482 |
|
|
"T is a libuv handle"); |
483 |
|
|
struct CloseData { |
484 |
|
|
Environment* env; |
485 |
|
|
OnCloseCallback callback; |
486 |
|
|
void* original_data; |
487 |
|
|
}; |
488 |
|
40695 |
handle->data = new CloseData { this, callback, handle->data }; |
489 |
|
41007 |
uv_close(reinterpret_cast<uv_handle_t*>(handle), [](uv_handle_t* handle) { |
490 |
|
81234 |
std::unique_ptr<CloseData> data { static_cast<CloseData*>(handle->data) }; |
491 |
|
40695 |
data->env->handle_cleanup_waiting_--; |
492 |
|
40695 |
handle->data = data->original_data; |
493 |
|
40695 |
data->callback(reinterpret_cast<T*>(handle)); |
494 |
|
|
}); |
495 |
|
40695 |
} |
496 |
|
|
|
497 |
|
90149 |
void Environment::IncreaseWaitingRequestCounter() { |
498 |
|
90149 |
request_waiting_++; |
499 |
|
90149 |
} |
500 |
|
|
|
501 |
|
90141 |
void Environment::DecreaseWaitingRequestCounter() { |
502 |
|
90141 |
request_waiting_--; |
503 |
✗✓ |
90141 |
CHECK_GE(request_waiting_, 0); |
504 |
|
90141 |
} |
505 |
|
|
|
506 |
|
1259830 |
inline uv_loop_t* Environment::event_loop() const { |
507 |
|
1259830 |
return isolate_data()->event_loop(); |
508 |
|
|
} |
509 |
|
|
|
510 |
|
170 |
inline void Environment::TryLoadAddon( |
511 |
|
|
const char* filename, |
512 |
|
|
int flags, |
513 |
|
|
const std::function<bool(binding::DLib*)>& was_loaded) { |
514 |
|
170 |
loaded_addons_.emplace_back(filename, flags); |
515 |
✓✓ |
170 |
if (!was_loaded(&loaded_addons_.back())) { |
516 |
|
8 |
loaded_addons_.pop_back(); |
517 |
|
|
} |
518 |
|
170 |
} |
519 |
|
|
|
520 |
|
|
#if HAVE_INSPECTOR |
521 |
|
43762 |
inline bool Environment::is_in_inspector_console_call() const { |
522 |
|
43762 |
return is_in_inspector_console_call_; |
523 |
|
|
} |
524 |
|
|
|
525 |
|
87522 |
inline void Environment::set_is_in_inspector_console_call(bool value) { |
526 |
|
87522 |
is_in_inspector_console_call_ = value; |
527 |
|
87522 |
} |
528 |
|
|
#endif |
529 |
|
|
|
530 |
|
5975653 |
inline AsyncHooks* Environment::async_hooks() { |
531 |
|
5975653 |
return &async_hooks_; |
532 |
|
|
} |
533 |
|
|
|
534 |
|
778054 |
inline ImmediateInfo* Environment::immediate_info() { |
535 |
|
778054 |
return &immediate_info_; |
536 |
|
|
} |
537 |
|
|
|
538 |
|
721491 |
inline TickInfo* Environment::tick_info() { |
539 |
|
721491 |
return &tick_info_; |
540 |
|
|
} |
541 |
|
|
|
542 |
|
100540 |
inline uint64_t Environment::timer_base() const { |
543 |
|
100540 |
return timer_base_; |
544 |
|
|
} |
545 |
|
|
|
546 |
|
1400918 |
inline std::shared_ptr<KVStore> Environment::env_vars() { |
547 |
|
1400918 |
return env_vars_; |
548 |
|
|
} |
549 |
|
|
|
550 |
|
7761 |
inline void Environment::set_env_vars(std::shared_ptr<KVStore> env_vars) { |
551 |
|
7761 |
env_vars_ = env_vars; |
552 |
|
7761 |
} |
553 |
|
|
|
554 |
|
19 |
inline bool Environment::printed_error() const { |
555 |
|
19 |
return printed_error_; |
556 |
|
|
} |
557 |
|
|
|
558 |
|
19 |
inline void Environment::set_printed_error(bool value) { |
559 |
|
19 |
printed_error_ = value; |
560 |
|
19 |
} |
561 |
|
|
|
562 |
|
11336 |
inline void Environment::set_trace_sync_io(bool value) { |
563 |
|
11336 |
trace_sync_io_ = value; |
564 |
|
11336 |
} |
565 |
|
|
|
566 |
|
118 |
inline bool Environment::abort_on_uncaught_exception() const { |
567 |
|
118 |
return options_->abort_on_uncaught_exception; |
568 |
|
|
} |
569 |
|
|
|
570 |
|
|
inline void Environment::set_force_context_aware(bool value) { |
571 |
|
|
options_->force_context_aware = value; |
572 |
|
|
} |
573 |
|
|
|
574 |
|
41 |
inline bool Environment::force_context_aware() const { |
575 |
|
41 |
return options_->force_context_aware; |
576 |
|
|
} |
577 |
|
|
|
578 |
|
1239 |
inline void Environment::set_abort_on_uncaught_exception(bool value) { |
579 |
|
1239 |
options_->abort_on_uncaught_exception = value; |
580 |
|
1239 |
} |
581 |
|
|
|
582 |
|
1322 |
inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() { |
583 |
|
1322 |
return should_abort_on_uncaught_toggle_; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
308026 |
inline AliasedInt32Array& Environment::stream_base_state() { |
587 |
|
308026 |
return stream_base_state_; |
588 |
|
|
} |
589 |
|
|
|
590 |
|
54972 |
inline uint32_t Environment::get_next_module_id() { |
591 |
|
54972 |
return module_id_counter_++; |
592 |
|
|
} |
593 |
|
3650 |
inline uint32_t Environment::get_next_script_id() { |
594 |
|
3650 |
return script_id_counter_++; |
595 |
|
|
} |
596 |
|
35707 |
inline uint32_t Environment::get_next_function_id() { |
597 |
|
35707 |
return function_id_counter_++; |
598 |
|
|
} |
599 |
|
|
|
600 |
|
113088 |
ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( |
601 |
|
113088 |
Environment* env) |
602 |
|
113088 |
: env_(env) { |
603 |
|
113088 |
env_->PushShouldNotAbortOnUncaughtScope(); |
604 |
|
113088 |
} |
605 |
|
|
|
606 |
|
226170 |
ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { |
607 |
|
113085 |
Close(); |
608 |
|
113085 |
} |
609 |
|
|
|
610 |
|
113277 |
void ShouldNotAbortOnUncaughtScope::Close() { |
611 |
✓✓ |
113277 |
if (env_ != nullptr) { |
612 |
|
113085 |
env_->PopShouldNotAbortOnUncaughtScope(); |
613 |
|
113085 |
env_ = nullptr; |
614 |
|
|
} |
615 |
|
113277 |
} |
616 |
|
|
|
617 |
|
113088 |
inline void Environment::PushShouldNotAbortOnUncaughtScope() { |
618 |
|
113088 |
should_not_abort_scope_counter_++; |
619 |
|
113088 |
} |
620 |
|
|
|
621 |
|
113085 |
inline void Environment::PopShouldNotAbortOnUncaughtScope() { |
622 |
|
113085 |
should_not_abort_scope_counter_--; |
623 |
|
113085 |
} |
624 |
|
|
|
625 |
|
1 |
inline bool Environment::inside_should_not_abort_on_uncaught_scope() const { |
626 |
|
1 |
return should_not_abort_scope_counter_ > 0; |
627 |
|
|
} |
628 |
|
|
|
629 |
|
387611 |
inline std::vector<double>* Environment::destroy_async_id_list() { |
630 |
|
387611 |
return &destroy_async_id_list_; |
631 |
|
|
} |
632 |
|
|
|
633 |
|
217433 |
inline double Environment::new_async_id() { |
634 |
|
217433 |
async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1; |
635 |
|
217433 |
return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter]; |
636 |
|
|
} |
637 |
|
|
|
638 |
|
246259 |
inline double Environment::execution_async_id() { |
639 |
|
246259 |
return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId]; |
640 |
|
|
} |
641 |
|
|
|
642 |
|
63699 |
inline double Environment::trigger_async_id() { |
643 |
|
63699 |
return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId]; |
644 |
|
|
} |
645 |
|
|
|
646 |
|
217430 |
inline double Environment::get_default_trigger_async_id() { |
647 |
|
|
double default_trigger_async_id = |
648 |
|
217430 |
async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; |
649 |
|
|
// If defaultTriggerAsyncId isn't set, use the executionAsyncId |
650 |
✓✓ |
217430 |
if (default_trigger_async_id < 0) |
651 |
|
182507 |
default_trigger_async_id = execution_async_id(); |
652 |
|
217430 |
return default_trigger_async_id; |
653 |
|
|
} |
654 |
|
|
|
655 |
|
74255 |
inline std::shared_ptr<EnvironmentOptions> Environment::options() { |
656 |
|
74255 |
return options_; |
657 |
|
|
} |
658 |
|
|
|
659 |
|
17969 |
inline const std::vector<std::string>& Environment::argv() { |
660 |
|
17969 |
return argv_; |
661 |
|
|
} |
662 |
|
|
|
663 |
|
7677 |
inline const std::vector<std::string>& Environment::exec_argv() { |
664 |
|
7677 |
return exec_argv_; |
665 |
|
|
} |
666 |
|
|
|
667 |
|
12988 |
inline const std::string& Environment::exec_path() const { |
668 |
|
12988 |
return exec_path_; |
669 |
|
|
} |
670 |
|
|
|
671 |
|
11 |
inline std::string Environment::GetCwd() { |
672 |
|
|
char cwd[PATH_MAX_BYTES]; |
673 |
|
11 |
size_t size = PATH_MAX_BYTES; |
674 |
|
11 |
const int err = uv_cwd(cwd, &size); |
675 |
|
|
|
676 |
✓✗ |
11 |
if (err == 0) { |
677 |
✗✓ |
11 |
CHECK_GT(size, 0); |
678 |
|
11 |
return cwd; |
679 |
|
|
} |
680 |
|
|
|
681 |
|
|
// This can fail if the cwd is deleted. In that case, fall back to |
682 |
|
|
// exec_path. |
683 |
|
|
const std::string& exec_path = exec_path_; |
684 |
|
|
return exec_path.substr(0, exec_path.find_last_of(kPathSeparator)); |
685 |
|
|
} |
686 |
|
|
|
687 |
|
|
#if HAVE_INSPECTOR |
688 |
|
6489 |
inline void Environment::set_coverage_directory(const char* dir) { |
689 |
|
6489 |
coverage_directory_ = std::string(dir); |
690 |
|
6489 |
} |
691 |
|
|
|
692 |
|
6513 |
inline void Environment::set_coverage_connection( |
693 |
|
|
std::unique_ptr<profiler::V8CoverageConnection> connection) { |
694 |
✗✓ |
6513 |
CHECK_NULL(coverage_connection_); |
695 |
|
6513 |
std::swap(coverage_connection_, connection); |
696 |
|
6513 |
} |
697 |
|
|
|
698 |
|
19538 |
inline profiler::V8CoverageConnection* Environment::coverage_connection() { |
699 |
|
19538 |
return coverage_connection_.get(); |
700 |
|
|
} |
701 |
|
|
|
702 |
|
6474 |
inline const std::string& Environment::coverage_directory() const { |
703 |
|
6474 |
return coverage_directory_; |
704 |
|
|
} |
705 |
|
|
|
706 |
|
12 |
inline void Environment::set_cpu_profiler_connection( |
707 |
|
|
std::unique_ptr<profiler::V8CpuProfilerConnection> connection) { |
708 |
✗✓ |
12 |
CHECK_NULL(cpu_profiler_connection_); |
709 |
|
12 |
std::swap(cpu_profiler_connection_, connection); |
710 |
|
12 |
} |
711 |
|
|
|
712 |
|
|
inline profiler::V8CpuProfilerConnection* |
713 |
|
6529 |
Environment::cpu_profiler_connection() { |
714 |
|
6529 |
return cpu_profiler_connection_.get(); |
715 |
|
|
} |
716 |
|
|
|
717 |
|
12 |
inline void Environment::set_cpu_prof_interval(uint64_t interval) { |
718 |
|
12 |
cpu_prof_interval_ = interval; |
719 |
|
12 |
} |
720 |
|
|
|
721 |
|
12 |
inline uint64_t Environment::cpu_prof_interval() const { |
722 |
|
12 |
return cpu_prof_interval_; |
723 |
|
|
} |
724 |
|
|
|
725 |
|
12 |
inline void Environment::set_cpu_prof_name(const std::string& name) { |
726 |
|
12 |
cpu_prof_name_ = name; |
727 |
|
12 |
} |
728 |
|
|
|
729 |
|
12 |
inline const std::string& Environment::cpu_prof_name() const { |
730 |
|
12 |
return cpu_prof_name_; |
731 |
|
|
} |
732 |
|
|
|
733 |
|
12 |
inline void Environment::set_cpu_prof_dir(const std::string& dir) { |
734 |
|
12 |
cpu_prof_dir_ = dir; |
735 |
|
12 |
} |
736 |
|
|
|
737 |
|
12 |
inline const std::string& Environment::cpu_prof_dir() const { |
738 |
|
12 |
return cpu_prof_dir_; |
739 |
|
|
} |
740 |
|
|
|
741 |
|
12 |
inline void Environment::set_heap_profiler_connection( |
742 |
|
|
std::unique_ptr<profiler::V8HeapProfilerConnection> connection) { |
743 |
✗✓ |
12 |
CHECK_NULL(heap_profiler_connection_); |
744 |
|
12 |
std::swap(heap_profiler_connection_, connection); |
745 |
|
12 |
} |
746 |
|
|
|
747 |
|
|
inline profiler::V8HeapProfilerConnection* |
748 |
|
6517 |
Environment::heap_profiler_connection() { |
749 |
|
6517 |
return heap_profiler_connection_.get(); |
750 |
|
|
} |
751 |
|
|
|
752 |
|
12 |
inline void Environment::set_heap_prof_name(const std::string& name) { |
753 |
|
12 |
heap_prof_name_ = name; |
754 |
|
12 |
} |
755 |
|
|
|
756 |
|
12 |
inline const std::string& Environment::heap_prof_name() const { |
757 |
|
12 |
return heap_prof_name_; |
758 |
|
|
} |
759 |
|
|
|
760 |
|
12 |
inline void Environment::set_heap_prof_dir(const std::string& dir) { |
761 |
|
12 |
heap_prof_dir_ = dir; |
762 |
|
12 |
} |
763 |
|
|
|
764 |
|
12 |
inline const std::string& Environment::heap_prof_dir() const { |
765 |
|
12 |
return heap_prof_dir_; |
766 |
|
|
} |
767 |
|
|
|
768 |
|
12 |
inline void Environment::set_heap_prof_interval(uint64_t interval) { |
769 |
|
12 |
heap_prof_interval_ = interval; |
770 |
|
12 |
} |
771 |
|
|
|
772 |
|
12 |
inline uint64_t Environment::heap_prof_interval() const { |
773 |
|
12 |
return heap_prof_interval_; |
774 |
|
|
} |
775 |
|
|
|
776 |
|
|
#endif // HAVE_INSPECTOR |
777 |
|
|
|
778 |
|
|
inline |
779 |
|
13224 |
std::shared_ptr<ExclusiveAccess<HostPort>> Environment::inspector_host_port() { |
780 |
|
13224 |
return inspector_host_port_; |
781 |
|
|
} |
782 |
|
|
|
783 |
|
63232 |
inline std::shared_ptr<PerIsolateOptions> IsolateData::options() { |
784 |
|
63232 |
return options_; |
785 |
|
|
} |
786 |
|
|
|
787 |
|
289 |
inline void IsolateData::set_options( |
788 |
|
|
std::shared_ptr<PerIsolateOptions> options) { |
789 |
|
289 |
options_ = std::move(options); |
790 |
|
289 |
} |
791 |
|
|
|
792 |
|
|
template <typename Fn> |
793 |
|
93997 |
void Environment::SetImmediate(Fn&& cb, CallbackFlags::Flags flags) { |
794 |
|
187994 |
auto callback = native_immediates_.CreateCallback(std::move(cb), flags); |
795 |
|
93997 |
native_immediates_.Push(std::move(callback)); |
796 |
|
|
|
797 |
✓✓ |
93997 |
if (flags & CallbackFlags::kRefed) { |
798 |
✓✓ |
69392 |
if (immediate_info()->ref_count() == 0) |
799 |
|
50674 |
ToggleImmediateRef(true); |
800 |
|
69392 |
immediate_info()->ref_count_inc(1); |
801 |
|
|
} |
802 |
|
93997 |
} |
803 |
|
|
|
804 |
|
|
template <typename Fn> |
805 |
|
3801 |
void Environment::SetImmediateThreadsafe(Fn&& cb, CallbackFlags::Flags flags) { |
806 |
|
7602 |
auto callback = native_immediates_threadsafe_.CreateCallback( |
807 |
|
3801 |
std::move(cb), flags); |
808 |
|
|
{ |
809 |
|
7602 |
Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); |
810 |
|
3801 |
native_immediates_threadsafe_.Push(std::move(callback)); |
811 |
✓✓ |
3801 |
if (task_queues_async_initialized_) |
812 |
|
3792 |
uv_async_send(&task_queues_async_); |
813 |
|
|
} |
814 |
|
3801 |
} |
815 |
|
|
|
816 |
|
|
template <typename Fn> |
817 |
|
11869 |
void Environment::RequestInterrupt(Fn&& cb) { |
818 |
|
23738 |
auto callback = native_immediates_interrupts_.CreateCallback( |
819 |
|
11869 |
std::move(cb), CallbackFlags::kRefed); |
820 |
|
|
{ |
821 |
|
23738 |
Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); |
822 |
|
11869 |
native_immediates_interrupts_.Push(std::move(callback)); |
823 |
✓✓ |
11869 |
if (task_queues_async_initialized_) |
824 |
|
5237 |
uv_async_send(&task_queues_async_); |
825 |
|
|
} |
826 |
|
11869 |
RequestInterruptFromV8(); |
827 |
|
11869 |
} |
828 |
|
|
|
829 |
|
3093268 |
inline bool Environment::can_call_into_js() const { |
830 |
✓✓✓✓
|
3093268 |
return can_call_into_js_ && !is_stopping(); |
831 |
|
|
} |
832 |
|
|
|
833 |
|
2584 |
inline void Environment::set_can_call_into_js(bool can_call_into_js) { |
834 |
|
2584 |
can_call_into_js_ = can_call_into_js; |
835 |
|
2584 |
} |
836 |
|
|
|
837 |
|
1544277 |
inline bool Environment::has_run_bootstrapping_code() const { |
838 |
|
1544277 |
return has_run_bootstrapping_code_; |
839 |
|
|
} |
840 |
|
|
|
841 |
|
6528 |
inline void Environment::DoneBootstrapping() { |
842 |
|
6528 |
has_run_bootstrapping_code_ = true; |
843 |
|
|
// This adjusts the return value of base_object_created_after_bootstrap() so |
844 |
|
|
// that tests that check the count do not have to account for internally |
845 |
|
|
// created BaseObjects. |
846 |
|
6528 |
base_object_created_by_bootstrap_ = base_object_count_; |
847 |
|
6528 |
} |
848 |
|
|
|
849 |
|
19 |
inline bool Environment::has_serialized_options() const { |
850 |
|
19 |
return has_serialized_options_; |
851 |
|
|
} |
852 |
|
|
|
853 |
|
7054 |
inline void Environment::set_has_serialized_options(bool value) { |
854 |
|
7054 |
has_serialized_options_ = value; |
855 |
|
7054 |
} |
856 |
|
|
|
857 |
|
12413 |
inline bool Environment::is_main_thread() const { |
858 |
|
12413 |
return worker_context() == nullptr; |
859 |
|
|
} |
860 |
|
|
|
861 |
|
1647 |
inline bool Environment::no_native_addons() const { |
862 |
✓✓ |
3290 |
return (flags_ & EnvironmentFlags::kNoNativeAddons) || |
863 |
✓✓ |
3290 |
!options_->allow_native_addons; |
864 |
|
|
} |
865 |
|
|
|
866 |
|
6492 |
inline bool Environment::should_not_register_esm_loader() const { |
867 |
|
6492 |
return flags_ & EnvironmentFlags::kNoRegisterESMLoader; |
868 |
|
|
} |
869 |
|
|
|
870 |
|
18761 |
inline bool Environment::owns_process_state() const { |
871 |
|
18761 |
return flags_ & EnvironmentFlags::kOwnsProcessState; |
872 |
|
|
} |
873 |
|
|
|
874 |
|
6522 |
inline bool Environment::owns_inspector() const { |
875 |
|
6522 |
return flags_ & EnvironmentFlags::kOwnsInspector; |
876 |
|
|
} |
877 |
|
|
|
878 |
|
19517 |
inline bool Environment::should_create_inspector() const { |
879 |
|
19517 |
return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0; |
880 |
|
|
} |
881 |
|
|
|
882 |
|
135152 |
inline bool Environment::tracks_unmanaged_fds() const { |
883 |
|
135152 |
return flags_ & EnvironmentFlags::kTrackUnmanagedFds; |
884 |
|
|
} |
885 |
|
|
|
886 |
|
4255 |
inline bool Environment::hide_console_windows() const { |
887 |
|
4255 |
return flags_ & EnvironmentFlags::kHideConsoleWindows; |
888 |
|
|
} |
889 |
|
|
|
890 |
|
7962 |
inline bool Environment::no_global_search_paths() const { |
891 |
✓✗ |
15924 |
return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) || |
892 |
✗✓ |
15924 |
!options_->global_search_paths; |
893 |
|
|
} |
894 |
|
|
|
895 |
|
2762 |
inline bool Environment::no_browser_globals() const { |
896 |
|
|
// configure --no-browser-globals |
897 |
|
|
#ifdef NODE_NO_BROWSER_GLOBALS |
898 |
|
|
return true; |
899 |
|
|
#else |
900 |
|
2762 |
return flags_ & EnvironmentFlags::kNoBrowserGlobals; |
901 |
|
|
#endif |
902 |
|
|
} |
903 |
|
|
|
904 |
|
4 |
bool Environment::filehandle_close_warning() const { |
905 |
|
4 |
return emit_filehandle_warning_; |
906 |
|
|
} |
907 |
|
|
|
908 |
|
3 |
void Environment::set_filehandle_close_warning(bool on) { |
909 |
|
3 |
emit_filehandle_warning_ = on; |
910 |
|
3 |
} |
911 |
|
|
|
912 |
|
6337 |
void Environment::set_source_maps_enabled(bool on) { |
913 |
|
6337 |
source_maps_enabled_ = on; |
914 |
|
6337 |
} |
915 |
|
|
|
916 |
|
931 |
bool Environment::source_maps_enabled() const { |
917 |
|
931 |
return source_maps_enabled_; |
918 |
|
|
} |
919 |
|
|
|
920 |
|
9086 |
inline uint64_t Environment::thread_id() const { |
921 |
|
9086 |
return thread_id_; |
922 |
|
|
} |
923 |
|
|
|
924 |
|
20130 |
inline worker::Worker* Environment::worker_context() const { |
925 |
|
20130 |
return isolate_data()->worker_context(); |
926 |
|
|
} |
927 |
|
|
|
928 |
|
1467 |
inline void Environment::add_sub_worker_context(worker::Worker* context) { |
929 |
|
1467 |
sub_worker_contexts_.insert(context); |
930 |
|
1467 |
} |
931 |
|
|
|
932 |
|
1495 |
inline void Environment::remove_sub_worker_context(worker::Worker* context) { |
933 |
|
1495 |
sub_worker_contexts_.erase(context); |
934 |
|
1495 |
} |
935 |
|
|
|
936 |
|
|
template <typename Fn> |
937 |
|
24 |
inline void Environment::ForEachWorker(Fn&& iterator) { |
938 |
✓✓ |
26 |
for (worker::Worker* w : sub_worker_contexts_) iterator(w); |
939 |
|
24 |
} |
940 |
|
|
|
941 |
|
2921 |
inline void Environment::add_refs(int64_t diff) { |
942 |
|
2921 |
task_queues_async_refs_ += diff; |
943 |
✗✓ |
2921 |
CHECK_GE(task_queues_async_refs_, 0); |
944 |
✓✓ |
2921 |
if (task_queues_async_refs_ == 0) |
945 |
|
193 |
uv_unref(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); |
946 |
|
|
else |
947 |
|
2728 |
uv_ref(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); |
948 |
|
2921 |
} |
949 |
|
|
|
950 |
|
4640904 |
inline bool Environment::is_stopping() const { |
951 |
|
4640904 |
return is_stopping_.load(); |
952 |
|
|
} |
953 |
|
|
|
954 |
|
6844 |
inline void Environment::set_stopping(bool value) { |
955 |
|
6844 |
is_stopping_.store(value); |
956 |
|
6844 |
} |
957 |
|
|
|
958 |
|
14 |
inline std::list<node_module>* Environment::extra_linked_bindings() { |
959 |
|
14 |
return &extra_linked_bindings_; |
960 |
|
|
} |
961 |
|
|
|
962 |
|
10 |
inline node_module* Environment::extra_linked_bindings_head() { |
963 |
✓✓ |
10 |
return extra_linked_bindings_.size() > 0 ? |
964 |
|
10 |
&extra_linked_bindings_.front() : nullptr; |
965 |
|
|
} |
966 |
|
|
|
967 |
|
9 |
inline node_module* Environment::extra_linked_bindings_tail() { |
968 |
✓✓ |
9 |
return extra_linked_bindings_.size() > 0 ? |
969 |
|
9 |
&extra_linked_bindings_.back() : nullptr; |
970 |
|
|
} |
971 |
|
|
|
972 |
|
19 |
inline const Mutex& Environment::extra_linked_bindings_mutex() const { |
973 |
|
19 |
return extra_linked_bindings_mutex_; |
974 |
|
|
} |
975 |
|
|
|
976 |
|
44352 |
inline performance::PerformanceState* Environment::performance_state() { |
977 |
|
44352 |
return performance_state_.get(); |
978 |
|
|
} |
979 |
|
|
|
980 |
|
8457852 |
inline IsolateData* Environment::isolate_data() const { |
981 |
|
8457852 |
return isolate_data_; |
982 |
|
|
} |
983 |
|
|
|
984 |
|
68429 |
inline uv_buf_t Environment::allocate_managed_buffer( |
985 |
|
|
const size_t suggested_size) { |
986 |
|
136858 |
NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data()); |
987 |
|
|
std::unique_ptr<v8::BackingStore> bs = |
988 |
|
68429 |
v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size); |
989 |
|
68429 |
uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength()); |
990 |
|
68429 |
released_allocated_buffers_.emplace(buf.base, std::move(bs)); |
991 |
|
68429 |
return buf; |
992 |
|
|
} |
993 |
|
|
|
994 |
|
83281 |
inline std::unique_ptr<v8::BackingStore> Environment::release_managed_buffer( |
995 |
|
|
const uv_buf_t& buf) { |
996 |
|
83281 |
std::unique_ptr<v8::BackingStore> bs; |
997 |
✓✓ |
83281 |
if (buf.base != nullptr) { |
998 |
|
68429 |
auto it = released_allocated_buffers_.find(buf.base); |
999 |
✗✓ |
68429 |
CHECK_NE(it, released_allocated_buffers_.end()); |
1000 |
|
68429 |
bs = std::move(it->second); |
1001 |
|
68429 |
released_allocated_buffers_.erase(it); |
1002 |
|
|
} |
1003 |
|
83281 |
return bs; |
1004 |
|
|
} |
1005 |
|
|
|
1006 |
|
8 |
inline void Environment::ThrowError(const char* errmsg) { |
1007 |
|
8 |
ThrowError(v8::Exception::Error, errmsg); |
1008 |
|
8 |
} |
1009 |
|
|
|
1010 |
|
|
inline void Environment::ThrowTypeError(const char* errmsg) { |
1011 |
|
|
ThrowError(v8::Exception::TypeError, errmsg); |
1012 |
|
|
} |
1013 |
|
|
|
1014 |
|
|
inline void Environment::ThrowRangeError(const char* errmsg) { |
1015 |
|
|
ThrowError(v8::Exception::RangeError, errmsg); |
1016 |
|
|
} |
1017 |
|
|
|
1018 |
|
8 |
inline void Environment::ThrowError( |
1019 |
|
|
v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), |
1020 |
|
|
const char* errmsg) { |
1021 |
|
16 |
v8::HandleScope handle_scope(isolate()); |
1022 |
|
8 |
isolate()->ThrowException(fun(OneByteString(isolate(), errmsg))); |
1023 |
|
8 |
} |
1024 |
|
|
|
1025 |
|
7 |
inline void Environment::ThrowErrnoException(int errorno, |
1026 |
|
|
const char* syscall, |
1027 |
|
|
const char* message, |
1028 |
|
|
const char* path) { |
1029 |
|
|
isolate()->ThrowException( |
1030 |
|
7 |
ErrnoException(isolate(), errorno, syscall, message, path)); |
1031 |
|
7 |
} |
1032 |
|
|
|
1033 |
|
15 |
inline void Environment::ThrowUVException(int errorno, |
1034 |
|
|
const char* syscall, |
1035 |
|
|
const char* message, |
1036 |
|
|
const char* path, |
1037 |
|
|
const char* dest) { |
1038 |
|
|
isolate()->ThrowException( |
1039 |
|
15 |
UVException(isolate(), errorno, syscall, message, path, dest)); |
1040 |
|
15 |
} |
1041 |
|
|
|
1042 |
|
1460247 |
inline v8::Local<v8::FunctionTemplate> Environment::NewFunctionTemplate( |
1043 |
|
|
v8::FunctionCallback callback, |
1044 |
|
|
v8::Local<v8::Signature> signature, |
1045 |
|
|
v8::ConstructorBehavior behavior, |
1046 |
|
|
v8::SideEffectType side_effect_type, |
1047 |
|
|
const v8::CFunction* c_function) { |
1048 |
|
|
return v8::FunctionTemplate::New(isolate(), |
1049 |
|
|
callback, |
1050 |
|
|
v8::Local<v8::Value>(), |
1051 |
|
|
signature, |
1052 |
|
|
0, |
1053 |
|
|
behavior, |
1054 |
|
|
side_effect_type, |
1055 |
|
1460247 |
c_function); |
1056 |
|
|
} |
1057 |
|
|
|
1058 |
|
371046 |
inline void Environment::SetMethod(v8::Local<v8::Object> that, |
1059 |
|
|
const char* name, |
1060 |
|
|
v8::FunctionCallback callback) { |
1061 |
|
371046 |
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
1062 |
|
|
v8::Local<v8::Function> function = |
1063 |
|
371046 |
NewFunctionTemplate(callback, v8::Local<v8::Signature>(), |
1064 |
|
|
v8::ConstructorBehavior::kThrow, |
1065 |
|
371046 |
v8::SideEffectType::kHasSideEffect) |
1066 |
|
371046 |
->GetFunction(context) |
1067 |
|
371046 |
.ToLocalChecked(); |
1068 |
|
|
// kInternalized strings are created in the old space. |
1069 |
|
371046 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1070 |
|
|
v8::Local<v8::String> name_string = |
1071 |
|
742092 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1072 |
|
742092 |
that->Set(context, name_string, function).Check(); |
1073 |
|
371046 |
function->SetName(name_string); // NODE_SET_METHOD() compatibility. |
1074 |
|
371046 |
} |
1075 |
|
|
|
1076 |
|
2584 |
inline void Environment::SetFastMethod(v8::Local<v8::Object> that, |
1077 |
|
|
const char* name, |
1078 |
|
|
v8::FunctionCallback slow_callback, |
1079 |
|
|
const v8::CFunction* c_function) { |
1080 |
|
2584 |
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
1081 |
|
|
v8::Local<v8::Function> function = |
1082 |
|
2584 |
NewFunctionTemplate(slow_callback, |
1083 |
|
|
v8::Local<v8::Signature>(), |
1084 |
|
|
v8::ConstructorBehavior::kThrow, |
1085 |
|
|
v8::SideEffectType::kHasNoSideEffect, |
1086 |
|
2584 |
c_function) |
1087 |
|
2584 |
->GetFunction(context) |
1088 |
|
2584 |
.ToLocalChecked(); |
1089 |
|
2584 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1090 |
|
|
v8::Local<v8::String> name_string = |
1091 |
|
5168 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1092 |
|
2584 |
that->Set(context, name_string, function).Check(); |
1093 |
|
2584 |
} |
1094 |
|
|
|
1095 |
|
112568 |
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that, |
1096 |
|
|
const char* name, |
1097 |
|
|
v8::FunctionCallback callback) { |
1098 |
|
112568 |
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
1099 |
|
|
v8::Local<v8::Function> function = |
1100 |
|
112568 |
NewFunctionTemplate(callback, v8::Local<v8::Signature>(), |
1101 |
|
|
v8::ConstructorBehavior::kThrow, |
1102 |
|
112568 |
v8::SideEffectType::kHasNoSideEffect) |
1103 |
|
112568 |
->GetFunction(context) |
1104 |
|
112568 |
.ToLocalChecked(); |
1105 |
|
|
// kInternalized strings are created in the old space. |
1106 |
|
112568 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1107 |
|
|
v8::Local<v8::String> name_string = |
1108 |
|
225136 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1109 |
|
225136 |
that->Set(context, name_string, function).Check(); |
1110 |
|
112568 |
function->SetName(name_string); // NODE_SET_METHOD() compatibility. |
1111 |
|
112568 |
} |
1112 |
|
|
|
1113 |
|
669799 |
inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that, |
1114 |
|
|
const char* name, |
1115 |
|
|
v8::FunctionCallback callback) { |
1116 |
|
669799 |
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that); |
1117 |
|
|
v8::Local<v8::FunctionTemplate> t = |
1118 |
|
|
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, |
1119 |
|
669799 |
v8::SideEffectType::kHasSideEffect); |
1120 |
|
|
// kInternalized strings are created in the old space. |
1121 |
|
669799 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1122 |
|
|
v8::Local<v8::String> name_string = |
1123 |
|
1339598 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1124 |
|
1339598 |
that->PrototypeTemplate()->Set(name_string, t); |
1125 |
|
669799 |
t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. |
1126 |
|
669799 |
} |
1127 |
|
|
|
1128 |
|
97714 |
inline void Environment::SetProtoMethodNoSideEffect( |
1129 |
|
|
v8::Local<v8::FunctionTemplate> that, |
1130 |
|
|
const char* name, |
1131 |
|
|
v8::FunctionCallback callback) { |
1132 |
|
97714 |
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that); |
1133 |
|
|
v8::Local<v8::FunctionTemplate> t = |
1134 |
|
|
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, |
1135 |
|
97714 |
v8::SideEffectType::kHasNoSideEffect); |
1136 |
|
|
// kInternalized strings are created in the old space. |
1137 |
|
97714 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1138 |
|
|
v8::Local<v8::String> name_string = |
1139 |
|
195428 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1140 |
|
195428 |
that->PrototypeTemplate()->Set(name_string, t); |
1141 |
|
97714 |
t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. |
1142 |
|
97714 |
} |
1143 |
|
|
|
1144 |
|
33 |
inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that, |
1145 |
|
|
const char* name, |
1146 |
|
|
v8::FunctionCallback callback) { |
1147 |
|
33 |
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that); |
1148 |
|
|
v8::Local<v8::FunctionTemplate> t = |
1149 |
|
|
NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, |
1150 |
|
33 |
v8::SideEffectType::kHasSideEffect); |
1151 |
|
|
// kInternalized strings are created in the old space. |
1152 |
|
33 |
const v8::NewStringType type = v8::NewStringType::kInternalized; |
1153 |
|
|
v8::Local<v8::String> name_string = |
1154 |
|
66 |
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked(); |
1155 |
|
66 |
that->InstanceTemplate()->Set(name_string, t); |
1156 |
|
33 |
t->SetClassName(name_string); |
1157 |
|
33 |
} |
1158 |
|
|
|
1159 |
|
133404 |
inline void Environment::SetConstructorFunction( |
1160 |
|
|
v8::Local<v8::Object> that, |
1161 |
|
|
const char* name, |
1162 |
|
|
v8::Local<v8::FunctionTemplate> tmpl, |
1163 |
|
|
SetConstructorFunctionFlag flag) { |
1164 |
|
133404 |
SetConstructorFunction(that, OneByteString(isolate(), name), tmpl, flag); |
1165 |
|
133404 |
} |
1166 |
|
|
|
1167 |
|
139864 |
inline void Environment::SetConstructorFunction( |
1168 |
|
|
v8::Local<v8::Object> that, |
1169 |
|
|
v8::Local<v8::String> name, |
1170 |
|
|
v8::Local<v8::FunctionTemplate> tmpl, |
1171 |
|
|
SetConstructorFunctionFlag flag) { |
1172 |
✓✓ |
139864 |
if (LIKELY(flag == SetConstructorFunctionFlag::SET_CLASS_NAME)) |
1173 |
|
125590 |
tmpl->SetClassName(name); |
1174 |
|
139864 |
that->Set( |
1175 |
|
|
context(), |
1176 |
|
|
name, |
1177 |
|
279728 |
tmpl->GetFunction(context()).ToLocalChecked()).Check(); |
1178 |
|
139864 |
} |
1179 |
|
|
|
1180 |
|
1458814 |
void Environment::AddCleanupHook(CleanupCallback fn, void* arg) { |
1181 |
|
2917628 |
auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback { |
1182 |
|
1458814 |
fn, arg, cleanup_hook_counter_++ |
1183 |
|
1458814 |
}); |
1184 |
|
|
// Make sure there was no existing element with these values. |
1185 |
✗✓ |
1458814 |
CHECK_EQ(insertion_info.second, true); |
1186 |
|
1458814 |
} |
1187 |
|
|
|
1188 |
|
1441864 |
void Environment::RemoveCleanupHook(CleanupCallback fn, void* arg) { |
1189 |
|
1441864 |
CleanupHookCallback search { fn, arg, 0 }; |
1190 |
|
1441864 |
cleanup_hooks_.erase(search); |
1191 |
|
1441864 |
} |
1192 |
|
|
|
1193 |
|
3206527 |
size_t CleanupHookCallback::Hash::operator()( |
1194 |
|
|
const CleanupHookCallback& cb) const { |
1195 |
|
3206527 |
return std::hash<void*>()(cb.arg_); |
1196 |
|
|
} |
1197 |
|
|
|
1198 |
|
1599917 |
bool CleanupHookCallback::Equal::operator()( |
1199 |
|
|
const CleanupHookCallback& a, const CleanupHookCallback& b) const { |
1200 |
✓✓✓✗
|
1599917 |
return a.fn_ == b.fn_ && a.arg_ == b.arg_; |
1201 |
|
|
} |
1202 |
|
|
|
1203 |
|
541 |
BaseObject* CleanupHookCallback::GetBaseObject() const { |
1204 |
✓✓ |
541 |
if (fn_ == BaseObject::DeleteMe) |
1205 |
|
513 |
return static_cast<BaseObject*>(arg_); |
1206 |
|
|
else |
1207 |
|
28 |
return nullptr; |
1208 |
|
|
} |
1209 |
|
|
|
1210 |
|
|
template <typename T> |
1211 |
|
48 |
void Environment::ForEachBaseObject(T&& iterator) { |
1212 |
✓✓ |
1130 |
for (const auto& hook : cleanup_hooks_) { |
1213 |
|
1082 |
BaseObject* obj = hook.GetBaseObject(); |
1214 |
✓✓ |
1082 |
if (obj != nullptr) |
1215 |
|
1026 |
iterator(obj); |
1216 |
|
|
} |
1217 |
|
|
} |
1218 |
|
|
|
1219 |
|
|
template <typename T> |
1220 |
|
6 |
void Environment::ForEachBindingData(T&& iterator) { |
1221 |
|
|
BindingDataStore* map = static_cast<BindingDataStore*>( |
1222 |
|
12 |
context()->GetAlignedPointerFromEmbedderData( |
1223 |
|
|
ContextEmbedderIndex::kBindingListIndex)); |
1224 |
|
|
DCHECK_NOT_NULL(map); |
1225 |
✓✓ |
30 |
for (auto& it : *map) { |
1226 |
|
24 |
iterator(it.first, it.second); |
1227 |
|
|
} |
1228 |
|
6 |
} |
1229 |
|
|
|
1230 |
|
2840686 |
void Environment::modify_base_object_count(int64_t delta) { |
1231 |
|
2840686 |
base_object_count_ += delta; |
1232 |
|
2840686 |
} |
1233 |
|
|
|
1234 |
|
14 |
int64_t Environment::base_object_created_after_bootstrap() const { |
1235 |
|
14 |
return base_object_count_ - base_object_created_by_bootstrap_; |
1236 |
|
|
} |
1237 |
|
|
|
1238 |
|
2 |
int64_t Environment::base_object_count() const { |
1239 |
|
2 |
return base_object_count_; |
1240 |
|
|
} |
1241 |
|
|
|
1242 |
|
17 |
void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) { |
1243 |
✗✓ |
17 |
CHECK(!main_utf16_); |
1244 |
|
17 |
main_utf16_ = std::move(str); |
1245 |
|
17 |
} |
1246 |
|
|
|
1247 |
|
1237 |
void Environment::set_process_exit_handler( |
1248 |
|
|
std::function<void(Environment*, int)>&& handler) { |
1249 |
|
1237 |
process_exit_handler_ = std::move(handler); |
1250 |
|
1237 |
} |
1251 |
|
|
|
1252 |
|
|
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
1253 |
|
|
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
1254 |
|
|
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
1255 |
|
|
#define V(TypeName, PropertyName) \ |
1256 |
|
|
inline \ |
1257 |
|
|
v8::Local<TypeName> IsolateData::PropertyName() const { \ |
1258 |
|
|
return PropertyName ## _ .Get(isolate_); \ |
1259 |
|
|
} |
1260 |
|
44122 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
1261 |
|
996512 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
1262 |
|
8336987 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
1263 |
|
|
#undef V |
1264 |
|
|
#undef VS |
1265 |
|
|
#undef VY |
1266 |
|
|
#undef VP |
1267 |
|
|
|
1268 |
|
|
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName) |
1269 |
|
|
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) |
1270 |
|
|
#define VS(PropertyName, StringValue) V(v8::String, PropertyName) |
1271 |
|
|
#define V(TypeName, PropertyName) \ |
1272 |
|
|
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
1273 |
|
|
return isolate_data()->PropertyName(); \ |
1274 |
|
|
} |
1275 |
|
44122 |
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) |
1276 |
|
872680 |
PER_ISOLATE_SYMBOL_PROPERTIES(VY) |
1277 |
|
11999931 |
PER_ISOLATE_STRING_PROPERTIES(VS) |
1278 |
|
|
#undef V |
1279 |
|
|
#undef VS |
1280 |
|
|
#undef VY |
1281 |
|
|
#undef VP |
1282 |
|
|
|
1283 |
|
|
#define V(PropertyName, TypeName) \ |
1284 |
|
|
inline v8::Local<TypeName> Environment::PropertyName() const { \ |
1285 |
|
|
return PersistentToLocal::Strong(PropertyName ## _); \ |
1286 |
|
|
} \ |
1287 |
|
|
inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) { \ |
1288 |
|
|
PropertyName ## _.Reset(isolate(), value); \ |
1289 |
|
|
} |
1290 |
|
1360468 |
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V) |
1291 |
|
6266004 |
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V) |
1292 |
|
|
#undef V |
1293 |
|
|
|
1294 |
|
9410253 |
v8::Local<v8::Context> Environment::context() const { |
1295 |
|
9410253 |
return PersistentToLocal::Strong(context_); |
1296 |
|
|
} |
1297 |
|
|
|
1298 |
|
|
} // namespace node |
1299 |
|
|
|
1300 |
|
|
// These two files depend on each other. Including base_object-inl.h after this |
1301 |
|
|
// file is the easiest way to avoid issues with that circular dependency. |
1302 |
|
|
#include "base_object-inl.h" |
1303 |
|
|
|
1304 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
1305 |
|
|
|
1306 |
|
|
#endif // SRC_ENV_INL_H_ |