From c4cf4ecd44be42b2481eea6fa4616c1f0f12bd14 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 21 May 2024 16:09:40 -0400 Subject: [PATCH] use native fn when possible --- .../src/getNativeImplementation.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/browser-utils/src/getNativeImplementation.ts b/packages/browser-utils/src/getNativeImplementation.ts index 781d1b40f56e..e06fb69f561e 100644 --- a/packages/browser-utils/src/getNativeImplementation.ts +++ b/packages/browser-utils/src/getNativeImplementation.ts @@ -15,6 +15,14 @@ interface CacheableImplementations { const cachedImplementations: Partial = {}; +/** + * isNative checks if the given function is a native implementation + */ +// eslint-disable-next-line @typescript-eslint/ban-types +function isNative(func: Function): boolean { + return func && /^function\s+\w+\(\)\s+\{\s+\[native code\]\s+\}$/.test(func.toString()); +} + /** * Get the native implementation of a browser function. * @@ -32,8 +40,14 @@ export function getNativeImplementation