Skip to content

Commit

Permalink
Make array and object prototype singletons immutable for now
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 16, 2021
1 parent c4f9d13 commit 8383cf9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ast/nodes/shared/ArrayPrototype.ts
Expand Up @@ -148,5 +148,6 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
unshift: METHOD_MUTATES_SELF_RETURNS_NUMBER,
values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
} as unknown as PropertyMap,
OBJECT_PROTOTYPE
OBJECT_PROTOTYPE,
true
);
15 changes: 10 additions & 5 deletions src/ast/nodes/shared/ObjectEntity.ts
Expand Up @@ -50,7 +50,8 @@ export class ObjectEntity extends ExpressionEntity {
// and we assume there are no setters or getters
constructor(
properties: ObjectProperty[] | PropertyMap,
private prototypeExpression: ExpressionEntity | null
private prototypeExpression: ExpressionEntity | null,
private immutable = false
) {
super();
if (Array.isArray(properties)) {
Expand Down Expand Up @@ -96,7 +97,7 @@ export class ObjectEntity extends ExpressionEntity {
}

deoptimizePath(path: ObjectPath): void {
if (this.hasUnknownDeoptimizedProperty) return;
if (this.hasUnknownDeoptimizedProperty || this.immutable) return;
const key = path[0];
if (path.length === 1) {
if (typeof key !== 'string') {
Expand Down Expand Up @@ -171,7 +172,9 @@ export class ObjectEntity extends ExpressionEntity {
property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
}
}
this.thisParametersToBeDeoptimized.add(thisParameter);
if (!this.immutable) {
this.thisParametersToBeDeoptimized.add(thisParameter);
}
return;
}
for (const property of relevantUnmatchableProperties) {
Expand All @@ -194,7 +197,9 @@ export class ObjectEntity extends ExpressionEntity {
property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
}
}
this.thisParametersToBeDeoptimized.add(thisParameter);
if (!this.immutable) {
this.thisParametersToBeDeoptimized.add(thisParameter);
}
this.prototypeExpression?.deoptimizeThisOnEventAtPath(
event,
path,
Expand Down Expand Up @@ -467,7 +472,7 @@ export class ObjectEntity extends ExpressionEntity {
return UNKNOWN_EXPRESSION;
}
const expression = this.getMemberExpression(key);
if (expression !== UNKNOWN_EXPRESSION) {
if (!(expression === UNKNOWN_EXPRESSION || this.immutable)) {
const expressionsToBeDeoptimized = (this.expressionsToBeDeoptimizedByKey[key] =
this.expressionsToBeDeoptimizedByKey[key] || []);
expressionsToBeDeoptimized.push(origin);
Expand Down
3 changes: 2 additions & 1 deletion src/ast/nodes/shared/ObjectPrototype.ts
Expand Up @@ -15,5 +15,6 @@ export const OBJECT_PROTOTYPE = new ObjectEntity(
toString: METHOD_RETURNS_STRING,
valueOf: METHOD_RETURNS_UNKNOWN
} as unknown as PropertyMap,
null
null,
true
);

0 comments on commit 8383cf9

Please sign in to comment.