Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
var ES = require('es-abstract/es5'); | ||
var bind = require('function-bind'); | ||
var isString = require('is-string'); | ||
|
||
// Check failure of by-index access of string characters (IE < 9) | ||
// and failure of `0 in boxedString` (Rhino) | ||
var boxedString = Object('a'); | ||
var splitString = boxedString[0] !== 'a' || !(0 in boxedString); | ||
|
||
var strSplit = bind.call(Function.call, String.prototype.split); | ||
|
||
module.exports = function some(callbackfn) { | ||
var O = ES.ToObject(this); | ||
var self = splitString && isString(O) ? strSplit(O, '') : O; | ||
var len = ES.ToUint32(self.length); | ||
var T; | ||
if (arguments.length > 1) { | ||
T = arguments[1]; | ||
} | ||
|
||
// If no callback function or if callback is not a callable function | ||
if (!ES.IsCallable(callbackfn)) { | ||
throw new TypeError('Array.prototype.some callback must be a function'); | ||
} | ||
|
||
for (var i = 0; i < len; i++) { | ||
if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, O) : callbackfn.call(T, self[i], i, O))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
var ES = require('es-abstract/es6'); | ||
|
||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var polyfill = getPolyfill(); | ||
var shim = require('./shim'); | ||
|
||
var slice = Array.prototype.slice; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
var boundEveryShim = function some(array, callbackfn) { | ||
ES.RequireObjectCoercible(array); | ||
return polyfill.apply(array, slice.call(arguments, 1)); | ||
}; | ||
define(boundEveryShim, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
|
||
module.exports = boundEveryShim; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var implementation = require('./implementation'); | ||
|
||
module.exports = function getPolyfill() { | ||
if (typeof Array.prototype.some === 'function') { | ||
var hasPrimitiveContextInStrict = [1].some(function () { | ||
'use strict'; | ||
return typeof this === 'string' && this === 'x'; | ||
}, 'x'); | ||
if (hasPrimitiveContextInStrict) { | ||
return Array.prototype.some; | ||
} | ||
} | ||
return implementation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
var getPolyfill = require('./polyfill'); | ||
|
||
module.exports = function shimArrayPrototypeSome() { | ||
var polyfill = getPolyfill(); | ||
define( | ||
Array.prototype, | ||
{ some: polyfill }, | ||
{ some: function () { return Array.prototype.some !== polyfill; } } | ||
); | ||
return polyfill; | ||
}; |