Skip to content

Commit

Permalink
Implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 21, 2016
1 parent 30cabe1 commit b2c3f0f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc
Expand Up @@ -8,6 +8,7 @@
"max-statements-per-line": [2, { "max": 2 }],
"max-statements": [2, 12],
"new-cap": [2, { "capIsNewExceptions": ["RequireObjectCoercible", "ToObject", "ToUint32", "IsCallable"] }],
"no-magic-numbers": 0
"no-magic-numbers": 0,
"strict": 1
}
}
34 changes: 34 additions & 0 deletions implementation.js
@@ -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;
};
24 changes: 24 additions & 0 deletions index.js
@@ -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;
14 changes: 14 additions & 0 deletions polyfill.js
@@ -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;
};
14 changes: 14 additions & 0 deletions shim.js
@@ -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;
};

0 comments on commit b2c3f0f

Please sign in to comment.