File tree Expand file tree Collapse file tree 3 files changed +21
-14
lines changed Expand file tree Collapse file tree 3 files changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -166,25 +166,15 @@ inline void AsyncHooks::push_async_context(double async_id,
166166inline bool AsyncHooks::pop_async_context (double async_id) {
167167 // In case of an exception then this may have already been reset, if the
168168 // stack was multiple MakeCallback()'s deep.
169- if (fields_[kStackLength ] == 0 ) return false ;
169+ if (UNLIKELY ( fields_[kStackLength ] == 0 ) ) return false ;
170170
171171 // Ask for the async_id to be restored as a check that the stack
172172 // hasn't been corrupted.
173173 // Since async_hooks is experimental, do only perform the check
174174 // when async_hooks is enabled.
175- if (fields_[kCheck ] > 0 && async_id_fields_[kExecutionAsyncId ] != async_id) {
176- fprintf (stderr,
177- " Error: async hook stack has become corrupted ("
178- " actual: %.f, expected: %.f)\n " ,
179- async_id_fields_.GetValue (kExecutionAsyncId ),
180- async_id);
181- DumpBacktrace (stderr);
182- fflush (stderr);
183- if (!env ()->abort_on_uncaught_exception ())
184- exit (1 );
185- fprintf (stderr, " \n " );
186- fflush (stderr);
187- ABORT_NO_BACKTRACE ();
175+ if (UNLIKELY (fields_[kCheck ] > 0 &&
176+ async_id_fields_[kExecutionAsyncId ] != async_id)) {
177+ FailWithCorruptedAsyncStack (async_id);
188178 }
189179
190180 uint32_t offset = fields_[kStackLength ] - 1 ;
Original file line number Diff line number Diff line change @@ -1196,6 +1196,21 @@ void AsyncHooks::grow_async_ids_stack() {
11961196 async_ids_stack_.GetJSArray ()).Check ();
11971197}
11981198
1199+ void AsyncHooks::FailWithCorruptedAsyncStack (double expected_async_id) {
1200+ fprintf (stderr,
1201+ " Error: async hook stack has become corrupted ("
1202+ " actual: %.f, expected: %.f)\n " ,
1203+ async_id_fields_.GetValue (kExecutionAsyncId ),
1204+ expected_async_id);
1205+ DumpBacktrace (stderr);
1206+ fflush (stderr);
1207+ if (!env ()->abort_on_uncaught_exception ())
1208+ exit (1 );
1209+ fprintf (stderr, " \n " );
1210+ fflush (stderr);
1211+ ABORT_NO_BACKTRACE ();
1212+ }
1213+
11991214void Environment::Exit (int exit_code) {
12001215 if (options ()->trace_exit ) {
12011216 HandleScope handle_scope (isolate ());
Original file line number Diff line number Diff line change @@ -774,6 +774,8 @@ class AsyncHooks : public MemoryRetainer {
774774 friend class Environment ; // So we can call the constructor.
775775 explicit AsyncHooks (v8::Isolate* isolate, const SerializeInfo* info);
776776
777+ [[noreturn]] void FailWithCorruptedAsyncStack (double expected_async_id);
778+
777779 // Stores the ids of the current execution context stack.
778780 AliasedFloat64Array async_ids_stack_;
779781 // Attached to a Uint32Array that tracks the number of active hooks for
You can’t perform that action at this time.
0 commit comments