GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/env-inl.h Lines: 622 628 99.0 %
Date: 2020-05-27 22:15:15 Branches: 90 122 73.8 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#ifndef SRC_ENV_INL_H_
23
#define SRC_ENV_INL_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "aliased_buffer.h"
28
#include "callback_queue-inl.h"
29
#include "env.h"
30
#include "node.h"
31
#include "util-inl.h"
32
#include "uv.h"
33
#include "v8.h"
34
#include "node_perf_common.h"
35
#include "node_context_data.h"
36
37
#include <cstddef>
38
#include <cstdint>
39
40
#include <utility>
41
42
namespace node {
43
44
inline v8::Isolate* IsolateData::isolate() const {
45
  return isolate_;
46
}
47
48
683654
inline uv_loop_t* IsolateData::event_loop() const {
49
683654
  return event_loop_;
50
}
51
52
294343
inline bool IsolateData::uses_node_allocator() const {
53
294343
  return uses_node_allocator_;
54
}
55
56
400827
inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const {
57
400827
  return allocator_;
58
}
59
60
299939
inline NodeArrayBufferAllocator* IsolateData::node_allocator() const {
61
299939
  return node_allocator_;
62
}
63
64
45639
inline MultiIsolatePlatform* IsolateData::platform() const {
65
45639
  return platform_;
66
}
67
68
315
inline void IsolateData::set_worker_context(worker::Worker* context) {
69
315
  CHECK_NULL(worker_context_);  // Should be set only once.
70
315
  worker_context_ = context;
71
315
}
72
73
22003
inline worker::Worker* IsolateData::worker_context() const {
74
22003
  return worker_context_;
75
}
76
77
182935
inline v8::Local<v8::String> IsolateData::async_wrap_provider(int index) const {
78
365870
  return async_wrap_providers_[index].Get(isolate_);
79
}
80
81
4594
inline AsyncHooks::AsyncHooks()
82
    : async_ids_stack_(env()->isolate(), 16 * 2),
83
      fields_(env()->isolate(), kFieldsCount),
84
4594
      async_id_fields_(env()->isolate(), kUidFieldsCount) {
85
4594
  clear_async_id_stack();
86
87
  // Always perform async_hooks checks, not just when async_hooks is enabled.
88
  // TODO(AndreasMadsen): Consider removing this for LTS releases.
89
  // See discussion in https://github.com/nodejs/node/pull/15454
90
  // When removing this, do it by reverting the commit. Otherwise the test
91
  // and flag changes won't be included.
92
4594
  fields_[kCheck] = 1;
93
94
  // kDefaultTriggerAsyncId should be -1, this indicates that there is no
95
  // specified default value and it should fallback to the executionAsyncId.
96
  // 0 is not used as the magic value, because that indicates a missing context
97
  // which is different from a default context.
98
4594
  async_id_fields_[AsyncHooks::kDefaultTriggerAsyncId] = -1;
99
100
  // kAsyncIdCounter should start at 1 because that'll be the id the execution
101
  // context during bootstrap (code that runs before entering uv_run()).
102
4594
  async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1;
103
4594
}
104
2726247
inline AliasedUint32Array& AsyncHooks::fields() {
105
2726247
  return fields_;
106
}
107
108
2210262
inline AliasedFloat64Array& AsyncHooks::async_id_fields() {
109
2210262
  return async_id_fields_;
110
}
111
112
4594
inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
113
4594
  return async_ids_stack_;
114
}
115
116
1327763
inline v8::Local<v8::Array> AsyncHooks::execution_async_resources() {
117
1327763
  return PersistentToLocal::Strong(execution_async_resources_);
118
}
119
120
182888
inline v8::Local<v8::String> AsyncHooks::provider_string(int idx) {
121
182888
  return env()->isolate_data()->async_wrap_provider(idx);
122
}
123
124
1
inline void AsyncHooks::no_force_checks() {
125
1
  fields_[kCheck] -= 1;
126
1
}
127
128
2185866
inline Environment* AsyncHooks::env() {
129
2185866
  return Environment::ForAsyncHooks(this);
130
}
131
132
// Remember to keep this code aligned with pushAsyncContext() in JS.
133
661722
inline void AsyncHooks::push_async_context(double async_id,
134
                                           double trigger_async_id,
135
                                           v8::Local<v8::Value> resource) {
136
1323791
  v8::HandleScope handle_scope(env()->isolate());
137
138
  // Since async_hooks is experimental, do only perform the check
139
  // when async_hooks is enabled.
140
662077
  if (fields_[kCheck] > 0) {
141
662038
    CHECK_GE(async_id, -1);
142
662038
    CHECK_GE(trigger_async_id, -1);
143
  }
144
145
662045
  uint32_t offset = fields_[kStackLength];
146
662084
  if (offset * 2 >= async_ids_stack_.Length())
147
4
    grow_async_ids_stack();
148
662015
  async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId];
149
662091
  async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId];
150
662069
  fields_[kStackLength] += 1;
151
662091
  async_id_fields_[kExecutionAsyncId] = async_id;
152
662098
  async_id_fields_[kTriggerAsyncId] = trigger_async_id;
153
154
662079
  auto resources = execution_async_resources();
155
1324130
  USE(resources->Set(env()->context(), offset, resource));
156
662074
}
157
158
// Remember to keep this code aligned with popAsyncContext() in JS.
159
661738
inline bool AsyncHooks::pop_async_context(double async_id) {
160
  // In case of an exception then this may have already been reset, if the
161
  // stack was multiple MakeCallback()'s deep.
162
661738
  if (fields_[kStackLength] == 0) return false;
163
164
  // Ask for the async_id to be restored as a check that the stack
165
  // hasn't been corrupted.
166
  // Since async_hooks is experimental, do only perform the check
167
  // when async_hooks is enabled.
168

661101
  if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) {
169
4
    fprintf(stderr,
170
            "Error: async hook stack has become corrupted ("
171
            "actual: %.f, expected: %.f)\n",
172
            async_id_fields_.GetValue(kExecutionAsyncId),
173
4
            async_id);
174
4
    DumpBacktrace(stderr);
175
4
    fflush(stderr);
176
4
    if (!env()->abort_on_uncaught_exception())
177
4
      exit(1);
178
    fprintf(stderr, "\n");
179
    fflush(stderr);
180
    ABORT_NO_BACKTRACE();
181
  }
182
183
661098
  uint32_t offset = fields_[kStackLength] - 1;
184
661101
  async_id_fields_[kExecutionAsyncId] = async_ids_stack_[2 * offset];
185
661097
  async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1];
186
661097
  fields_[kStackLength] = offset;
187
188
661094
  auto resources = execution_async_resources();
189
1322196
  USE(resources->Delete(env()->context(), offset));
190
191
661099
  return fields_[kStackLength] > 0;
192
}
193
194
// Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js.
195
4640
inline void AsyncHooks::clear_async_id_stack() {
196
4640
  auto isolate = env()->isolate();
197
9280
  v8::HandleScope handle_scope(isolate);
198
9280
  execution_async_resources_.Reset(isolate, v8::Array::New(isolate));
199
200
4640
  async_id_fields_[kExecutionAsyncId] = 0;
201
4640
  async_id_fields_[kTriggerAsyncId] = 0;
202
4640
  fields_[kStackLength] = 0;
203
4640
}
204
205
// The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in
206
// async_wrap-inl.h to avoid a circular dependency.
207
208
475364
inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope(
209
475364
    Environment* env, double default_trigger_async_id)
210
475364
    : async_hooks_(env->async_hooks()) {
211
475364
  if (env->async_hooks()->fields()[AsyncHooks::kCheck] > 0) {
212
475364
    CHECK_GE(default_trigger_async_id, 0);
213
  }
214
215
475364
  old_default_trigger_async_id_ =
216
950728
    async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId];
217
475364
  async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] =
218
475364
    default_trigger_async_id;
219
475364
}
220
221
950726
inline AsyncHooks::DefaultTriggerAsyncIdScope ::~DefaultTriggerAsyncIdScope() {
222
475363
  async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] =
223
950726
    old_default_trigger_async_id_;
224
475363
}
225
226
2185662
Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) {
227
2185662
  return ContainerOf(&Environment::async_hooks_, hooks);
228
}
229
230
661687
inline size_t Environment::async_callback_scope_depth() const {
231
661687
  return async_callback_scope_depth_;
232
}
233
234
661561
inline void Environment::PushAsyncCallbackScope() {
235
661561
  async_callback_scope_depth_++;
236
661561
}
237
238
661876
inline void Environment::PopAsyncCallbackScope() {
239
661876
  async_callback_scope_depth_--;
240
661876
}
241
242
4594
inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate)
243
4594
    : fields_(isolate, kFieldsCount) {}
244
245
4594
inline AliasedUint32Array& ImmediateInfo::fields() {
246
4594
  return fields_;
247
}
248
249
401526
inline uint32_t ImmediateInfo::count() const {
250
401526
  return fields_[kCount];
251
}
252
253
474048
inline uint32_t ImmediateInfo::ref_count() const {
254
474048
  return fields_[kRefCount];
255
}
256
257
30715
inline bool ImmediateInfo::has_outstanding() const {
258
30715
  return fields_[kHasOutstanding] == 1;
259
}
260
261
32897
inline void ImmediateInfo::ref_count_inc(uint32_t increment) {
262
32897
  fields_[kRefCount] += increment;
263
32897
}
264
265
410976
inline void ImmediateInfo::ref_count_dec(uint32_t decrement) {
266
410976
  fields_[kRefCount] -= decrement;
267
410986
}
268
269
4594
inline TickInfo::TickInfo(v8::Isolate* isolate)
270
4594
    : fields_(isolate, kFieldsCount) {}
271
272
4594
inline AliasedUint8Array& TickInfo::fields() {
273
4594
  return fields_;
274
}
275
276
1200944
inline bool TickInfo::has_tick_scheduled() const {
277
1200944
  return fields_[kHasTickScheduled] == 1;
278
}
279
280
183329
inline bool TickInfo::has_rejection_to_warn() const {
281
183329
  return fields_[kHasRejectionToWarn] == 1;
282
}
283
284
5172
inline void Environment::AssignToContext(v8::Local<v8::Context> context,
285
                                         const ContextInfo& info) {
286
5172
  context->SetAlignedPointerInEmbedderData(
287
5172
      ContextEmbedderIndex::kEnvironment, this);
288
  // Used by Environment::GetCurrent to know that we are on a node context.
289
10344
  context->SetAlignedPointerInEmbedderData(
290
5172
    ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr);
291
  // Used to retrieve bindings
292
5172
  context->SetAlignedPointerInEmbedderData(
293
10344
      ContextEmbedderIndex::kBindingListIndex, &(this->bindings_));
294
295
#if HAVE_INSPECTOR
296
5172
  inspector_agent()->ContextCreated(context, info);
297
#endif  // HAVE_INSPECTOR
298
5172
}
299
300
683523
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
301
683523
  if (UNLIKELY(!isolate->InContext())) return nullptr;
302
1367408
  v8::HandleScope handle_scope(isolate);
303
683767
  return GetCurrent(isolate->GetCurrentContext());
304
}
305
306
6369538
inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
307
6369538
  if (UNLIKELY(context.IsEmpty())) {
308
1
    return nullptr;
309
  }
310
6369537
  if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <=
311
               ContextEmbedderIndex::kContextTag)) {
312
11
    return nullptr;
313
  }
314
12738866
  if (UNLIKELY(context->GetAlignedPointerFromEmbedderData(
315
                   ContextEmbedderIndex::kContextTag) !=
316
               Environment::kNodeContextTagPtr)) {
317
    return nullptr;
318
  }
319
  return static_cast<Environment*>(
320
6369433
      context->GetAlignedPointerFromEmbedderData(
321
6369433
          ContextEmbedderIndex::kEnvironment));
322
}
323
324
4287501
inline Environment* Environment::GetCurrent(
325
    const v8::FunctionCallbackInfo<v8::Value>& info) {
326
4287501
  return GetCurrent(info.GetIsolate()->GetCurrentContext());
327
}
328
329
template <typename T>
330
1082132
inline Environment* Environment::GetCurrent(
331
    const v8::PropertyCallbackInfo<T>& info) {
332
1082132
  return GetCurrent(info.GetIsolate()->GetCurrentContext());
333
}
334
335
template <typename T, typename U>
336
inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) {
337
  return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
338
}
339
340
template <typename T>
341
506450
inline T* Environment::GetBindingData(
342
    const v8::FunctionCallbackInfo<v8::Value>& info) {
343
506450
  return GetBindingData<T>(info.GetIsolate()->GetCurrentContext());
344
}
345
346
template <typename T>
347
506450
inline T* Environment::GetBindingData(v8::Local<v8::Context> context) {
348
  BindingDataStore* map = static_cast<BindingDataStore*>(
349
506450
      context->GetAlignedPointerFromEmbedderData(
350
506450
          ContextEmbedderIndex::kBindingListIndex));
351
  DCHECK_NOT_NULL(map);
352
506450
  auto it = map->find(T::binding_data_name);
353
506450
  if (UNLIKELY(it == map->end())) return nullptr;
354
506449
  T* result = static_cast<T*>(it->second.get());
355
  DCHECK_NOT_NULL(result);
356
  DCHECK_EQ(result->env(), GetCurrent(context));
357
506450
  return result;
358
}
359
360
template <typename T>
361
6018
inline T* Environment::AddBindingData(
362
    v8::Local<v8::Context> context,
363
    v8::Local<v8::Object> target) {
364
  DCHECK_EQ(GetCurrent(context), this);
365
  // This won't compile if T is not a BaseObject subclass.
366
12036
  BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target);
367
  BindingDataStore* map = static_cast<BindingDataStore*>(
368
6018
      context->GetAlignedPointerFromEmbedderData(
369
6018
          ContextEmbedderIndex::kBindingListIndex));
370
  DCHECK_NOT_NULL(map);
371
6018
  auto result = map->emplace(T::binding_data_name, item);
372
6018
  CHECK(result.second);
373
  DCHECK_EQ(GetBindingData<T>(context), item.get());
374
12036
  return item.get();
375
}
376
377
1
inline Environment* Environment::GetThreadLocalEnv() {
378
1
  return static_cast<Environment*>(uv_key_get(&thread_local_env));
379
}
380
381
inline bool Environment::profiler_idle_notifier_started() const {
382
  return profiler_idle_notifier_started_;
383
}
384
385
29164712
inline v8::Isolate* Environment::isolate() const {
386
29164712
  return isolate_;
387
}
388
389
4615
inline Environment* Environment::from_timer_handle(uv_timer_t* handle) {
390
4615
  return ContainerOf(&Environment::timer_handle_, handle);
391
}
392
393
20469
inline uv_timer_t* Environment::timer_handle() {
394
20469
  return &timer_handle_;
395
}
396
397
401521
inline Environment* Environment::from_immediate_check_handle(
398
    uv_check_t* handle) {
399
401521
  return ContainerOf(&Environment::immediate_check_handle_, handle);
400
}
401
402
18280
inline uv_check_t* Environment::immediate_check_handle() {
403
18280
  return &immediate_check_handle_;
404
}
405
406
438382
inline uv_idle_t* Environment::immediate_idle_handle() {
407
438382
  return &immediate_idle_handle_;
408
}
409
410
27420
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
411
                                               HandleCleanupCb cb,
412
                                               void* arg) {
413
27420
  handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg});
414
27420
}
415
416
template <typename T, typename OnCloseCallback>
417
28770
inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) {
418
28770
  handle_cleanup_waiting_++;
419
  static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle");
420
  static_assert(offsetof(T, data) == offsetof(uv_handle_t, data),
421
                "T is a libuv handle");
422
  static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb),
423
                "T is a libuv handle");
424
  struct CloseData {
425
    Environment* env;
426
    OnCloseCallback callback;
427
    void* original_data;
428
  };
429
28770
  handle->data = new CloseData { this, callback, handle->data };
430
115077
  uv_close(reinterpret_cast<uv_handle_t*>(handle), [](uv_handle_t* handle) {
431
57542
    std::unique_ptr<CloseData> data { static_cast<CloseData*>(handle->data) };
432
28771
    data->env->handle_cleanup_waiting_--;
433
28771
    handle->data = data->original_data;
434
28771
    data->callback(reinterpret_cast<T*>(handle));
435
28771
  });
436
28766
}
437
438
75638
void Environment::IncreaseWaitingRequestCounter() {
439
75638
  request_waiting_++;
440
75638
}
441
442
75630
void Environment::DecreaseWaitingRequestCounter() {
443
75630
  request_waiting_--;
444
75630
  CHECK_GE(request_waiting_, 0);
445
75630
}
446
447
679055
inline uv_loop_t* Environment::event_loop() const {
448
679055
  return isolate_data()->event_loop();
449
}
450
451
152
inline void Environment::TryLoadAddon(
452
    const char* filename,
453
    int flags,
454
    const std::function<bool(binding::DLib*)>& was_loaded) {
455
152
  loaded_addons_.emplace_back(filename, flags);
456
152
  if (!was_loaded(&loaded_addons_.back())) {
457
8
    loaded_addons_.pop_back();
458
  }
459
152
}
460
461
#if HAVE_INSPECTOR
462
40355
inline bool Environment::is_in_inspector_console_call() const {
463
40355
  return is_in_inspector_console_call_;
464
}
465
466
80708
inline void Environment::set_is_in_inspector_console_call(bool value) {
467
80708
  is_in_inspector_console_call_ = value;
468
80708
}
469
#endif
470
471
5501222
inline AsyncHooks* Environment::async_hooks() {
472
5501222
  return &async_hooks_;
473
}
474
475
1354764
inline ImmediateInfo* Environment::immediate_info() {
476
1354764
  return &immediate_info_;
477
}
478
479
605084
inline TickInfo* Environment::tick_info() {
480
605084
  return &tick_info_;
481
}
482
483
46420
inline uint64_t Environment::timer_base() const {
484
46420
  return timer_base_;
485
}
486
487
1094720
inline std::shared_ptr<KVStore> Environment::env_vars() {
488
1094720
  return env_vars_;
489
}
490
491
4894
inline void Environment::set_env_vars(std::shared_ptr<KVStore> env_vars) {
492
4894
  env_vars_ = env_vars;
493
4894
}
494
495
14
inline bool Environment::printed_error() const {
496
14
  return printed_error_;
497
}
498
499
14
inline void Environment::set_printed_error(bool value) {
500
14
  printed_error_ = value;
501
14
}
502
503
7824
inline void Environment::set_trace_sync_io(bool value) {
504
7824
  trace_sync_io_ = value;
505
7824
}
506
507
28
inline bool Environment::abort_on_uncaught_exception() const {
508
28
  return options_->abort_on_uncaught_exception;
509
}
510
511
inline void Environment::set_abort_on_uncaught_exception(bool value) {
512
  options_->abort_on_uncaught_exception = value;
513
}
514
515
4625
inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() {
516
4625
  return should_abort_on_uncaught_toggle_;
517
}
518
519
1298959
inline AliasedInt32Array& Environment::stream_base_state() {
520
1298959
  return stream_base_state_;
521
}
522
523
30785
inline uint32_t Environment::get_next_module_id() {
524
30785
  return module_id_counter_++;
525
}
526
1860
inline uint32_t Environment::get_next_script_id() {
527
1860
  return script_id_counter_++;
528
}
529
24854
inline uint32_t Environment::get_next_function_id() {
530
24854
  return function_id_counter_++;
531
}
532
533
63230
ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope(
534
63230
    Environment* env)
535
63230
    : env_(env) {
536
63230
  env_->PushShouldNotAbortOnUncaughtScope();
537
63231
}
538
539
126457
ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() {
540
63228
  Close();
541
63229
}
542
543
63408
void ShouldNotAbortOnUncaughtScope::Close() {
544
63408
  if (env_ != nullptr) {
545
63228
    env_->PopShouldNotAbortOnUncaughtScope();
546
63228
    env_ = nullptr;
547
  }
548
63408
}
549
550
63231
inline void Environment::PushShouldNotAbortOnUncaughtScope() {
551
63231
  should_not_abort_scope_counter_++;
552
63231
}
553
554
63228
inline void Environment::PopShouldNotAbortOnUncaughtScope() {
555
63228
  should_not_abort_scope_counter_--;
556
63228
}
557
558
1
inline bool Environment::inside_should_not_abort_on_uncaught_scope() const {
559
1
  return should_not_abort_scope_counter_ > 0;
560
}
561
562
199200
inline std::vector<double>* Environment::destroy_async_id_list() {
563
199200
  return &destroy_async_id_list_;
564
}
565
566
183451
inline double Environment::new_async_id() {
567
183451
  async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1;
568
183451
  return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter];
569
}
570
571
191095
inline double Environment::execution_async_id() {
572
191095
  return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId];
573
}
574
575
38135
inline double Environment::trigger_async_id() {
576
38135
  return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId];
577
}
578
579
183448
inline double Environment::get_default_trigger_async_id() {
580
  double default_trigger_async_id =
581
183448
    async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId];
582
  // If defaultTriggerAsyncId isn't set, use the executionAsyncId
583
183448
  if (default_trigger_async_id < 0)
584
152416
    default_trigger_async_id = execution_async_id();
585
183448
  return default_trigger_async_id;
586
}
587
588
47854
inline std::shared_ptr<EnvironmentOptions> Environment::options() {
589
47854
  return options_;
590
}
591
592
13316
inline const std::vector<std::string>& Environment::argv() {
593
13316
  return argv_;
594
}
595
596
5078
inline const std::vector<std::string>& Environment::exec_argv() {
597
5078
  return exec_argv_;
598
}
599
600
9140
inline const std::string& Environment::exec_path() const {
601
9140
  return exec_path_;
602
}
603
604
#if HAVE_INSPECTOR
605
4561
inline void Environment::set_coverage_directory(const char* dir) {
606
4561
  coverage_directory_ = std::string(dir);
607
4561
}
608
609
4582
inline void Environment::set_coverage_connection(
610
    std::unique_ptr<profiler::V8CoverageConnection> connection) {
611
4582
  CHECK_NULL(coverage_connection_);
612
4583
  std::swap(coverage_connection_, connection);
613
4584
}
614
615
13747
inline profiler::V8CoverageConnection* Environment::coverage_connection() {
616
13747
  return coverage_connection_.get();
617
}
618
619
4543
inline const std::string& Environment::coverage_directory() const {
620
4543
  return coverage_directory_;
621
}
622
623
10
inline void Environment::set_cpu_profiler_connection(
624
    std::unique_ptr<profiler::V8CpuProfilerConnection> connection) {
625
10
  CHECK_NULL(cpu_profiler_connection_);
626
10
  std::swap(cpu_profiler_connection_, connection);
627
10
}
628
629
inline profiler::V8CpuProfilerConnection*
630
4599
Environment::cpu_profiler_connection() {
631
4599
  return cpu_profiler_connection_.get();
632
}
633
634
10
inline void Environment::set_cpu_prof_interval(uint64_t interval) {
635
10
  cpu_prof_interval_ = interval;
636
10
}
637
638
10
inline uint64_t Environment::cpu_prof_interval() const {
639
10
  return cpu_prof_interval_;
640
}
641
642
10
inline void Environment::set_cpu_prof_name(const std::string& name) {
643
10
  cpu_prof_name_ = name;
644
10
}
645
646
10
inline const std::string& Environment::cpu_prof_name() const {
647
10
  return cpu_prof_name_;
648
}
649
650
10
inline void Environment::set_cpu_prof_dir(const std::string& dir) {
651
10
  cpu_prof_dir_ = dir;
652
10
}
653
654
10
inline const std::string& Environment::cpu_prof_dir() const {
655
10
  return cpu_prof_dir_;
656
}
657
658
10
inline void Environment::set_heap_profiler_connection(
659
    std::unique_ptr<profiler::V8HeapProfilerConnection> connection) {
660
10
  CHECK_NULL(heap_profiler_connection_);
661
10
  std::swap(heap_profiler_connection_, connection);
662
10
}
663
664
inline profiler::V8HeapProfilerConnection*
665
4589
Environment::heap_profiler_connection() {
666
4589
  return heap_profiler_connection_.get();
667
}
668
669
10
inline void Environment::set_heap_prof_name(const std::string& name) {
670
10
  heap_prof_name_ = name;
671
10
}
672
673
10
inline const std::string& Environment::heap_prof_name() const {
674
10
  return heap_prof_name_;
675
}
676
677
10
inline void Environment::set_heap_prof_dir(const std::string& dir) {
678
10
  heap_prof_dir_ = dir;
679
10
}
680
681
10
inline const std::string& Environment::heap_prof_dir() const {
682
10
  return heap_prof_dir_;
683
}
684
685
10
inline void Environment::set_heap_prof_interval(uint64_t interval) {
686
10
  heap_prof_interval_ = interval;
687
10
}
688
689
10
inline uint64_t Environment::heap_prof_interval() const {
690
10
  return heap_prof_interval_;
691
}
692
693
#endif  // HAVE_INSPECTOR
694
695
inline
696
9288
std::shared_ptr<ExclusiveAccess<HostPort>> Environment::inspector_host_port() {
697
9288
  return inspector_host_port_;
698
}
699
700
49722
inline std::shared_ptr<PerIsolateOptions> IsolateData::options() {
701
49722
  return options_;
702
}
703
704
40
inline void IsolateData::set_options(
705
    std::shared_ptr<PerIsolateOptions> options) {
706
40
  options_ = std::move(options);
707
40
}
708
709
template <typename Fn>
710
55284
void Environment::SetImmediate(Fn&& cb, CallbackFlags::Flags flags) {
711
110568
  auto callback = native_immediates_.CreateCallback(std::move(cb), flags);
712
55284
  native_immediates_.Push(std::move(callback));
713
714


55284
  if (flags & CallbackFlags::kRefed) {
715


32897
    if (immediate_info()->ref_count() == 0)
716
24628
      ToggleImmediateRef(true);
717
32897
    immediate_info()->ref_count_inc(1);
718
  }
719
55284
}
720
721
template <typename Fn>
722
658
void Environment::SetImmediateThreadsafe(Fn&& cb, CallbackFlags::Flags flags) {
723
  auto callback = native_immediates_threadsafe_.CreateCallback(
724
1316
      std::move(cb), flags);
725
  {
726
1316
    Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
727
658
    native_immediates_threadsafe_.Push(std::move(callback));
728

658
    if (task_queues_async_initialized_)
729
649
      uv_async_send(&task_queues_async_);
730
  }
731
658
}
732
733
template <typename Fn>
734
6356
void Environment::RequestInterrupt(Fn&& cb) {
735
  auto callback = native_immediates_interrupts_.CreateCallback(
736
12714
      std::move(cb), CallbackFlags::kRefed);
737
  {
738
12716
    Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_);
739
6358
    native_immediates_interrupts_.Push(std::move(callback));
740
6358
    if (task_queues_async_initialized_)
741
1647
      uv_async_send(&task_queues_async_);
742
  }
743
6358
  RequestInterruptFromV8();
744
6358
}
745
746
2577394
inline bool Environment::can_call_into_js() const {
747

2577394
  return can_call_into_js_ && !is_stopping();
748
}
749
750
812
inline void Environment::set_can_call_into_js(bool can_call_into_js) {
751
812
  can_call_into_js_ = can_call_into_js;
752
812
}
753
754
1218486
inline bool Environment::has_run_bootstrapping_code() const {
755
1218486
  return has_run_bootstrapping_code_;
756
}
757
758
4594
inline void Environment::set_has_run_bootstrapping_code(bool value) {
759
4594
  has_run_bootstrapping_code_ = value;
760
4594
}
761
762
19
inline bool Environment::has_serialized_options() const {
763
19
  return has_serialized_options_;
764
}
765
766
4570
inline void Environment::set_has_serialized_options(bool value) {
767
4570
  has_serialized_options_ = value;
768
4570
}
769
770
17143
inline bool Environment::is_main_thread() const {
771
17143
  return worker_context() == nullptr;
772
}
773
774
27317
inline bool Environment::owns_process_state() const {
775
27317
  return flags_ & EnvironmentFlags::kOwnsProcessState;
776
}
777
778
4593
inline bool Environment::owns_inspector() const {
779
4593
  return flags_ & EnvironmentFlags::kOwnsInspector;
780
}
781
782
3
bool Environment::filehandle_close_warning() const {
783
3
  return emit_filehandle_warning_;
784
}
785
786
3
void Environment::set_filehandle_close_warning(bool on) {
787
3
  emit_filehandle_warning_ = on;
788
3
}
789
790
180
bool Environment::emit_insecure_umask_warning() const {
791
180
  return emit_insecure_umask_warning_;
792
}
793
794
5
void Environment::set_emit_insecure_umask_warning(bool on) {
795
5
  emit_insecure_umask_warning_ = on;
796
5
}
797
798
13
void Environment::set_source_maps_enabled(bool on) {
799
13
  source_maps_enabled_ = on;
800
13
}
801
802
923
bool Environment::source_maps_enabled() const {
803
923
  return source_maps_enabled_;
804
}
805
806
8776
inline uint64_t Environment::thread_id() const {
807
8776
  return thread_id_;
808
}
809
810
22003
inline worker::Worker* Environment::worker_context() const {
811
22003
  return isolate_data()->worker_context();
812
}
813
814
544
inline void Environment::add_sub_worker_context(worker::Worker* context) {
815
544
  sub_worker_contexts_.insert(context);
816
544
}
817
818
569
inline void Environment::remove_sub_worker_context(worker::Worker* context) {
819
569
  sub_worker_contexts_.erase(context);
820
569
}
821
822
template <typename Fn>
823
20
inline void Environment::ForEachWorker(Fn&& iterator) {
824
20
  for (worker::Worker* w : sub_worker_contexts_) iterator(w);
825
20
}
826
827
1072
inline void Environment::add_refs(int64_t diff) {
828
1072
  task_queues_async_refs_ += diff;
829
1072
  CHECK_GE(task_queues_async_refs_, 0);
830
1072
  if (task_queues_async_refs_ == 0)
831
132
    uv_unref(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
832
  else
833
940
    uv_ref(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
834
1072
}
835
836
3843648
inline bool Environment::is_stopping() const {
837
3843648
  return is_stopping_.load();
838
}
839
840
4249
inline void Environment::set_stopping(bool value) {
841
4249
  is_stopping_.store(value);
842
4249
}
843
844
1
inline std::list<node_module>* Environment::extra_linked_bindings() {
845
1
  return &extra_linked_bindings_;
846
}
847
848
3
inline node_module* Environment::extra_linked_bindings_head() {
849
4
  return extra_linked_bindings_.size() > 0 ?
850
4
      &extra_linked_bindings_.front() : nullptr;
851
}
852
853
3
inline const Mutex& Environment::extra_linked_bindings_mutex() const {
854
3
  return extra_linked_bindings_mutex_;
855
}
856
857
38011
inline performance::PerformanceState* Environment::performance_state() {
858
38011
  return performance_state_.get();
859
}
860
861
inline std::unordered_map<std::string, uint64_t>*
862
49
    Environment::performance_marks() {
863
49
  return &performance_marks_;
864
}
865
866
5442083
inline IsolateData* Environment::isolate_data() const {
867
5442083
  return isolate_data_;
868
}
869
870
352802
inline char* Environment::AllocateUnchecked(size_t size) {
871
  return static_cast<char*>(
872
352802
      isolate_data()->allocator()->AllocateUninitialized(size));
873
}
874
875
341416
inline char* Environment::Allocate(size_t size) {
876
341416
  char* ret = AllocateUnchecked(size);
877
341416
  CHECK_NE(ret, nullptr);
878
341416
  return ret;
879
}
880
881
48025
inline void Environment::Free(char* data, size_t size) {
882
48025
  if (data != nullptr)
883
48025
    isolate_data()->allocator()->Free(data, size);
884
48025
}
885
886
352802
inline AllocatedBuffer Environment::AllocateManaged(size_t size, bool checked) {
887
352802
  char* data = checked ? Allocate(size) : AllocateUnchecked(size);
888
352802
  if (data == nullptr) size = 0;
889
352802
  return AllocatedBuffer(this, uv_buf_init(data, size));
890
}
891
892
688244
inline AllocatedBuffer::AllocatedBuffer(Environment* env, uv_buf_t buf)
893
688244
    : env_(env), buffer_(buf) {}
894
895
316256
inline void AllocatedBuffer::Resize(size_t len) {
896
  // The `len` check is to make sure we don't end up with `nullptr` as our base.
897
316256
  char* new_data = env_->Reallocate(buffer_.base, buffer_.len,
898
316256
                                    len > 0 ? len : 1);
899
316256
  CHECK_NOT_NULL(new_data);
900
316256
  buffer_ = uv_buf_init(new_data, len);
901
316256
}
902
903
1526646
inline uv_buf_t AllocatedBuffer::release() {
904
1526646
  uv_buf_t ret = buffer_;
905
1526646
  buffer_ = uv_buf_init(nullptr, 0);
906
1526646
  return ret;
907
}
908
909
130750
inline char* AllocatedBuffer::data() {
910
130750
  return buffer_.base;
911
}
912
913
5
inline const char* AllocatedBuffer::data() const {
914
5
  return buffer_.base;
915
}
916
917
362435
inline size_t AllocatedBuffer::size() const {
918
362435
  return buffer_.len;
919
}
920
921
51482
inline AllocatedBuffer::AllocatedBuffer(Environment* env)
922
51482
    : env_(env), buffer_(uv_buf_init(nullptr, 0)) {}
923
924
599
inline AllocatedBuffer::AllocatedBuffer(AllocatedBuffer&& other)
925
599
    : AllocatedBuffer() {
926
599
  *this = std::move(other);
927
599
}
928
929
64750
inline AllocatedBuffer& AllocatedBuffer::operator=(AllocatedBuffer&& other) {
930
64750
  clear();
931
64750
  env_ = other.env_;
932
64750
  buffer_ = other.release();
933
64750
  return *this;
934
}
935
936
1479230
inline AllocatedBuffer::~AllocatedBuffer() {
937
739615
  clear();
938
739615
}
939
940
835384
inline void AllocatedBuffer::clear() {
941
835384
  uv_buf_t buf = release();
942
835384
  if (buf.base != nullptr) {
943
48025
    CHECK_NOT_NULL(env_);
944
48025
    env_->Free(buf.base, buf.len);
945
  }
946
835384
}
947
948
// It's a bit awkward to define this Buffer::New() overload here, but it
949
// avoids a circular dependency with node_internals.h.
950
namespace Buffer {
951
v8::MaybeLocal<v8::Object> New(Environment* env,
952
                               char* data,
953
                               size_t length,
954
                               bool uses_malloc);
955
}
956
957
15737
inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer() {
958
15737
  CHECK_NOT_NULL(env_);
959
15737
  v8::MaybeLocal<v8::Object> obj = Buffer::New(env_, data(), size(), false);
960
15737
  if (!obj.IsEmpty()) release();
961
15737
  return obj;
962
}
963
964
289730
inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer() {
965
289730
  CHECK_NOT_NULL(env_);
966
289730
  uv_buf_t buf = release();
967
868954
  auto callback = [](void* data, size_t length, void* deleter_data){
968
289612
    CHECK_NOT_NULL(deleter_data);
969
970
289612
    static_cast<v8::ArrayBuffer::Allocator*>(deleter_data)
971
289612
        ->Free(data, length);
972
868954
  };
973
  std::unique_ptr<v8::BackingStore> backing =
974
289730
      v8::ArrayBuffer::NewBackingStore(buf.base,
975
                                       buf.len,
976
                                       callback,
977
289730
                                       env_->isolate()
978
869190
                                          ->GetArrayBufferAllocator());
979
289730
  return v8::ArrayBuffer::New(env_->isolate(),
980
869190
                              std::move(backing));
981
}
982
983
706
inline void Environment::ThrowError(const char* errmsg) {
984
706
  ThrowError(v8::Exception::Error, errmsg);
985
706
}
986
987
2
inline void Environment::ThrowTypeError(const char* errmsg) {
988
2
  ThrowError(v8::Exception::TypeError, errmsg);
989
2
}
990
991
inline void Environment::ThrowRangeError(const char* errmsg) {
992
  ThrowError(v8::Exception::RangeError, errmsg);
993
}
994
995
708
inline void Environment::ThrowError(
996
    v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
997
    const char* errmsg) {
998
1416
  v8::HandleScope handle_scope(isolate());
999
708
  isolate()->ThrowException(fun(OneByteString(isolate(), errmsg)));
1000
708
}
1001
1002
3
inline void Environment::ThrowErrnoException(int errorno,
1003
                                             const char* syscall,
1004
                                             const char* message,
1005
                                             const char* path) {
1006
  isolate()->ThrowException(
1007
3
      ErrnoException(isolate(), errorno, syscall, message, path));
1008
3
}
1009
1010
13
inline void Environment::ThrowUVException(int errorno,
1011
                                          const char* syscall,
1012
                                          const char* message,
1013
                                          const char* path,
1014
                                          const char* dest) {
1015
  isolate()->ThrowException(
1016
13
      UVException(isolate(), errorno, syscall, message, path, dest));
1017
13
}
1018
1019
inline v8::Local<v8::FunctionTemplate>
1020
1790381
    Environment::NewFunctionTemplate(v8::FunctionCallback callback,
1021
                                     v8::Local<v8::Signature> signature,
1022
                                     v8::ConstructorBehavior behavior,
1023
                                     v8::SideEffectType side_effect_type) {
1024
  return v8::FunctionTemplate::New(isolate(), callback, v8::Local<v8::Value>(),
1025
1790381
                                   signature, 0, behavior, side_effect_type);
1026
}
1027
1028
749462
inline void Environment::SetMethod(v8::Local<v8::Object> that,
1029
                                   const char* name,
1030
                                   v8::FunctionCallback callback) {
1031
749462
  v8::Local<v8::Context> context = isolate()->GetCurrentContext();
1032
  v8::Local<v8::Function> function =
1033
1498923
      NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
1034
                          v8::ConstructorBehavior::kThrow,
1035
749461
                          v8::SideEffectType::kHasSideEffect)
1036
1498926
          ->GetFunction(context)
1037
749461
          .ToLocalChecked();
1038
  // kInternalized strings are created in the old space.
1039
749461
  const v8::NewStringType type = v8::NewStringType::kInternalized;
1040
  v8::Local<v8::String> name_string =
1041
1498924
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1042
1498927
  that->Set(context, name_string, function).Check();
1043
749464
  function->SetName(name_string);  // NODE_SET_METHOD() compatibility.
1044
749464
}
1045
1046
302047
inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
1047
                                               const char* name,
1048
                                               v8::FunctionCallback callback) {
1049
302047
  v8::Local<v8::Context> context = isolate()->GetCurrentContext();
1050
  v8::Local<v8::Function> function =
1051
604096
      NewFunctionTemplate(callback, v8::Local<v8::Signature>(),
1052
                          v8::ConstructorBehavior::kThrow,
1053
302046
                          v8::SideEffectType::kHasNoSideEffect)
1054
604096
          ->GetFunction(context)
1055
302046
          .ToLocalChecked();
1056
  // kInternalized strings are created in the old space.
1057
302046
  const v8::NewStringType type = v8::NewStringType::kInternalized;
1058
  v8::Local<v8::String> name_string =
1059
604096
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1060
604098
  that->Set(context, name_string, function).Check();
1061
302048
  function->SetName(name_string);  // NODE_SET_METHOD() compatibility.
1062
302047
}
1063
1064
506758
inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
1065
                                        const char* name,
1066
                                        v8::FunctionCallback callback) {
1067
506758
  v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1068
  v8::Local<v8::FunctionTemplate> t =
1069
      NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1070
506758
                          v8::SideEffectType::kHasSideEffect);
1071
  // kInternalized strings are created in the old space.
1072
506759
  const v8::NewStringType type = v8::NewStringType::kInternalized;
1073
  v8::Local<v8::String> name_string =
1074
1013517
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1075
1013517
  that->PrototypeTemplate()->Set(name_string, t);
1076
506759
  t->SetClassName(name_string);  // NODE_SET_PROTOTYPE_METHOD() compatibility.
1077
506759
}
1078
1079
48829
inline void Environment::SetProtoMethodNoSideEffect(
1080
    v8::Local<v8::FunctionTemplate> that,
1081
    const char* name,
1082
    v8::FunctionCallback callback) {
1083
48829
  v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1084
  v8::Local<v8::FunctionTemplate> t =
1085
      NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1086
48829
                          v8::SideEffectType::kHasNoSideEffect);
1087
  // kInternalized strings are created in the old space.
1088
48829
  const v8::NewStringType type = v8::NewStringType::kInternalized;
1089
  v8::Local<v8::String> name_string =
1090
97658
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1091
97658
  that->PrototypeTemplate()->Set(name_string, t);
1092
48829
  t->SetClassName(name_string);  // NODE_SET_PROTOTYPE_METHOD() compatibility.
1093
48829
}
1094
1095
28
inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
1096
                                           const char* name,
1097
                                           v8::FunctionCallback callback) {
1098
28
  v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
1099
  v8::Local<v8::FunctionTemplate> t =
1100
      NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow,
1101
28
                          v8::SideEffectType::kHasSideEffect);
1102
  // kInternalized strings are created in the old space.
1103
28
  const v8::NewStringType type = v8::NewStringType::kInternalized;
1104
  v8::Local<v8::String> name_string =
1105
56
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
1106
56
  that->InstanceTemplate()->Set(name_string, t);
1107
28
  t->SetClassName(name_string);
1108
28
}
1109
1110
601045
void Environment::AddCleanupHook(void (*fn)(void*), void* arg) {
1111
1202095
  auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback {
1112
601045
    fn, arg, cleanup_hook_counter_++
1113
601047
  });
1114
  // Make sure there was no existing element with these values.
1115
601050
  CHECK_EQ(insertion_info.second, true);
1116
601050
}
1117
1118
590312
void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) {
1119
590312
  CleanupHookCallback search { fn, arg, 0 };
1120
590312
  cleanup_hooks_.erase(search);
1121
590314
}
1122
1123
1367337
size_t CleanupHookCallback::Hash::operator()(
1124
    const CleanupHookCallback& cb) const {
1125
1367337
  return std::hash<void*>()(cb.arg_);
1126
}
1127
1128
681962
bool CleanupHookCallback::Equal::operator()(
1129
    const CleanupHookCallback& a, const CleanupHookCallback& b) const {
1130

681962
  return a.fn_ == b.fn_ && a.arg_ == b.arg_;
1131
}
1132
1133
348
BaseObject* CleanupHookCallback::GetBaseObject() const {
1134
348
  if (fn_ == BaseObject::DeleteMe)
1135
328
    return static_cast<BaseObject*>(arg_);
1136
  else
1137
20
    return nullptr;
1138
}
1139
1140
template <typename T>
1141
void Environment::ForEachBaseObject(T&& iterator) {
1142
  for (const auto& hook : cleanup_hooks_) {
1143
    BaseObject* obj = hook.GetBaseObject();
1144
    if (obj != nullptr)
1145
      iterator(obj);
1146
  }
1147
}
1148
1149
1181453
void Environment::modify_base_object_count(int64_t delta) {
1150
1181453
  base_object_count_ += delta;
1151
1181453
}
1152
1153
4609
int64_t Environment::base_object_count() const {
1154
4609
  return base_object_count_ - initial_base_object_count_;
1155
}
1156
1157
9
void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) {
1158
9
  CHECK(!main_utf16_);
1159
9
  main_utf16_ = std::move(str);
1160
9
}
1161
1162
301
void Environment::set_process_exit_handler(
1163
    std::function<void(Environment*, int)>&& handler) {
1164
301
  process_exit_handler_ = std::move(handler);
1165
301
}
1166
1167
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
1168
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
1169
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
1170
#define V(TypeName, PropertyName)                                             \
1171
  inline                                                                      \
1172
  v8::Local<TypeName> IsolateData::PropertyName() const {                     \
1173
    return PropertyName ## _ .Get(isolate_);                                  \
1174
  }
1175
47524
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
1176
681978
  PER_ISOLATE_SYMBOL_PROPERTIES(VY)
1177
5994942
  PER_ISOLATE_STRING_PROPERTIES(VS)
1178
#undef V
1179
#undef VS
1180
#undef VY
1181
#undef VP
1182
1183
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
1184
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
1185
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
1186
#define V(TypeName, PropertyName)                                             \
1187
  inline v8::Local<TypeName> Environment::PropertyName() const {              \
1188
    return isolate_data()->PropertyName();                                    \
1189
  }
1190
23762
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
1191
341025
  PER_ISOLATE_SYMBOL_PROPERTIES(VY)
1192
2993209
  PER_ISOLATE_STRING_PROPERTIES(VS)
1193
#undef V
1194
#undef VS
1195
#undef VY
1196
#undef VP
1197
1198
#define V(PropertyName, TypeName)                                             \
1199
  inline v8::Local<TypeName> Environment::PropertyName() const {              \
1200
    return PersistentToLocal::Strong(PropertyName ## _);                      \
1201
  }                                                                           \
1202
  inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) {  \
1203
    PropertyName ## _.Reset(isolate(), value);                                \
1204
  }
1205
601241
  ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
1206
3620828
  ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
1207
#undef V
1208
1209
11565873
v8::Local<v8::Context> Environment::context() const {
1210
11565873
  return PersistentToLocal::Strong(context_);
1211
}
1212
1213
}  // namespace node
1214
1215
// These two files depend on each other. Including base_object-inl.h after this
1216
// file is the easiest way to avoid issues with that circular dependency.
1217
#include "base_object-inl.h"
1218
1219
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1220
1221
#endif  // SRC_ENV_INL_H_