@ -56,12 +56,9 @@ function setupNextTick() {
// Two arrays that share state between C++ and JS.
const { async_hook_fields , async_uid_fields } = async_wrap ;
// Used to change the state of the async id stack.
const { pushAsyncIds , popAsyncIds } = async_wrap ;
// The needed emit*() functions.
const { emitInit , emitBefore , emitAfter , emitDestroy } = async_hooks ;
// Grab the constants necessary for working with internal arrays.
const { kInit , kBefore , kAfter , kDestroy , kAsyncUidCntr } =
async_wrap . constants ;
const { kInit , kDestroy , kAsyncUidCntr } = async_wrap . constants ;
const { async_id_symbol , trigger_id_symbol } = async_wrap ;
var nextTickQueue = new NextTickQueue ( ) ;
var microtasksScheduled = false ;
@ -149,24 +146,6 @@ function setupNextTick() {
}
}
// TODO(trevnorris): Using std::stack of Environment::AsyncHooks::ids_stack_
// is much slower here than was the Float64Array stack used in a previous
// implementation. Problem is the Float64Array stack was a bit brittle.
// Investigate how to harden that implementation and possibly reintroduce it.
function nextTickEmitBefore ( asyncId , triggerAsyncId ) {
if ( async_hook_fields [ kBefore ] > 0 )
emitBefore ( asyncId , triggerAsyncId ) ;
else
pushAsyncIds ( asyncId , triggerAsyncId ) ;
}
function nextTickEmitAfter ( asyncId ) {
if ( async_hook_fields [ kAfter ] > 0 )
emitAfter ( asyncId ) ;
else
popAsyncIds ( asyncId ) ;
}
// Run callbacks that have no domain.
// Using domains will cause this to be overridden.
function _ tickCallback ( ) {
@ -182,7 +161,7 @@ function setupNextTick() {
// CHECK(Number.isSafeInteger(tock[trigger_id_symbol]))
// CHECK(tock[trigger_id_symbol] > 0)
n extTickE mitBefore( tock [ async_id_symbol ] , tock [ trigger_id_symbol ] ) ;
emitBefore ( tock [ async_id_symbol ] , tock [ trigger_id_symbol ] ) ;
// emitDestroy() places the async_id_symbol into an asynchronous queue
// that calls the destroy callback in the future. It's called before
// calling tock.callback so destroy will be called even if the callback
@ -200,7 +179,7 @@ function setupNextTick() {
// performance hit associated with using `fn.apply()`
_ combinedTickCallback ( args , callback ) ;
n extTickE mitAfter( tock [ async_id_symbol ] ) ;
emitAfter ( tock [ async_id_symbol ] ) ;
if ( kMaxCallbacksPerLoop < tickInfo [ kIndex ] )
tickDone ( ) ;
@ -227,7 +206,7 @@ function setupNextTick() {
// CHECK(Number.isSafeInteger(tock[trigger_id_symbol]))
// CHECK(tock[trigger_id_symbol] > 0)
n extTickE mitBefore( tock [ async_id_symbol ] , tock [ trigger_id_symbol ] ) ;
emitBefore ( tock [ async_id_symbol ] , tock [ trigger_id_symbol ] ) ;
// TODO(trevnorris): See comment in _tickCallback() as to why this
// isn't a good solution.
if ( async_hook_fields [ kDestroy ] > 0 )
@ -238,7 +217,7 @@ function setupNextTick() {
// performance hit associated with using `fn.apply()`
_ combinedTickCallback ( args , callback ) ;
n extTickE mitAfter( tock [ async_id_symbol ] ) ;
emitAfter ( tock [ async_id_symbol ] ) ;
if ( kMaxCallbacksPerLoop < tickInfo [ kIndex ] )
tickDone ( ) ;