Skip to content

Commit 761c748

Browse files
committed
fix Firefox instanceof comparison
1 parent 6aa1b4d commit 761c748

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"public/*.html"
1313
],
1414
"rules": {
15-
"tags": ["recommended"]
15+
"tags": ["recommended"],
16+
"exclude": ["no-window"]
1617
}
1718
},
1819
"fmt": {

src/api/clone.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,21 @@ function isNumericSpecials(value: unknown): value is bigint | number {
244244

245245
function isArray(that: unknown): that is unknown[] {
246246
return (
247-
that instanceof Array ||
248-
that instanceof Uint8Array ||
249-
that instanceof Uint8ClampedArray ||
250-
that instanceof Uint16Array ||
251-
that instanceof Uint32Array ||
252-
that instanceof Int8Array ||
253-
that instanceof Int16Array ||
254-
that instanceof Int32Array ||
255-
that instanceof Float16Array ||
256-
that instanceof Float32Array ||
257-
that instanceof Float64Array ||
258-
that instanceof BigUint64Array ||
259-
that instanceof BigInt64Array
247+
// NOTE: firefox content script has instances to compare with
248+
// in `window` (not in `globalThis`)
249+
that instanceof window.Array ||
250+
that instanceof window.Uint8Array ||
251+
that instanceof window.Uint8ClampedArray ||
252+
that instanceof window.Uint16Array ||
253+
that instanceof window.Uint32Array ||
254+
that instanceof window.Int8Array ||
255+
that instanceof window.Int16Array ||
256+
that instanceof window.Int32Array ||
257+
that instanceof window.Float16Array ||
258+
that instanceof window.Float32Array ||
259+
that instanceof window.Float64Array ||
260+
that instanceof window.BigUint64Array ||
261+
that instanceof window.BigInt64Array
260262
);
261263
}
262264

@@ -269,11 +271,11 @@ function isFunction(that: unknown): that is IFunction {
269271
}
270272

271273
function isSet(that: unknown): that is Set<unknown> {
272-
return that instanceof Set;
274+
return that instanceof window.Set;
273275
}
274276

275277
function isMap(that: unknown): that is Map<unknown, unknown> {
276-
return that instanceof Map;
278+
return that instanceof window.Map;
277279
}
278280

279281
function isSelfSerializableObject(that: unknown): that is IHasToJSON {
@@ -304,11 +306,12 @@ function isGlobalSymbol(that: symbol): that is symbol {
304306
}
305307

306308
function isObject(that: unknown): that is object {
307-
return (that !== null && typeof that === 'object') || that instanceof Object;
309+
return (that !== null && typeof that === 'object') ||
310+
that instanceof window.Object;
308311
}
309312

310313
function isRegExp(that: unknown): that is RegExp {
311-
return that instanceof RegExp;
314+
return that instanceof window.RegExp;
312315
}
313316

314317
function isURL(that: unknown): that is URL {

tests/clone.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Object.assign(globalThis, {
1717
Document: class Document {
1818
nodeName = 'stub-document';
1919
},
20+
window: globalThis,
2021
});
2122

2223
describe('clone', () => {

0 commit comments

Comments
 (0)