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