Skip to content

Commit c526145

Browse files
committed
Use Map instead of an object in EvaluationContext's cache
1 parent 2e69da8 commit c526145

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/expression/evaluation_context.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ export class EvaluationContext {
1313
availableImages: Array<string>;
1414
canonical: ICanonicalTileID;
1515

16-
_parseColorCache: {[_: string]: Color};
16+
_parseColorCache: Map<string, Color>;
1717

1818
constructor() {
1919
this.globals = null;
2020
this.feature = null;
2121
this.featureState = null;
2222
this.formattedSection = null;
23-
// the cache keys are user controlled (from the source JSON), so
24-
// avoid prototype pollution by creating a record with a null prototype
25-
this._parseColorCache = Object.create(null) as {[_: string]: Color};
23+
this._parseColorCache = new Map<string, Color>();
2624
this.availableImages = null;
2725
this.canonical = null;
2826
}
@@ -48,9 +46,10 @@ export class EvaluationContext {
4846
}
4947

5048
parseColor(input: string): Color {
51-
let cached = this._parseColorCache[input];
49+
let cached = this._parseColorCache.get(input);
5250
if (!cached) {
53-
cached = this._parseColorCache[input] = Color.parse(input);
51+
cached = Color.parse(input);
52+
this._parseColorCache.set(input, cached)
5453
}
5554
return cached;
5655
}

0 commit comments

Comments
 (0)