GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/env.h Lines: 49 49 100.0 %
Date: 2021-04-16 04:11:37 Branches: 0 0 - %

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_H_
23
#define SRC_ENV_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "aliased_buffer.h"
28
#if HAVE_INSPECTOR
29
#include "inspector_agent.h"
30
#include "inspector_profiler.h"
31
#endif
32
#include "callback_queue.h"
33
#include "debug_utils.h"
34
#include "handle_wrap.h"
35
#include "node.h"
36
#include "node_binding.h"
37
#include "node_main_instance.h"
38
#include "node_options.h"
39
#include "node_perf_common.h"
40
#include "node_snapshotable.h"
41
#include "req_wrap.h"
42
#include "util.h"
43
#include "uv.h"
44
#include "v8.h"
45
46
#include <array>
47
#include <atomic>
48
#include <cstdint>
49
#include <functional>
50
#include <iostream>
51
#include <list>
52
#include <unordered_map>
53
#include <unordered_set>
54
#include <vector>
55
56
namespace node {
57
58
namespace contextify {
59
class ContextifyScript;
60
class CompiledFnEntry;
61
}
62
63
namespace performance {
64
class PerformanceState;
65
}
66
67
namespace tracing {
68
class AgentWriterHandle;
69
}
70
71
#if HAVE_INSPECTOR
72
namespace profiler {
73
class V8CoverageConnection;
74
class V8CpuProfilerConnection;
75
class V8HeapProfilerConnection;
76
}  // namespace profiler
77
78
namespace inspector {
79
class ParentInspectorHandle;
80
}
81
#endif  // HAVE_INSPECTOR
82
83
namespace worker {
84
class Worker;
85
}
86
87
namespace loader {
88
class ModuleWrap;
89
90
struct PackageConfig {
91
  enum class Exists { Yes, No };
92
  enum class IsValid { Yes, No };
93
  enum class HasMain { Yes, No };
94
  enum class HasName { Yes, No };
95
  enum PackageType : uint32_t { None = 0, CommonJS, Module };
96
97
  const Exists exists;
98
  const IsValid is_valid;
99
  const HasMain has_main;
100
  const std::string main;
101
  const HasName has_name;
102
  const std::string name;
103
  const PackageType type;
104
105
  v8::Global<v8::Value> exports;
106
};
107
}  // namespace loader
108
109
enum class FsStatsOffset {
110
  kDev = 0,
111
  kMode,
112
  kNlink,
113
  kUid,
114
  kGid,
115
  kRdev,
116
  kBlkSize,
117
  kIno,
118
  kSize,
119
  kBlocks,
120
  kATimeSec,
121
  kATimeNsec,
122
  kMTimeSec,
123
  kMTimeNsec,
124
  kCTimeSec,
125
  kCTimeNsec,
126
  kBirthTimeSec,
127
  kBirthTimeNsec,
128
  kFsStatsFieldsNumber
129
};
130
131
// Stat fields buffers contain twice the number of entries in an uv_stat_t
132
// because `fs.StatWatcher` needs room to store 2 `fs.Stats` instances.
133
constexpr size_t kFsStatsBufferLength =
134
    static_cast<size_t>(FsStatsOffset::kFsStatsFieldsNumber) * 2;
135
136
// PER_ISOLATE_* macros: We have a lot of per-isolate properties
137
// and adding and maintaining their getters and setters by hand would be
138
// difficult so let's make the preprocessor generate them for us.
139
//
140
// In each macro, `V` is expected to be the name of a macro or function which
141
// accepts the number of arguments provided in each tuple in the macro body,
142
// typically two. The named function will be invoked against each tuple.
143
//
144
// Make sure that any macro V defined for use with the PER_ISOLATE_* macros is
145
// undefined again after use.
146
147
// Private symbols are per-isolate primitives but Environment proxies them
148
// for the sake of convenience.  Strings should be ASCII-only and have a
149
// "node:" prefix to avoid name clashes with third-party code.
150
#define PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)                              \
151
  V(alpn_buffer_private_symbol, "node:alpnBuffer")                            \
152
  V(arrow_message_private_symbol, "node:arrowMessage")                        \
153
  V(contextify_context_private_symbol, "node:contextify:context")             \
154
  V(contextify_global_private_symbol, "node:contextify:global")               \
155
  V(decorated_private_symbol, "node:decorated")                               \
156
  V(napi_type_tag, "node:napi:type_tag")                                      \
157
  V(napi_wrapper, "node:napi:wrapper")                                        \
158
  V(untransferable_object_private_symbol, "node:untransferableObject")        \
159
160
// Symbols are per-isolate primitives but Environment proxies them
161
// for the sake of convenience.
162
#define PER_ISOLATE_SYMBOL_PROPERTIES(V)                                       \
163
  V(async_id_symbol, "async_id_symbol")                                        \
164
  V(handle_onclose_symbol, "handle_onclose")                                   \
165
  V(no_message_symbol, "no_message_symbol")                                    \
166
  V(messaging_deserialize_symbol, "messaging_deserialize_symbol")              \
167
  V(messaging_transfer_symbol, "messaging_transfer_symbol")                    \
168
  V(messaging_clone_symbol, "messaging_clone_symbol")                          \
169
  V(messaging_transfer_list_symbol, "messaging_transfer_list_symbol")          \
170
  V(oninit_symbol, "oninit")                                                   \
171
  V(owner_symbol, "owner_symbol")                                              \
172
  V(onpskexchange_symbol, "onpskexchange")                                     \
173
  V(resource_symbol, "resource_symbol")                                        \
174
  V(trigger_async_id_symbol, "trigger_async_id_symbol")                        \
175
176
// Strings are per-isolate primitives but Environment proxies them
177
// for the sake of convenience.  Strings should be ASCII-only.
178
#define PER_ISOLATE_STRING_PROPERTIES(V)                                       \
179
  V(ack_string, "ack")                                                         \
180
  V(address_string, "address")                                                 \
181
  V(aliases_string, "aliases")                                                 \
182
  V(args_string, "args")                                                       \
183
  V(asn1curve_string, "asn1Curve")                                             \
184
  V(async_ids_stack_string, "async_ids_stack")                                 \
185
  V(bits_string, "bits")                                                       \
186
  V(block_list_string, "blockList")                                            \
187
  V(buffer_string, "buffer")                                                   \
188
  V(bytes_parsed_string, "bytesParsed")                                        \
189
  V(bytes_read_string, "bytesRead")                                            \
190
  V(bytes_written_string, "bytesWritten")                                      \
191
  V(cached_data_produced_string, "cachedDataProduced")                         \
192
  V(cached_data_rejected_string, "cachedDataRejected")                         \
193
  V(cached_data_string, "cachedData")                                          \
194
  V(cache_key_string, "cacheKey")                                              \
195
  V(change_string, "change")                                                   \
196
  V(channel_string, "channel")                                                 \
197
  V(chunks_sent_since_last_write_string, "chunksSentSinceLastWrite")           \
198
  V(clone_unsupported_type_str, "Cannot transfer object of unsupported type.") \
199
  V(code_string, "code")                                                       \
200
  V(commonjs_string, "commonjs")                                               \
201
  V(config_string, "config")                                                   \
202
  V(constants_string, "constants")                                             \
203
  V(crypto_dh_string, "dh")                                                    \
204
  V(crypto_dsa_string, "dsa")                                                  \
205
  V(crypto_ec_string, "ec")                                                    \
206
  V(crypto_ed25519_string, "ed25519")                                          \
207
  V(crypto_ed448_string, "ed448")                                              \
208
  V(crypto_x25519_string, "x25519")                                            \
209
  V(crypto_x448_string, "x448")                                                \
210
  V(crypto_rsa_string, "rsa")                                                  \
211
  V(crypto_rsa_pss_string, "rsa-pss")                                          \
212
  V(cwd_string, "cwd")                                                         \
213
  V(data_string, "data")                                                       \
214
  V(deserialize_info_string, "deserializeInfo")                                \
215
  V(dest_string, "dest")                                                       \
216
  V(destroyed_string, "destroyed")                                             \
217
  V(detached_string, "detached")                                               \
218
  V(dh_string, "DH")                                                           \
219
  V(divisor_length_string, "divisorLength")                                    \
220
  V(dns_a_string, "A")                                                         \
221
  V(dns_aaaa_string, "AAAA")                                                   \
222
  V(dns_caa_string, "CAA")                                                     \
223
  V(dns_critical_string, "critical")                                           \
224
  V(dns_cname_string, "CNAME")                                                 \
225
  V(dns_mx_string, "MX")                                                       \
226
  V(dns_naptr_string, "NAPTR")                                                 \
227
  V(dns_ns_string, "NS")                                                       \
228
  V(dns_ptr_string, "PTR")                                                     \
229
  V(dns_soa_string, "SOA")                                                     \
230
  V(dns_srv_string, "SRV")                                                     \
231
  V(dns_txt_string, "TXT")                                                     \
232
  V(done_string, "done")                                                       \
233
  V(duration_string, "duration")                                               \
234
  V(ecdh_string, "ECDH")                                                       \
235
  V(emit_string, "emit")                                                       \
236
  V(emit_warning_string, "emitWarning")                                        \
237
  V(empty_object_string, "{}")                                                 \
238
  V(encoding_string, "encoding")                                               \
239
  V(entries_string, "entries")                                                 \
240
  V(entry_type_string, "entryType")                                            \
241
  V(env_pairs_string, "envPairs")                                              \
242
  V(env_var_settings_string, "envVarSettings")                                 \
243
  V(errno_string, "errno")                                                     \
244
  V(error_string, "error")                                                     \
245
  V(exchange_string, "exchange")                                               \
246
  V(exit_code_string, "exitCode")                                              \
247
  V(expire_string, "expire")                                                   \
248
  V(exponent_string, "exponent")                                               \
249
  V(exports_string, "exports")                                                 \
250
  V(ext_key_usage_string, "ext_key_usage")                                     \
251
  V(external_stream_string, "_externalStream")                                 \
252
  V(family_string, "family")                                                   \
253
  V(fatal_exception_string, "_fatalException")                                 \
254
  V(fd_string, "fd")                                                           \
255
  V(fields_string, "fields")                                                   \
256
  V(file_string, "file")                                                       \
257
  V(filename_string, "filename")                                               \
258
  V(fingerprint256_string, "fingerprint256")                                   \
259
  V(fingerprint_string, "fingerprint")                                         \
260
  V(flags_string, "flags")                                                     \
261
  V(flowlabel_string, "flowlabel")                                             \
262
  V(fragment_string, "fragment")                                               \
263
  V(frames_received_string, "framesReceived")                                  \
264
  V(frames_sent_string, "framesSent")                                          \
265
  V(function_string, "function")                                               \
266
  V(get_data_clone_error_string, "_getDataCloneError")                         \
267
  V(get_shared_array_buffer_id_string, "_getSharedArrayBufferId")              \
268
  V(gid_string, "gid")                                                         \
269
  V(h2_string, "h2")                                                           \
270
  V(handle_string, "handle")                                                   \
271
  V(help_text_string, "helpText")                                              \
272
  V(homedir_string, "homedir")                                                 \
273
  V(host_string, "host")                                                       \
274
  V(hostmaster_string, "hostmaster")                                           \
275
  V(http_1_1_string, "http/1.1")                                               \
276
  V(id_string, "id")                                                           \
277
  V(identity_string, "identity")                                               \
278
  V(ignore_string, "ignore")                                                   \
279
  V(infoaccess_string, "infoAccess")                                           \
280
  V(inherit_string, "inherit")                                                 \
281
  V(input_string, "input")                                                     \
282
  V(internal_binding_string, "internalBinding")                                \
283
  V(internal_string, "internal")                                               \
284
  V(ipv4_string, "IPv4")                                                       \
285
  V(ipv6_string, "IPv6")                                                       \
286
  V(isclosing_string, "isClosing")                                             \
287
  V(issuer_string, "issuer")                                                   \
288
  V(issuercert_string, "issuerCertificate")                                    \
289
  V(jwk_crv_string, "crv")                                                     \
290
  V(jwk_d_string, "d")                                                         \
291
  V(jwk_dp_string, "dp")                                                       \
292
  V(jwk_dq_string, "dq")                                                       \
293
  V(jwk_dsa_string, "DSA")                                                     \
294
  V(jwk_e_string, "e")                                                         \
295
  V(jwk_ec_string, "EC")                                                       \
296
  V(jwk_g_string, "g")                                                         \
297
  V(jwk_k_string, "k")                                                         \
298
  V(jwk_p_string, "p")                                                         \
299
  V(jwk_q_string, "q")                                                         \
300
  V(jwk_qi_string, "qi")                                                       \
301
  V(jwk_kty_string, "kty")                                                     \
302
  V(jwk_n_string, "n")                                                         \
303
  V(jwk_oct_string, "oct")                                                     \
304
  V(jwk_okp_string, "OKP")                                                     \
305
  V(jwk_rsa_string, "RSA")                                                     \
306
  V(jwk_x_string, "x")                                                         \
307
  V(jwk_y_string, "y")                                                         \
308
  V(kill_signal_string, "killSignal")                                          \
309
  V(kind_string, "kind")                                                       \
310
  V(length_string, "length")                                                   \
311
  V(library_string, "library")                                                 \
312
  V(mac_string, "mac")                                                         \
313
  V(max_buffer_string, "maxBuffer")                                            \
314
  V(max_concurrent_streams_string, "maxConcurrentStreams")                     \
315
  V(message_port_constructor_string, "MessagePort")                            \
316
  V(message_port_string, "messagePort")                                        \
317
  V(message_string, "message")                                                 \
318
  V(messageerror_string, "messageerror")                                       \
319
  V(minttl_string, "minttl")                                                   \
320
  V(module_string, "module")                                                   \
321
  V(modulus_string, "modulus")                                                 \
322
  V(modulus_length_string, "modulusLength")                                    \
323
  V(name_string, "name")                                                       \
324
  V(named_curve_string, "namedCurve")                                          \
325
  V(netmask_string, "netmask")                                                 \
326
  V(next_string, "next")                                                       \
327
  V(nistcurve_string, "nistCurve")                                             \
328
  V(node_string, "node")                                                       \
329
  V(nsname_string, "nsname")                                                   \
330
  V(ocsp_request_string, "OCSPRequest")                                        \
331
  V(oncertcb_string, "oncertcb")                                               \
332
  V(onchange_string, "onchange")                                               \
333
  V(onclienthello_string, "onclienthello")                                     \
334
  V(oncomplete_string, "oncomplete")                                           \
335
  V(onconnection_string, "onconnection")                                       \
336
  V(ondone_string, "ondone")                                                   \
337
  V(onerror_string, "onerror")                                                 \
338
  V(onexit_string, "onexit")                                                   \
339
  V(onhandshakedone_string, "onhandshakedone")                                 \
340
  V(onhandshakestart_string, "onhandshakestart")                               \
341
  V(onkeylog_string, "onkeylog")                                               \
342
  V(onmessage_string, "onmessage")                                             \
343
  V(onnewsession_string, "onnewsession")                                       \
344
  V(onocspresponse_string, "onocspresponse")                                   \
345
  V(onreadstart_string, "onreadstart")                                         \
346
  V(onreadstop_string, "onreadstop")                                           \
347
  V(onshutdown_string, "onshutdown")                                           \
348
  V(onsignal_string, "onsignal")                                               \
349
  V(onunpipe_string, "onunpipe")                                               \
350
  V(onwrite_string, "onwrite")                                                 \
351
  V(openssl_error_stack, "opensslErrorStack")                                  \
352
  V(options_string, "options")                                                 \
353
  V(order_string, "order")                                                     \
354
  V(output_string, "output")                                                   \
355
  V(overlapped_string, "overlapped")                                           \
356
  V(parse_error_string, "Parse Error")                                         \
357
  V(password_string, "password")                                               \
358
  V(path_string, "path")                                                       \
359
  V(pending_handle_string, "pendingHandle")                                    \
360
  V(pid_string, "pid")                                                         \
361
  V(ping_rtt_string, "pingRTT")                                                \
362
  V(pipe_source_string, "pipeSource")                                          \
363
  V(pipe_string, "pipe")                                                       \
364
  V(pipe_target_string, "pipeTarget")                                          \
365
  V(port1_string, "port1")                                                     \
366
  V(port2_string, "port2")                                                     \
367
  V(port_string, "port")                                                       \
368
  V(preference_string, "preference")                                           \
369
  V(primordials_string, "primordials")                                         \
370
  V(priority_string, "priority")                                               \
371
  V(process_string, "process")                                                 \
372
  V(promise_string, "promise")                                                 \
373
  V(psk_string, "psk")                                                         \
374
  V(pubkey_string, "pubkey")                                                   \
375
  V(public_exponent_string, "publicExponent")                                  \
376
  V(query_string, "query")                                                     \
377
  V(rate_string, "rate")                                                       \
378
  V(raw_string, "raw")                                                         \
379
  V(read_host_object_string, "_readHostObject")                                \
380
  V(readable_string, "readable")                                               \
381
  V(reason_string, "reason")                                                   \
382
  V(refresh_string, "refresh")                                                 \
383
  V(regexp_string, "regexp")                                                   \
384
  V(rename_string, "rename")                                                   \
385
  V(replacement_string, "replacement")                                         \
386
  V(require_string, "require")                                                 \
387
  V(retry_string, "retry")                                                     \
388
  V(scheme_string, "scheme")                                                   \
389
  V(scopeid_string, "scopeid")                                                 \
390
  V(serial_number_string, "serialNumber")                                      \
391
  V(serial_string, "serial")                                                   \
392
  V(servername_string, "servername")                                           \
393
  V(service_string, "service")                                                 \
394
  V(session_id_string, "sessionId")                                            \
395
  V(shell_string, "shell")                                                     \
396
  V(signal_string, "signal")                                                   \
397
  V(sink_string, "sink")                                                       \
398
  V(size_string, "size")                                                       \
399
  V(sni_context_err_string, "Invalid SNI context")                             \
400
  V(sni_context_string, "sni_context")                                         \
401
  V(source_string, "source")                                                   \
402
  V(stack_string, "stack")                                                     \
403
  V(standard_name_string, "standardName")                                      \
404
  V(start_time_string, "startTime")                                            \
405
  V(state_string, "state")                                                     \
406
  V(stats_string, "stats")                                                     \
407
  V(status_string, "status")                                                   \
408
  V(stdio_string, "stdio")                                                     \
409
  V(stream_average_duration_string, "streamAverageDuration")                   \
410
  V(stream_count_string, "streamCount")                                        \
411
  V(subject_string, "subject")                                                 \
412
  V(subjectaltname_string, "subjectaltname")                                   \
413
  V(syscall_string, "syscall")                                                 \
414
  V(target_string, "target")                                                   \
415
  V(thread_id_string, "threadId")                                              \
416
  V(ticketkeycallback_string, "onticketkeycallback")                           \
417
  V(timeout_string, "timeout")                                                 \
418
  V(time_to_first_byte_string, "timeToFirstByte")                              \
419
  V(time_to_first_byte_sent_string, "timeToFirstByteSent")                     \
420
  V(time_to_first_header_string, "timeToFirstHeader")                          \
421
  V(tls_ticket_string, "tlsTicket")                                            \
422
  V(transfer_string, "transfer")                                               \
423
  V(ttl_string, "ttl")                                                         \
424
  V(type_string, "type")                                                       \
425
  V(uid_string, "uid")                                                         \
426
  V(unknown_string, "<unknown>")                                               \
427
  V(url_special_ftp_string, "ftp:")                                            \
428
  V(url_special_file_string, "file:")                                          \
429
  V(url_special_http_string, "http:")                                          \
430
  V(url_special_https_string, "https:")                                        \
431
  V(url_special_ws_string, "ws:")                                              \
432
  V(url_special_wss_string, "wss:")                                            \
433
  V(url_string, "url")                                                         \
434
  V(username_string, "username")                                               \
435
  V(valid_from_string, "valid_from")                                           \
436
  V(valid_to_string, "valid_to")                                               \
437
  V(value_string, "value")                                                     \
438
  V(verify_error_string, "verifyError")                                        \
439
  V(version_string, "version")                                                 \
440
  V(weight_string, "weight")                                                   \
441
  V(windows_hide_string, "windowsHide")                                        \
442
  V(windows_verbatim_arguments_string, "windowsVerbatimArguments")             \
443
  V(wrap_string, "wrap")                                                       \
444
  V(writable_string, "writable")                                               \
445
  V(write_host_object_string, "_writeHostObject")                              \
446
  V(write_queue_size_string, "writeQueueSize")                                 \
447
  V(x_forwarded_string, "x-forwarded-for")                                     \
448
  V(zero_return_string, "ZERO_RETURN")
449
450
#define ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)                             \
451
  V(async_wrap_ctor_template, v8::FunctionTemplate)                            \
452
  V(async_wrap_object_ctor_template, v8::FunctionTemplate)                     \
453
  V(base_object_ctor_template, v8::FunctionTemplate)                           \
454
  V(binding_data_ctor_template, v8::FunctionTemplate)                          \
455
  V(blob_constructor_template, v8::FunctionTemplate)                           \
456
  V(blocklist_constructor_template, v8::FunctionTemplate)                      \
457
  V(compiled_fn_entry_template, v8::ObjectTemplate)                            \
458
  V(dir_instance_template, v8::ObjectTemplate)                                 \
459
  V(fd_constructor_template, v8::ObjectTemplate)                               \
460
  V(fdclose_constructor_template, v8::ObjectTemplate)                          \
461
  V(filehandlereadwrap_template, v8::ObjectTemplate)                           \
462
  V(fsreqpromise_constructor_template, v8::ObjectTemplate)                     \
463
  V(handle_wrap_ctor_template, v8::FunctionTemplate)                           \
464
  V(histogram_ctor_template, v8::FunctionTemplate)                             \
465
  V(http2settings_constructor_template, v8::ObjectTemplate)                    \
466
  V(http2stream_constructor_template, v8::ObjectTemplate)                      \
467
  V(http2ping_constructor_template, v8::ObjectTemplate)                        \
468
  V(i18n_converter_template, v8::ObjectTemplate)                               \
469
  V(intervalhistogram_constructor_template, v8::FunctionTemplate)              \
470
  V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate)                     \
471
  V(message_port_constructor_template, v8::FunctionTemplate)                   \
472
  V(microtask_queue_ctor_template, v8::FunctionTemplate)                       \
473
  V(pipe_constructor_template, v8::FunctionTemplate)                           \
474
  V(promise_wrap_template, v8::ObjectTemplate)                                 \
475
  V(sab_lifetimepartner_constructor_template, v8::FunctionTemplate)            \
476
  V(script_context_constructor_template, v8::FunctionTemplate)                 \
477
  V(secure_context_constructor_template, v8::FunctionTemplate)                 \
478
  V(shutdown_wrap_template, v8::ObjectTemplate)                                \
479
  V(socketaddress_constructor_template, v8::FunctionTemplate)                  \
480
  V(streambaseoutputstream_constructor_template, v8::ObjectTemplate)           \
481
  V(qlogoutputstream_constructor_template, v8::ObjectTemplate)                 \
482
  V(tcp_constructor_template, v8::FunctionTemplate)                            \
483
  V(tty_constructor_template, v8::FunctionTemplate)                            \
484
  V(write_wrap_template, v8::ObjectTemplate)                                   \
485
  V(worker_heap_snapshot_taker_template, v8::ObjectTemplate)                   \
486
  V(x509_constructor_template, v8::FunctionTemplate)
487
488
#define ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)                                \
489
  V(async_hooks_after_function, v8::Function)                                  \
490
  V(async_hooks_before_function, v8::Function)                                 \
491
  V(async_hooks_callback_trampoline, v8::Function)                             \
492
  V(async_hooks_binding, v8::Object)                                           \
493
  V(async_hooks_destroy_function, v8::Function)                                \
494
  V(async_hooks_init_function, v8::Function)                                   \
495
  V(async_hooks_promise_resolve_function, v8::Function)                        \
496
  V(buffer_prototype_object, v8::Object)                                       \
497
  V(crypto_key_object_constructor, v8::Function)                               \
498
  V(crypto_key_object_handle_constructor, v8::Function)                        \
499
  V(crypto_key_object_private_constructor, v8::Function)                       \
500
  V(crypto_key_object_public_constructor, v8::Function)                        \
501
  V(crypto_key_object_secret_constructor, v8::Function)                        \
502
  V(domexception_function, v8::Function)                                       \
503
  V(enhance_fatal_stack_after_inspector, v8::Function)                         \
504
  V(enhance_fatal_stack_before_inspector, v8::Function)                        \
505
  V(fs_use_promises_symbol, v8::Symbol)                                        \
506
  V(host_import_module_dynamically_callback, v8::Function)                     \
507
  V(host_initialize_import_meta_object_callback, v8::Function)                 \
508
  V(http2session_on_altsvc_function, v8::Function)                             \
509
  V(http2session_on_error_function, v8::Function)                              \
510
  V(http2session_on_frame_error_function, v8::Function)                        \
511
  V(http2session_on_goaway_data_function, v8::Function)                        \
512
  V(http2session_on_headers_function, v8::Function)                            \
513
  V(http2session_on_origin_function, v8::Function)                             \
514
  V(http2session_on_ping_function, v8::Function)                               \
515
  V(http2session_on_priority_function, v8::Function)                           \
516
  V(http2session_on_settings_function, v8::Function)                           \
517
  V(http2session_on_stream_close_function, v8::Function)                       \
518
  V(http2session_on_stream_trailers_function, v8::Function)                    \
519
  V(internal_binding_loader, v8::Function)                                     \
520
  V(immediate_callback_function, v8::Function)                                 \
521
  V(inspector_console_extension_installer, v8::Function)                       \
522
  V(messaging_deserialize_create_object, v8::Function)                         \
523
  V(message_port, v8::Object)                                                  \
524
  V(native_module_require, v8::Function)                                       \
525
  V(performance_entry_callback, v8::Function)                                  \
526
  V(performance_entry_template, v8::Function)                                  \
527
  V(prepare_stack_trace_callback, v8::Function)                                \
528
  V(process_object, v8::Object)                                                \
529
  V(primordials, v8::Object)                                                   \
530
  V(primordials_safe_map_prototype_object, v8::Object)                         \
531
  V(primordials_safe_set_prototype_object, v8::Object)                         \
532
  V(primordials_safe_weak_map_prototype_object, v8::Object)                    \
533
  V(primordials_safe_weak_set_prototype_object, v8::Object)                    \
534
  V(promise_hook_handler, v8::Function)                                        \
535
  V(promise_reject_callback, v8::Function)                                     \
536
  V(script_data_constructor_function, v8::Function)                            \
537
  V(source_map_cache_getter, v8::Function)                                     \
538
  V(tick_callback_function, v8::Function)                                      \
539
  V(timers_callback_function, v8::Function)                                    \
540
  V(tls_wrap_constructor_function, v8::Function)                               \
541
  V(trace_category_state_function, v8::Function)                               \
542
  V(udp_constructor_function, v8::Function)                                    \
543
  V(url_constructor_function, v8::Function)
544
545
class Environment;
546
struct AllocatedBuffer;
547
548
typedef size_t SnapshotIndex;
549
9256
class IsolateData : public MemoryRetainer {
550
 public:
551
  IsolateData(v8::Isolate* isolate,
552
              uv_loop_t* event_loop,
553
              MultiIsolatePlatform* platform = nullptr,
554
              ArrayBufferAllocator* node_allocator = nullptr,
555
              const std::vector<size_t>* indexes = nullptr);
556
22
  SET_MEMORY_INFO_NAME(IsolateData)
557
22
  SET_SELF_SIZE(IsolateData)
558
  void MemoryInfo(MemoryTracker* tracker) const override;
559
  std::vector<size_t> Serialize(v8::SnapshotCreator* creator);
560
561
  inline uv_loop_t* event_loop() const;
562
  inline MultiIsolatePlatform* platform() const;
563
  inline std::shared_ptr<PerIsolateOptions> options();
564
  inline void set_options(std::shared_ptr<PerIsolateOptions> options);
565
566
  inline NodeArrayBufferAllocator* node_allocator() const;
567
568
  inline worker::Worker* worker_context() const;
569
  inline void set_worker_context(worker::Worker* context);
570
571
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
572
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
573
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
574
#define V(TypeName, PropertyName)                                             \
575
  inline v8::Local<TypeName> PropertyName() const;
576
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
577
  PER_ISOLATE_SYMBOL_PROPERTIES(VY)
578
  PER_ISOLATE_STRING_PROPERTIES(VS)
579
#undef V
580
#undef VY
581
#undef VS
582
#undef VP
583
  inline v8::Local<v8::String> async_wrap_provider(int index) const;
584
585
  size_t max_young_gen_size = 1;
586
  std::unordered_map<const char*, v8::Eternal<v8::String>> static_str_map;
587
588
  inline v8::Isolate* isolate() const;
589
  IsolateData(const IsolateData&) = delete;
590
  IsolateData& operator=(const IsolateData&) = delete;
591
  IsolateData(IsolateData&&) = delete;
592
  IsolateData& operator=(IsolateData&&) = delete;
593
594
 private:
595
  void DeserializeProperties(const std::vector<size_t>* indexes);
596
  void CreateProperties();
597
598
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
599
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
600
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
601
#define V(TypeName, PropertyName)                                             \
602
  v8::Eternal<TypeName> PropertyName ## _;
603
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
604
  PER_ISOLATE_SYMBOL_PROPERTIES(VY)
605
  PER_ISOLATE_STRING_PROPERTIES(VS)
606
#undef V
607
#undef VY
608
#undef VS
609
#undef VP
610
  // Keep a list of all Persistent strings used for AsyncWrap Provider types.
611
  std::array<v8::Eternal<v8::String>, AsyncWrap::PROVIDERS_LENGTH>
612
      async_wrap_providers_;
613
614
  v8::Isolate* const isolate_;
615
  uv_loop_t* const event_loop_;
616
  NodeArrayBufferAllocator* const node_allocator_;
617
  MultiIsolatePlatform* platform_;
618
  std::shared_ptr<PerIsolateOptions> options_;
619
  worker::Worker* worker_context_ = nullptr;
620
};
621
622
10830
struct ContextInfo {
623
10830
  explicit ContextInfo(const std::string& name) : name(name) {}
624
  const std::string name;
625
  std::string origin;
626
  bool is_default = false;
627
};
628
629
class EnabledDebugList;
630
631
class KVStore {
632
 public:
633
5426
  KVStore() = default;
634
4882
  virtual ~KVStore() = default;
635
  KVStore(const KVStore&) = delete;
636
  KVStore& operator=(const KVStore&) = delete;
637
  KVStore(KVStore&&) = delete;
638
  KVStore& operator=(KVStore&&) = delete;
639
640
  virtual v8::MaybeLocal<v8::String> Get(v8::Isolate* isolate,
641
                                         v8::Local<v8::String> key) const = 0;
642
  virtual v8::Maybe<std::string> Get(const char* key) const = 0;
643
  virtual void Set(v8::Isolate* isolate,
644
                   v8::Local<v8::String> key,
645
                   v8::Local<v8::String> value) = 0;
646
  virtual int32_t Query(v8::Isolate* isolate,
647
                        v8::Local<v8::String> key) const = 0;
648
  virtual int32_t Query(const char* key) const = 0;
649
  virtual void Delete(v8::Isolate* isolate, v8::Local<v8::String> key) = 0;
650
  virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0;
651
652
  virtual std::shared_ptr<KVStore> Clone(v8::Isolate* isolate) const;
653
  virtual v8::Maybe<bool> AssignFromObject(v8::Local<v8::Context> context,
654
                                           v8::Local<v8::Object> entries);
655
656
  static std::shared_ptr<KVStore> CreateMapKVStore();
657
};
658
659
namespace per_process {
660
extern std::shared_ptr<KVStore> system_environment;
661
}
662
663
struct EnvSerializeInfo;
664
665
class AsyncHooks : public MemoryRetainer {
666
 public:
667
22
  SET_MEMORY_INFO_NAME(AsyncHooks)
668
22
  SET_SELF_SIZE(AsyncHooks)
669
  void MemoryInfo(MemoryTracker* tracker) const override;
670
671
  // Reason for both UidFields and Fields are that one is stored as a double*
672
  // and the other as a uint32_t*.
673
  enum Fields {
674
    kInit,
675
    kBefore,
676
    kAfter,
677
    kDestroy,
678
    kPromiseResolve,
679
    kTotals,
680
    kCheck,
681
    kStackLength,
682
    kUsesExecutionAsyncResource,
683
    kFieldsCount,
684
  };
685
686
  enum UidFields {
687
    kExecutionAsyncId,
688
    kTriggerAsyncId,
689
    kAsyncIdCounter,
690
    kDefaultTriggerAsyncId,
691
    kUidFieldsCount,
692
  };
693
694
  inline AliasedUint32Array& fields();
695
  inline AliasedFloat64Array& async_id_fields();
696
  inline AliasedFloat64Array& async_ids_stack();
697
  inline v8::Local<v8::Array> js_execution_async_resources();
698
  // Returns the native executionAsyncResource value at stack index `index`.
699
  // Resources provided on the JS side are not stored on the native stack,
700
  // in which case an empty `Local<>` is returned.
701
  // The `js_execution_async_resources` array contains the value in that case.
702
  inline v8::Local<v8::Object> native_execution_async_resource(size_t index);
703
704
  inline v8::Local<v8::String> provider_string(int idx);
705
706
  inline void no_force_checks();
707
  inline Environment* env();
708
709
  inline void push_async_context(double async_id, double trigger_async_id,
710
      v8::Local<v8::Object> execution_async_resource_);
711
  inline bool pop_async_context(double async_id);
712
  inline void clear_async_id_stack();  // Used in fatal exceptions.
713
714
  AsyncHooks(const AsyncHooks&) = delete;
715
  AsyncHooks& operator=(const AsyncHooks&) = delete;
716
  AsyncHooks(AsyncHooks&&) = delete;
717
  AsyncHooks& operator=(AsyncHooks&&) = delete;
718
9226
  ~AsyncHooks() = default;
719
720
  // Used to set the kDefaultTriggerAsyncId in a scope. This is instead of
721
  // passing the trigger_async_id along with other constructor arguments.
722
  class DefaultTriggerAsyncIdScope {
723
   public:
724
    DefaultTriggerAsyncIdScope() = delete;
725
    explicit DefaultTriggerAsyncIdScope(Environment* env,
726
                                        double init_trigger_async_id);
727
    explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap);
728
    ~DefaultTriggerAsyncIdScope();
729
730
    DefaultTriggerAsyncIdScope(const DefaultTriggerAsyncIdScope&) = delete;
731
    DefaultTriggerAsyncIdScope& operator=(const DefaultTriggerAsyncIdScope&) =
732
        delete;
733
    DefaultTriggerAsyncIdScope(DefaultTriggerAsyncIdScope&&) = delete;
734
    DefaultTriggerAsyncIdScope& operator=(DefaultTriggerAsyncIdScope&&) =
735
        delete;
736
737
   private:
738
    AsyncHooks* async_hooks_;
739
    double old_default_trigger_async_id_;
740
  };
741
742
4810
  struct SerializeInfo {
743
    AliasedBufferIndex async_ids_stack;
744
    AliasedBufferIndex fields;
745
    AliasedBufferIndex async_id_fields;
746
    SnapshotIndex js_execution_async_resources;
747
    std::vector<SnapshotIndex> native_execution_async_resources;
748
  };
749
750
  SerializeInfo Serialize(v8::Local<v8::Context> context,
751
                          v8::SnapshotCreator* creator);
752
  void Deserialize(v8::Local<v8::Context> context);
753
754
 private:
755
  friend class Environment;  // So we can call the constructor.
756
  explicit AsyncHooks(v8::Isolate* isolate, const SerializeInfo* info);
757
758
  // Stores the ids of the current execution context stack.
759
  AliasedFloat64Array async_ids_stack_;
760
  // Attached to a Uint32Array that tracks the number of active hooks for
761
  // each type.
762
  AliasedUint32Array fields_;
763
  // Attached to a Float64Array that tracks the state of async resources.
764
  AliasedFloat64Array async_id_fields_;
765
766
  void grow_async_ids_stack();
767
768
  v8::Global<v8::Array> js_execution_async_resources_;
769
  std::vector<v8::Global<v8::Object>> native_execution_async_resources_;
770
771
  // Non-empty during deserialization
772
  const SerializeInfo* info_ = nullptr;
773
};
774
775
class ImmediateInfo : public MemoryRetainer {
776
 public:
777
  inline AliasedUint32Array& fields();
778
  inline uint32_t count() const;
779
  inline uint32_t ref_count() const;
780
  inline bool has_outstanding() const;
781
  inline void ref_count_inc(uint32_t increment);
782
  inline void ref_count_dec(uint32_t decrement);
783
784
  ImmediateInfo(const ImmediateInfo&) = delete;
785
  ImmediateInfo& operator=(const ImmediateInfo&) = delete;
786
  ImmediateInfo(ImmediateInfo&&) = delete;
787
  ImmediateInfo& operator=(ImmediateInfo&&) = delete;
788
4613
  ~ImmediateInfo() = default;
789
790
22
  SET_MEMORY_INFO_NAME(ImmediateInfo)
791
22
  SET_SELF_SIZE(ImmediateInfo)
792
  void MemoryInfo(MemoryTracker* tracker) const override;
793
794
  struct SerializeInfo {
795
    AliasedBufferIndex fields;
796
  };
797
  SerializeInfo Serialize(v8::Local<v8::Context> context,
798
                          v8::SnapshotCreator* creator);
799
  void Deserialize(v8::Local<v8::Context> context);
800
801
 private:
802
  friend class Environment;  // So we can call the constructor.
803
  explicit ImmediateInfo(v8::Isolate* isolate, const SerializeInfo* info);
804
805
  enum Fields { kCount, kRefCount, kHasOutstanding, kFieldsCount };
806
807
  AliasedUint32Array fields_;
808
};
809
810
class TickInfo : public MemoryRetainer {
811
 public:
812
  inline AliasedUint8Array& fields();
813
  inline bool has_tick_scheduled() const;
814
  inline bool has_rejection_to_warn() const;
815
816
22
  SET_MEMORY_INFO_NAME(TickInfo)
817
22
  SET_SELF_SIZE(TickInfo)
818
  void MemoryInfo(MemoryTracker* tracker) const override;
819
820
  TickInfo(const TickInfo&) = delete;
821
  TickInfo& operator=(const TickInfo&) = delete;
822
  TickInfo(TickInfo&&) = delete;
823
  TickInfo& operator=(TickInfo&&) = delete;
824
4613
  ~TickInfo() = default;
825
826
  struct SerializeInfo {
827
    AliasedBufferIndex fields;
828
  };
829
  SerializeInfo Serialize(v8::Local<v8::Context> context,
830
                          v8::SnapshotCreator* creator);
831
  void Deserialize(v8::Local<v8::Context> context);
832
833
 private:
834
  friend class Environment;  // So we can call the constructor.
835
  explicit TickInfo(v8::Isolate* isolate, const SerializeInfo* info);
836
837
  enum Fields { kHasTickScheduled = 0, kHasRejectionToWarn, kFieldsCount };
838
839
  AliasedUint8Array fields_;
840
};
841
842
9226
class TrackingTraceStateObserver :
843
    public v8::TracingController::TraceStateObserver {
844
 public:
845
5157
  explicit TrackingTraceStateObserver(Environment* env) : env_(env) {}
846
847
87
  void OnTraceEnabled() override {
848
87
    UpdateTraceCategoryState();
849
87
  }
850
851
34
  void OnTraceDisabled() override {
852
34
    UpdateTraceCategoryState();
853
34
  }
854
855
 private:
856
  void UpdateTraceCategoryState();
857
858
  Environment* env_;
859
};
860
861
class ShouldNotAbortOnUncaughtScope {
862
 public:
863
  explicit inline ShouldNotAbortOnUncaughtScope(Environment* env);
864
  inline void Close();
865
  inline ~ShouldNotAbortOnUncaughtScope();
866
  ShouldNotAbortOnUncaughtScope(const ShouldNotAbortOnUncaughtScope&) = delete;
867
  ShouldNotAbortOnUncaughtScope& operator=(
868
      const ShouldNotAbortOnUncaughtScope&) = delete;
869
  ShouldNotAbortOnUncaughtScope(ShouldNotAbortOnUncaughtScope&&) = delete;
870
  ShouldNotAbortOnUncaughtScope& operator=(ShouldNotAbortOnUncaughtScope&&) =
871
      delete;
872
873
 private:
874
  Environment* env_;
875
};
876
877
class CleanupHookCallback {
878
 public:
879
  typedef void (*Callback)(void*);
880
881
705101
  CleanupHookCallback(Callback fn,
882
                      void* arg,
883
                      uint64_t insertion_order_counter)
884
705101
      : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {}
885
886
  // Only hashes `arg_`, since that is usually enough to identify the hook.
887
5157
  struct Hash {
888
    inline size_t operator()(const CleanupHookCallback& cb) const;
889
  };
890
891
  // Compares by `fn_` and `arg_` being equal.
892
5157
  struct Equal {
893
    inline bool operator()(const CleanupHookCallback& a,
894
                           const CleanupHookCallback& b) const;
895
  };
896
897
  inline BaseObject* GetBaseObject() const;
898
899
 private:
900
  friend class Environment;
901
  Callback fn_;
902
  void* arg_;
903
904
  // We keep track of the insertion order for these objects, so that we can
905
  // call the callbacks in reverse order when we are cleaning up.
906
  uint64_t insertion_order_counter_;
907
};
908
909
637997
struct PropInfo {
910
  std::string name;     // name for debugging
911
  size_t id;            // In the list - in case there are any empty entires
912
  SnapshotIndex index;  // In the snapshot
913
};
914
915
typedef void (*DeserializeRequestCallback)(v8::Local<v8::Context> context,
916
                                           v8::Local<v8::Object> holder,
917
                                           int index,
918
                                           InternalFieldInfo* info);
919
56340
struct DeserializeRequest {
920
  DeserializeRequestCallback cb;
921
  v8::Global<v8::Object> holder;
922
  int index;
923
  InternalFieldInfo* info = nullptr;  // Owned by the request
924
925
  // Move constructor
926
37560
  DeserializeRequest(DeserializeRequest&& other) = default;
927
};
928
929
4685
struct EnvSerializeInfo {
930
  std::vector<PropInfo> bindings;
931
  std::vector<std::string> native_modules;
932
  AsyncHooks::SerializeInfo async_hooks;
933
  TickInfo::SerializeInfo tick_info;
934
  ImmediateInfo::SerializeInfo immediate_info;
935
  performance::PerformanceState::SerializeInfo performance_state;
936
  AliasedBufferIndex stream_base_state;
937
  AliasedBufferIndex should_abort_on_uncaught_toggle;
938
939
  std::vector<PropInfo> persistent_templates;
940
  std::vector<PropInfo> persistent_values;
941
942
  SnapshotIndex context;
943
  friend std::ostream& operator<<(std::ostream& o, const EnvSerializeInfo& i);
944
};
945
946
class Environment : public MemoryRetainer {
947
 public:
948
  Environment(const Environment&) = delete;
949
  Environment& operator=(const Environment&) = delete;
950
  Environment(Environment&&) = delete;
951
  Environment& operator=(Environment&&) = delete;
952
953
22
  SET_MEMORY_INFO_NAME(Environment)
954
955
  inline size_t SelfSize() const override;
956
44
  bool IsRootNode() const override { return true; }
957
  void MemoryInfo(MemoryTracker* tracker) const override;
958
959
  EnvSerializeInfo Serialize(v8::SnapshotCreator* creator);
960
  void CreateProperties();
961
  void DeserializeProperties(const EnvSerializeInfo* info);
962
963
  void PrintInfoForSnapshotIfDebug();
964
  void PrintAllBaseObjects();
965
  void VerifyNoStrongBaseObjects();
966
  void EnqueueDeserializeRequest(DeserializeRequestCallback cb,
967
                                 v8::Local<v8::Object> holder,
968
                                 int index,
969
                                 InternalFieldInfo* info);
970
  void RunDeserializeRequests();
971
  // Should be called before InitializeInspector()
972
  void InitializeDiagnostics();
973
974
  std::string GetCwd();
975
976
#if HAVE_INSPECTOR
977
  // If the environment is created for a worker, pass parent_handle and
978
  // the ownership if transferred into the Environment.
979
  int InitializeInspector(
980
      std::unique_ptr<inspector::ParentInspectorHandle> parent_handle);
981
#endif
982
983
  v8::MaybeLocal<v8::Value> BootstrapInternalLoaders();
984
  v8::MaybeLocal<v8::Value> BootstrapNode();
985
  v8::MaybeLocal<v8::Value> RunBootstrapping();
986
987
  inline size_t async_callback_scope_depth() const;
988
  inline void PushAsyncCallbackScope();
989
  inline void PopAsyncCallbackScope();
990
991
  static inline Environment* GetCurrent(v8::Isolate* isolate);
992
  static inline Environment* GetCurrent(v8::Local<v8::Context> context);
993
  static inline Environment* GetCurrent(
994
      const v8::FunctionCallbackInfo<v8::Value>& info);
995
996
  template <typename T>
997
  static inline Environment* GetCurrent(
998
      const v8::PropertyCallbackInfo<T>& info);
999
1000
  // Methods created using SetMethod(), SetPrototypeMethod(), etc. inside
1001
  // this scope can access the created T* object using
1002
  // GetBindingData<T>(args) later.
1003
  template <typename T>
1004
  T* AddBindingData(v8::Local<v8::Context> context,
1005
                    v8::Local<v8::Object> target);
1006
  template <typename T, typename U>
1007
  static inline T* GetBindingData(const v8::PropertyCallbackInfo<U>& info);
1008
  template <typename T>
1009
  static inline T* GetBindingData(
1010
      const v8::FunctionCallbackInfo<v8::Value>& info);
1011
  template <typename T>
1012
  static inline T* GetBindingData(v8::Local<v8::Context> context);
1013
1014
  typedef std::unordered_map<
1015
      FastStringKey,
1016
      BaseObjectPtr<BaseObject>,
1017
      FastStringKey::Hash> BindingDataStore;
1018
1019
  // Create an Environment without initializing a main Context. Use
1020
  // InitializeMainContext() to initialize a main context for it.
1021
  Environment(IsolateData* isolate_data,
1022
              v8::Isolate* isolate,
1023
              const std::vector<std::string>& args,
1024
              const std::vector<std::string>& exec_args,
1025
              const EnvSerializeInfo* env_info,
1026
              EnvironmentFlags::Flags flags,
1027
              ThreadId thread_id);
1028
  void InitializeMainContext(v8::Local<v8::Context> context,
1029
                             const EnvSerializeInfo* env_info);
1030
  // Create an Environment and initialize the provided main context for it.
1031
  Environment(IsolateData* isolate_data,
1032
              v8::Local<v8::Context> context,
1033
              const std::vector<std::string>& args,
1034
              const std::vector<std::string>& exec_args,
1035
              const EnvSerializeInfo* env_info,
1036
              EnvironmentFlags::Flags flags,
1037
              ThreadId thread_id);
1038
  ~Environment() override;
1039
1040
  void InitializeLibuv();
1041
  inline const std::vector<std::string>& exec_argv();
1042
  inline const std::vector<std::string>& argv();
1043
  const std::string& exec_path() const;
1044
1045
  typedef void (*HandleCleanupCb)(Environment* env,
1046
                                  uv_handle_t* handle,
1047
                                  void* arg);
1048
  struct HandleCleanup {
1049
    uv_handle_t* handle_;
1050
    HandleCleanupCb cb_;
1051
    void* arg_;
1052
  };
1053
1054
  void RegisterHandleCleanups();
1055
  void CleanupHandles();
1056
  void Exit(int code);
1057
  void ExitEnv();
1058
1059
  // Register clean-up cb to be called on environment destruction.
1060
  inline void RegisterHandleCleanup(uv_handle_t* handle,
1061
                                    HandleCleanupCb cb,
1062
                                    void* arg);
1063
1064
  template <typename T, typename OnCloseCallback>
1065
  inline void CloseHandle(T* handle, OnCloseCallback callback);
1066
1067
  inline void AssignToContext(v8::Local<v8::Context> context,
1068
                              const ContextInfo& info);
1069
1070
  void StartProfilerIdleNotifier();
1071
1072
  inline v8::Isolate* isolate() const;
1073
  inline uv_loop_t* event_loop() const;
1074
  inline void TryLoadAddon(
1075
      const char* filename,
1076
      int flags,
1077
      const std::function<bool(binding::DLib*)>& was_loaded);
1078
1079
  static inline Environment* from_timer_handle(uv_timer_t* handle);
1080
  inline uv_timer_t* timer_handle();
1081
1082
  static inline Environment* from_immediate_check_handle(uv_check_t* handle);
1083
  inline uv_check_t* immediate_check_handle();
1084
  inline uv_idle_t* immediate_idle_handle();
1085
1086
  inline void IncreaseWaitingRequestCounter();
1087
  inline void DecreaseWaitingRequestCounter();
1088
1089
  inline AsyncHooks* async_hooks();
1090
  inline ImmediateInfo* immediate_info();
1091
  inline TickInfo* tick_info();
1092
  inline uint64_t timer_base() const;
1093
  inline std::shared_ptr<KVStore> env_vars();
1094
  inline void set_env_vars(std::shared_ptr<KVStore> env_vars);
1095
1096
  inline IsolateData* isolate_data() const;
1097
1098
  inline bool printed_error() const;
1099
  inline void set_printed_error(bool value);
1100
1101
  void PrintSyncTrace() const;
1102
  inline void set_trace_sync_io(bool value);
1103
1104
  inline void set_force_context_aware(bool value);
1105
  inline bool force_context_aware() const;
1106
1107
  // This stores whether the --abort-on-uncaught-exception flag was passed
1108
  // to Node.
1109
  inline bool abort_on_uncaught_exception() const;
1110
  inline void set_abort_on_uncaught_exception(bool value);
1111
  // This is a pseudo-boolean that keeps track of whether an uncaught exception
1112
  // should abort the process or not if --abort-on-uncaught-exception was
1113
  // passed to Node. If the flag was not passed, it is ignored.
1114
  inline AliasedUint32Array& should_abort_on_uncaught_toggle();
1115
1116
  inline AliasedInt32Array& stream_base_state();
1117
1118
  // The necessary API for async_hooks.
1119
  inline double new_async_id();
1120
  inline double execution_async_id();
1121
  inline double trigger_async_id();
1122
  inline double get_default_trigger_async_id();
1123
1124
  // List of id's that have been destroyed and need the destroy() cb called.
1125
  inline std::vector<double>* destroy_async_id_list();
1126
1127
  std::set<struct node_module*> internal_bindings;
1128
  std::set<std::string> native_modules_with_cache;
1129
  std::set<std::string> native_modules_without_cache;
1130
  // This is only filled during deserialization. We use a vector since
1131
  // it's only used for tests.
1132
  std::vector<std::string> native_modules_in_snapshot;
1133
1134
  std::unordered_multimap<int, loader::ModuleWrap*> hash_to_module_map;
1135
  std::unordered_map<uint32_t, loader::ModuleWrap*> id_to_module_map;
1136
  std::unordered_map<uint32_t, contextify::ContextifyScript*>
1137
      id_to_script_map;
1138
  std::unordered_map<uint32_t, contextify::CompiledFnEntry*> id_to_function_map;
1139
1140
  inline uint32_t get_next_module_id();
1141
  inline uint32_t get_next_script_id();
1142
  inline uint32_t get_next_function_id();
1143
1144
1277243
  EnabledDebugList* enabled_debug_list() { return &enabled_debug_list_; }
1145
1146
  inline performance::PerformanceState* performance_state();
1147
1148
  void CollectUVExceptionInfo(v8::Local<v8::Value> context,
1149
                              int errorno,
1150
                              const char* syscall = nullptr,
1151
                              const char* message = nullptr,
1152
                              const char* path = nullptr,
1153
                              const char* dest = nullptr);
1154
1155
  // If this flag is set, calls into JS (if they would be observable
1156
  // from userland) must be avoided.  This flag does not indicate whether
1157
  // calling into JS is allowed from a VM perspective at this point.
1158
  inline bool can_call_into_js() const;
1159
  inline void set_can_call_into_js(bool can_call_into_js);
1160
1161
  // Increase or decrease a counter that manages whether this Environment
1162
  // keeps the event loop alive on its own or not. The counter starts out at 0,
1163
  // meaning it does not, and any positive value will make it keep the event
1164
  // loop alive.
1165
  // This is used by Workers to manage their own .ref()/.unref() implementation,
1166
  // as Workers aren't directly associated with their own libuv handles.
1167
  inline void add_refs(int64_t diff);
1168
1169
  inline bool has_run_bootstrapping_code() const;
1170
  inline void DoneBootstrapping();
1171
1172
  inline bool has_serialized_options() const;
1173
  inline void set_has_serialized_options(bool has_serialized_options);
1174
1175
  inline bool is_main_thread() const;
1176
  inline bool should_not_register_esm_loader() const;
1177
  inline bool owns_process_state() const;
1178
  inline bool owns_inspector() const;
1179
  inline bool tracks_unmanaged_fds() const;
1180
  inline uint64_t thread_id() const;
1181
  inline worker::Worker* worker_context() const;
1182
  Environment* worker_parent_env() const;
1183
  inline void add_sub_worker_context(worker::Worker* context);
1184
  inline void remove_sub_worker_context(worker::Worker* context);
1185
  void stop_sub_worker_contexts();
1186
  template <typename Fn>
1187
  inline void ForEachWorker(Fn&& iterator);
1188
  inline bool is_stopping() const;
1189
  inline void set_stopping(bool value);
1190
  inline std::list<node_module>* extra_linked_bindings();
1191
  inline node_module* extra_linked_bindings_head();
1192
  inline const Mutex& extra_linked_bindings_mutex() const;
1193
1194
  inline bool filehandle_close_warning() const;
1195
  inline void set_filehandle_close_warning(bool on);
1196
1197
  inline void set_source_maps_enabled(bool on);
1198
  inline bool source_maps_enabled() const;
1199
1200
  inline void ThrowError(const char* errmsg);
1201
  inline void ThrowTypeError(const char* errmsg);
1202
  inline void ThrowRangeError(const char* errmsg);
1203
  inline void ThrowErrnoException(int errorno,
1204
                                  const char* syscall = nullptr,
1205
                                  const char* message = nullptr,
1206
                                  const char* path = nullptr);
1207
  inline void ThrowUVException(int errorno,
1208
                               const char* syscall = nullptr,
1209
                               const char* message = nullptr,
1210
                               const char* path = nullptr,
1211
                               const char* dest = nullptr);
1212
1213
  inline v8::Local<v8::FunctionTemplate>
1214
      NewFunctionTemplate(v8::FunctionCallback callback,
1215
                          v8::Local<v8::Signature> signature =
1216
                              v8::Local<v8::Signature>(),
1217
                          v8::ConstructorBehavior behavior =
1218
                              v8::ConstructorBehavior::kAllow,
1219
                          v8::SideEffectType side_effect =
1220
                              v8::SideEffectType::kHasSideEffect);
1221
1222
  // Convenience methods for NewFunctionTemplate().
1223
  inline void SetMethod(v8::Local<v8::Object> that,
1224
                        const char* name,
1225
                        v8::FunctionCallback callback);
1226
1227
  inline void SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
1228
                             const char* name,
1229
                             v8::FunctionCallback callback);
1230
1231
  inline void SetInstanceMethod(v8::Local<v8::FunctionTemplate> that,
1232
                                const char* name,
1233
                                v8::FunctionCallback callback);
1234
1235
1236
  // Safe variants denote the function has no side effects.
1237
  inline void SetMethodNoSideEffect(v8::Local<v8::Object> that,
1238
                                    const char* name,
1239
                                    v8::FunctionCallback callback);
1240
  inline void SetProtoMethodNoSideEffect(v8::Local<v8::FunctionTemplate> that,
1241
                                         const char* name,
1242
                                         v8::FunctionCallback callback);
1243
1244
  enum class SetConstructorFunctionFlag {
1245
    NONE,
1246
    SET_CLASS_NAME,
1247
  };
1248
1249
  inline void SetConstructorFunction(v8::Local<v8::Object> that,
1250
                          const char* name,
1251
                          v8::Local<v8::FunctionTemplate> tmpl,
1252
                          SetConstructorFunctionFlag flag =
1253
                              SetConstructorFunctionFlag::SET_CLASS_NAME);
1254
1255
  inline void SetConstructorFunction(v8::Local<v8::Object> that,
1256
                          v8::Local<v8::String> name,
1257
                          v8::Local<v8::FunctionTemplate> tmpl,
1258
                          SetConstructorFunctionFlag flag =
1259
                              SetConstructorFunctionFlag::SET_CLASS_NAME);
1260
1261
  void AtExit(void (*cb)(void* arg), void* arg);
1262
  void RunAtExitCallbacks();
1263
1264
  void RunWeakRefCleanup();
1265
1266
  // Strings and private symbols are shared across shared contexts
1267
  // The getters simply proxy to the per-isolate primitive.
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> PropertyName() const;
1273
  PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
1274
  PER_ISOLATE_SYMBOL_PROPERTIES(VY)
1275
  PER_ISOLATE_STRING_PROPERTIES(VS)
1276
#undef V
1277
#undef VS
1278
#undef VY
1279
#undef VP
1280
1281
#define V(PropertyName, TypeName)                                             \
1282
  inline v8::Local<TypeName> PropertyName() const;                            \
1283
  inline void set_ ## PropertyName(v8::Local<TypeName> value);
1284
  ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
1285
  ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
1286
#undef V
1287
1288
  inline v8::Local<v8::Context> context() const;
1289
1290
#if HAVE_INSPECTOR
1291
48316
  inline inspector::Agent* inspector_agent() const {
1292
48316
    return inspector_agent_.get();
1293
  }
1294
1295
  inline bool is_in_inspector_console_call() const;
1296
  inline void set_is_in_inspector_console_call(bool value);
1297
#endif
1298
1299
  typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
1300
  typedef ListHead<ReqWrapBase, &ReqWrapBase::req_wrap_queue_> ReqWrapQueue;
1301
1302
59749
  inline HandleWrapQueue* handle_wrap_queue() { return &handle_wrap_queue_; }
1303
77202
  inline ReqWrapQueue* req_wrap_queue() { return &req_wrap_queue_; }
1304
1305
1
  inline bool EmitProcessEnvWarning() {
1306
1
    bool current_value = emit_env_nonstring_warning_;
1307
1
    emit_env_nonstring_warning_ = false;
1308
1
    return current_value;
1309
  }
1310
1311
1
  inline bool EmitErrNameWarning() {
1312
1
    bool current_value = emit_err_name_warning_;
1313
1
    emit_err_name_warning_ = false;
1314
1
    return current_value;
1315
  }
1316
1317
  // cb will be called as cb(env) on the next event loop iteration.
1318
  // Unlike the JS setImmediate() function, nested SetImmediate() calls will
1319
  // be run without returning control to the event loop, similar to nextTick().
1320
  template <typename Fn>
1321
  inline void SetImmediate(
1322
      Fn&& cb, CallbackFlags::Flags flags = CallbackFlags::kRefed);
1323
  template <typename Fn>
1324
  // This behaves like SetImmediate() but can be called from any thread.
1325
  inline void SetImmediateThreadsafe(
1326
      Fn&& cb, CallbackFlags::Flags flags = CallbackFlags::kRefed);
1327
  // This behaves like V8's Isolate::RequestInterrupt(), but also accounts for
1328
  // the event loop (i.e. combines the V8 function with SetImmediate()).
1329
  // The passed callback may not throw exceptions.
1330
  // This function can be called from any thread.
1331
  template <typename Fn>
1332
  inline void RequestInterrupt(Fn&& cb);
1333
  // This needs to be available for the JS-land setImmediate().
1334
  void ToggleImmediateRef(bool ref);
1335
1336
  inline void PushShouldNotAbortOnUncaughtScope();
1337
  inline void PopShouldNotAbortOnUncaughtScope();
1338
  inline bool inside_should_not_abort_on_uncaught_scope() const;
1339
1340
  static inline Environment* ForAsyncHooks(AsyncHooks* hooks);
1341
1342
  v8::Local<v8::Value> GetNow();
1343
  void ScheduleTimer(int64_t duration);
1344
  void ToggleTimerRef(bool ref);
1345
1346
  using CleanupCallback = CleanupHookCallback::Callback;
1347
  inline void AddCleanupHook(CleanupCallback cb, void* arg);
1348
  inline void RemoveCleanupHook(CleanupCallback cb, void* arg);
1349
  void RunCleanup();
1350
1351
  static size_t NearHeapLimitCallback(void* data,
1352
                                      size_t current_heap_limit,
1353
                                      size_t initial_heap_limit);
1354
  static void BuildEmbedderGraph(v8::Isolate* isolate,
1355
                                 v8::EmbedderGraph* graph,
1356
                                 void* data);
1357
1358
  inline std::shared_ptr<EnvironmentOptions> options();
1359
  inline std::shared_ptr<ExclusiveAccess<HostPort>> inspector_host_port();
1360
1361
  // The BaseObject count is a debugging helper that makes sure that there are
1362
  // no memory leaks caused by BaseObjects staying alive longer than expected
1363
  // (in particular, no circular BaseObjectPtr references).
1364
  inline void modify_base_object_count(int64_t delta);
1365
  inline int64_t base_object_created_after_bootstrap() const;
1366
  inline int64_t base_object_count() const;
1367
1368
3
  inline int32_t stack_trace_limit() const { return 10; }
1369
1370
#if HAVE_INSPECTOR
1371
  void set_coverage_connection(
1372
      std::unique_ptr<profiler::V8CoverageConnection> connection);
1373
  profiler::V8CoverageConnection* coverage_connection();
1374
1375
  inline void set_coverage_directory(const char* directory);
1376
  inline const std::string& coverage_directory() const;
1377
1378
  void set_cpu_profiler_connection(
1379
      std::unique_ptr<profiler::V8CpuProfilerConnection> connection);
1380
  profiler::V8CpuProfilerConnection* cpu_profiler_connection();
1381
1382
  inline void set_cpu_prof_name(const std::string& name);
1383
  inline const std::string& cpu_prof_name() const;
1384
1385
  inline void set_cpu_prof_interval(uint64_t interval);
1386
  inline uint64_t cpu_prof_interval() const;
1387
1388
  inline void set_cpu_prof_dir(const std::string& dir);
1389
  inline const std::string& cpu_prof_dir() const;
1390
1391
  void set_heap_profiler_connection(
1392
      std::unique_ptr<profiler::V8HeapProfilerConnection> connection);
1393
  profiler::V8HeapProfilerConnection* heap_profiler_connection();
1394
1395
  inline void set_heap_prof_name(const std::string& name);
1396
  inline const std::string& heap_prof_name() const;
1397
1398
  inline void set_heap_prof_dir(const std::string& dir);
1399
  inline const std::string& heap_prof_dir() const;
1400
1401
  inline void set_heap_prof_interval(uint64_t interval);
1402
  inline uint64_t heap_prof_interval() const;
1403
1404
#endif  // HAVE_INSPECTOR
1405
1406
  inline void set_main_utf16(std::unique_ptr<v8::String::Value>);
1407
  inline void set_process_exit_handler(
1408
      std::function<void(Environment*, int)>&& handler);
1409
1410
  void RunAndClearNativeImmediates(bool only_refed = false);
1411
  void RunAndClearInterrupts();
1412
1413
  inline std::unordered_map<char*, std::unique_ptr<v8::BackingStore>>*
1414
      released_allocated_buffers();
1415
1416
  void AddUnmanagedFd(int fd);
1417
  void RemoveUnmanagedFd(int fd);
1418
1419
  template <typename T>
1420
  void ForEachBindingData(T&& iterator);
1421
1422
 private:
1423
  inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
1424
                         const char* errmsg);
1425
1426
  std::list<binding::DLib> loaded_addons_;
1427
  v8::Isolate* const isolate_;
1428
  IsolateData* const isolate_data_;
1429
  uv_timer_t timer_handle_;
1430
  uv_check_t immediate_check_handle_;
1431
  uv_idle_t immediate_idle_handle_;
1432
  uv_prepare_t idle_prepare_handle_;
1433
  uv_check_t idle_check_handle_;
1434
  uv_async_t task_queues_async_;
1435
  int64_t task_queues_async_refs_ = 0;
1436
1437
  AsyncHooks async_hooks_;
1438
  ImmediateInfo immediate_info_;
1439
  TickInfo tick_info_;
1440
  const uint64_t timer_base_;
1441
  std::shared_ptr<KVStore> env_vars_;
1442
  bool printed_error_ = false;
1443
  bool trace_sync_io_ = false;
1444
  bool emit_env_nonstring_warning_ = true;
1445
  bool emit_err_name_warning_ = true;
1446
  bool emit_filehandle_warning_ = true;
1447
  bool source_maps_enabled_ = false;
1448
1449
  size_t async_callback_scope_depth_ = 0;
1450
  std::vector<double> destroy_async_id_list_;
1451
1452
#if HAVE_INSPECTOR
1453
  std::unique_ptr<profiler::V8CoverageConnection> coverage_connection_;
1454
  std::unique_ptr<profiler::V8CpuProfilerConnection> cpu_profiler_connection_;
1455
  std::string coverage_directory_;
1456
  std::string cpu_prof_dir_;
1457
  std::string cpu_prof_name_;
1458
  uint64_t cpu_prof_interval_;
1459
  std::unique_ptr<profiler::V8HeapProfilerConnection> heap_profiler_connection_;
1460
  std::string heap_prof_dir_;
1461
  std::string heap_prof_name_;
1462
  uint64_t heap_prof_interval_;
1463
#endif  // HAVE_INSPECTOR
1464
1465
  std::shared_ptr<EnvironmentOptions> options_;
1466
  // options_ contains debug options parsed from CLI arguments,
1467
  // while inspector_host_port_ stores the actual inspector host
1468
  // and port being used. For example the port is -1 by default
1469
  // and can be specified as 0 (meaning any port allocated when the
1470
  // server starts listening), but when the inspector server starts
1471
  // the inspector_host_port_->port() will be the actual port being
1472
  // used.
1473
  std::shared_ptr<ExclusiveAccess<HostPort>> inspector_host_port_;
1474
  std::vector<std::string> exec_argv_;
1475
  std::vector<std::string> argv_;
1476
  std::string exec_path_;
1477
1478
  bool is_processing_heap_limit_callback_ = false;
1479
  int64_t heap_limit_snapshot_taken_ = 0;
1480
1481
  uint32_t module_id_counter_ = 0;
1482
  uint32_t script_id_counter_ = 0;
1483
  uint32_t function_id_counter_ = 0;
1484
1485
  AliasedUint32Array should_abort_on_uncaught_toggle_;
1486
  int should_not_abort_scope_counter_ = 0;
1487
1488
  std::unique_ptr<TrackingTraceStateObserver> trace_state_observer_;
1489
1490
  AliasedInt32Array stream_base_state_;
1491
1492
  uint64_t environment_start_time_;
1493
  std::unique_ptr<performance::PerformanceState> performance_state_;
1494
1495
  bool has_run_bootstrapping_code_ = false;
1496
  bool has_serialized_options_ = false;
1497
1498
  std::atomic_bool can_call_into_js_ { true };
1499
  uint64_t flags_;
1500
  uint64_t thread_id_;
1501
  std::unordered_set<worker::Worker*> sub_worker_contexts_;
1502
1503
  static void* const kNodeContextTagPtr;
1504
  static int const kNodeContextTag;
1505
1506
#if HAVE_INSPECTOR
1507
  std::unique_ptr<inspector::Agent> inspector_agent_;
1508
  bool is_in_inspector_console_call_ = false;
1509
#endif
1510
1511
  std::list<DeserializeRequest> deserialize_requests_;
1512
1513
  // handle_wrap_queue_ and req_wrap_queue_ needs to be at a fixed offset from
1514
  // the start of the class because it is used by
1515
  // src/node_postmortem_metadata.cc to calculate offsets and generate debug
1516
  // symbols for Environment, which assumes that the position of members in
1517
  // memory are predictable. For more information please refer to
1518
  // `doc/guides/node-postmortem-support.md`
1519
  friend int GenDebugSymbols();
1520
  HandleWrapQueue handle_wrap_queue_;
1521
  ReqWrapQueue req_wrap_queue_;
1522
  std::list<HandleCleanup> handle_cleanup_queue_;
1523
  int handle_cleanup_waiting_ = 0;
1524
  int request_waiting_ = 0;
1525
1526
  EnabledDebugList enabled_debug_list_;
1527
1528
  std::list<node_module> extra_linked_bindings_;
1529
  Mutex extra_linked_bindings_mutex_;
1530
1531
  static void RunTimers(uv_timer_t* handle);
1532
1533
  struct ExitCallback {
1534
    void (*cb_)(void* arg);
1535
    void* arg_;
1536
  };
1537
1538
  std::list<ExitCallback> at_exit_functions_;
1539
1540
  typedef CallbackQueue<void, Environment*> NativeImmediateQueue;
1541
  NativeImmediateQueue native_immediates_;
1542
  Mutex native_immediates_threadsafe_mutex_;
1543
  NativeImmediateQueue native_immediates_threadsafe_;
1544
  NativeImmediateQueue native_immediates_interrupts_;
1545
  // Also guarded by native_immediates_threadsafe_mutex_. This can be used when
1546
  // trying to post tasks from other threads to an Environment, as the libuv
1547
  // handle for the immediate queues (task_queues_async_) may not be initialized
1548
  // yet or already have been destroyed.
1549
  bool task_queues_async_initialized_ = false;
1550
1551
  std::atomic<Environment**> interrupt_data_ {nullptr};
1552
  void RequestInterruptFromV8();
1553
  static void CheckImmediate(uv_check_t* handle);
1554
1555
  BindingDataStore bindings_;
1556
1557
  // Use an unordered_set, so that we have efficient insertion and removal.
1558
  std::unordered_set<CleanupHookCallback,
1559
                     CleanupHookCallback::Hash,
1560
                     CleanupHookCallback::Equal> cleanup_hooks_;
1561
  uint64_t cleanup_hook_counter_ = 0;
1562
  bool started_cleanup_ = false;
1563
1564
  int64_t base_object_count_ = 0;
1565
  int64_t base_object_created_by_bootstrap_ = 0;
1566
  std::atomic_bool is_stopping_ { false };
1567
1568
  std::unordered_set<int> unmanaged_fds_;
1569
1570
  std::function<void(Environment*, int)> process_exit_handler_ {
1571
      DefaultProcessExitHandler };
1572
1573
  template <typename T>
1574
  void ForEachBaseObject(T&& iterator);
1575
1576
#define V(PropertyName, TypeName) v8::Global<TypeName> PropertyName ## _;
1577
  ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
1578
  ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
1579
#undef V
1580
1581
  v8::Global<v8::Context> context_;
1582
1583
  // Keeps the main script source alive is one was passed to LoadEnvironment().
1584
  // We should probably find a way to just use plain `v8::String`s created from
1585
  // the source passed to LoadEnvironment() directly instead.
1586
  std::unique_ptr<v8::String::Value> main_utf16_;
1587
1588
  // Used by AllocatedBuffer::release() to keep track of the BackingStore for
1589
  // a given pointer.
1590
  std::unordered_map<char*, std::unique_ptr<v8::BackingStore>>
1591
      released_allocated_buffers_;
1592
};
1593
1594
}  // namespace node
1595
1596
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1597
1598
#endif  // SRC_ENV_H_