| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4968ebf commit e7d30b4
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,13 +57,32 @@ const { | |||
| 57 | 57 | const config = internalBinding('config'); | |
| 58 | 58 | const internalTimers = require('internal/timers'); | |
| 59 | 59 | const { deprecate } = require('internal/util'); | |
| 60 | + const { | ||
| 61 | + exiting_aliased_Uint32Array, | ||
| 62 | + getHiddenValue, | ||
| 63 | + } = internalBinding('util'); | ||
| 60 | 64 | ||
| 61 | 65 | setupProcessObject(); | |
| 62 | 66 | ||
| 63 | 67 | setupGlobalProxy(); | |
| 64 | 68 | setupBuffer(); | |
| 65 | 69 | ||
| 66 | 70 | process.domain = null; | |
| 71 | + { | ||
| 72 | + const exitingAliasedUint32Array = | ||
| 73 | + getHiddenValue(process, exiting_aliased_Uint32Array); | ||
| 74 | + ObjectDefineProperty(process, '_exiting', { | ||
| 75 | + __proto__: null, | ||
| 76 | + get() { | ||
| 77 | + return exitingAliasedUint32Array[0] === 1; | ||
| 78 | + }, | ||
| 79 | + set(value) { | ||
| 80 | + exitingAliasedUint32Array[0] = value ? 1 : 0; | ||
| 81 | + }, | ||
| 82 | + enumerable: true, | ||
| 83 | + configurable: true, | ||
| 84 | + }); | ||
| 85 | + } | ||
| 67 | 86 | process._exiting = false; | |
| 68 | 87 | ||
| 69 | 88 | // process.config is serialized config.gypi | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,14 +65,11 @@ Maybe<int> EmitProcessExit(Environment* env) { | |||
| 65 | 65 | Context::Scope context_scope(context); | |
| 66 | 66 | Local<Object> process_object = env->process_object(); | |
| 67 | 67 | ||
| 68 | - // TODO(addaleax): It might be nice to share process._exiting and | ||
| 69 | - // process.exitCode via getter/setter pairs that pass data directly to the | ||
| 70 | - // native side, so that we don't manually have to read and write JS properties | ||
| 71 | - // here. These getters could use e.g. a typed array for performance. | ||
| 72 | - if (process_object | ||
| 73 | - ->Set(context, | ||
| 74 | - FIXED_ONE_BYTE_STRING(isolate, "_exiting"), | ||
| 75 | - True(isolate)).IsNothing()) return Nothing<int>(); | ||
| 68 | + // TODO(addaleax): It might be nice to share process.exitCode via | ||
| 69 | + // getter/setter pairs that pass data directly to the native side, so that we | ||
| 70 | + // don't manually have to read and write JS properties here. These getters | ||
| 71 | + // could use e.g. a typed array for performance. | ||
| 72 | + env->set_exiting(true); | ||
| 76 | 73 | ||
| 77 | 74 | Local<String> exit_code = env->exit_code_string(); | |
| 78 | 75 | Local<Value> code_v; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -362,6 +362,14 @@ inline bool Environment::force_context_aware() const { | |||
| 362 | 362 | return options_->force_context_aware; | |
| 363 | 363 | } | |
| 364 | 364 | ||
| 365 | + inline void Environment::set_exiting(bool value) { | ||
| 366 | + exiting_[0] = value ? 1 : 0; | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | + inline AliasedUint32Array& Environment::exiting() { | ||
| 370 | + return exiting_; | ||
| 371 | + } | ||
| 372 | + | ||
| 365 | 373 | inline void Environment::set_abort_on_uncaught_exception(bool value) { | |
| 366 | 374 | options_->abort_on_uncaught_exception = value; | |
| 367 | 375 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -734,6 +734,7 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 734 | 734 | exec_argv_(exec_args), | |
| 735 | 735 | argv_(args), | |
| 736 | 736 | exec_path_(GetExecPath(args)), | |
| 737 | + exiting_(isolate_, 1, MAYBE_FIELD_PTR(env_info, exiting)), | ||
| 737 | 738 | should_abort_on_uncaught_toggle_( | |
| 738 | 739 | isolate_, | |
| 739 | 740 | 1, | |
@@ -840,6 +841,9 @@ void Environment::InitializeMainContext(Local<Context> context, | |||
| 840 | 841 | // By default, always abort when --abort-on-uncaught-exception was passed. | |
| 841 | 842 | should_abort_on_uncaught_toggle_[0] = 1; | |
| 842 | 843 | ||
| 844 | + // The process is not exiting by default. | ||
| 845 | + set_exiting(false); | ||
| 846 | + | ||
| 843 | 847 | performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT, | |
| 844 | 848 | environment_start_time_); | |
| 845 | 849 | performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START, | |
@@ -1741,6 +1745,7 @@ EnvSerializeInfo Environment::Serialize(SnapshotCreator* creator) { | |||
| 1741 | 1745 | info.immediate_info = immediate_info_.Serialize(ctx, creator); | |
| 1742 | 1746 | info.tick_info = tick_info_.Serialize(ctx, creator); | |
| 1743 | 1747 | info.performance_state = performance_state_->Serialize(ctx, creator); | |
| 1748 | + info.exiting = exiting_.Serialize(ctx, creator); | ||
| 1744 | 1749 | info.stream_base_state = stream_base_state_.Serialize(ctx, creator); | |
| 1745 | 1750 | info.should_abort_on_uncaught_toggle = | |
| 1746 | 1751 | should_abort_on_uncaught_toggle_.Serialize(ctx, creator); | |
@@ -1812,6 +1817,7 @@ std::ostream& operator<<(std::ostream& output, const EnvSerializeInfo& i) { | |||
| 1812 | 1817 | << "// -- performance_state begins --\n" | |
| 1813 | 1818 | << i.performance_state << ",\n" | |
| 1814 | 1819 | << "// -- performance_state ends --\n" | |
| 1820 | + << i.exiting << ", // exiting\n" | ||
| 1815 | 1821 | << i.stream_base_state << ", // stream_base_state\n" | |
| 1816 | 1822 | << i.should_abort_on_uncaught_toggle | |
| 1817 | 1823 | << ", // should_abort_on_uncaught_toggle\n" | |
@@ -1858,6 +1864,7 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) { | |||
| 1858 | 1864 | immediate_info_.Deserialize(ctx); | |
| 1859 | 1865 | tick_info_.Deserialize(ctx); | |
| 1860 | 1866 | performance_state_->Deserialize(ctx); | |
| 1867 | + exiting_.Deserialize(ctx); | ||
| 1861 | 1868 | stream_base_state_.Deserialize(ctx); | |
| 1862 | 1869 | should_abort_on_uncaught_toggle_.Deserialize(ctx); | |
| 1863 | 1870 | ||
@@ -2088,6 +2095,7 @@ void Environment::MemoryInfo(MemoryTracker* tracker) const { | |||
| 2088 | 2095 | native_modules_without_cache); | |
| 2089 | 2096 | tracker->TrackField("destroy_async_id_list", destroy_async_id_list_); | |
| 2090 | 2097 | tracker->TrackField("exec_argv", exec_argv_); | |
| 2098 | + tracker->TrackField("exiting", exiting_); | ||
| 2091 | 2099 | tracker->TrackField("should_abort_on_uncaught_toggle", | |
| 2092 | 2100 | should_abort_on_uncaught_toggle_); | |
| 2093 | 2101 | tracker->TrackField("stream_base_state", stream_base_state_); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,15 +165,16 @@ class NoArrayBufferZeroFillScope { | |||
| 165 | 165 | // Private symbols are per-isolate primitives but Environment proxies them | |
| 166 | 166 | // for the sake of convenience. Strings should be ASCII-only and have a | |
| 167 | 167 | // "node:" prefix to avoid name clashes with third-party code. | |
| 168 | - #define PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) \ | ||
| 169 | - V(alpn_buffer_private_symbol, "node:alpnBuffer") \ | ||
| 170 | - V(arrow_message_private_symbol, "node:arrowMessage") \ | ||
| 171 | - V(contextify_context_private_symbol, "node:contextify:context") \ | ||
| 172 | - V(contextify_global_private_symbol, "node:contextify:global") \ | ||
| 173 | - V(decorated_private_symbol, "node:decorated") \ | ||
| 174 | - V(napi_type_tag, "node:napi:type_tag") \ | ||
| 175 | - V(napi_wrapper, "node:napi:wrapper") \ | ||
| 176 | - V(untransferable_object_private_symbol, "node:untransferableObject") \ | ||
| 168 | + #define PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) \ | ||
| 169 | + V(alpn_buffer_private_symbol, "node:alpnBuffer") \ | ||
| 170 | + V(arrow_message_private_symbol, "node:arrowMessage") \ | ||
| 171 | + V(contextify_context_private_symbol, "node:contextify:context") \ | ||
| 172 | + V(contextify_global_private_symbol, "node:contextify:global") \ | ||
| 173 | + V(decorated_private_symbol, "node:decorated") \ | ||
| 174 | + V(napi_type_tag, "node:napi:type_tag") \ | ||
| 175 | + V(napi_wrapper, "node:napi:wrapper") \ | ||
| 176 | + V(untransferable_object_private_symbol, "node:untransferableObject") \ | ||
| 177 | + V(exiting_aliased_Uint32Array, "node:exiting_aliased_Uint32Array") | ||
| 177 | 178 | ||
| 178 | 179 | // Symbols are per-isolate primitives but Environment proxies them | |
| 179 | 180 | // for the sake of convenience. | |
@@ -951,6 +952,7 @@ struct EnvSerializeInfo { | |||
| 951 | 952 | TickInfo::SerializeInfo tick_info; | |
| 952 | 953 | ImmediateInfo::SerializeInfo immediate_info; | |
| 953 | 954 | performance::PerformanceState::SerializeInfo performance_state; | |
| 955 | + AliasedBufferIndex exiting; | ||
| 954 | 956 | AliasedBufferIndex stream_base_state; | |
| 955 | 957 | AliasedBufferIndex should_abort_on_uncaught_toggle; | |
| 956 | 958 | ||
@@ -1126,6 +1128,11 @@ class Environment : public MemoryRetainer { | |||
| 1126 | 1128 | inline void set_force_context_aware(bool value); | |
| 1127 | 1129 | inline bool force_context_aware() const; | |
| 1128 | 1130 | ||
| 1131 | + // This is a pseudo-boolean that keeps track of whether the process is | ||
| 1132 | + // exiting. | ||
| 1133 | + inline void set_exiting(bool value); | ||
| 1134 | + inline AliasedUint32Array& exiting(); | ||
| 1135 | + | ||
| 1129 | 1136 | // This stores whether the --abort-on-uncaught-exception flag was passed | |
| 1130 | 1137 | // to Node. | |
| 1131 | 1138 | inline bool abort_on_uncaught_exception() const; | |
@@ -1515,6 +1522,8 @@ class Environment : public MemoryRetainer { | |||
| 1515 | 1522 | uint32_t script_id_counter_ = 0; | |
| 1516 | 1523 | uint32_t function_id_counter_ = 0; | |
| 1517 | 1524 | ||
| 1525 | + AliasedUint32Array exiting_; | ||
| 1526 | + | ||
| 1518 | 1527 | AliasedUint32Array should_abort_on_uncaught_toggle_; | |
| 1519 | 1528 | int should_not_abort_scope_counter_ = 0; | |
| 1520 | 1529 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,6 +91,15 @@ MaybeLocal<Object> CreateProcessObject(Environment* env) { | |||
| 91 | 91 | return MaybeLocal<Object>(); | |
| 92 | 92 | } | |
| 93 | 93 | ||
| 94 | + // process[exiting_aliased_Uint32Array] | ||
| 95 | + if (process | ||
| 96 | + ->SetPrivate(context, | ||
| 97 | + env->exiting_aliased_Uint32Array(), | ||
| 98 | + env->exiting().GetJSArray()) | ||
| 99 | + .IsNothing()) { | ||
| 100 | + return {}; | ||
| 101 | + } | ||
| 102 | + | ||
| 94 | 103 | // process.version | |
| 95 | 104 | READONLY_PROPERTY(process, | |
| 96 | 105 | "version", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ declare function InternalBinding(binding: 'util'): { | |||
| 17 | 17 | napi_type_tag: 5; | |
| 18 | 18 | napi_wrapper: 6; | |
| 19 | 19 | untransferable_object_private_symbol: 7; | |
| 20 | + exiting_aliased_Uint32Array: 8; | ||
| 20 | 21 | ||
| 21 | 22 | kPending: 0; | |
| 22 | 23 | kFulfilled: 1; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments