diff --git a/components/instrumentation/default/visit.mjs b/components/instrumentation/default/visit.mjs index a11dd7d8c..a6264bacb 100644 --- a/components/instrumentation/default/visit.mjs +++ b/components/instrumentation/default/visit.mjs @@ -253,7 +253,10 @@ const makeReturnStatement = (argument) => ({ const isJumpClosureNode = (node) => { if (node.type === "Program") { return node.sourceType === "module"; - } else if (node.type === "FunctionExpression" || node.type === "FunctionDeclaration") { + } else if ( + node.type === "FunctionExpression" || + node.type === "FunctionDeclaration" + ) { return node.async || node.generator; } else if (node.type === "ArrowFunctionExpression") { return node.async; @@ -500,6 +503,38 @@ const instrumentClosure = (node, parent, grand_parent, closure, context) => { ]), ), makeBlockStatement([ + ...(isJumpClosureNode(node) + ? [ + makeIfStatement( + makeBinaryExpression( + "!==", + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeLiteral(null), + ), + makeBlockStatement([ + makeStatement( + makeCallExpression( + makeRegularMemberExpression( + context.apply, + "recordResolve", + ), + [ + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeRegularMemberExpression(context.apply, "empty"), + ], + ), + ), + makeStatement( + makeAssignmentExpression( + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeLiteral(null), + ), + ), + ]), + null, + ), + ] + : []), makeIfStatement( makeUnaryExpression("!", makeIdentifier(`${context.apply}_DONE`)), makeBlockStatement([ @@ -707,9 +742,36 @@ const instrumenters = { ]), ]), ), - node.finalizer === null - ? null - : visitNode(node.finalizer, node, parent, closure, context), + makeBlockStatement([ + makeIfStatement( + makeBinaryExpression( + "!==", + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeLiteral(null), + ), + makeBlockStatement([ + makeStatement( + makeCallExpression( + makeRegularMemberExpression(context.apply, "recordResolve"), + [ + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeRegularMemberExpression(context.apply, "empty"), + ], + ), + ), + makeStatement( + makeAssignmentExpression( + makeIdentifier(`${context.apply}_JUMP_TAB`), + makeLiteral(null), + ), + ), + ]), + null, + ), + ...(node.finalizer === null + ? [] + : [visitNode(node.finalizer, node, parent, closure, context)]), + ]), ); } else { return null; diff --git a/components/instrumentation/default/visit.test.mjs b/components/instrumentation/default/visit.test.mjs index d99b0ea92..930b86f7f 100644 --- a/components/instrumentation/default/visit.test.mjs +++ b/components/instrumentation/default/visit.test.mjs @@ -263,6 +263,10 @@ const makeCodeLocation = (source, line, column) => ); throw APPLY_ERROR; } finally { + if (APPLY_JUMP_TAB !== null) { + APPLY.recordResolve(APPLY_JUMP_TAB, APPLY.empty); + APPLY_JUMP_TAB = null; + } if (!APPLY_DONE) { APPLY.recordReturn( APPLY_BUNDLE_TAB, @@ -336,7 +340,13 @@ const makeCodeLocation = (source, line, column) => 456; } } finally { - 789; + if (APPLY_JUMP_TAB !== null) { + APPLY.recordResolve(APPLY_JUMP_TAB, APPLY.empty); + APPLY_JUMP_TAB = null; + } + { + 789; + } } } } catch (APPLY_ERROR) { @@ -352,6 +362,10 @@ const makeCodeLocation = (source, line, column) => ); throw APPLY_ERROR; } finally { + if (APPLY_JUMP_TAB !== null) { + APPLY.recordResolve(APPLY_JUMP_TAB, APPLY.empty); + APPLY_JUMP_TAB = null; + } if (!APPLY_DONE) { APPLY.recordReturn( APPLY_BUNDLE_TAB, @@ -421,6 +435,11 @@ assertEqual( { 456; } + } finally { + if (APPLY_JUMP_TAB !== null) { + APPLY.recordResolve(APPLY_JUMP_TAB, APPLY.empty); + APPLY_JUMP_TAB = null; + } } export default 789; `, @@ -451,7 +470,13 @@ assertEqual( APPLY_JUMP_TAB = null; } } finally { - 456; + if (APPLY_JUMP_TAB !== null) { + APPLY.recordResolve(APPLY_JUMP_TAB, APPLY.empty); + APPLY_JUMP_TAB = null; + } + { + 456; + } } export default 789; `,