Skip to content

Commit

Permalink
use hasOwn instead of in in some required cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 24, 2021
1 parent e41af69 commit 61ebde0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/core-js/internals/function-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var global = require('../internals/global');
var uncurryThis = require('../internals/function-uncurry-this');
var aCallable = require('../internals/a-callable');
var isObject = require('../internals/is-object');
var hasOwn = require('../internals/has-own-property');
var arraySlice = require('../internals/array-slice');

var Function = global.Function;
Expand All @@ -11,7 +12,7 @@ var join = uncurryThis([].join);
var factories = {};

var construct = function (C, argsLength, args) {
if (!(argsLength in factories)) {
if (!hasOwn(factories, argsLength)) {
for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']';
factories[argsLength] = Function('C,a', 'return new C(' + join(list, ',') + ')');
} return factories[argsLength](C, args);
Expand All @@ -20,12 +21,13 @@ var construct = function (C, argsLength, args) {
// `Function.prototype.bind` method implementation
// https://tc39.es/ecma262/#sec-function.prototype.bind
module.exports = Function.bind || function bind(that /* , ...args */) {
var fn = aCallable(this);
var F = aCallable(this);
var Prototype = F.prototype;
var partArgs = arraySlice(arguments, 1);
var boundFunction = function bound(/* args... */) {
var args = concat(partArgs, arraySlice(arguments));
return this instanceof boundFunction ? construct(fn, args.length, args) : fn.apply(that, args);
return this instanceof boundFunction ? construct(F, args.length, args) : F.apply(that, args);
};
if (isObject(fn.prototype)) boundFunction.prototype = fn.prototype;
if (isObject(Prototype)) boundFunction.prototype = Prototype;
return boundFunction;
};
3 changes: 2 additions & 1 deletion packages/core-js/modules/es.date.to-primitive.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var hasOwn = require('../internals/has-own-property');
var redefine = require('../internals/redefine');
var dateToPrimitive = require('../internals/date-to-primitive');
var wellKnownSymbol = require('../internals/well-known-symbol');
Expand All @@ -7,6 +8,6 @@ var DatePrototype = Date.prototype;

// `Date.prototype[@@toPrimitive]` method
// https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
if (!(TO_PRIMITIVE in DatePrototype)) {
if (!hasOwn(DatePrototype, TO_PRIMITIVE)) {
redefine(DatePrototype, TO_PRIMITIVE, dateToPrimitive);
}
6 changes: 4 additions & 2 deletions packages/core-js/modules/es.symbol.description.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ var defineProperty = require('../internals/object-define-property').f;
var copyConstructorProperties = require('../internals/copy-constructor-properties');

var NativeSymbol = global.Symbol;
var SymbolPrototype = NativeSymbol && NativeSymbol.prototype;

if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in NativeSymbol.prototype) ||
if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototype) ||
// Safari 12 bug
NativeSymbol().description !== undefined
)) {
Expand All @@ -29,8 +30,9 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in NativeSymbol.
if (description === '') EmptyStringDescriptionStore[result] = true;
return result;
};

copyConstructorProperties(SymbolWrapper, NativeSymbol);
var SymbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype;
SymbolWrapper.prototype = SymbolPrototype;
SymbolPrototype.constructor = SymbolWrapper;

var NATIVE_SYMBOL = String(NativeSymbol('test')) == 'Symbol(test)';
Expand Down

0 comments on commit 61ebde0

Please sign in to comment.