Skip to content

Commit

Permalink
make instance methods work with prototypes in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 12, 2018
1 parent 49de8b9 commit 83e4d40
Show file tree
Hide file tree
Showing 39 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/at.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.at;
return (own === StringPrototype.at && (typeof it === "string" || it instanceof String)) ? at : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.at) ? at : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var FunctionPrototype = Function.prototype;

module.exports = function (it) {
var own = it.bind;
return (own === FunctionPrototype.bind && it instanceof Function) ? bind : own;
return it === FunctionPrototype || (it instanceof Function && own === FunctionPrototype.bind) ? bind : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/code-point-at.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.codePointAt;
return (own === StringPrototype.codePointAt && (typeof it === "string" || it instanceof String)) ? codePointAt : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.codePointAt) ? codePointAt : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.concat;
return (own === ArrayPrototype.concat && it instanceof Array) ? concat : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.concat) ? concat : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/copy-within.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.copyWithin;
return (own === ArrayPrototype.copyWithin && it instanceof Array) ? copyWithin : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.copyWithin) ? copyWithin : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/ends-with.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.endsWith;
return (own === StringPrototype.endsWith && (typeof it === "string" || it instanceof String)) ? endsWith : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.endsWith) ? endsWith : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var DOMIterables = {

module.exports = function (it) {
var own = it.entries;
return (own === ArrayPrototype.entries && (it instanceof Array || DOMIterables.hasOwnProperty(toString.call(it)))) ? entries : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.entries) || DOMIterables.hasOwnProperty(toString.call(it)) ? entries : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/every.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.every;
return (own === ArrayPrototype.every && it instanceof Array) ? every : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.every) ? every : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.fill;
return (own === ArrayPrototype.fill && it instanceof Array) ? fill : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.fill) ? fill : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.filter;
return (own === ArrayPrototype.filter && it instanceof Array) ? filter : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.filter) ? filter : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/find-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.findIndex;
return (own === ArrayPrototype.findIndex && it instanceof Array) ? findIndex : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.findIndex) ? findIndex : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.find;
return (own === ArrayPrototype.find && it instanceof Array) ? find : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.find) ? find : own;
};
3 changes: 2 additions & 1 deletion packages/babel-runtime/core-js/instance/flags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var flags = require("core-js-pure/features/regexp/flags");
var RegExpPrototype = RegExp.prototype;

module.exports = function (it) {
return (it instanceof RegExp && !('flags' in it)) ? flags(it) : it.flags;
return (it === RegExpPrototype || it instanceof RegExp) && !('flags' in it) ? flags(it) : it.flags;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/flat-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.flatMap;
return (own === ArrayPrototype.flatMap && it instanceof Array) ? flatMap : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.flatMap) ? flatMap : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.flatten;
return (own === ArrayPrototype.flatten && it instanceof Array) ? flatten : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.flatten) ? flatten : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/for-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var DOMIterables = {

module.exports = function (it) {
var own = it.forEach;
return (own === ArrayPrototype.forEach && (it instanceof Array || DOMIterables.hasOwnProperty(toString.call(it)))) ? forEach : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.forEach) || DOMIterables.hasOwnProperty(toString.call(it)) ? forEach : own;
};
4 changes: 2 additions & 2 deletions packages/babel-runtime/core-js/instance/includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.includes;
if (own === ArrayPrototype.includes && it instanceof Array) return arrayIncludes;
if (own === StringPrototype.includes && (typeof it === "string" || it instanceof String)) return stringIncludes;
if (it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.includes)) return arrayIncludes;
if (typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.includes)) return stringIncludes;
return own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/index-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.indexOf;
return (own === ArrayPrototype.indexOf && it instanceof Array) ? indexOf : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.indexOf) ? indexOf : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var DOMIterables = {

module.exports = function (it) {
var own = it.keys;
return (own === ArrayPrototype.keys && (it instanceof Array || DOMIterables.hasOwnProperty(toString.call(it)))) ? keys : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.keys) || DOMIterables.hasOwnProperty(toString.call(it)) ? keys : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/last-index-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.lastIndexOf;
return (own === ArrayPrototype.lastIndexOf && it instanceof Array) ? lastIndexOf : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.lastIndexOf) ? lastIndexOf : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.map;
return (own === ArrayPrototype.map && it instanceof Array) ? map : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.map) ? map : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/match-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.matchAll;
return (own === StringPrototype.matchAll && (typeof it === "string" || it instanceof String)) ? matchAll : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.matchAll) ? matchAll : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/pad-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.padEnd;
return (own === StringPrototype.padEnd && (typeof it === "string" || it instanceof String)) ? padEnd : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.padEnd) ? padEnd : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/pad-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.padStart;
return (own === StringPrototype.padStart && (typeof it === "string" || it instanceof String)) ? padStart : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.padStart) ? padStart : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/reduce-right.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.reduceRight;
return (own === ArrayPrototype.reduceRight && it instanceof Array) ? reduceRight : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.reduceRight) ? reduceRight : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.reduce;
return (own === ArrayPrototype.reduce && it instanceof Array) ? reduce : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.reduce) ? reduce : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.repeat;
return (own === StringPrototype.repeat && (typeof it === "string" || it instanceof String)) ? repeat : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.repeat) ? repeat : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/replace-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.replaceAll;
return (own === StringPrototype.replaceAll && (typeof it === "string" || it instanceof String)) ? replaceAll : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.replaceAll) ? replaceAll : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.slice;
return (own === ArrayPrototype.slice && it instanceof Array) ? slice : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.slice) ? slice : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/some.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.some;
return (own === ArrayPrototype.some && it instanceof Array) ? some : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.some) ? some : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.sort;
return (own === ArrayPrototype.sort && it instanceof Array) ? sort : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.sort) ? sort : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/splice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var ArrayPrototype = Array.prototype;

module.exports = function (it) {
var own = it.splice;
return (own === ArrayPrototype.splice && it instanceof Array) ? splice : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.splice) ? splice : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/starts-with.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.startsWith;
return (own === StringPrototype.startsWith && (typeof it === "string" || it instanceof String)) ? startsWith : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.startsWith) ? startsWith : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/trim-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.trimEnd;
return (own === StringPrototype.trimEnd && (typeof it === "string" || it instanceof String)) ? trimEnd : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.trimEnd) ? trimEnd : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/trim-left.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.trimLeft;
return (own === StringPrototype.trimLeft && (typeof it === "string" || it instanceof String)) ? trimLeft : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.trimLeft) ? trimLeft : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/trim-right.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.trimRight;
return (own === StringPrototype.trimRight && (typeof it === "string" || it instanceof String)) ? trimRight : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.trimRight) ? trimRight : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/trim-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.trimStart;
return (own === StringPrototype.trimStart && (typeof it === "string" || it instanceof String)) ? trimStart : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.trimStart) ? trimStart : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/trim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var StringPrototype = String.prototype;

module.exports = function (it) {
var own = it.trim;
return (own === StringPrototype.trim && (typeof it === "string" || it instanceof String)) ? trim : own;
return typeof it === "string" || it === StringPrototype || (it instanceof String && own === StringPrototype.trim) ? trim : own;
};
2 changes: 1 addition & 1 deletion packages/babel-runtime/core-js/instance/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var DOMIterables = {

module.exports = function (it) {
var own = it.values;
return (own === ArrayPrototype.values && (it instanceof Array || DOMIterables.hasOwnProperty(toString.call(it)))) ? values : own;
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.values) || DOMIterables.hasOwnProperty(toString.call(it)) ? values : own;
};

0 comments on commit 83e4d40

Please sign in to comment.