Skip to content

Commit ad5d0e9

Browse files
committed
isMap
1 parent 03ef15d commit ad5d0e9

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module.exports = [
6060
selector: "BinaryExpression[operator='instanceof'][right.name='Promise']",
6161
message: "Use Utils.isPromise() instead of instanceof Promise (cross-realm safe).",
6262
},
63+
{
64+
selector: "BinaryExpression[operator='instanceof'][right.name='Map']",
65+
message: "Use Utils.isMap() instead of instanceof Map (cross-realm safe).",
66+
},
6367
]
6468
},
6569
},

spec/Utils.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ describe('Utils', () => {
333333
});
334334
it('should return true for a cross-realm Map', () => {
335335
const crossRealmMap = vm.runInNewContext('new Map()');
336+
// eslint-disable-next-line no-restricted-syntax -- intentional: proving instanceof fails cross-realm
336337
expect(crossRealmMap instanceof Map).toBe(false);
337338
expect(Utils.isMap(crossRealmMap)).toBe(true);
338339
});

spec/eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ module.exports = [
8181
selector: "BinaryExpression[operator='instanceof'][right.name='Promise']",
8282
message: "Use Utils.isPromise() instead of instanceof Promise (cross-realm safe).",
8383
},
84+
{
85+
selector: "BinaryExpression[operator='instanceof'][right.name='Map']",
86+
message: "Use Utils.isMap() instead of instanceof Map (cross-realm safe).",
87+
},
8488
],
8589
},
8690
},

src/Utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class Utils {
498498
static getCircularReplacer() {
499499
const seen = new WeakSet();
500500
return (key, value) => {
501-
if (value instanceof Map) {
501+
if (Utils.isMap(value)) {
502502
return Object.fromEntries(value);
503503
}
504504
if (value instanceof Set) {

0 commit comments

Comments
 (0)