Skip to content

Commit

Permalink
Record frozen function names in instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 22, 2023
1 parent 4779692 commit 38f6309
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/instrument/visitors/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function FunctionDeclaration(node, state, parent, key) {
if (!binding) {
const isTopLevel = block === hoistBlock;
binding = createBinding(block, fnName, {isVar: isTopLevel, isFrozenName: true}, state);
state.currentFunction?.reservedVarNames.add(fnName);

// If is a sloppy-mode function declaration which may need to be hoisted, record that.
// Determine whether to hoist after 1st pass is complete, once all other bindings created.
Expand Down Expand Up @@ -154,6 +155,7 @@ function FunctionExpression(node, state, parent, key) {
function createAndEnterFunctionOrClassNameBlock(fnName, isSilentConst, state) {
const block = createAndEnterBlock(fnName, false, state);
createBinding(block, fnName, {isConst: true, isSilentConst, isFrozenName: true}, state);
state.currentFunction?.reservedVarNames.add(fnName);
return block;
}

Expand Down Expand Up @@ -436,6 +438,7 @@ function createFunction(id, node, isStrict, state) {
externalVars: new Map(), // Keyed by block
scopes: undefined,
globalVarNames: new Set(),
reservedVarNames: new Set(),
amendments: [],
superIsProto: false,
containsEval: false,
Expand Down Expand Up @@ -724,7 +727,7 @@ function insertTrackerComment(fnId, fnType, commentHolderNode, commentType, stat
function createFunctionInfoFunction(fn, state) {
// Compile internal vars and reserved var names
const internalVars = Object.create(null),
reservedVarNames = new Set();
{reservedVarNames} = fn;
for (const {name: varName, trails, isFrozenName} of fn.bindings) {
if (isFrozenName) {
reservedVarNames.add(varName);
Expand Down
6 changes: 0 additions & 6 deletions lib/serialize/parseFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,6 @@ function resolveFunctionInfo(
setProp(fnNode, trail, childInfo.ast);
});

// Record function name
if (isNestedFunction) {
const idNode = fnNode.id;
if (idNode) reservedVarNames.add(idNode.name);
}

// Get external var nodes
for (const scope of fnInfo.scopes) {
const {blockId} = scope;
Expand Down

0 comments on commit 38f6309

Please sign in to comment.