Skip to content

Commit 1141013

Browse files
committed
Deoptimize all parameters when losing track of a function
1 parent 801ffd1 commit 1141013

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/ast/nodes/shared/FunctionBase.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ export default abstract class FunctionBase extends NodeBase {
7474
this.getObjectEntity().deoptimizePath(path);
7575
if (path.length === 1 && path[0] === UnknownKey) {
7676
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
77-
// which means the return expression needs to be reassigned
77+
// which means the return expression and parameters need to be reassigned
7878
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
79+
for (const parameterList of this.scope.parameters) {
80+
for (const parameter of parameterList) {
81+
parameter.deoptimizePath(UNKNOWN_PATH);
82+
}
83+
}
7984
}
8085
}
8186

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const assert = require('node:assert');
2+
3+
module.exports = defineTest({
4+
description:
5+
'respects variable mutations via unknown parameter values if we lose track of a function',
6+
exports({ test }) {
7+
assert.ok(test(state => (state.modified = true)));
8+
}
9+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function test(callback) {
2+
const state = {
3+
modified: false
4+
};
5+
callback(state);
6+
if (state.modified) return true;
7+
return false;
8+
}

0 commit comments

Comments
 (0)