From fd6fbc6a45589b3e0ee741e348acb71297bdf7dc Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Tue, 20 Mar 2018 23:54:52 -0500 Subject: [PATCH] Fix async hooks in earlier version of v8.x Fixes #366 --- fibers.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fibers.js b/fibers.js index 85b7989..ad3c639 100644 --- a/fibers.js +++ b/fibers.js @@ -47,17 +47,29 @@ function setupAsyncHacks(Fiber) { throw new Error('Push/pop do not exist'); } - var kExecutionAsyncId = aw.constants.kExecutionAsyncId; - var kTriggerAsyncId = aw.constants.kTriggerAsyncId; + var kExecutionAsyncId; + if (aw.constants.kExecutionAsyncId === undefined) { + kExecutionAsyncId = aw.constants.kCurrentAsyncId; + } else { + kExecutionAsyncId = aw.constants.kExecutionAsyncId; + } + var kTriggerAsyncId; + if (aw.constants.kTriggerAsyncId === undefined) { + kTriggerAsyncId = aw.constants.kCurrentTriggerId; + } else { + kTriggerAsyncId = aw.constants.kTriggerAsyncId; + } + + var asyncIds = aw.async_id_fields || aw.async_uid_fields; function getAndClearStack() { var ii = getAsyncIdStackSize(); var stack = new Array(ii); for (; ii > 0; --ii) { - var asyncId = aw.async_id_fields[kExecutionAsyncId]; + var asyncId = asyncIds[kExecutionAsyncId]; stack[ii - 1] = { asyncId: asyncId, - triggerId: aw.async_id_fields[kTriggerAsyncId], + triggerId: asyncIds[kTriggerAsyncId], }; aw.popAsyncIds(asyncId); }