GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/env-inl.h Lines: 296 303 97.7 %
Date: 2017-06-14 Branches: 43 56 76.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 "env.h"
28
#include "node.h"
29
#include "util.h"
30
#include "util-inl.h"
31
#include "uv.h"
32
#include "v8.h"
33
34
#include <stddef.h>
35
#include <stdint.h>
36
37
namespace node {
38
39
2405
inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop,
40
                                uint32_t* zero_fill_field) :
41
42
// Create string and private symbol properties as internalized one byte strings.
43
//
44
// Internalized because it makes property lookups a little faster and because
45
// the string is created in the old space straight away.  It's going to end up
46
// in the old space sooner or later anyway but now it doesn't go through
47
// v8::Eternal's new space handling first.
48
//
49
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
50
// decoding step.  It's a one-time cost, but why pay it when you don't have to?
51
#define V(PropertyName, StringValue)                                          \
52
    PropertyName ## _(                                                        \
53
        isolate,                                                              \
54
        v8::Private::New(                                                     \
55
            isolate,                                                          \
56
            v8::String::NewFromOneByte(                                       \
57
                isolate,                                                      \
58
                reinterpret_cast<const uint8_t*>(StringValue),                \
59
                v8::NewStringType::kInternalized,                             \
60
                sizeof(StringValue) - 1).ToLocalChecked())),
61
21645
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
62
#undef V
63
#define V(PropertyName, StringValue)                                          \
64
    PropertyName ## _(                                                        \
65
        isolate,                                                              \
66
        v8::String::NewFromOneByte(                                           \
67
            isolate,                                                          \
68
            reinterpret_cast<const uint8_t*>(StringValue),                    \
69
            v8::NewStringType::kInternalized,                                 \
70
            sizeof(StringValue) - 1).ToLocalChecked()),
71
425685
    PER_ISOLATE_STRING_PROPERTIES(V)
72
#undef V
73
1341990
    event_loop_(event_loop), zero_fill_field_(zero_fill_field) {}
74
75
5718018
inline uv_loop_t* IsolateData::event_loop() const {
76
5718018
  return event_loop_;
77
}
78
79
2403
inline uint32_t* IsolateData::zero_fill_field() const {
80
2403
  return zero_fill_field_;
81
}
82
83
2405
inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate)
84
    : isolate_(isolate),
85
      fields_(),
86

67340
      uid_fields_() {
87
2405
  v8::HandleScope handle_scope(isolate_);
88
89
  // kAsyncUidCntr should start at 1 because that'll be the id the execution
90
  // context during bootstrap (code that runs before entering uv_run()).
91
2405
  uid_fields_[AsyncHooks::kAsyncUidCntr] = 1;
92
93
  // Create all the provider strings that will be passed to JS. Place them in
94
  // an array so the array index matches the PROVIDER id offset. This way the
95
  // strings can be retrieved quickly.
96
#define V(Provider)                                                           \
97
  providers_[AsyncWrap::PROVIDER_ ## Provider].Set(                           \
98
      isolate_,                                                               \
99
      v8::String::NewFromOneByte(                                             \
100
        isolate_,                                                             \
101
        reinterpret_cast<const uint8_t*>(#Provider),                          \
102
        v8::NewStringType::kInternalized,                                     \
103
        sizeof(#Provider) - 1).ToLocalChecked());
104
132275
  NODE_ASYNC_PROVIDER_TYPES(V)
105
#undef V
106
2405
}
107
108
438992
inline uint32_t* Environment::AsyncHooks::fields() {
109
438992
  return fields_;
110
}
111
112
2401
inline int Environment::AsyncHooks::fields_count() const {
113
2401
  return kFieldsCount;
114
}
115
116
599515
inline double* Environment::AsyncHooks::uid_fields() {
117
599515
  return uid_fields_;
118
}
119
120
2401
inline int Environment::AsyncHooks::uid_fields_count() const {
121
2401
  return kUidFieldsCount;
122
}
123
124
63021
inline v8::Local<v8::String> Environment::AsyncHooks::provider_string(int idx) {
125
126042
  return providers_[idx].Get(isolate_);
126
}
127
128
539553
inline void Environment::AsyncHooks::push_ids(double async_id,
129
                                              double trigger_id) {
130
539553
  CHECK_GE(async_id, 0);
131
539553
  CHECK_GE(trigger_id, 0);
132
133
539553
  ids_stack_.push({ uid_fields_[kCurrentAsyncId],
134
539553
                    uid_fields_[kCurrentTriggerId] });
135
539553
  uid_fields_[kCurrentAsyncId] = async_id;
136
539553
  uid_fields_[kCurrentTriggerId] = trigger_id;
137
539553
}
138
139
537090
inline bool Environment::AsyncHooks::pop_ids(double async_id) {
140
  // In case of an exception then this may have already been reset, if the
141
  // stack was multiple MakeCallback()'s deep.
142
537090
  if (ids_stack_.empty()) return false;
143
144
  // Ask for the async_id to be restored as a sanity check that the stack
145
  // hasn't been corrupted.
146
535990
  if (uid_fields_[kCurrentAsyncId] != async_id) {
147
    fprintf(stderr,
148
            "Error: async hook stack has become corrupted ("
149
            "actual: %.f, expected: %.f)\n",
150
            uid_fields_[kCurrentAsyncId],
151
4
            async_id);
152
4
    Environment* env = Environment::GetCurrent(isolate_);
153
4
    DumpBacktrace(stderr);
154
4
    fflush(stderr);
155
4
    if (!env->abort_on_uncaught_exception())
156
4
      exit(1);
157
    fprintf(stderr, "\n");
158
    fflush(stderr);
159
    ABORT_NO_BACKTRACE();
160
  }
161
162
535986
  auto ids = ids_stack_.top();
163
535986
  ids_stack_.pop();
164
535986
  uid_fields_[kCurrentAsyncId] = ids.async_id;
165
535986
  uid_fields_[kCurrentTriggerId] = ids.trigger_id;
166
535986
  return !ids_stack_.empty();
167
}
168
169
1123
inline void Environment::AsyncHooks::clear_id_stack() {
170
5432
  while (!ids_stack_.empty())
171
3186
    ids_stack_.pop();
172
1123
  uid_fields_[kCurrentAsyncId] = 0;
173
1123
  uid_fields_[kCurrentTriggerId] = 0;
174
1123
}
175
176
51239
inline Environment::AsyncHooks::InitScope::InitScope(
177
    Environment* env, double init_trigger_id)
178
        : env_(env),
179
51239
          uid_fields_(env->async_hooks()->uid_fields()) {
180
51239
  env->async_hooks()->push_ids(uid_fields_[AsyncHooks::kCurrentAsyncId],
181
51239
                               init_trigger_id);
182
51239
}
183
184
51239
inline Environment::AsyncHooks::InitScope::~InitScope() {
185
51239
  env_->async_hooks()->pop_ids(uid_fields_[AsyncHooks::kCurrentAsyncId]);
186
51239
}
187
188
185119
inline Environment::AsyncHooks::ExecScope::ExecScope(
189
    Environment* env, double async_id, double trigger_id)
190
        : env_(env),
191
          async_id_(async_id),
192
185119
          disposed_(false) {
193
185119
  env->async_hooks()->push_ids(async_id, trigger_id);
194
185119
}
195
196
184817
inline Environment::AsyncHooks::ExecScope::~ExecScope() {
197
184817
  if (disposed_) return;
198
40673
  Dispose();
199
184816
}
200
201
184864
inline void Environment::AsyncHooks::ExecScope::Dispose() {
202
184864
  disposed_ = true;
203
184864
  env_->async_hooks()->pop_ids(async_id_);
204
184863
}
205
206
213131
inline Environment::AsyncCallbackScope::AsyncCallbackScope(Environment* env)
207
213131
    : env_(env) {
208
213131
  env_->makecallback_cntr_++;
209
213131
}
210
211
212822
inline Environment::AsyncCallbackScope::~AsyncCallbackScope() {
212
212822
  env_->makecallback_cntr_--;
213
212822
}
214
215
182564
inline bool Environment::AsyncCallbackScope::in_makecallback() {
216
182564
  return env_->makecallback_cntr_ > 1;
217
}
218
219
2405
inline Environment::DomainFlag::DomainFlag() {
220
2405
  for (int i = 0; i < kFieldsCount; ++i) fields_[i] = 0;
221
2405
}
222
223
121
inline uint32_t* Environment::DomainFlag::fields() {
224
121
  return fields_;
225
}
226
227
121
inline int Environment::DomainFlag::fields_count() const {
228
121
  return kFieldsCount;
229
}
230
231
570
inline uint32_t Environment::DomainFlag::count() const {
232
570
  return fields_[kCount];
233
}
234
235
2405
inline Environment::TickInfo::TickInfo() {
236
7215
  for (int i = 0; i < kFieldsCount; ++i)
237
4810
    fields_[i] = 0;
238
2405
}
239
240
2401
inline uint32_t* Environment::TickInfo::fields() {
241
2401
  return fields_;
242
}
243
244
2401
inline int Environment::TickInfo::fields_count() const {
245
2401
  return kFieldsCount;
246
}
247
248
inline uint32_t Environment::TickInfo::index() const {
249
  return fields_[kIndex];
250
}
251
252
295028
inline uint32_t Environment::TickInfo::length() const {
253
295028
  return fields_[kLength];
254
}
255
256
113276
inline void Environment::TickInfo::set_index(uint32_t value) {
257
113276
  fields_[kIndex] = value;
258
113276
}
259
260
2630
inline void Environment::AssignToContext(v8::Local<v8::Context> context) {
261
2630
  context->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, this);
262
2630
}
263
264
23735
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
265
23735
  return GetCurrent(isolate->GetCurrentContext());
266
}
267
268
112749
inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
269
  return static_cast<Environment*>(
270
225498
      context->GetAlignedPointerFromEmbedderData(kContextEmbedderDataIndex));
271
}
272
273
4459178
inline Environment* Environment::GetCurrent(
274
    const v8::FunctionCallbackInfo<v8::Value>& info) {
275
8918356
  ASSERT(info.Data()->IsExternal());
276
13377534
  return static_cast<Environment*>(info.Data().As<v8::External>()->Value());
277
}
278
279
template <typename T>
280
41862
inline Environment* Environment::GetCurrent(
281
    const v8::PropertyCallbackInfo<T>& info) {
282

83724
  ASSERT(info.Data()->IsExternal());
283
  // XXX(bnoordhuis) Work around a g++ 4.9.2 template type inferrer bug
284
  // when the expression is written as info.Data().As<v8::External>().
285
41862
  v8::Local<v8::Value> data = info.Data();
286
83724
  return static_cast<Environment*>(data.As<v8::External>()->Value());
287
}
288
289
2405
inline Environment::Environment(IsolateData* isolate_data,
290
                                v8::Local<v8::Context> context)
291
2405
    : isolate_(context->GetIsolate()),
292
      isolate_data_(isolate_data),
293
      async_hooks_(context->GetIsolate()),
294
2405
      timer_base_(uv_now(isolate_data->event_loop())),
295
      cares_query_last_ok_(true),
296
      cares_is_servers_default_(true),
297
      using_domains_(false),
298
      printed_error_(false),
299
      trace_sync_io_(false),
300
      abort_on_uncaught_exception_(false),
301
      makecallback_cntr_(0),
302
#if HAVE_INSPECTOR
303
      inspector_agent_(this),
304
#endif
305
      handle_cleanup_waiting_(0),
306
      http_parser_buffer_(nullptr),
307
      fs_stats_field_array_(nullptr),
308
79365
      context_(context->GetIsolate(), context) {
309
  // We'll be creating new objects so make sure we've entered the context.
310
2405
  v8::HandleScope handle_scope(isolate());
311
  v8::Context::Scope context_scope(context);
312
2405
  set_as_external(v8::External::New(isolate(), this));
313
2405
  set_binding_cache_object(v8::Object::New(isolate()));
314
2405
  set_module_load_list_array(v8::Array::New(isolate()));
315
316
2405
  RB_INIT(&cares_task_list_);
317
2405
  AssignToContext(context);
318
319
4810
  destroy_ids_list_.reserve(512);
320
2405
}
321
322
4202
inline Environment::~Environment() {
323
2101
  v8::HandleScope handle_scope(isolate());
324
325
  context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
326
4202
                                             nullptr);
327
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
328
65131
  ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
329
#undef V
330
331
2101
  delete[] heap_statistics_buffer_;
332
2101
  delete[] heap_space_statistics_buffer_;
333
2101
  delete[] http_parser_buffer_;
334
2101
}
335
336
9034145
inline v8::Isolate* Environment::isolate() const {
337
9034145
  return isolate_;
338
}
339
340
35447
inline bool Environment::in_domain() const {
341
  // The const_cast is okay, it doesn't violate conceptual const-ness.
342

36017
  return using_domains() &&
343
36017
         const_cast<Environment*>(this)->domain_flag()->count() > 0;
344
}
345
346
34073
inline Environment* Environment::from_immediate_check_handle(
347
    uv_check_t* handle) {
348
34073
  return ContainerOf(&Environment::immediate_check_handle_, handle);
349
}
350
351
47324
inline uv_check_t* Environment::immediate_check_handle() {
352
47324
  return &immediate_check_handle_;
353
}
354
355
8505
inline uv_idle_t* Environment::immediate_idle_handle() {
356
8505
  return &immediate_idle_handle_;
357
}
358
359
30155
inline Environment* Environment::from_destroy_ids_timer_handle(
360
    uv_timer_t* handle) {
361
30155
  return ContainerOf(&Environment::destroy_ids_timer_handle_, handle);
362
}
363
364
32562
inline uv_timer_t* Environment::destroy_ids_timer_handle() {
365
32562
  return &destroy_ids_timer_handle_;
366
}
367
368
11939
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
369
                                               HandleCleanupCb cb,
370
                                               void *arg) {
371
11939
  handle_cleanup_queue_.PushBack(new HandleCleanup(handle, cb, arg));
372
11939
}
373
374
16
inline void Environment::FinishHandleCleanup(uv_handle_t* handle) {
375
16
  handle_cleanup_waiting_--;
376
16
}
377
378
5715617
inline uv_loop_t* Environment::event_loop() const {
379
5715617
  return isolate_data()->event_loop();
380
}
381
382
2184096
inline Environment::AsyncHooks* Environment::async_hooks() {
383
2184096
  return &async_hooks_;
384
}
385
386
812
inline Environment::DomainFlag* Environment::domain_flag() {
387
812
  return &domain_flag_;
388
}
389
390
152316
inline Environment::TickInfo* Environment::tick_info() {
391
152316
  return &tick_info_;
392
}
393
394
5423848
inline uint64_t Environment::timer_base() const {
395
5423848
  return timer_base_;
396
}
397
398
399856
inline bool Environment::using_domains() const {
399
399856
  return using_domains_;
400
}
401
402
121
inline void Environment::set_using_domains(bool value) {
403
121
  using_domains_ = value;
404
121
}
405
406
10
inline bool Environment::printed_error() const {
407
10
  return printed_error_;
408
}
409
410
10
inline void Environment::set_printed_error(bool value) {
411
10
  printed_error_ = value;
412
10
}
413
414
4351
inline void Environment::set_trace_sync_io(bool value) {
415
4351
  trace_sync_io_ = value;
416
4351
}
417
418
4
inline bool Environment::abort_on_uncaught_exception() const {
419
4
  return abort_on_uncaught_exception_;
420
}
421
422
2401
inline void Environment::set_abort_on_uncaught_exception(bool value) {
423
2401
  abort_on_uncaught_exception_ = value;
424
2401
}
425
426
121006
inline std::vector<double>* Environment::destroy_ids_list() {
427
121006
  return &destroy_ids_list_;
428
}
429
430
63030
inline double Environment::new_async_id() {
431
63030
  return ++async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr];
432
}
433
434
220885
inline double Environment::current_async_id() {
435
220885
  return async_hooks()->uid_fields()[AsyncHooks::kCurrentAsyncId];
436
}
437
438
179389
inline double Environment::trigger_id() {
439
179389
  return async_hooks()->uid_fields()[AsyncHooks::kCurrentTriggerId];
440
}
441
442
63027
inline double Environment::get_init_trigger_id() {
443
63027
  double* uid_fields = async_hooks()->uid_fields();
444
63027
  double tid = uid_fields[AsyncHooks::kInitTriggerId];
445
63027
  uid_fields[AsyncHooks::kInitTriggerId] = 0;
446
63027
  if (tid <= 0) tid = current_async_id();
447
63027
  return tid;
448
}
449
450
19544
inline void Environment::set_init_trigger_id(const double id) {
451
19544
  async_hooks()->uid_fields()[AsyncHooks::kInitTriggerId] = id;
452
19544
}
453
454
7
inline double* Environment::heap_statistics_buffer() const {
455
7
  CHECK_NE(heap_statistics_buffer_, nullptr);
456
7
  return heap_statistics_buffer_;
457
}
458
459
6
inline void Environment::set_heap_statistics_buffer(double* pointer) {
460
6
  CHECK_EQ(heap_statistics_buffer_, nullptr);  // Should be set only once.
461
6
  heap_statistics_buffer_ = pointer;
462
6
}
463
464
7
inline double* Environment::heap_space_statistics_buffer() const {
465
7
  CHECK_NE(heap_space_statistics_buffer_, nullptr);
466
7
  return heap_space_statistics_buffer_;
467
}
468
469
6
inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
470
6
  CHECK_EQ(heap_space_statistics_buffer_, nullptr);  // Should be set only once.
471
6
  heap_space_statistics_buffer_ = pointer;
472
6
}
473
474
475
5426
inline char* Environment::http_parser_buffer() const {
476
5426
  return http_parser_buffer_;
477
}
478
479
233
inline void Environment::set_http_parser_buffer(char* buffer) {
480
233
  CHECK_EQ(http_parser_buffer_, nullptr);  // Should be set only once.
481
233
  http_parser_buffer_ = buffer;
482
233
}
483
484
73417
inline double* Environment::fs_stats_field_array() const {
485
73417
  return fs_stats_field_array_;
486
}
487
488
2401
inline void Environment::set_fs_stats_field_array(double* fields) {
489
2401
  CHECK_EQ(fs_stats_field_array_, nullptr);  // Should be set only once.
490
2401
  fs_stats_field_array_ = fields;
491
2401
}
492
493
inline Environment* Environment::from_cares_timer_handle(uv_timer_t* handle) {
494
  return ContainerOf(&Environment::cares_timer_handle_, handle);
495
}
496
497
4644
inline uv_timer_t* Environment::cares_timer_handle() {
498
4644
  return &cares_timer_handle_;
499
}
500
501
27
inline ares_channel Environment::cares_channel() {
502
27
  return cares_channel_;
503
}
504
505
// Only used in the call to ares_init_options().
506
2319
inline ares_channel* Environment::cares_channel_ptr() {
507
2319
  return &cares_channel_;
508
}
509
510
2
inline bool Environment::cares_query_last_ok() {
511
2
  return cares_query_last_ok_;
512
}
513
514
3
inline void Environment::set_cares_query_last_ok(bool ok) {
515
3
  cares_query_last_ok_ = ok;
516
3
}
517
518
inline bool Environment::cares_is_servers_default() {
519
  return cares_is_servers_default_;
520
}
521
522
6
inline void Environment::set_cares_is_servers_default(bool is_default) {
523
6
  cares_is_servers_default_ = is_default;
524
6
}
525
526
12
inline node_ares_task_list* Environment::cares_task_list() {
527
12
  return &cares_task_list_;
528
}
529
530
6390183
inline IsolateData* Environment::isolate_data() const {
531
6390183
  return isolate_data_;
532
}
533
534
713
inline void Environment::ThrowError(const char* errmsg) {
535
713
  ThrowError(v8::Exception::Error, errmsg);
536
713
}
537
538
109
inline void Environment::ThrowTypeError(const char* errmsg) {
539
109
  ThrowError(v8::Exception::TypeError, errmsg);
540
109
}
541
542
29
inline void Environment::ThrowRangeError(const char* errmsg) {
543
29
  ThrowError(v8::Exception::RangeError, errmsg);
544
29
}
545
546
851
inline void Environment::ThrowError(
547
    v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
548
    const char* errmsg) {
549
851
  v8::HandleScope handle_scope(isolate());
550
851
  isolate()->ThrowException(fun(OneByteString(isolate(), errmsg)));
551
851
}
552
553
2
inline void Environment::ThrowErrnoException(int errorno,
554
                                             const char* syscall,
555
                                             const char* message,
556
                                             const char* path) {
557
  isolate()->ThrowException(
558
2
      ErrnoException(isolate(), errorno, syscall, message, path));
559
2
}
560
561
3039
inline void Environment::ThrowUVException(int errorno,
562
                                          const char* syscall,
563
                                          const char* message,
564
                                          const char* path,
565
                                          const char* dest) {
566
  isolate()->ThrowException(
567
3039
      UVException(isolate(), errorno, syscall, message, path, dest));
568
3039
}
569
570
inline v8::Local<v8::FunctionTemplate>
571
761006
    Environment::NewFunctionTemplate(v8::FunctionCallback callback,
572
                                     v8::Local<v8::Signature> signature) {
573
761006
  v8::Local<v8::External> external = as_external();
574
761006
  return v8::FunctionTemplate::New(isolate(), callback, external, signature);
575
}
576
577
443251
inline void Environment::SetMethod(v8::Local<v8::Object> that,
578
                                   const char* name,
579
                                   v8::FunctionCallback callback) {
580
  v8::Local<v8::Function> function =
581
886502
      NewFunctionTemplate(callback)->GetFunction();
582
  // kInternalized strings are created in the old space.
583
443251
  const v8::NewStringType type = v8::NewStringType::kInternalized;
584
  v8::Local<v8::String> name_string =
585
886502
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
586
443251
  that->Set(name_string, function);
587
443251
  function->SetName(name_string);  // NODE_SET_METHOD() compatibility.
588
443251
}
589
590
288746
inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
591
                                        const char* name,
592
                                        v8::FunctionCallback callback) {
593
288746
  v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
594
288746
  v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback, signature);
595
  // kInternalized strings are created in the old space.
596
288746
  const v8::NewStringType type = v8::NewStringType::kInternalized;
597
  v8::Local<v8::String> name_string =
598
577492
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
599
577492
  that->PrototypeTemplate()->Set(name_string, t);
600
288746
  t->SetClassName(name_string);  // NODE_SET_PROTOTYPE_METHOD() compatibility.
601
288746
}
602
603
2401
inline void Environment::SetTemplateMethod(v8::Local<v8::FunctionTemplate> that,
604
                                           const char* name,
605
                                           v8::FunctionCallback callback) {
606
2401
  v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback);
607
  // kInternalized strings are created in the old space.
608
2401
  const v8::NewStringType type = v8::NewStringType::kInternalized;
609
  v8::Local<v8::String> name_string =
610
4802
      v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
611
2401
  that->Set(name_string, t);
612
2401
  t->SetClassName(name_string);  // NODE_SET_METHOD() compatibility.
613
2401
}
614
615
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
616
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
617
#define V(TypeName, PropertyName)                                             \
618
  inline                                                                      \
619
  v8::Local<TypeName> IsolateData::PropertyName(v8::Isolate* isolate) const { \
620
    /* Strings are immutable so casting away const-ness here is okay. */      \
621
    return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate);    \
622
  }
623
10222
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
624
1334112
  PER_ISOLATE_STRING_PROPERTIES(VS)
625
#undef V
626
#undef VS
627
#undef VP
628
629
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
630
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
631
#define V(TypeName, PropertyName)                                             \
632
  inline v8::Local<TypeName> Environment::PropertyName() const {              \
633
    return isolate_data()->PropertyName(isolate());                           \
634
  }
635
5111
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
636
667056
  PER_ISOLATE_STRING_PROPERTIES(VS)
637
#undef V
638
#undef VS
639
#undef VP
640
641
#define V(PropertyName, TypeName)                                             \
642
  inline v8::Local<TypeName> Environment::PropertyName() const {              \
643
    return StrongPersistentToLocal(PropertyName ## _);                        \
644
  }                                                                           \
645
  inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) {  \
646
    PropertyName ## _.Reset(isolate(), value);                                \
647
  }
648
5083396
  ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
649
#undef V
650
651
}  // namespace node
652
653
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
654
655
#endif  // SRC_ENV_INL_H_