Skip to content

Commit a47f045

Browse files
committed
Test for forEach this arg.. yea
1 parent 26a0fe6 commit a47f045

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

backend/src/common/ttlMap.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,21 @@ suite("TTLMap", () => {
121121

122122
assertConsistentData(map, {});
123123
}));
124+
125+
test("forEach this arg", () => mockTime(() => {
126+
const map: TTLMap<string, null> = new TTLMap(SECOND);
127+
map.set("a", null);
128+
map.set("b", null);
129+
130+
function unbound(this: undefined): void {
131+
assert.equal(this, undefined);
132+
}
133+
134+
function bound(this: string): void {
135+
assert.equal(this, "foo");
136+
}
137+
138+
map.forEach(unbound);
139+
map.forEach(bound, "foo");
140+
}));
124141
});

backend/src/common/ttlMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class TTLMap<K, V> {
4646
}
4747

4848
forEach(callbackfn: (value: V, key: K, map: TTLMap<K, V>) => void, thisArg?: any): void {
49-
if (thisArg !== undefined && thisArg !== null)
49+
if (thisArg != null)
5050
callbackfn = callbackfn.bind(thisArg);
5151

5252
for (const entry of this)

0 commit comments

Comments
 (0)