Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/nodejs/src/env-inl.h
$ cat -n /usr/include/nodejs/src/env-inl.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_INL_H_ 23 #define SRC_ENV_INL_H_ 24 25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 26 27 #include "aliased_buffer-inl.h" 28 #include "callback_queue-inl.h" 29 #include "env.h" 30 #include "node.h" 31 #include "node_context_data.h" 32 #include "node_internals.h" 33 #include "node_perf_common.h" 34 #include "node_realm-inl.h" 35 #include "util-inl.h" 36 #include "uv.h" 37 #include "v8.h" 38 39 #include
40 #include
41 42 #include
43 44 namespace node { 45 46 NoArrayBufferZeroFillScope::NoArrayBufferZeroFillScope( 47 IsolateData* isolate_data) 48 : node_allocator_(isolate_data->node_allocator()) { 49 if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 0; 50 } 51 52 NoArrayBufferZeroFillScope::~NoArrayBufferZeroFillScope() { 53 if (node_allocator_ != nullptr) node_allocator_->zero_fill_field()[0] = 1; 54 } 55 56 inline v8::Isolate* IsolateData::isolate() const { 57 return isolate_; 58 } 59 60 inline uv_loop_t* IsolateData::event_loop() const { 61 return event_loop_; 62 } 63 64 inline NodeArrayBufferAllocator* IsolateData::node_allocator() const { 65 return node_allocator_; 66 } 67 68 inline MultiIsolatePlatform* IsolateData::platform() const { 69 return platform_; 70 } 71 72 inline void IsolateData::set_worker_context(worker::Worker* context) { 73 CHECK_NULL(worker_context_); // Should be set only once. 74 worker_context_ = context; 75 } 76 77 inline worker::Worker* IsolateData::worker_context() const { 78 return worker_context_; 79 } 80 81 inline v8::Local
IsolateData::async_wrap_provider(int index) const { 82 return async_wrap_providers_[index].Get(isolate_); 83 } 84 85 inline AliasedUint32Array& AsyncHooks::fields() { 86 return fields_; 87 } 88 89 inline AliasedFloat64Array& AsyncHooks::async_id_fields() { 90 return async_id_fields_; 91 } 92 93 inline AliasedFloat64Array& AsyncHooks::async_ids_stack() { 94 return async_ids_stack_; 95 } 96 97 v8::Local
AsyncHooks::js_execution_async_resources() { 98 if (UNLIKELY(js_execution_async_resources_.IsEmpty())) { 99 js_execution_async_resources_.Reset( 100 env()->isolate(), v8::Array::New(env()->isolate())); 101 } 102 return PersistentToLocal::Strong(js_execution_async_resources_); 103 } 104 105 v8::Local
AsyncHooks::native_execution_async_resource(size_t i) { 106 if (i >= native_execution_async_resources_.size()) return {}; 107 return native_execution_async_resources_[i]; 108 } 109 110 inline v8::Local
AsyncHooks::provider_string(int idx) { 111 return env()->isolate_data()->async_wrap_provider(idx); 112 } 113 114 inline void AsyncHooks::no_force_checks() { 115 fields_[kCheck] -= 1; 116 } 117 118 inline Environment* AsyncHooks::env() { 119 return Environment::ForAsyncHooks(this); 120 } 121 122 Environment* Environment::ForAsyncHooks(AsyncHooks* hooks) { 123 return ContainerOf(&Environment::async_hooks_, hooks); 124 } 125 126 inline size_t Environment::async_callback_scope_depth() const { 127 return async_callback_scope_depth_; 128 } 129 130 inline void Environment::PushAsyncCallbackScope() { 131 async_callback_scope_depth_++; 132 } 133 134 inline void Environment::PopAsyncCallbackScope() { 135 async_callback_scope_depth_--; 136 } 137 138 inline AliasedUint32Array& ImmediateInfo::fields() { 139 return fields_; 140 } 141 142 inline uint32_t ImmediateInfo::count() const { 143 return fields_[kCount]; 144 } 145 146 inline uint32_t ImmediateInfo::ref_count() const { 147 return fields_[kRefCount]; 148 } 149 150 inline bool ImmediateInfo::has_outstanding() const { 151 return fields_[kHasOutstanding] == 1; 152 } 153 154 inline void ImmediateInfo::ref_count_inc(uint32_t increment) { 155 fields_[kRefCount] += increment; 156 } 157 158 inline void ImmediateInfo::ref_count_dec(uint32_t decrement) { 159 fields_[kRefCount] -= decrement; 160 } 161 162 inline AliasedUint8Array& TickInfo::fields() { 163 return fields_; 164 } 165 166 inline bool TickInfo::has_tick_scheduled() const { 167 return fields_[kHasTickScheduled] == 1; 168 } 169 170 inline bool TickInfo::has_rejection_to_warn() const { 171 return fields_[kHasRejectionToWarn] == 1; 172 } 173 174 inline Environment* Environment::GetCurrent(v8::Isolate* isolate) { 175 if (UNLIKELY(!isolate->InContext())) return nullptr; 176 v8::HandleScope handle_scope(isolate); 177 return GetCurrent(isolate->GetCurrentContext()); 178 } 179 180 inline Environment* Environment::GetCurrent(v8::Local
context) { 181 if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) { 182 return nullptr; 183 } 184 return static_cast
( 185 context->GetAlignedPointerFromEmbedderData( 186 ContextEmbedderIndex::kEnvironment)); 187 } 188 189 inline Environment* Environment::GetCurrent( 190 const v8::FunctionCallbackInfo
& info) { 191 return GetCurrent(info.GetIsolate()->GetCurrentContext()); 192 } 193 194 template
195 inline Environment* Environment::GetCurrent( 196 const v8::PropertyCallbackInfo
& info) { 197 return GetCurrent(info.GetIsolate()->GetCurrentContext()); 198 } 199 200 inline v8::Isolate* Environment::isolate() const { 201 return isolate_; 202 } 203 204 inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { 205 return ContainerOf(&Environment::timer_handle_, handle); 206 } 207 208 inline uv_timer_t* Environment::timer_handle() { 209 return &timer_handle_; 210 } 211 212 inline Environment* Environment::from_immediate_check_handle( 213 uv_check_t* handle) { 214 return ContainerOf(&Environment::immediate_check_handle_, handle); 215 } 216 217 inline uv_check_t* Environment::immediate_check_handle() { 218 return &immediate_check_handle_; 219 } 220 221 inline uv_idle_t* Environment::immediate_idle_handle() { 222 return &immediate_idle_handle_; 223 } 224 225 inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, 226 HandleCleanupCb cb, 227 void* arg) { 228 handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg}); 229 } 230 231 template
232 inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) { 233 handle_cleanup_waiting_++; 234 static_assert(sizeof(T) >= sizeof(uv_handle_t), "T is a libuv handle"); 235 static_assert(offsetof(T, data) == offsetof(uv_handle_t, data), 236 "T is a libuv handle"); 237 static_assert(offsetof(T, close_cb) == offsetof(uv_handle_t, close_cb), 238 "T is a libuv handle"); 239 struct CloseData { 240 Environment* env; 241 OnCloseCallback callback; 242 void* original_data; 243 }; 244 handle->data = new CloseData { this, callback, handle->data }; 245 uv_close(reinterpret_cast
(handle), [](uv_handle_t* handle) { 246 std::unique_ptr
data { static_cast
(handle->data) }; 247 data->env->handle_cleanup_waiting_--; 248 handle->data = data->original_data; 249 data->callback(reinterpret_cast
(handle)); 250 }); 251 } 252 253 void Environment::IncreaseWaitingRequestCounter() { 254 request_waiting_++; 255 } 256 257 void Environment::DecreaseWaitingRequestCounter() { 258 request_waiting_--; 259 CHECK_GE(request_waiting_, 0); 260 } 261 262 inline uv_loop_t* Environment::event_loop() const { 263 return isolate_data()->event_loop(); 264 } 265 266 #if HAVE_INSPECTOR 267 inline bool Environment::is_in_inspector_console_call() const { 268 return is_in_inspector_console_call_; 269 } 270 271 inline void Environment::set_is_in_inspector_console_call(bool value) { 272 is_in_inspector_console_call_ = value; 273 } 274 #endif 275 276 inline AsyncHooks* Environment::async_hooks() { 277 return &async_hooks_; 278 } 279 280 inline ImmediateInfo* Environment::immediate_info() { 281 return &immediate_info_; 282 } 283 284 inline AliasedInt32Array& Environment::timeout_info() { 285 return timeout_info_; 286 } 287 288 inline TickInfo* Environment::tick_info() { 289 return &tick_info_; 290 } 291 292 inline uint64_t Environment::timer_base() const { 293 return timer_base_; 294 } 295 296 inline std::shared_ptr
Environment::env_vars() { 297 return env_vars_; 298 } 299 300 inline void Environment::set_env_vars(std::shared_ptr
env_vars) { 301 env_vars_ = env_vars; 302 } 303 304 inline bool Environment::printed_error() const { 305 return printed_error_; 306 } 307 308 inline void Environment::set_printed_error(bool value) { 309 printed_error_ = value; 310 } 311 312 inline void Environment::set_trace_sync_io(bool value) { 313 trace_sync_io_ = value; 314 } 315 316 inline bool Environment::abort_on_uncaught_exception() const { 317 return options_->abort_on_uncaught_exception; 318 } 319 320 inline void Environment::set_force_context_aware(bool value) { 321 options_->force_context_aware = value; 322 } 323 324 inline bool Environment::force_context_aware() const { 325 return options_->force_context_aware; 326 } 327 328 inline void Environment::set_exiting(bool value) { 329 exiting_[0] = value ? 1 : 0; 330 } 331 332 inline AliasedUint32Array& Environment::exiting() { 333 return exiting_; 334 } 335 336 inline void Environment::set_abort_on_uncaught_exception(bool value) { 337 options_->abort_on_uncaught_exception = value; 338 } 339 340 inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() { 341 return should_abort_on_uncaught_toggle_; 342 } 343 344 inline AliasedInt32Array& Environment::stream_base_state() { 345 return stream_base_state_; 346 } 347 348 inline uint32_t Environment::get_next_module_id() { 349 return module_id_counter_++; 350 } 351 inline uint32_t Environment::get_next_script_id() { 352 return script_id_counter_++; 353 } 354 inline uint32_t Environment::get_next_function_id() { 355 return function_id_counter_++; 356 } 357 358 ShouldNotAbortOnUncaughtScope::ShouldNotAbortOnUncaughtScope( 359 Environment* env) 360 : env_(env) { 361 env_->PushShouldNotAbortOnUncaughtScope(); 362 } 363 364 ShouldNotAbortOnUncaughtScope::~ShouldNotAbortOnUncaughtScope() { 365 Close(); 366 } 367 368 void ShouldNotAbortOnUncaughtScope::Close() { 369 if (env_ != nullptr) { 370 env_->PopShouldNotAbortOnUncaughtScope(); 371 env_ = nullptr; 372 } 373 } 374 375 inline void Environment::PushShouldNotAbortOnUncaughtScope() { 376 should_not_abort_scope_counter_++; 377 } 378 379 inline void Environment::PopShouldNotAbortOnUncaughtScope() { 380 should_not_abort_scope_counter_--; 381 } 382 383 inline bool Environment::inside_should_not_abort_on_uncaught_scope() const { 384 return should_not_abort_scope_counter_ > 0; 385 } 386 387 inline std::vector
* Environment::destroy_async_id_list() { 388 return &destroy_async_id_list_; 389 } 390 391 inline builtins::BuiltinLoader* Environment::builtin_loader() { 392 return &builtin_loader_; 393 } 394 395 inline double Environment::new_async_id() { 396 async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1; 397 return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter]; 398 } 399 400 inline double Environment::execution_async_id() { 401 return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId]; 402 } 403 404 inline double Environment::trigger_async_id() { 405 return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId]; 406 } 407 408 inline double Environment::get_default_trigger_async_id() { 409 double default_trigger_async_id = 410 async_hooks()->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; 411 // If defaultTriggerAsyncId isn't set, use the executionAsyncId 412 if (default_trigger_async_id < 0) 413 default_trigger_async_id = execution_async_id(); 414 return default_trigger_async_id; 415 } 416 417 inline std::shared_ptr
Environment::options() { 418 return options_; 419 } 420 421 inline const std::vector
& Environment::argv() { 422 return argv_; 423 } 424 425 inline const std::vector
& Environment::exec_argv() { 426 return exec_argv_; 427 } 428 429 inline const std::string& Environment::exec_path() const { 430 return exec_path_; 431 } 432 433 #if HAVE_INSPECTOR 434 inline void Environment::set_coverage_directory(const char* dir) { 435 coverage_directory_ = std::string(dir); 436 } 437 438 inline void Environment::set_coverage_connection( 439 std::unique_ptr
connection) { 440 CHECK_NULL(coverage_connection_); 441 std::swap(coverage_connection_, connection); 442 } 443 444 inline profiler::V8CoverageConnection* Environment::coverage_connection() { 445 return coverage_connection_.get(); 446 } 447 448 inline const std::string& Environment::coverage_directory() const { 449 return coverage_directory_; 450 } 451 452 inline void Environment::set_cpu_profiler_connection( 453 std::unique_ptr
connection) { 454 CHECK_NULL(cpu_profiler_connection_); 455 std::swap(cpu_profiler_connection_, connection); 456 } 457 458 inline profiler::V8CpuProfilerConnection* 459 Environment::cpu_profiler_connection() { 460 return cpu_profiler_connection_.get(); 461 } 462 463 inline void Environment::set_cpu_prof_interval(uint64_t interval) { 464 cpu_prof_interval_ = interval; 465 } 466 467 inline uint64_t Environment::cpu_prof_interval() const { 468 return cpu_prof_interval_; 469 } 470 471 inline void Environment::set_cpu_prof_name(const std::string& name) { 472 cpu_prof_name_ = name; 473 } 474 475 inline const std::string& Environment::cpu_prof_name() const { 476 return cpu_prof_name_; 477 } 478 479 inline void Environment::set_cpu_prof_dir(const std::string& dir) { 480 cpu_prof_dir_ = dir; 481 } 482 483 inline const std::string& Environment::cpu_prof_dir() const { 484 return cpu_prof_dir_; 485 } 486 487 inline void Environment::set_heap_profiler_connection( 488 std::unique_ptr
connection) { 489 CHECK_NULL(heap_profiler_connection_); 490 std::swap(heap_profiler_connection_, connection); 491 } 492 493 inline profiler::V8HeapProfilerConnection* 494 Environment::heap_profiler_connection() { 495 return heap_profiler_connection_.get(); 496 } 497 498 inline void Environment::set_heap_prof_name(const std::string& name) { 499 heap_prof_name_ = name; 500 } 501 502 inline const std::string& Environment::heap_prof_name() const { 503 return heap_prof_name_; 504 } 505 506 inline void Environment::set_heap_prof_dir(const std::string& dir) { 507 heap_prof_dir_ = dir; 508 } 509 510 inline const std::string& Environment::heap_prof_dir() const { 511 return heap_prof_dir_; 512 } 513 514 inline void Environment::set_heap_prof_interval(uint64_t interval) { 515 heap_prof_interval_ = interval; 516 } 517 518 inline uint64_t Environment::heap_prof_interval() const { 519 return heap_prof_interval_; 520 } 521 522 #endif // HAVE_INSPECTOR 523 524 inline 525 std::shared_ptr
> Environment::inspector_host_port() { 526 return inspector_host_port_; 527 } 528 529 inline std::shared_ptr
IsolateData::options() { 530 return options_; 531 } 532 533 inline void IsolateData::set_options( 534 std::shared_ptr
options) { 535 options_ = std::move(options); 536 } 537 538 template
539 void Environment::SetImmediate(Fn&& cb, CallbackFlags::Flags flags) { 540 auto callback = native_immediates_.CreateCallback(std::move(cb), flags); 541 native_immediates_.Push(std::move(callback)); 542 543 if (flags & CallbackFlags::kRefed) { 544 if (immediate_info()->ref_count() == 0) 545 ToggleImmediateRef(true); 546 immediate_info()->ref_count_inc(1); 547 } 548 } 549 550 template
551 void Environment::SetImmediateThreadsafe(Fn&& cb, CallbackFlags::Flags flags) { 552 auto callback = native_immediates_threadsafe_.CreateCallback( 553 std::move(cb), flags); 554 { 555 Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); 556 native_immediates_threadsafe_.Push(std::move(callback)); 557 if (task_queues_async_initialized_) 558 uv_async_send(&task_queues_async_); 559 } 560 } 561 562 template
563 void Environment::RequestInterrupt(Fn&& cb) { 564 auto callback = native_immediates_interrupts_.CreateCallback( 565 std::move(cb), CallbackFlags::kRefed); 566 { 567 Mutex::ScopedLock lock(native_immediates_threadsafe_mutex_); 568 native_immediates_interrupts_.Push(std::move(callback)); 569 if (task_queues_async_initialized_) 570 uv_async_send(&task_queues_async_); 571 } 572 RequestInterruptFromV8(); 573 } 574 575 inline bool Environment::can_call_into_js() const { 576 return can_call_into_js_ && !is_stopping(); 577 } 578 579 inline void Environment::set_can_call_into_js(bool can_call_into_js) { 580 can_call_into_js_ = can_call_into_js; 581 } 582 583 inline bool Environment::has_run_bootstrapping_code() const { 584 return principal_realm_->has_run_bootstrapping_code(); 585 } 586 587 inline bool Environment::has_serialized_options() const { 588 return has_serialized_options_; 589 } 590 591 inline void Environment::set_has_serialized_options(bool value) { 592 has_serialized_options_ = value; 593 } 594 595 inline bool Environment::is_main_thread() const { 596 return worker_context() == nullptr; 597 } 598 599 inline bool Environment::no_native_addons() const { 600 return (flags_ & EnvironmentFlags::kNoNativeAddons) || 601 !options_->allow_native_addons; 602 } 603 604 inline bool Environment::should_not_register_esm_loader() const { 605 return flags_ & EnvironmentFlags::kNoRegisterESMLoader; 606 } 607 608 inline bool Environment::owns_process_state() const { 609 return flags_ & EnvironmentFlags::kOwnsProcessState; 610 } 611 612 inline bool Environment::owns_inspector() const { 613 return flags_ & EnvironmentFlags::kOwnsInspector; 614 } 615 616 inline bool Environment::should_create_inspector() const { 617 return (flags_ & EnvironmentFlags::kNoCreateInspector) == 0 && 618 !options_->test_runner && !options_->watch_mode; 619 } 620 621 inline bool Environment::tracks_unmanaged_fds() const { 622 return flags_ & EnvironmentFlags::kTrackUnmanagedFds; 623 } 624 625 inline bool Environment::hide_console_windows() const { 626 return flags_ & EnvironmentFlags::kHideConsoleWindows; 627 } 628 629 inline bool Environment::no_global_search_paths() const { 630 return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) || 631 !options_->global_search_paths; 632 } 633 634 inline bool Environment::no_browser_globals() const { 635 // configure --no-browser-globals 636 #ifdef NODE_NO_BROWSER_GLOBALS 637 return true; 638 #else 639 return flags_ & EnvironmentFlags::kNoBrowserGlobals; 640 #endif 641 } 642 643 bool Environment::filehandle_close_warning() const { 644 return emit_filehandle_warning_; 645 } 646 647 void Environment::set_filehandle_close_warning(bool on) { 648 emit_filehandle_warning_ = on; 649 } 650 651 void Environment::set_source_maps_enabled(bool on) { 652 source_maps_enabled_ = on; 653 } 654 655 bool Environment::source_maps_enabled() const { 656 return source_maps_enabled_; 657 } 658 659 inline uint64_t Environment::thread_id() const { 660 return thread_id_; 661 } 662 663 inline worker::Worker* Environment::worker_context() const { 664 return isolate_data()->worker_context(); 665 } 666 667 inline void Environment::add_sub_worker_context(worker::Worker* context) { 668 sub_worker_contexts_.insert(context); 669 } 670 671 inline void Environment::remove_sub_worker_context(worker::Worker* context) { 672 sub_worker_contexts_.erase(context); 673 } 674 675 template
676 inline void Environment::ForEachWorker(Fn&& iterator) { 677 for (worker::Worker* w : sub_worker_contexts_) iterator(w); 678 } 679 680 inline bool Environment::is_stopping() const { 681 return is_stopping_.load(); 682 } 683 684 inline void Environment::set_stopping(bool value) { 685 is_stopping_.store(value); 686 } 687 688 inline std::list
* Environment::extra_linked_bindings() { 689 return &extra_linked_bindings_; 690 } 691 692 inline node_module* Environment::extra_linked_bindings_head() { 693 return extra_linked_bindings_.size() > 0 ? 694 &extra_linked_bindings_.front() : nullptr; 695 } 696 697 inline node_module* Environment::extra_linked_bindings_tail() { 698 return extra_linked_bindings_.size() > 0 ? 699 &extra_linked_bindings_.back() : nullptr; 700 } 701 702 inline const Mutex& Environment::extra_linked_bindings_mutex() const { 703 return extra_linked_bindings_mutex_; 704 } 705 706 inline performance::PerformanceState* Environment::performance_state() { 707 return performance_state_.get(); 708 } 709 710 inline IsolateData* Environment::isolate_data() const { 711 return isolate_data_; 712 } 713 714 template
715 inline void Environment::ForEachRealm(T&& iterator) const { 716 // TODO(legendecas): iterate over more realms bound to the environment. 717 iterator(principal_realm()); 718 } 719 720 inline void Environment::ThrowError(const char* errmsg) { 721 ThrowError(v8::Exception::Error, errmsg); 722 } 723 724 inline void Environment::ThrowTypeError(const char* errmsg) { 725 ThrowError(v8::Exception::TypeError, errmsg); 726 } 727 728 inline void Environment::ThrowRangeError(const char* errmsg) { 729 ThrowError(v8::Exception::RangeError, errmsg); 730 } 731 732 inline void Environment::ThrowError( 733 v8::Local
(*fun)(v8::Local
), 734 const char* errmsg) { 735 v8::HandleScope handle_scope(isolate()); 736 isolate()->ThrowException(fun(OneByteString(isolate(), errmsg))); 737 } 738 739 inline void Environment::ThrowErrnoException(int errorno, 740 const char* syscall, 741 const char* message, 742 const char* path) { 743 isolate()->ThrowException( 744 ErrnoException(isolate(), errorno, syscall, message, path)); 745 } 746 747 inline void Environment::ThrowUVException(int errorno, 748 const char* syscall, 749 const char* message, 750 const char* path, 751 const char* dest) { 752 isolate()->ThrowException( 753 UVException(isolate(), errorno, syscall, message, path, dest)); 754 } 755 756 void Environment::AddCleanupHook(CleanupQueue::Callback fn, void* arg) { 757 cleanup_queue_.Add(fn, arg); 758 } 759 760 void Environment::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) { 761 cleanup_queue_.Remove(fn, arg); 762 } 763 764 void Environment::set_process_exit_handler( 765 std::function
&& handler) { 766 process_exit_handler_ = std::move(handler); 767 } 768 769 #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) 770 #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) 771 #define VS(PropertyName, StringValue) V(v8::String, PropertyName) 772 #define V(TypeName, PropertyName) \ 773 inline \ 774 v8::Local
IsolateData::PropertyName() const { \ 775 return PropertyName ## _ .Get(isolate_); \ 776 } 777 PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) 778 PER_ISOLATE_SYMBOL_PROPERTIES(VY) 779 PER_ISOLATE_STRING_PROPERTIES(VS) 780 #undef V 781 #undef VS 782 #undef VY 783 #undef VP 784 785 #define VM(PropertyName) V(PropertyName##_binding, v8::FunctionTemplate) 786 #define V(PropertyName, TypeName) \ 787 inline v8::Local
IsolateData::PropertyName() const { \ 788 return PropertyName##_.Get(isolate_); \ 789 } \ 790 inline void IsolateData::set_##PropertyName(v8::Local
value) { \ 791 PropertyName##_.Set(isolate_, value); \ 792 } 793 PER_ISOLATE_TEMPLATE_PROPERTIES(V) 794 NODE_BINDINGS_WITH_PER_ISOLATE_INIT(VM) 795 #undef V 796 #undef VM 797 798 #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) 799 #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) 800 #define VS(PropertyName, StringValue) V(v8::String, PropertyName) 801 #define V(TypeName, PropertyName) \ 802 inline v8::Local
Environment::PropertyName() const { \ 803 return isolate_data()->PropertyName(); \ 804 } 805 PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) 806 PER_ISOLATE_SYMBOL_PROPERTIES(VY) 807 PER_ISOLATE_STRING_PROPERTIES(VS) 808 #undef V 809 #undef VS 810 #undef VY 811 #undef VP 812 813 #define V(PropertyName, TypeName) \ 814 inline v8::Local
Environment::PropertyName() const { \ 815 return isolate_data()->PropertyName(); \ 816 } \ 817 inline void Environment::set_##PropertyName(v8::Local
value) { \ 818 DCHECK(isolate_data()->PropertyName().IsEmpty()); \ 819 isolate_data()->set_##PropertyName(value); \ 820 } 821 PER_ISOLATE_TEMPLATE_PROPERTIES(V) 822 #undef V 823 824 #define V(PropertyName, TypeName) \ 825 inline v8::Local
Environment::PropertyName() const { \ 826 DCHECK_NOT_NULL(principal_realm_); \ 827 return principal_realm_->PropertyName(); \ 828 } \ 829 inline void Environment::set_##PropertyName(v8::Local
value) { \ 830 DCHECK_NOT_NULL(principal_realm_); \ 831 principal_realm_->set_##PropertyName(value); \ 832 } 833 PER_REALM_STRONG_PERSISTENT_VALUES(V) 834 #undef V 835 836 v8::Local
Environment::context() const { 837 return principal_realm()->context(); 838 } 839 840 Realm* Environment::principal_realm() const { 841 return principal_realm_.get(); 842 } 843 844 inline void Environment::set_heap_snapshot_near_heap_limit(uint32_t limit) { 845 heap_snapshot_near_heap_limit_ = limit; 846 } 847 848 inline bool Environment::is_in_heapsnapshot_heap_limit_callback() const { 849 return is_in_heapsnapshot_heap_limit_callback_; 850 } 851 852 inline void Environment::AddHeapSnapshotNearHeapLimitCallback() { 853 DCHECK(!heapsnapshot_near_heap_limit_callback_added_); 854 heapsnapshot_near_heap_limit_callback_added_ = true; 855 isolate_->AddNearHeapLimitCallback(Environment::NearHeapLimitCallback, this); 856 } 857 858 inline void Environment::RemoveHeapSnapshotNearHeapLimitCallback( 859 size_t heap_limit) { 860 DCHECK(heapsnapshot_near_heap_limit_callback_added_); 861 heapsnapshot_near_heap_limit_callback_added_ = false; 862 isolate_->RemoveNearHeapLimitCallback(Environment::NearHeapLimitCallback, 863 heap_limit); 864 } 865 866 } // namespace node 867 868 // These two files depend on each other. Including base_object-inl.h after this 869 // file is the easiest way to avoid issues with that circular dependency. 870 #include "base_object-inl.h" 871 872 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 873 874 #endif // SRC_ENV_INL_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™