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