Skip to content

Commit 4e92d60

Browse files
authored
Deoptimize all parameters when losing track of a function (#5158)
1 parent 801ffd1 commit 4e92d60

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy