From c89c7538c98ad6f1db56555d3af449d5c8c3bde1 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Mon, 7 Aug 2023 16:02:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20avoid=20document.all=20accessing?= =?UTF-8?q?=20error=20in=20safari=20(#2575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0da6841..88e312c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -71,20 +71,18 @@ export function isConstructable(fn: () => any | FunctionConstructor) { return constructable; } -/** - * in safari - * typeof document.all === 'undefined' // true - * typeof document.all === 'function' // true - * We need to discriminate safari for better performance - */ -const naughtySafari = typeof document.all === 'function' && typeof document.all === 'undefined'; const callableFnCacheMap = new WeakMap(); -export function isCallable(fn: any) { +export function isCallable(fn: any): boolean { if (callableFnCacheMap.has(fn)) { return true; } - const callable = naughtySafari ? typeof fn === 'function' && typeof fn !== 'undefined' : typeof fn === 'function'; + /** + * We can not use typeof to confirm it is function as in some safari version + * typeof document.all === 'undefined' // true + * typeof document.all === 'function' // true + */ + const callable = typeof fn === 'function' && fn instanceof Function; if (callable) { callableFnCacheMap.set(fn, callable); }