From bc4262f90192215dc5be22944fad0480bb3bf2d4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 9 Jan 2017 18:07:23 -0800 Subject: [PATCH] Remove core-js guard. --- _baseIsNative.js | 48 ------------------------------------------------ _coreJsData.js | 6 ------ _getNative.js | 7 +++---- _getValue.js | 13 ------------- _isMaskable.js | 14 -------------- _isMasked.js | 20 -------------------- isNative.js | 47 ++++++++++++++++++++++++++++++++--------------- 7 files changed, 35 insertions(+), 120 deletions(-) delete mode 100644 _baseIsNative.js delete mode 100644 _coreJsData.js delete mode 100644 _getValue.js delete mode 100644 _isMaskable.js delete mode 100644 _isMasked.js diff --git a/_baseIsNative.js b/_baseIsNative.js deleted file mode 100644 index fa955efd6..000000000 --- a/_baseIsNative.js +++ /dev/null @@ -1,48 +0,0 @@ -import isFunction from './isFunction.js'; -import isMasked from './_isMasked.js'; -import isObject from './isObject.js'; -import toSource from './_toSource.js'; - -/** - * Used to match `RegExp` - * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). - */ -const reRegExpChar = /[\\^$.*+?()[\]{}|]/g; - -/** Used to detect host constructors (Safari). */ -const reIsHostCtor = /^\[object .+?Constructor\]$/; - -/** Used for built-in method references. */ -const funcProto = Function.prototype; -const objectProto = Object.prototype; - -/** Used to resolve the decompiled source of functions. */ -const funcToString = funcProto.toString; - -/** Used to check objects for own properties. */ -const hasOwnProperty = objectProto.hasOwnProperty; - -/** Used to detect if a method is native. */ -const reIsNative = RegExp(`^${ - funcToString.call(hasOwnProperty) - .replace(reRegExpChar, '\\$&') - .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') -}$`); - -/** - * The base implementation of `isNative` without bad shim checks. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, - * else `false`. - */ -function baseIsNative(value) { - if (!isObject(value) || isMasked(value)) { - return false; - } - const pattern = isFunction(value) ? reIsNative : reIsHostCtor; - return pattern.test(toSource(value)); -} - -export default baseIsNative; diff --git a/_coreJsData.js b/_coreJsData.js deleted file mode 100644 index 7e944be80..000000000 --- a/_coreJsData.js +++ /dev/null @@ -1,6 +0,0 @@ -import root from './_root.js'; - -/** Used to detect overreaching core-js shims. */ -const coreJsData = root['__core-js_shared__']; - -export default coreJsData; diff --git a/_getNative.js b/_getNative.js index 1a737ad9b..007b1bbfb 100644 --- a/_getNative.js +++ b/_getNative.js @@ -1,5 +1,4 @@ -import baseIsNative from './_baseIsNative.js'; -import getValue from './_getValue.js'; +import isNative from './isNative.js'; /** * Gets the native function at `key` of `object`. @@ -10,8 +9,8 @@ import getValue from './_getValue.js'; * @returns {*} Returns the function if it's native, else `undefined`. */ function getNative(object, key) { - const value = getValue(object, key); - return baseIsNative(value) ? value : undefined; + const value = object == null ? undefined : object[key]; + return isNative(value) ? value : undefined; } export default getNative; diff --git a/_getValue.js b/_getValue.js deleted file mode 100644 index cbdd538d0..000000000 --- a/_getValue.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Gets the value at `key` of `object`. - * - * @private - * @param {Object} [object] The object to query. - * @param {string} key The key of the property to get. - * @returns {*} Returns the property value. - */ -function getValue(object, key) { - return object == null ? undefined : object[key]; -} - -export default getValue; diff --git a/_isMaskable.js b/_isMaskable.js deleted file mode 100644 index 18caa73fe..000000000 --- a/_isMaskable.js +++ /dev/null @@ -1,14 +0,0 @@ -import coreJsData from './_coreJsData.js'; -import isFunction from './isFunction.js'; -import stubFalse from './stubFalse.js'; - -/** - * Checks if `func` is capable of being masked. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `func` is maskable, else `false`. - */ -const isMaskable = coreJsData ? isFunction : stubFalse; - -export default isMaskable; diff --git a/_isMasked.js b/_isMasked.js deleted file mode 100644 index 4f0aafc63..000000000 --- a/_isMasked.js +++ /dev/null @@ -1,20 +0,0 @@ -import coreJsData from './_coreJsData.js'; - -/** Used to detect methods masquerading as native. */ -const maskSrcKey = ((() => { - const uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); - return uid ? `Symbol(src)_1.${ uid }` : ''; -})()); - -/** - * Checks if `func` has its source masked. - * - * @private - * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` is masked, else `false`. - */ -function isMasked(func) { - return !!maskSrcKey && (maskSrcKey in func); -} - -export default isMasked; diff --git a/isNative.js b/isNative.js index 8f82ef92a..56bad0508 100644 --- a/isNative.js +++ b/isNative.js @@ -1,20 +1,36 @@ -import baseIsNative from './_baseIsNative.js'; -import isMaskable from './_isMaskable.js'; +import isFunction from './isFunction.js'; +import isObject from './isObject.js'; +import toSource from './_toSource.js'; -/** Error message constants. */ -const CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.'; +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ +const reRegExpChar = /[\\^$.*+?()[\]{}|]/g; + +/** Used to detect host constructors (Safari). */ +const reIsHostCtor = /^\[object .+?Constructor\]$/; + +/** Used for built-in method references. */ +const funcProto = Function.prototype; +const objectProto = Object.prototype; + +/** Used to resolve the decompiled source of functions. */ +const funcToString = funcProto.toString; + +/** Used to check objects for own properties. */ +const hasOwnProperty = objectProto.hasOwnProperty; + +/** Used to detect if a method is native. */ +const reIsNative = RegExp(`^${ + funcToString.call(hasOwnProperty) + .replace(reRegExpChar, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') +}$`); /** * Checks if `value` is a pristine native function. * - * **Note:** This method can't reliably detect native functions in the presence - * of the core-js package because core-js circumvents this kind of detection. - * Despite multiple requests, the core-js maintainer has made it clear: any - * attempt to fix the detection will be obstructed. As a result, we're left - * with little choice but to throw an error. Unfortunately, this also affects - * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), - * which rely on core-js. - * * @static * @since 3.0.0 * @category Lang @@ -30,10 +46,11 @@ const CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=p * // => false */ function isNative(value) { - if (isMaskable(value)) { - throw new Error(CORE_ERROR_TEXT); + if (!isObject(value)) { + return false; } - return baseIsNative(value); + const pattern = isFunction(value) ? reIsNative : reIsHostCtor; + return pattern.test(toSource(value)); } export default isNative;