Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure arguments are deoptimized when arguments variable is used
- Loading branch information
1 parent
6cc3fef
commit cb345fb
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import type { AstContext } from '../../Module'; | ||
import type { NodeInteraction } from '../NodeInteractions'; | ||
import { INTERACTION_ACCESSED } from '../NodeInteractions'; | ||
import type { ExpressionEntity } from '../nodes/shared/Expression'; | ||
import { UNKNOWN_EXPRESSION } from '../nodes/shared/Expression'; | ||
import type { ObjectPath } from '../utils/PathTracker'; | ||
import { UNKNOWN_PATH } from '../utils/PathTracker'; | ||
import LocalVariable from './LocalVariable'; | ||
|
||
export default class ArgumentsVariable extends LocalVariable { | ||
private deoptimizedArguments: ExpressionEntity[] = []; | ||
|
||
constructor(context: AstContext) { | ||
super('arguments', null, UNKNOWN_EXPRESSION, context); | ||
} | ||
|
||
addArgumentToBeDeoptimized(argument: ExpressionEntity): void { | ||
if (this.included) { | ||
argument.deoptimizePath(UNKNOWN_PATH); | ||
} else { | ||
this.deoptimizedArguments.push(argument); | ||
} | ||
} | ||
|
||
hasEffectsOnInteractionAtPath(path: ObjectPath, { type }: NodeInteraction): boolean { | ||
return type !== INTERACTION_ACCESSED || path.length > 1; | ||
} | ||
|
||
include() { | ||
if (!this.included) { | ||
super.include(); | ||
for (const argument of this.deoptimizedArguments) { | ||
argument.deoptimizePath(UNKNOWN_PATH); | ||
} | ||
this.deoptimizedArguments.length = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'deoptimize call parameters when arguments variable is used' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function mutate(a) { | ||
arguments[0].x = true; | ||
arguments[1].x = true; | ||
} | ||
|
||
var obj1 = { | ||
x: false | ||
}; | ||
|
||
var obj2 = { | ||
x: false | ||
}; | ||
|
||
mutate(obj1, obj2); | ||
|
||
assert.ok(obj1.x ? true : false); | ||
assert.ok(obj2.x ? true : false); |