Skip to content

Commit

Permalink
split get-built-in and get-built-in-static-method helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 30, 2023
1 parent 1fa053e commit aed9a13
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/core-js-pure/override/internals/entry-unbind.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');

module.exports = getBuiltIn;
module.exports = getBuiltInStaticMethod;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
var path = require('../internals/path');
var global = require('../internals/global');

var getMethod = function (C, METHOD) {
return C && C[METHOD];
};

module.exports = function (NAMESPACE, METHOD) {
return getMethod(path[NAMESPACE], METHOD) || getMethod(global[NAMESPACE], METHOD);
};
9 changes: 4 additions & 5 deletions packages/core-js-pure/override/internals/get-built-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ var path = require('../internals/path');
var global = require('../internals/global');
var isCallable = require('../internals/is-callable');

var aFunction = function (variable) {
return isCallable(variable) ? variable : undefined;
var aFunction = function (argument) {
return isCallable(argument) ? argument : undefined;
};

module.exports = function (namespace, method) {
return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace])
: path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method];
module.exports = function (NAMESPACE) {
return aFunction(path[NAMESPACE]) || aFunction(global[NAMESPACE]);
};
4 changes: 2 additions & 2 deletions packages/core-js/es/object/create.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var getBuiltIn = require('../../internals/get-built-in');
var getBuiltInStaticMethod = require('../../internals/get-built-in-static-method');

module.exports = function create(P, D) {
return getBuiltIn('Object', 'create')(P, D);
return getBuiltInStaticMethod('Object', 'create')(P, D);
};
7 changes: 7 additions & 0 deletions packages/core-js/internals/get-built-in-static-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
var global = require('../internals/global');

module.exports = function (NAMESPACE, METHOD) {
var C = global[NAMESPACE];
return C && C[METHOD];
};
9 changes: 3 additions & 6 deletions packages/core-js/internals/get-built-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
var global = require('../internals/global');
var isCallable = require('../internals/is-callable');

var aFunction = function (argument) {
return isCallable(argument) ? argument : undefined;
};

module.exports = function (namespace, method) {
return arguments.length < 2 ? aFunction(global[namespace]) : global[namespace] && global[namespace][method];
module.exports = function (CONSTRUCTOR) {
var C = global[CONSTRUCTOR];
return isCallable(C) ? C : undefined;
};
4 changes: 2 additions & 2 deletions packages/core-js/internals/html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');

module.exports = getBuiltIn('document', 'documentElement');
module.exports = getBuiltInStaticMethod('document', 'documentElement');
4 changes: 2 additions & 2 deletions packages/core-js/internals/is-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ var uncurryThis = require('../internals/function-uncurry-this');
var fails = require('../internals/fails');
var isCallable = require('../internals/is-callable');
var classof = require('../internals/classof');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var inspectSource = require('../internals/inspect-source');

var noop = function () { /* empty */ };
var empty = [];
var construct = getBuiltIn('Reflect', 'construct');
var construct = getBuiltInStaticMethod('Reflect', 'construct');
var constructorRegExp = /^\s*(?:class|function)\b/;
var exec = uncurryThis(constructorRegExp.exec);
var INCORRECT_TO_STRING = !constructorRegExp.test(noop);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/own-keys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var uncurryThis = require('../internals/function-uncurry-this');
var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
Expand All @@ -8,7 +8,7 @@ var anObject = require('../internals/an-object');
var concat = uncurryThis([].concat);

// all object keys, includes non-enumerable and symbols
module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
module.exports = getBuiltInStaticMethod('Reflect', 'ownKeys') || function ownKeys(it) {
var keys = getOwnPropertyNamesModule.f(anObject(it));
var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/string-parse.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
// adapted from https://github.com/jridgewell/string-dedent
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var uncurryThis = require('../internals/function-uncurry-this');

var fromCharCode = String.fromCharCode;
var fromCodePoint = getBuiltIn('String', 'fromCodePoint');
var fromCodePoint = getBuiltInStaticMethod('String', 'fromCodePoint');
var charAt = uncurryThis(''.charAt);
var charCodeAt = uncurryThis(''.charCodeAt);
var stringIndexOf = uncurryThis(''.indexOf);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var hasOwn = require('../internals/has-own-property');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
var isPrototypeOf = require('../internals/object-is-prototype-of');
Expand All @@ -17,7 +18,7 @@ module.exports = function (FULL_NAME, wrapper, FORCED, IS_AGGREGATE_ERROR) {
var OPTIONS_POSITION = IS_AGGREGATE_ERROR ? 2 : 1;
var path = FULL_NAME.split('.');
var ERROR_NAME = path[path.length - 1];
var OriginalError = getBuiltIn.apply(null, path);
var OriginalError = path.length > 1 ? getBuiltInStaticMethod(path[0], path[1]) : getBuiltIn(path[0]);

if (!OriginalError) return;

Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/modules/es.json.stringify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var apply = require('../internals/function-apply');
var call = require('../internals/function-call');
var uncurryThis = require('../internals/function-uncurry-this');
Expand All @@ -12,7 +13,7 @@ var getReplacerFunction = require('../internals/get-json-replacer-function');
var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');

var $String = String;
var $stringify = getBuiltIn('JSON', 'stringify');
var $stringify = getBuiltInStaticMethod('JSON', 'stringify');
var exec = uncurryThis(/./.exec);
var charAt = uncurryThis(''.charAt);
var charCodeAt = uncurryThis(''.charCodeAt);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.reflect.construct.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var apply = require('../internals/function-apply');
var aConstructor = require('../internals/a-constructor');
var anObject = require('../internals/an-object');
Expand All @@ -9,7 +9,7 @@ var fails = require('../internals/fails');

var ObjectPrototype = Object.prototype;
var create = Object.create;
var nativeConstruct = getBuiltIn('Reflect', 'construct');
var nativeConstruct = getBuiltInStaticMethod('Reflect', 'construct');
var bind = create.bind;
var push = [].push;

Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.reflect.prevent-extensions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var anObject = require('../internals/an-object');

// `Reflect.preventExtensions` method
Expand All @@ -9,7 +9,7 @@ $({ target: 'Reflect', stat: true }, {
preventExtensions: function preventExtensions(target) {
anObject(target);
try {
var objectPreventExtensions = getBuiltIn('Object', 'preventExtensions');
var objectPreventExtensions = getBuiltInStaticMethod('Object', 'preventExtensions');
if (objectPreventExtensions) objectPreventExtensions(target);
return true;
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core-js/modules/esnext.json.raw-json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var $ = require('../internals/export');
var NATIVE_RAW_JSON = require('../internals/native-raw-json');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var call = require('../internals/function-call');
var uncurryThis = require('../internals/function-uncurry-this');
var isCallable = require('../internals/is-callable');
Expand All @@ -15,8 +15,8 @@ var setInternalState = require('../internals/internal-state').set;

var $String = String;
var $SyntaxError = SyntaxError;
var parse = getBuiltIn('JSON', 'parse');
var $stringify = getBuiltIn('JSON', 'stringify');
var parse = getBuiltInStaticMethod('JSON', 'parse');
var $stringify = getBuiltInStaticMethod('JSON', 'stringify');
var create = Object.create;
var freeze = Object.freeze;
var at = uncurryThis(''.charAt);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/esnext.number.from-string.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var uncurryThis = require('../internals/function-uncurry-this');
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');

Expand All @@ -9,7 +9,7 @@ var INVALID_RADIX = 'Invalid radix';
var $RangeError = RangeError;
var $SyntaxError = SyntaxError;
var $TypeError = TypeError;
var parseInt = getBuiltIn('Number', 'parseInt');
var parseInt = getBuiltInStaticMethod('Number', 'parseInt');
var pow = Math.pow;
var valid = /^[\d.a-z]+$/;
var charAt = uncurryThis(''.charAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
var $ = require('../internals/export');
var shared = require('../internals/shared');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var uncurryThis = require('../internals/function-uncurry-this');
var isSymbol = require('../internals/is-symbol');
var wellKnownSymbol = require('../internals/well-known-symbol');

var Symbol = getBuiltIn('Symbol');
var $isWellKnownSymbol = Symbol.isWellKnownSymbol;
var getOwnPropertyNames = getBuiltIn('Object', 'getOwnPropertyNames');
var getOwnPropertyNames = getBuiltInStaticMethod('Object', 'getOwnPropertyNames');
var thisSymbolValue = uncurryThis(Symbol.prototype.valueOf);
var WellKnownSymbolsStore = shared('wks');

Expand Down
6 changes: 3 additions & 3 deletions packages/core-js/modules/web.url.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var $ = require('../internals/export');
var USE_NATIVE_URL = require('../internals/url-constructor-detection');
var global = require('../internals/global');
var getBuiltIn = require('../internals/get-built-in');
var getBuiltInStaticMethod = require('../internals/get-built-in-static-method');
var bind = require('../internals/function-bind-context');
var uncurryThis = require('../internals/function-uncurry-this');
var defineBuiltIn = require('../internals/define-built-in');
Expand All @@ -26,8 +26,8 @@ var getInternalSearchParamsState = URLSearchParamsModule.getState;
var NativeURL = global.URL;
var TypeError = global.TypeError;
var parseInt = global.parseInt;
var assign = getBuiltIn('Object', 'assign');
var arrayFrom = getBuiltIn('Array', 'from');
var assign = getBuiltInStaticMethod('Object', 'assign');
var arrayFrom = getBuiltInStaticMethod('Array', 'from');
var floor = Math.floor;
var pow = Math.pow;
var charAt = uncurryThis(''.charAt);
Expand Down

0 comments on commit aed9a13

Please sign in to comment.