mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
...
This commit is contained in:
@@ -73,6 +73,7 @@ function unbind(that){
|
||||
function tie(key){
|
||||
var that = this
|
||||
, fn = that[key];
|
||||
assertFunction(fn);
|
||||
return function(){
|
||||
return fn.apply(that, arguments);
|
||||
}
|
||||
@@ -86,6 +87,7 @@ function part(/*args...*/){
|
||||
, argsPart = Array(lengthPart)
|
||||
, i = 0
|
||||
, placeholder = false;
|
||||
assertFunction(fn);
|
||||
while(lengthPart > i)if((argsPart[i] = arguments[i++]) === _)placeholder = true;
|
||||
return function(/*args...*/){
|
||||
var length = arguments.length
|
||||
@@ -133,6 +135,8 @@ function getOwnPropertyDescriptors(object){
|
||||
}
|
||||
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
|
||||
var assign = Object.assign || function(target, source){
|
||||
target = Object(target);
|
||||
source = ES5Object(source);
|
||||
var props = keys(source)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -141,6 +145,7 @@ var assign = Object.assign || function(target, source){
|
||||
return target;
|
||||
}
|
||||
function invert(object){
|
||||
object = ES5Object(object);
|
||||
var result = {}
|
||||
, names = keys(object)
|
||||
, length = names.length
|
||||
@@ -160,9 +165,8 @@ var push = $Array.push
|
||||
, $slice = Array.slice || function(arrayLike, from){
|
||||
return slice.call(arrayLike, from);
|
||||
};
|
||||
// How to get the context for calling Array.prototype methods
|
||||
// Dummy, polyfill for not array-like strings for old ie in es5 shim
|
||||
var arrayLikeSelf = Object;
|
||||
// Dummy, fix for not array-like ES3 string in es5.js
|
||||
var ES5Object = Object;
|
||||
// simple reduce to object
|
||||
function reduceTo(target, callbackfn){
|
||||
if(arguments.length < 2){
|
||||
@@ -244,16 +248,16 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* https://github.com/inexorabletash/polyfill/blob/master/es5.js
|
||||
*/
|
||||
!function(){
|
||||
var Empty = Function()
|
||||
, whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]'
|
||||
, trimRegExp = RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g')
|
||||
var Empty = Function()
|
||||
, whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]'
|
||||
, trimRegExp = RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g')
|
||||
// for fix IE 8- don't enum bug https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute
|
||||
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
||||
, hidenNames1 = array('toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,constructor')
|
||||
, hidenNames2 = hidenNames1.concat(['length'])
|
||||
, hidenNames1Length = hidenNames1.length
|
||||
, nativeSlice = slice
|
||||
, nativeJoin = $Array.join
|
||||
, hiddenNames1 = array('toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,constructor')
|
||||
, hiddenNames2 = hiddenNames1.concat(['length'])
|
||||
, hiddenNames1Length = hiddenNames1.length
|
||||
, nativeSlice = slice
|
||||
, nativeJoin = $Array.join
|
||||
// Create object with null as it's prototype
|
||||
, createNullProtoObject = PROTO
|
||||
? function(){
|
||||
@@ -262,7 +266,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
: function(){
|
||||
// Thrash, waste and sodomy
|
||||
var iframe = document.createElement('iframe')
|
||||
, i = hidenNames1Length
|
||||
, i = hiddenNames1Length
|
||||
, body = document.body || document.documentElement
|
||||
, iframeDocument;
|
||||
iframe.style.display = 'none';
|
||||
@@ -273,16 +277,17 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
iframeDocument.write('<script>document._=Object</script>');
|
||||
iframeDocument.close();
|
||||
createNullProtoObject = iframeDocument._;
|
||||
while(i--)delete createNullProtoObject[prototype][hidenNames1[i]];
|
||||
while(i--)delete createNullProtoObject[prototype][hiddenNames1[i]];
|
||||
return createNullProtoObject();
|
||||
}
|
||||
, createGetKeys = function(names, length){
|
||||
return function(O){
|
||||
O = ES5Object(O);
|
||||
var i = 0
|
||||
, result = []
|
||||
, key;
|
||||
for(key in O)has(O, key) && result.push(key);
|
||||
// hiden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys
|
||||
// hidden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys
|
||||
while(length > i)has(O, key = names[i++]) && !~result.indexOf(key) && result.push(key);
|
||||
return result;
|
||||
}
|
||||
@@ -305,6 +310,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.2.3.6
|
||||
*/
|
||||
Object.defineProperty = defineProperty = function(O, P, Attributes){
|
||||
assertObject(O);
|
||||
if('value' in Attributes)O[P] = Attributes.value;
|
||||
return O;
|
||||
};
|
||||
@@ -313,12 +319,16 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.2.3.7
|
||||
*/
|
||||
Object.defineProperties = function(O, Properties){
|
||||
// IE 9- don't enum bug => Object.keys
|
||||
assertObject(O);
|
||||
var names = keys(Properties)
|
||||
, length = names.length
|
||||
, i = 0
|
||||
, key;
|
||||
while(length > i)O[key = names[i++]] = Properties[key].value;
|
||||
, P, Attributes;
|
||||
while(length > i){
|
||||
P = names[i++];
|
||||
Attributes = Properties[P];
|
||||
if('value' in Attributes)O[P] = Attributes.value;
|
||||
}
|
||||
return O;
|
||||
}
|
||||
}
|
||||
@@ -336,7 +346,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* 15.2.3.4 Object.getOwnPropertyNames ( O )
|
||||
* http://es5.github.io/#x15.2.3.4
|
||||
*/
|
||||
getOwnPropertyNames: createGetKeys(hidenNames2, hidenNames2.length),
|
||||
getOwnPropertyNames: createGetKeys(hiddenNames2, hiddenNames2.length),
|
||||
/**
|
||||
* 15.2.3.5 Object.create ( O [, Properties] )
|
||||
* http://es5.github.io/#x15.2.3.5
|
||||
@@ -355,19 +365,19 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* 15.2.3.14 Object.keys ( O )
|
||||
* http://es5.github.io/#x15.2.3.14
|
||||
*/
|
||||
keys: createGetKeys(hidenNames1, hidenNames1Length)
|
||||
keys: createGetKeys(hiddenNames1, hiddenNames1Length)
|
||||
});
|
||||
// not array-like strings fix
|
||||
if(!(0 in Object('q') && 'q'[0] == 'q')){
|
||||
arrayLikeSelf = function(it){
|
||||
ES5Object = function(it){
|
||||
return classof(it) == 'String' ? it.split('') : Object(it);
|
||||
}
|
||||
// Array.prototype methods for strings in ES3
|
||||
$Array.slice = slice = function(){
|
||||
return nativeSlice.apply(arrayLikeSelf(this), arguments);
|
||||
return nativeSlice.apply(ES5Object(this), arguments);
|
||||
}
|
||||
$Array.join = function(){
|
||||
return nativeJoin.apply(arrayLikeSelf(this), arguments);
|
||||
return nativeJoin.apply(ES5Object(this), arguments);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -401,7 +411,8 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
return classof(it) == 'Array'
|
||||
}});
|
||||
function forEach(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++)i in self && callbackfn.call(thisArg, self[i], i, this);
|
||||
@@ -412,7 +423,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.14
|
||||
*/
|
||||
indexOf: function(searchElement, fromIndex /* = 0 */){
|
||||
var self = arrayLikeSelf(this)
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = fromIndex | 0;
|
||||
if(0 > i)i = toLength(length + i);
|
||||
@@ -424,7 +435,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.15
|
||||
*/
|
||||
lastIndexOf: function(searchElement, fromIndex /* = @[*-1] */){
|
||||
var self = arrayLikeSelf(this)
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = length - 1;
|
||||
if(arguments.length > 1)i = min(i, fromIndex | 0);
|
||||
@@ -437,7 +448,8 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.16
|
||||
*/
|
||||
every: function(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++){
|
||||
@@ -450,7 +462,8 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.17
|
||||
*/
|
||||
some: function(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++){
|
||||
@@ -468,6 +481,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.19
|
||||
*/
|
||||
map: function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var result = Array(toLength(this.length));
|
||||
forEach.call(this, function(val, key, that){
|
||||
result[key] = callbackfn.call(thisArg, val, key, that);
|
||||
@@ -479,6 +493,7 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.20
|
||||
*/
|
||||
filter: function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var result = [];
|
||||
forEach.call(this, function(val){
|
||||
callbackfn.apply(thisArg, arguments) && result.push(val);
|
||||
@@ -490,7 +505,8 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.21
|
||||
*/
|
||||
reduce: function(callbackfn, memo /* = @.1 */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
if(2 > arguments.length)for(;;){
|
||||
@@ -508,7 +524,8 @@ function extendBuiltInObject(target, source, forced /* = false */){
|
||||
* http://es5.github.io/#x15.4.4.22
|
||||
*/
|
||||
reduceRight: function(callbackfn, memo /* = @[*-1] */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, i = toLength(self.length) - 1;
|
||||
if(2 > arguments.length)for(;;){
|
||||
if(i in self){
|
||||
@@ -667,7 +684,8 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
*/
|
||||
PROTO && extendBuiltInObject(Object, {
|
||||
setPrototypeOf: function(O, proto){
|
||||
assert(isObject(O) && (isObject(proto) || proto === null), "Can't set", proto, 'as prototype of', O);
|
||||
assertObject(O);
|
||||
assert(isObject(proto) || proto === null, "Can't set", proto, 'as prototype');
|
||||
O.__proto__ = proto;
|
||||
return O;
|
||||
}
|
||||
@@ -816,11 +834,11 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
hypot: function(value1, value2){
|
||||
var sum = 0
|
||||
, length = arguments.length
|
||||
, val;
|
||||
, value;
|
||||
while(length--){
|
||||
val = +arguments[length];
|
||||
if(val == Infinity || val == - Infinity)return Infinity;
|
||||
sum += val * val;
|
||||
value = +arguments[length];
|
||||
if(value == Infinity || value == -Infinity)return Infinity;
|
||||
sum += value * value;
|
||||
}
|
||||
return sqrt(sum);
|
||||
},
|
||||
@@ -970,7 +988,8 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
* http://kangax.github.io/es5-compat-table/es6/#Array.from
|
||||
*/
|
||||
from: function(arrayLike, mapfn /* -> it */, thisArg /* = undefind */){
|
||||
var O = arrayLikeSelf(arrayLike)
|
||||
(mapfn === undefined) || assertFunction(mapfn);
|
||||
var O = ES5Object(arrayLike)
|
||||
, i = 0
|
||||
, length = toLength(O.length)
|
||||
, result = new (isFunction(this) ? this : Array)(length);
|
||||
@@ -992,8 +1011,9 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
}
|
||||
});
|
||||
function findIndex(predicate, thisArg /* = undefind */){
|
||||
var O = Object(this)
|
||||
, self = arrayLikeSelf(O)
|
||||
assertFunction(predicate);
|
||||
var O = Object(this)
|
||||
, self = ES5Object(O)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(; i < length; i++){
|
||||
@@ -1025,7 +1045,7 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
*/
|
||||
find: function(predicate, thisArg /* = undefind */){
|
||||
var index = findIndex.call(this, predicate, thisArg);
|
||||
return index === -1 ? undefined : arrayLikeSelf(this)[index];
|
||||
return index === -1 ? undefined : ES5Object(this)[index];
|
||||
},
|
||||
/**
|
||||
* 22.1.3.9 Array.prototype.findIndex ( predicate , thisArg = undefined )
|
||||
@@ -1107,6 +1127,7 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
}
|
||||
function createForEach(key){
|
||||
return function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var values = this[VALUES_STORE]
|
||||
, keyz = this[key]
|
||||
, names = keys(keyz)
|
||||
@@ -1630,6 +1651,8 @@ if(!isSetImmediate){
|
||||
* Module : function
|
||||
*/
|
||||
function inherits(parent){
|
||||
assertFunction(this);
|
||||
assertFunction(parent);
|
||||
this[prototype] = create(parent[prototype], getOwnPropertyDescriptors(this[prototype]));
|
||||
return this;
|
||||
}
|
||||
@@ -1649,8 +1672,9 @@ extendBuiltInObject(Function, {
|
||||
});
|
||||
extendBuiltInObject($Function, {
|
||||
invoke: function(args){
|
||||
assertFunction(this);
|
||||
var instance = create(this[prototype])
|
||||
, result = this.apply(instance, arrayLikeSelf(args || []));
|
||||
, result = this.apply(instance, ES5Object(args || []));
|
||||
return isObject(result) ? result : instance;
|
||||
},
|
||||
// deferred call
|
||||
@@ -1859,7 +1883,8 @@ extendBuiltInObject(Object, {
|
||||
return true;
|
||||
}
|
||||
function forOwnKeys(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1868,7 +1893,8 @@ extendBuiltInObject(Object, {
|
||||
return object;
|
||||
}
|
||||
function findIndex(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1971,7 +1997,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-every
|
||||
*/
|
||||
every: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1986,7 +2013,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-filter
|
||||
*/
|
||||
filter: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -2004,7 +2032,7 @@ extendBuiltInObject(Object, {
|
||||
*/
|
||||
find: function(object, fn, that /* = undefined */){
|
||||
var index = findIndex(object, fn, that);
|
||||
return index === undefined ? undefined : arrayLikeSelf(object)[index];
|
||||
return index === undefined ? undefined : ES5Object(object)[index];
|
||||
},
|
||||
findIndex: findIndex,
|
||||
/**
|
||||
@@ -2021,7 +2049,7 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-keyOf
|
||||
*/
|
||||
indexOf: function(object, searchElement){
|
||||
var O = arrayLikeSelf(object)
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -2036,7 +2064,8 @@ extendBuiltInObject(Object, {
|
||||
* http://api.jquery.com/jQuery.map/
|
||||
*/
|
||||
map: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -2051,7 +2080,8 @@ extendBuiltInObject(Object, {
|
||||
* http://sugarjs.com/api/Object/enumerable
|
||||
*/
|
||||
reduce: function(object, fn, result /* = undefined */, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, i = 0
|
||||
, length = props.length
|
||||
@@ -2070,7 +2100,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-some
|
||||
*/
|
||||
some: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -2084,7 +2115,7 @@ extendBuiltInObject(Object, {
|
||||
* http://sugarjs.com/api/Array/map
|
||||
*/
|
||||
pluck: function(object, prop){
|
||||
object = arrayLikeSelf(object);
|
||||
object = ES5Object(object);
|
||||
var names = keys(object)
|
||||
, result = create(null)
|
||||
, length = names.length
|
||||
@@ -2144,7 +2175,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.prototypejs.org/language/Enumerable/prototype/pluck/
|
||||
*/
|
||||
pluck: function(key){
|
||||
var that = arrayLikeSelf(this)
|
||||
var that = ES5Object(this)
|
||||
, length = toLength(that.length)
|
||||
, result = Array(length)
|
||||
, i = 0
|
||||
@@ -2162,7 +2193,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.jquery.com/jQuery.merge/
|
||||
*/
|
||||
merge: function(arrayLike){
|
||||
push.apply(this, arrayLikeSelf(arrayLike));
|
||||
push.apply(this, ES5Object(arrayLike));
|
||||
return this;
|
||||
}
|
||||
});
|
||||
@@ -2180,8 +2211,7 @@ extendBuiltInObject($Array, {
|
||||
* http://mootools.net/docs/core/Core/Core#Type:generics
|
||||
*/
|
||||
extendBuiltInObject(Array, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames($Array),
|
||||
// IE... getOwnPropertyNames($Array),
|
||||
array(
|
||||
// ES3:
|
||||
// http://www.2ality.com/2012/02/concat-not-generic.html
|
||||
@@ -2249,11 +2279,10 @@ extendBuiltInObject($Number, {
|
||||
* http://mootools.net/docs/core/Types/Number#Number-Math
|
||||
*/
|
||||
extendBuiltInObject($Number, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames(Math)
|
||||
// IE... getOwnPropertyNames(Math)
|
||||
array(
|
||||
// ES3
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,pow,sqrt,max,min,pow,atan2,' +
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,sqrt,max,min,pow,atan2,' +
|
||||
// ES6
|
||||
'acosh,asinh,atanh,cbrt,cosh,expm1,hypot,imul,log1p,log10,log2,sign,sinh,tanh,trunc'
|
||||
),
|
||||
@@ -2418,12 +2447,14 @@ extendBuiltInObject($Number, reduceTo.call(
|
||||
*/
|
||||
var extendCollections = {
|
||||
reduce: function(fn, memo){
|
||||
assertFunction(fn);
|
||||
this.forEach(function(val, key, foo){
|
||||
memo = fn(memo, val, key, foo);
|
||||
});
|
||||
return memo;
|
||||
},
|
||||
some: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2436,6 +2467,7 @@ var extendCollections = {
|
||||
return false;
|
||||
},
|
||||
every: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2448,6 +2480,7 @@ var extendCollections = {
|
||||
return true;
|
||||
},
|
||||
find: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2480,6 +2513,7 @@ var extendCollections = {
|
||||
};
|
||||
extendBuiltInObject(Map[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
result.set(key, fn.apply(that, arguments));
|
||||
@@ -2487,6 +2521,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
if(fn.apply(that, arguments))result.set(key, val);
|
||||
@@ -2516,6 +2551,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
}, extendCollections));
|
||||
extendBuiltInObject(Set[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(){
|
||||
result.add(fn.apply(that, arguments));
|
||||
@@ -2523,6 +2559,7 @@ extendBuiltInObject(Set[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(val){
|
||||
if(fn.apply(that, arguments))result.add(val);
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
@@ -69,6 +69,7 @@ function unbind(that){
|
||||
function tie(key){
|
||||
var that = this
|
||||
, fn = that[key];
|
||||
assertFunction(fn);
|
||||
return function(){
|
||||
return fn.apply(that, arguments);
|
||||
}
|
||||
@@ -82,6 +83,7 @@ function part(/*args...*/){
|
||||
, argsPart = Array(lengthPart)
|
||||
, i = 0
|
||||
, placeholder = false;
|
||||
assertFunction(fn);
|
||||
while(lengthPart > i)if((argsPart[i] = arguments[i++]) === _)placeholder = true;
|
||||
return function(/*args...*/){
|
||||
var length = arguments.length
|
||||
@@ -129,6 +131,8 @@ function getOwnPropertyDescriptors(object){
|
||||
}
|
||||
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
|
||||
var assign = Object.assign || function(target, source){
|
||||
target = Object(target);
|
||||
source = ES5Object(source);
|
||||
var props = keys(source)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -137,6 +141,7 @@ var assign = Object.assign || function(target, source){
|
||||
return target;
|
||||
}
|
||||
function invert(object){
|
||||
object = ES5Object(object);
|
||||
var result = {}
|
||||
, names = keys(object)
|
||||
, length = names.length
|
||||
@@ -156,9 +161,8 @@ var push = $Array.push
|
||||
, $slice = Array.slice || function(arrayLike, from){
|
||||
return slice.call(arrayLike, from);
|
||||
};
|
||||
// How to get the context for calling Array.prototype methods
|
||||
// Dummy, polyfill for not array-like strings for old ie in es5 shim
|
||||
var arrayLikeSelf = Object;
|
||||
// Dummy, fix for not array-like ES3 string in es5.js
|
||||
var ES5Object = Object;
|
||||
// simple reduce to object
|
||||
function reduceTo(target, callbackfn){
|
||||
if(arguments.length < 2){
|
||||
@@ -356,7 +360,8 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
*/
|
||||
PROTO && extendBuiltInObject(Object, {
|
||||
setPrototypeOf: function(O, proto){
|
||||
assert(isObject(O) && (isObject(proto) || proto === null), "Can't set", proto, 'as prototype of', O);
|
||||
assertObject(O);
|
||||
assert(isObject(proto) || proto === null, "Can't set", proto, 'as prototype');
|
||||
O.__proto__ = proto;
|
||||
return O;
|
||||
}
|
||||
@@ -505,11 +510,11 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
hypot: function(value1, value2){
|
||||
var sum = 0
|
||||
, length = arguments.length
|
||||
, val;
|
||||
, value;
|
||||
while(length--){
|
||||
val = +arguments[length];
|
||||
if(val == Infinity || val == - Infinity)return Infinity;
|
||||
sum += val * val;
|
||||
value = +arguments[length];
|
||||
if(value == Infinity || value == -Infinity)return Infinity;
|
||||
sum += value * value;
|
||||
}
|
||||
return sqrt(sum);
|
||||
},
|
||||
@@ -659,7 +664,8 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
* http://kangax.github.io/es5-compat-table/es6/#Array.from
|
||||
*/
|
||||
from: function(arrayLike, mapfn /* -> it */, thisArg /* = undefind */){
|
||||
var O = arrayLikeSelf(arrayLike)
|
||||
(mapfn === undefined) || assertFunction(mapfn);
|
||||
var O = ES5Object(arrayLike)
|
||||
, i = 0
|
||||
, length = toLength(O.length)
|
||||
, result = new (isFunction(this) ? this : Array)(length);
|
||||
@@ -681,8 +687,9 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
}
|
||||
});
|
||||
function findIndex(predicate, thisArg /* = undefind */){
|
||||
var O = Object(this)
|
||||
, self = arrayLikeSelf(O)
|
||||
assertFunction(predicate);
|
||||
var O = Object(this)
|
||||
, self = ES5Object(O)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(; i < length; i++){
|
||||
@@ -714,7 +721,7 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
*/
|
||||
find: function(predicate, thisArg /* = undefind */){
|
||||
var index = findIndex.call(this, predicate, thisArg);
|
||||
return index === -1 ? undefined : arrayLikeSelf(this)[index];
|
||||
return index === -1 ? undefined : ES5Object(this)[index];
|
||||
},
|
||||
/**
|
||||
* 22.1.3.9 Array.prototype.findIndex ( predicate , thisArg = undefined )
|
||||
@@ -796,6 +803,7 @@ isSetImmediate || !function(process, postMessage, MessageChannel, onreadystatech
|
||||
}
|
||||
function createForEach(key){
|
||||
return function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var values = this[VALUES_STORE]
|
||||
, keyz = this[key]
|
||||
, names = keys(keyz)
|
||||
@@ -1296,6 +1304,8 @@ if(!isSetImmediate){
|
||||
* Module : function
|
||||
*/
|
||||
function inherits(parent){
|
||||
assertFunction(this);
|
||||
assertFunction(parent);
|
||||
this[prototype] = create(parent[prototype], getOwnPropertyDescriptors(this[prototype]));
|
||||
return this;
|
||||
}
|
||||
@@ -1315,8 +1325,9 @@ extendBuiltInObject(Function, {
|
||||
});
|
||||
extendBuiltInObject($Function, {
|
||||
invoke: function(args){
|
||||
assertFunction(this);
|
||||
var instance = create(this[prototype])
|
||||
, result = this.apply(instance, arrayLikeSelf(args || []));
|
||||
, result = this.apply(instance, ES5Object(args || []));
|
||||
return isObject(result) ? result : instance;
|
||||
},
|
||||
// deferred call
|
||||
@@ -1525,7 +1536,8 @@ extendBuiltInObject(Object, {
|
||||
return true;
|
||||
}
|
||||
function forOwnKeys(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1534,7 +1546,8 @@ extendBuiltInObject(Object, {
|
||||
return object;
|
||||
}
|
||||
function findIndex(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1637,7 +1650,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-every
|
||||
*/
|
||||
every: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1652,7 +1666,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-filter
|
||||
*/
|
||||
filter: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -1670,7 +1685,7 @@ extendBuiltInObject(Object, {
|
||||
*/
|
||||
find: function(object, fn, that /* = undefined */){
|
||||
var index = findIndex(object, fn, that);
|
||||
return index === undefined ? undefined : arrayLikeSelf(object)[index];
|
||||
return index === undefined ? undefined : ES5Object(object)[index];
|
||||
},
|
||||
findIndex: findIndex,
|
||||
/**
|
||||
@@ -1687,7 +1702,7 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-keyOf
|
||||
*/
|
||||
indexOf: function(object, searchElement){
|
||||
var O = arrayLikeSelf(object)
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1702,7 +1717,8 @@ extendBuiltInObject(Object, {
|
||||
* http://api.jquery.com/jQuery.map/
|
||||
*/
|
||||
map: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -1717,7 +1733,8 @@ extendBuiltInObject(Object, {
|
||||
* http://sugarjs.com/api/Object/enumerable
|
||||
*/
|
||||
reduce: function(object, fn, result /* = undefined */, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, i = 0
|
||||
, length = props.length
|
||||
@@ -1736,7 +1753,8 @@ extendBuiltInObject(Object, {
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-some
|
||||
*/
|
||||
some: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -1750,7 +1768,7 @@ extendBuiltInObject(Object, {
|
||||
* http://sugarjs.com/api/Array/map
|
||||
*/
|
||||
pluck: function(object, prop){
|
||||
object = arrayLikeSelf(object);
|
||||
object = ES5Object(object);
|
||||
var names = keys(object)
|
||||
, result = create(null)
|
||||
, length = names.length
|
||||
@@ -1810,7 +1828,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.prototypejs.org/language/Enumerable/prototype/pluck/
|
||||
*/
|
||||
pluck: function(key){
|
||||
var that = arrayLikeSelf(this)
|
||||
var that = ES5Object(this)
|
||||
, length = toLength(that.length)
|
||||
, result = Array(length)
|
||||
, i = 0
|
||||
@@ -1828,7 +1846,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.jquery.com/jQuery.merge/
|
||||
*/
|
||||
merge: function(arrayLike){
|
||||
push.apply(this, arrayLikeSelf(arrayLike));
|
||||
push.apply(this, ES5Object(arrayLike));
|
||||
return this;
|
||||
}
|
||||
});
|
||||
@@ -1846,8 +1864,7 @@ extendBuiltInObject($Array, {
|
||||
* http://mootools.net/docs/core/Core/Core#Type:generics
|
||||
*/
|
||||
extendBuiltInObject(Array, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames($Array),
|
||||
// IE... getOwnPropertyNames($Array),
|
||||
array(
|
||||
// ES3:
|
||||
// http://www.2ality.com/2012/02/concat-not-generic.html
|
||||
@@ -1915,11 +1932,10 @@ extendBuiltInObject($Number, {
|
||||
* http://mootools.net/docs/core/Types/Number#Number-Math
|
||||
*/
|
||||
extendBuiltInObject($Number, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames(Math)
|
||||
// IE... getOwnPropertyNames(Math)
|
||||
array(
|
||||
// ES3
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,pow,sqrt,max,min,pow,atan2,' +
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,sqrt,max,min,pow,atan2,' +
|
||||
// ES6
|
||||
'acosh,asinh,atanh,cbrt,cosh,expm1,hypot,imul,log1p,log10,log2,sign,sinh,tanh,trunc'
|
||||
),
|
||||
@@ -2084,12 +2100,14 @@ extendBuiltInObject($Number, reduceTo.call(
|
||||
*/
|
||||
var extendCollections = {
|
||||
reduce: function(fn, memo){
|
||||
assertFunction(fn);
|
||||
this.forEach(function(val, key, foo){
|
||||
memo = fn(memo, val, key, foo);
|
||||
});
|
||||
return memo;
|
||||
},
|
||||
some: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2102,6 +2120,7 @@ var extendCollections = {
|
||||
return false;
|
||||
},
|
||||
every: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2114,6 +2133,7 @@ var extendCollections = {
|
||||
return true;
|
||||
},
|
||||
find: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -2146,6 +2166,7 @@ var extendCollections = {
|
||||
};
|
||||
extendBuiltInObject(Map[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
result.set(key, fn.apply(that, arguments));
|
||||
@@ -2153,6 +2174,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
if(fn.apply(that, arguments))result.set(key, val);
|
||||
@@ -2182,6 +2204,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
}, extendCollections));
|
||||
extendBuiltInObject(Set[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(){
|
||||
result.add(fn.apply(that, arguments));
|
||||
@@ -2189,6 +2212,7 @@ extendBuiltInObject(Set[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(val){
|
||||
if(fn.apply(that, arguments))result.add(val);
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.prototypejs.org/language/Enumerable/prototype/pluck/
|
||||
*/
|
||||
pluck: function(key){
|
||||
var that = arrayLikeSelf(this)
|
||||
var that = ES5Object(this)
|
||||
, length = toLength(that.length)
|
||||
, result = Array(length)
|
||||
, i = 0
|
||||
@@ -32,7 +32,7 @@ extendBuiltInObject($Array, {
|
||||
* http://api.jquery.com/jQuery.merge/
|
||||
*/
|
||||
merge: function(arrayLike){
|
||||
push.apply(this, arrayLikeSelf(arrayLike));
|
||||
push.apply(this, ES5Object(arrayLike));
|
||||
return this;
|
||||
}
|
||||
});
|
||||
+1
-2
@@ -9,8 +9,7 @@
|
||||
* http://mootools.net/docs/core/Core/Core#Type:generics
|
||||
*/
|
||||
extendBuiltInObject(Array, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames($Array),
|
||||
// IE... getOwnPropertyNames($Array),
|
||||
array(
|
||||
// ES3:
|
||||
// http://www.2ality.com/2012/02/concat-not-generic.html
|
||||
|
||||
+39
-26
@@ -7,16 +7,16 @@
|
||||
* https://github.com/inexorabletash/polyfill/blob/master/es5.js
|
||||
*/
|
||||
!function(){
|
||||
var Empty = Function()
|
||||
, whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]'
|
||||
, trimRegExp = RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g')
|
||||
var Empty = Function()
|
||||
, whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]'
|
||||
, trimRegExp = RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g')
|
||||
// for fix IE 8- don't enum bug https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute
|
||||
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
||||
, hidenNames1 = array('toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,constructor')
|
||||
, hidenNames2 = hidenNames1.concat(['length'])
|
||||
, hidenNames1Length = hidenNames1.length
|
||||
, nativeSlice = slice
|
||||
, nativeJoin = $Array.join
|
||||
, hiddenNames1 = array('toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,constructor')
|
||||
, hiddenNames2 = hiddenNames1.concat(['length'])
|
||||
, hiddenNames1Length = hiddenNames1.length
|
||||
, nativeSlice = slice
|
||||
, nativeJoin = $Array.join
|
||||
// Create object with null as it's prototype
|
||||
, createNullProtoObject = PROTO
|
||||
? function(){
|
||||
@@ -25,7 +25,7 @@
|
||||
: function(){
|
||||
// Thrash, waste and sodomy
|
||||
var iframe = document.createElement('iframe')
|
||||
, i = hidenNames1Length
|
||||
, i = hiddenNames1Length
|
||||
, body = document.body || document.documentElement
|
||||
, iframeDocument;
|
||||
iframe.style.display = 'none';
|
||||
@@ -36,16 +36,17 @@
|
||||
iframeDocument.write('<script>document._=Object</script>');
|
||||
iframeDocument.close();
|
||||
createNullProtoObject = iframeDocument._;
|
||||
while(i--)delete createNullProtoObject[prototype][hidenNames1[i]];
|
||||
while(i--)delete createNullProtoObject[prototype][hiddenNames1[i]];
|
||||
return createNullProtoObject();
|
||||
}
|
||||
, createGetKeys = function(names, length){
|
||||
return function(O){
|
||||
O = ES5Object(O);
|
||||
var i = 0
|
||||
, result = []
|
||||
, key;
|
||||
for(key in O)has(O, key) && result.push(key);
|
||||
// hiden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys
|
||||
// hidden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys
|
||||
while(length > i)has(O, key = names[i++]) && !~result.indexOf(key) && result.push(key);
|
||||
return result;
|
||||
}
|
||||
@@ -68,6 +69,7 @@
|
||||
* http://es5.github.io/#x15.2.3.6
|
||||
*/
|
||||
Object.defineProperty = defineProperty = function(O, P, Attributes){
|
||||
assertObject(O);
|
||||
if('value' in Attributes)O[P] = Attributes.value;
|
||||
return O;
|
||||
};
|
||||
@@ -76,12 +78,16 @@
|
||||
* http://es5.github.io/#x15.2.3.7
|
||||
*/
|
||||
Object.defineProperties = function(O, Properties){
|
||||
// IE 9- don't enum bug => Object.keys
|
||||
assertObject(O);
|
||||
var names = keys(Properties)
|
||||
, length = names.length
|
||||
, i = 0
|
||||
, key;
|
||||
while(length > i)O[key = names[i++]] = Properties[key].value;
|
||||
, P, Attributes;
|
||||
while(length > i){
|
||||
P = names[i++];
|
||||
Attributes = Properties[P];
|
||||
if('value' in Attributes)O[P] = Attributes.value;
|
||||
}
|
||||
return O;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +105,7 @@
|
||||
* 15.2.3.4 Object.getOwnPropertyNames ( O )
|
||||
* http://es5.github.io/#x15.2.3.4
|
||||
*/
|
||||
getOwnPropertyNames: createGetKeys(hidenNames2, hidenNames2.length),
|
||||
getOwnPropertyNames: createGetKeys(hiddenNames2, hiddenNames2.length),
|
||||
/**
|
||||
* 15.2.3.5 Object.create ( O [, Properties] )
|
||||
* http://es5.github.io/#x15.2.3.5
|
||||
@@ -118,19 +124,19 @@
|
||||
* 15.2.3.14 Object.keys ( O )
|
||||
* http://es5.github.io/#x15.2.3.14
|
||||
*/
|
||||
keys: createGetKeys(hidenNames1, hidenNames1Length)
|
||||
keys: createGetKeys(hiddenNames1, hiddenNames1Length)
|
||||
});
|
||||
// not array-like strings fix
|
||||
if(!(0 in Object('q') && 'q'[0] == 'q')){
|
||||
arrayLikeSelf = function(it){
|
||||
ES5Object = function(it){
|
||||
return classof(it) == 'String' ? it.split('') : Object(it);
|
||||
}
|
||||
// Array.prototype methods for strings in ES3
|
||||
$Array.slice = slice = function(){
|
||||
return nativeSlice.apply(arrayLikeSelf(this), arguments);
|
||||
return nativeSlice.apply(ES5Object(this), arguments);
|
||||
}
|
||||
$Array.join = function(){
|
||||
return nativeJoin.apply(arrayLikeSelf(this), arguments);
|
||||
return nativeJoin.apply(ES5Object(this), arguments);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -164,7 +170,8 @@
|
||||
return classof(it) == 'Array'
|
||||
}});
|
||||
function forEach(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++)i in self && callbackfn.call(thisArg, self[i], i, this);
|
||||
@@ -175,7 +182,7 @@
|
||||
* http://es5.github.io/#x15.4.4.14
|
||||
*/
|
||||
indexOf: function(searchElement, fromIndex /* = 0 */){
|
||||
var self = arrayLikeSelf(this)
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = fromIndex | 0;
|
||||
if(0 > i)i = toLength(length + i);
|
||||
@@ -187,7 +194,7 @@
|
||||
* http://es5.github.io/#x15.4.4.15
|
||||
*/
|
||||
lastIndexOf: function(searchElement, fromIndex /* = @[*-1] */){
|
||||
var self = arrayLikeSelf(this)
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = length - 1;
|
||||
if(arguments.length > 1)i = min(i, fromIndex | 0);
|
||||
@@ -200,7 +207,8 @@
|
||||
* http://es5.github.io/#x15.4.4.16
|
||||
*/
|
||||
every: function(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++){
|
||||
@@ -213,7 +221,8 @@
|
||||
* http://es5.github.io/#x15.4.4.17
|
||||
*/
|
||||
some: function(callbackfn, thisArg /* = undefined */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(;length > i; i++){
|
||||
@@ -231,6 +240,7 @@
|
||||
* http://es5.github.io/#x15.4.4.19
|
||||
*/
|
||||
map: function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var result = Array(toLength(this.length));
|
||||
forEach.call(this, function(val, key, that){
|
||||
result[key] = callbackfn.call(thisArg, val, key, that);
|
||||
@@ -242,6 +252,7 @@
|
||||
* http://es5.github.io/#x15.4.4.20
|
||||
*/
|
||||
filter: function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var result = [];
|
||||
forEach.call(this, function(val){
|
||||
callbackfn.apply(thisArg, arguments) && result.push(val);
|
||||
@@ -253,7 +264,8 @@
|
||||
* http://es5.github.io/#x15.4.4.21
|
||||
*/
|
||||
reduce: function(callbackfn, memo /* = @.1 */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
if(2 > arguments.length)for(;;){
|
||||
@@ -271,7 +283,8 @@
|
||||
* http://es5.github.io/#x15.4.4.22
|
||||
*/
|
||||
reduceRight: function(callbackfn, memo /* = @[*-1] */){
|
||||
var self = arrayLikeSelf(this)
|
||||
assertFunction(callbackfn);
|
||||
var self = ES5Object(this)
|
||||
, i = toLength(self.length) - 1;
|
||||
if(2 > arguments.length)for(;;){
|
||||
if(i in self){
|
||||
|
||||
+12
-9
@@ -37,7 +37,8 @@
|
||||
*/
|
||||
PROTO && extendBuiltInObject(Object, {
|
||||
setPrototypeOf: function(O, proto){
|
||||
assert(isObject(O) && (isObject(proto) || proto === null), "Can't set", proto, 'as prototype of', O);
|
||||
assertObject(O);
|
||||
assert(isObject(proto) || proto === null, "Can't set", proto, 'as prototype');
|
||||
O.__proto__ = proto;
|
||||
return O;
|
||||
}
|
||||
@@ -186,11 +187,11 @@
|
||||
hypot: function(value1, value2){
|
||||
var sum = 0
|
||||
, length = arguments.length
|
||||
, val;
|
||||
, value;
|
||||
while(length--){
|
||||
val = +arguments[length];
|
||||
if(val == Infinity || val == - Infinity)return Infinity;
|
||||
sum += val * val;
|
||||
value = +arguments[length];
|
||||
if(value == Infinity || value == -Infinity)return Infinity;
|
||||
sum += value * value;
|
||||
}
|
||||
return sqrt(sum);
|
||||
},
|
||||
@@ -340,7 +341,8 @@
|
||||
* http://kangax.github.io/es5-compat-table/es6/#Array.from
|
||||
*/
|
||||
from: function(arrayLike, mapfn /* -> it */, thisArg /* = undefind */){
|
||||
var O = arrayLikeSelf(arrayLike)
|
||||
(mapfn === undefined) || assertFunction(mapfn);
|
||||
var O = ES5Object(arrayLike)
|
||||
, i = 0
|
||||
, length = toLength(O.length)
|
||||
, result = new (isFunction(this) ? this : Array)(length);
|
||||
@@ -362,8 +364,9 @@
|
||||
}
|
||||
});
|
||||
function findIndex(predicate, thisArg /* = undefind */){
|
||||
var O = Object(this)
|
||||
, self = arrayLikeSelf(O)
|
||||
assertFunction(predicate);
|
||||
var O = Object(this)
|
||||
, self = ES5Object(O)
|
||||
, length = toLength(self.length)
|
||||
, i = 0;
|
||||
for(; i < length; i++){
|
||||
@@ -395,7 +398,7 @@
|
||||
*/
|
||||
find: function(predicate, thisArg /* = undefind */){
|
||||
var index = findIndex.call(this, predicate, thisArg);
|
||||
return index === -1 ? undefined : arrayLikeSelf(this)[index];
|
||||
return index === -1 ? undefined : ES5Object(this)[index];
|
||||
},
|
||||
/**
|
||||
* 22.1.3.9 Array.prototype.findIndex ( predicate , thisArg = undefined )
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
}
|
||||
function createForEach(key){
|
||||
return function(callbackfn, thisArg /* = undefined */){
|
||||
assertFunction(callbackfn);
|
||||
var values = this[VALUES_STORE]
|
||||
, keyz = this[key]
|
||||
, names = keys(keyz)
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
*/
|
||||
var extendCollections = {
|
||||
reduce: function(fn, memo){
|
||||
assertFunction(fn);
|
||||
this.forEach(function(val, key, foo){
|
||||
memo = fn(memo, val, key, foo);
|
||||
});
|
||||
return memo;
|
||||
},
|
||||
some: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -23,6 +25,7 @@ var extendCollections = {
|
||||
return false;
|
||||
},
|
||||
every: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -35,6 +38,7 @@ var extendCollections = {
|
||||
return true;
|
||||
},
|
||||
find: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var DONE = {};
|
||||
try {
|
||||
this.forEach(function(val, key, foo){
|
||||
@@ -67,6 +71,7 @@ var extendCollections = {
|
||||
};
|
||||
extendBuiltInObject(Map[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
result.set(key, fn.apply(that, arguments));
|
||||
@@ -74,6 +79,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Map;
|
||||
this.forEach(function(val, key){
|
||||
if(fn.apply(that, arguments))result.set(key, val);
|
||||
@@ -103,6 +109,7 @@ extendBuiltInObject(Map[prototype], assign({
|
||||
}, extendCollections));
|
||||
extendBuiltInObject(Set[prototype], assign({
|
||||
map: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(){
|
||||
result.add(fn.apply(that, arguments));
|
||||
@@ -110,6 +117,7 @@ extendBuiltInObject(Set[prototype], assign({
|
||||
return result;
|
||||
},
|
||||
filter: function(fn, that){
|
||||
assertFunction(fn);
|
||||
var result = new Set;
|
||||
this.forEach(function(val){
|
||||
if(fn.apply(that, arguments))result.add(val);
|
||||
|
||||
+4
-1
@@ -1,4 +1,6 @@
|
||||
function inherits(parent){
|
||||
assertFunction(this);
|
||||
assertFunction(parent);
|
||||
this[prototype] = create(parent[prototype], getOwnPropertyDescriptors(this[prototype]));
|
||||
return this;
|
||||
}
|
||||
@@ -18,8 +20,9 @@ extendBuiltInObject(Function, {
|
||||
});
|
||||
extendBuiltInObject($Function, {
|
||||
invoke: function(args){
|
||||
assertFunction(this);
|
||||
var instance = create(this[prototype])
|
||||
, result = this.apply(instance, arrayLikeSelf(args || []));
|
||||
, result = this.apply(instance, ES5Object(args || []));
|
||||
return isObject(result) ? result : instance;
|
||||
},
|
||||
// deferred call
|
||||
|
||||
+7
-3
@@ -58,6 +58,7 @@ function unbind(that){
|
||||
function tie(key){
|
||||
var that = this
|
||||
, fn = that[key];
|
||||
assertFunction(fn);
|
||||
return function(){
|
||||
return fn.apply(that, arguments);
|
||||
}
|
||||
@@ -71,6 +72,7 @@ function part(/*args...*/){
|
||||
, argsPart = Array(lengthPart)
|
||||
, i = 0
|
||||
, placeholder = false;
|
||||
assertFunction(fn);
|
||||
while(lengthPart > i)if((argsPart[i] = arguments[i++]) === _)placeholder = true;
|
||||
return function(/*args...*/){
|
||||
var length = arguments.length
|
||||
@@ -118,6 +120,8 @@ function getOwnPropertyDescriptors(object){
|
||||
}
|
||||
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
|
||||
var assign = Object.assign || function(target, source){
|
||||
target = Object(target);
|
||||
source = ES5Object(source);
|
||||
var props = keys(source)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -126,6 +130,7 @@ var assign = Object.assign || function(target, source){
|
||||
return target;
|
||||
}
|
||||
function invert(object){
|
||||
object = ES5Object(object);
|
||||
var result = {}
|
||||
, names = keys(object)
|
||||
, length = names.length
|
||||
@@ -145,9 +150,8 @@ var push = $Array.push
|
||||
, $slice = Array.slice || function(arrayLike, from){
|
||||
return slice.call(arrayLike, from);
|
||||
};
|
||||
// How to get the context for calling Array.prototype methods
|
||||
// Dummy, polyfill for not array-like strings for old ie in es5 shim
|
||||
var arrayLikeSelf = Object;
|
||||
// Dummy, fix for not array-like ES3 string in es5.js
|
||||
var ES5Object = Object;
|
||||
// simple reduce to object
|
||||
function reduceTo(target, callbackfn){
|
||||
if(arguments.length < 2){
|
||||
|
||||
+2
-3
@@ -47,11 +47,10 @@ extendBuiltInObject($Number, {
|
||||
* http://mootools.net/docs/core/Types/Number#Number-Math
|
||||
*/
|
||||
extendBuiltInObject($Number, reduceTo.call(
|
||||
// IE...
|
||||
// getOwnPropertyNames(Math)
|
||||
// IE... getOwnPropertyNames(Math)
|
||||
array(
|
||||
// ES3
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,pow,sqrt,max,min,pow,atan2,' +
|
||||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,sqrt,max,min,pow,atan2,' +
|
||||
// ES6
|
||||
'acosh,asinh,atanh,cbrt,cosh,expm1,hypot,imul,log1p,log10,log2,sign,sinh,tanh,trunc'
|
||||
),
|
||||
|
||||
+17
-10
@@ -121,7 +121,8 @@
|
||||
return true;
|
||||
}
|
||||
function forOwnKeys(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -130,7 +131,8 @@
|
||||
return object;
|
||||
}
|
||||
function findIndex(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -233,7 +235,8 @@
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-every
|
||||
*/
|
||||
every: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -248,7 +251,8 @@
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-filter
|
||||
*/
|
||||
filter: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -266,7 +270,7 @@
|
||||
*/
|
||||
find: function(object, fn, that /* = undefined */){
|
||||
var index = findIndex(object, fn, that);
|
||||
return index === undefined ? undefined : arrayLikeSelf(object)[index];
|
||||
return index === undefined ? undefined : ES5Object(object)[index];
|
||||
},
|
||||
findIndex: findIndex,
|
||||
/**
|
||||
@@ -283,7 +287,7 @@
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-keyOf
|
||||
*/
|
||||
indexOf: function(object, searchElement){
|
||||
var O = arrayLikeSelf(object)
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -298,7 +302,8 @@
|
||||
* http://api.jquery.com/jQuery.map/
|
||||
*/
|
||||
map: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, result = create(null)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
@@ -313,7 +318,8 @@
|
||||
* http://sugarjs.com/api/Object/enumerable
|
||||
*/
|
||||
reduce: function(object, fn, result /* = undefined */, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, i = 0
|
||||
, length = props.length
|
||||
@@ -332,7 +338,8 @@
|
||||
* http://mootools.net/docs/core/Types/Object#Object:Object-some
|
||||
*/
|
||||
some: function(object, fn, that /* = undefined */){
|
||||
var O = arrayLikeSelf(object)
|
||||
assertFunction(fn);
|
||||
var O = ES5Object(object)
|
||||
, props = keys(O)
|
||||
, length = props.length
|
||||
, i = 0
|
||||
@@ -346,7 +353,7 @@
|
||||
* http://sugarjs.com/api/Array/map
|
||||
*/
|
||||
pluck: function(object, prop){
|
||||
object = arrayLikeSelf(object);
|
||||
object = ES5Object(object);
|
||||
var names = keys(object)
|
||||
, result = create(null)
|
||||
, length = names.length
|
||||
|
||||
+132
-245
@@ -1281,188 +1281,126 @@
|
||||
return Math.abs(a - b) <= Number.EPSILON;
|
||||
};
|
||||
test('Object.assign', function(){
|
||||
var assign, foo, foo2;
|
||||
var assign, foo;
|
||||
assign = Object.assign;
|
||||
ok(isFunction(assign));
|
||||
ok(isFunction(assign), 'Object.assign is function');
|
||||
foo = {
|
||||
q: 1
|
||||
};
|
||||
ok(foo === assign(foo, {
|
||||
w: 2
|
||||
}));
|
||||
ok(foo.w === 2);
|
||||
bar: 2
|
||||
}), 'assign return target');
|
||||
ok(foo.bar === 2, 'assign define properties');
|
||||
if (isNative(getOwnPropertyDescriptor)) {
|
||||
foo = {
|
||||
q: 1
|
||||
baz: 1
|
||||
};
|
||||
foo2 = defineProperty({}, 'w', {
|
||||
assign(foo, defineProperty({}, 'bar', {
|
||||
get: function(){
|
||||
return this.q + 1;
|
||||
return this.baz + 1;
|
||||
}
|
||||
});
|
||||
assign(foo, foo2);
|
||||
ok(foo.w === void 8);
|
||||
}));
|
||||
ok(foo.bar === void 8, "assign don't copy descriptors");
|
||||
}
|
||||
});
|
||||
test('Object.is', function(){
|
||||
ok(isFunction(same));
|
||||
ok(same(1, 1));
|
||||
ok(same(NaN, NaN));
|
||||
ok(!same(0, -0));
|
||||
ok(!same({}, {}));
|
||||
ok(isFunction(same), 'Object.is is function');
|
||||
ok(same(1, 1), '1 is 1');
|
||||
ok(same(NaN, NaN), '1 is 1');
|
||||
ok(!same(0, -0), '0 isnt -0');
|
||||
ok(!same({}, {}), '{} isnt {}');
|
||||
});
|
||||
if (Object.setPrototypeOf) {
|
||||
test('Object.setPrototypeOf', function(){
|
||||
var setPrototypeOf, tmp;
|
||||
setPrototypeOf = Object.setPrototypeOf;
|
||||
ok(isFunction(setPrototypeOf));
|
||||
ok('apply' in setPrototypeOf({}, Function.prototype));
|
||||
ok(isFunction(setPrototypeOf), 'Object.setPrototypeOf is function');
|
||||
ok('apply' in setPrototypeOf({}, Function.prototype), 'Parent properties in target');
|
||||
ok(setPrototypeOf({
|
||||
a: 2
|
||||
}, {
|
||||
b: function(){
|
||||
return Math.pow(this.a, 2);
|
||||
}
|
||||
}).b() === 4);
|
||||
}).b() === 4, 'Child and parent properties in target');
|
||||
ok(setPrototypeOf(tmp = {}, {
|
||||
a: 1
|
||||
}) === tmp);
|
||||
ok(!('toString' in setPrototypeOf({}, null)));
|
||||
}) === tmp, 'setPrototypeOf return target');
|
||||
ok(!('toString' in setPrototypeOf({}, null)), 'Can set null as prototype');
|
||||
});
|
||||
}
|
||||
test('Number.EPSILON', function(){
|
||||
ok('EPSILON' in Number);
|
||||
ok(Number.EPSILON === 2.220446049250313e-16);
|
||||
ok(1 !== 1 + Number.EPSILON);
|
||||
ok(1 === 1 + Number.EPSILON / 2);
|
||||
var EPSILON;
|
||||
EPSILON = Number.EPSILON;
|
||||
ok('EPSILON' in Number, 'EPSILON in Number');
|
||||
ok(EPSILON === Math.pow(2, -52), 'Number.EPSILON is 2^-52');
|
||||
ok(1 !== 1 + EPSILON, '1 isnt 1 + EPSILON');
|
||||
ok(1 === 1 + EPSILON / 2, '1 is 1 + EPSILON / 2');
|
||||
});
|
||||
test('Number.isFinite', function(){
|
||||
var isFinite;
|
||||
var isFinite, i$, x$, ref$, len$, y$;
|
||||
isFinite = Number.isFinite;
|
||||
ok(isFunction(isFinite));
|
||||
ok(isFinite(1));
|
||||
ok(isFinite(0.1));
|
||||
ok(isFinite(-1));
|
||||
ok(isFinite(Math.pow(2, 16)));
|
||||
ok(isFinite(Math.pow(2, 16) - 1));
|
||||
ok(isFinite(Math.pow(2, 31)));
|
||||
ok(isFinite(Math.pow(2, 31) - 1));
|
||||
ok(isFinite(Math.pow(2, 32)));
|
||||
ok(isFinite(Math.pow(2, 32) - 1));
|
||||
ok(isFinite(-0));
|
||||
ok(!isFinite(NaN));
|
||||
ok(!isFinite(Infinity));
|
||||
ok(!isFinite('NaN'));
|
||||
ok(!isFinite('5'));
|
||||
ok(!isFinite(false));
|
||||
ok(!isFinite(new Number(NaN)));
|
||||
ok(!isFinite(new Number(Infinity)));
|
||||
ok(!isFinite(new Number(5)));
|
||||
ok(!isFinite(new Number(0.1)));
|
||||
ok(!isFinite(void 8));
|
||||
ok(!isFinite(null));
|
||||
ok(!isFinite({}));
|
||||
ok(!isFinite(function(){}));
|
||||
ok(isFunction(isFinite), 'Number.isFinite is function');
|
||||
for (i$ = 0, len$ = (ref$ = [1, 0.1, -1, Math.pow(2, 16), Math.pow(2, 16) - 1, Math.pow(2, 31), Math.pow(2, 31) - 1, Math.pow(2, 32), Math.pow(2, 32) - 1, -0]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(isFinite(x$), "isFinite " + typeof x$ + " " + x$);
|
||||
}
|
||||
for (i$ = 0, len$ = (ref$ = [NaN, Infinity, 'NaN', '5', false, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void 8, null, {}, fn$]).length; i$ < len$; ++i$) {
|
||||
y$ = ref$[i$];
|
||||
ok(!isFinite(y$), "not isFinite " + typeof y$ + " " + y$);
|
||||
}
|
||||
function fn$(){}
|
||||
});
|
||||
test('Number.isInteger', function(){
|
||||
var isInteger;
|
||||
var isInteger, i$, x$, ref$, len$, y$;
|
||||
isInteger = Number.isInteger;
|
||||
ok(isFunction(isInteger));
|
||||
ok(isInteger(1));
|
||||
ok(isInteger(-1));
|
||||
ok(isInteger(Math.pow(2, 16)));
|
||||
ok(isInteger(Math.pow(2, 16) - 1));
|
||||
ok(isInteger(Math.pow(2, 31)));
|
||||
ok(isInteger(Math.pow(2, 31) - 1));
|
||||
ok(isInteger(Math.pow(2, 32)));
|
||||
ok(isInteger(Math.pow(2, 32) - 1));
|
||||
ok(!isInteger(NaN));
|
||||
ok(!isInteger(0.1));
|
||||
ok(!isInteger(Infinity));
|
||||
ok(!isInteger('NaN'));
|
||||
ok(!isInteger('5'));
|
||||
ok(!isInteger(false));
|
||||
ok(!isInteger(new Number(NaN)));
|
||||
ok(!isInteger(new Number(Infinity)));
|
||||
ok(!isInteger(new Number(5)));
|
||||
ok(!isInteger(new Number(0.1)));
|
||||
ok(!isInteger(void 8));
|
||||
ok(!isInteger(null));
|
||||
ok(!isInteger({}));
|
||||
ok(!isInteger(function(){}));
|
||||
ok(isInteger(-0));
|
||||
ok(isFunction(isInteger), 'Number.isInteger is function');
|
||||
for (i$ = 0, len$ = (ref$ = [1, -1, Math.pow(2, 16), Math.pow(2, 16) - 1, Math.pow(2, 31), Math.pow(2, 31) - 1, Math.pow(2, 32), Math.pow(2, 32) - 1, -0]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(isInteger(x$), "isInteger " + typeof x$ + " " + x$);
|
||||
}
|
||||
for (i$ = 0, len$ = (ref$ = [NaN, 0.1, Infinity, 'NaN', '5', false, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void 8, null, {}, fn$]).length; i$ < len$; ++i$) {
|
||||
y$ = ref$[i$];
|
||||
ok(!isInteger(y$), "not isInteger " + typeof y$ + " " + y$);
|
||||
}
|
||||
function fn$(){}
|
||||
});
|
||||
test('Number.isNaN', function(){
|
||||
var isNaN;
|
||||
var isNaN, i$, x$, ref$, len$;
|
||||
isNaN = Number.isNaN;
|
||||
ok(isFunction(isNaN));
|
||||
ok(isNaN(NaN));
|
||||
ok(!isNaN(1));
|
||||
ok(!isNaN(0.1));
|
||||
ok(!isNaN(-1));
|
||||
ok(!isNaN(Math.pow(2, 16)));
|
||||
ok(!isNaN(Math.pow(2, 16) - 1));
|
||||
ok(!isNaN(Math.pow(2, 31)));
|
||||
ok(!isNaN(Math.pow(2, 31) - 1));
|
||||
ok(!isNaN(Math.pow(2, 32)));
|
||||
ok(!isNaN(Math.pow(2, 32) - 1));
|
||||
ok(!isNaN(Infinity));
|
||||
ok(!isNaN('NaN'));
|
||||
ok(!isNaN('5'));
|
||||
ok(!isNaN(false));
|
||||
ok(!isNaN(new Number(NaN)));
|
||||
ok(!isNaN(new Number(Infinity)));
|
||||
ok(!isNaN(new Number(5)));
|
||||
ok(!isNaN(new Number(0.1)));
|
||||
ok(!isNaN(void 8));
|
||||
ok(!isNaN(null));
|
||||
ok(!isNaN({}));
|
||||
ok(!isNaN(function(){}));
|
||||
ok(!isNaN(-0));
|
||||
ok(isFunction(isNaN), 'Number.isNaN is function');
|
||||
ok(isNaN(NaN), 'Number.isNaN NaN');
|
||||
for (i$ = 0, len$ = (ref$ = [1, 0.1, -1, Math.pow(2, 16), Math.pow(2, 16) - 1, Math.pow(2, 31), Math.pow(2, 31) - 1, Math.pow(2, 32), Math.pow(2, 32) - 1, -0, Infinity, 'NaN', '5', false, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void 8, null, {}, fn$]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(!isNaN(x$), "not Number.isNaN " + typeof x$ + " " + x$);
|
||||
}
|
||||
function fn$(){}
|
||||
});
|
||||
test('Number.isSafeInteger', function(){
|
||||
var isSafeInteger;
|
||||
var isSafeInteger, i$, x$, ref$, len$, y$;
|
||||
isSafeInteger = Number.isSafeInteger;
|
||||
ok(isFunction(isSafeInteger));
|
||||
ok(isSafeInteger(1));
|
||||
ok(isSafeInteger(-1));
|
||||
ok(isSafeInteger(Math.pow(2, 16)));
|
||||
ok(isSafeInteger(Math.pow(2, 16) - 1));
|
||||
ok(isSafeInteger(Math.pow(2, 31)));
|
||||
ok(isSafeInteger(Math.pow(2, 31) - 1));
|
||||
ok(isSafeInteger(Math.pow(2, 32)));
|
||||
ok(isSafeInteger(Math.pow(2, 32) - 1));
|
||||
ok(isSafeInteger(9007199254740991));
|
||||
ok(isSafeInteger(-9007199254740991));
|
||||
ok(isSafeInteger(-0));
|
||||
ok(!isSafeInteger(NaN));
|
||||
ok(!isSafeInteger(0.1));
|
||||
ok(!isSafeInteger(9007199254740992));
|
||||
ok(!isSafeInteger(-9007199254740992));
|
||||
ok(!isSafeInteger(Infinity));
|
||||
ok(!isSafeInteger('NaN'));
|
||||
ok(!isSafeInteger('5'));
|
||||
ok(!isSafeInteger(false));
|
||||
ok(!isSafeInteger(new Number(NaN)));
|
||||
ok(!isSafeInteger(new Number(Infinity)));
|
||||
ok(!isSafeInteger(new Number(5)));
|
||||
ok(!isSafeInteger(new Number(0.1)));
|
||||
ok(!isSafeInteger(void 8));
|
||||
ok(!isSafeInteger(null));
|
||||
ok(!isSafeInteger({}));
|
||||
ok(!isSafeInteger(function(){}));
|
||||
ok(isFunction(isSafeInteger), 'Number.isSafeInteger is function');
|
||||
for (i$ = 0, len$ = (ref$ = [1, -1, Math.pow(2, 16), Math.pow(2, 16) - 1, Math.pow(2, 31), Math.pow(2, 31) - 1, Math.pow(2, 32), Math.pow(2, 32) - 1, -0, 9007199254740991, -9007199254740991]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(isSafeInteger(x$), "isSafeInteger " + typeof x$ + " " + x$);
|
||||
}
|
||||
for (i$ = 0, len$ = (ref$ = [9007199254740992, -9007199254740992, NaN, 0.1, Infinity, 'NaN', '5', false, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void 8, null, {}, fn$]).length; i$ < len$; ++i$) {
|
||||
y$ = ref$[i$];
|
||||
ok(!isSafeInteger(y$), "not isSafeInteger " + typeof y$ + " " + y$);
|
||||
}
|
||||
function fn$(){}
|
||||
});
|
||||
test('Number.MAX_SAFE_INTEGER', function(){
|
||||
ok(Number.MAX_SAFE_INTEGER === 9007199254740991);
|
||||
ok(Number.MAX_SAFE_INTEGER === Math.pow(2, 53) - 1, 'Number.MAX_SAFE_INTEGER is 2^53 - 1');
|
||||
});
|
||||
test('Number.MIN_SAFE_INTEGER', function(){
|
||||
ok(Number.MIN_SAFE_INTEGER === -9007199254740991);
|
||||
ok(Number.MIN_SAFE_INTEGER === -Math.pow(2, 53) + 1, 'Number.MIN_SAFE_INTEGER is -2^53 + 1');
|
||||
});
|
||||
test('Number.parseFloat', function(){
|
||||
ok(isFunction(Number.parseFloat));
|
||||
ok(isFunction(Number.parseFloat), 'Number.parseFloat is function');
|
||||
});
|
||||
test('Number.parseInt', function(){
|
||||
ok(isFunction(Number.parseInt));
|
||||
ok(isFunction(Number.parseInt), 'Number.parseInt is function');
|
||||
});
|
||||
test('Math.acosh', function(){
|
||||
var acosh;
|
||||
@@ -2197,50 +2135,42 @@
|
||||
test('Function.inherits', function(){
|
||||
var inherits, A, B;
|
||||
inherits = Function.inherits;
|
||||
ok(isFunction(inherits));
|
||||
ok(isFunction(inherits), 'Function.inherits is function');
|
||||
A = function(){};
|
||||
B = function(){};
|
||||
B.prototype.prop = 42;
|
||||
B.prototype.foo = 42;
|
||||
inherits(B, A);
|
||||
ok(new B instanceof B);
|
||||
ok(new B instanceof A);
|
||||
ok(new B().prop === 42);
|
||||
ok(new B().constructor === B);
|
||||
ok(new B instanceof B, 'new B instanceof B');
|
||||
ok(new B instanceof A, 'new B instanceof A');
|
||||
ok(new B().foo === 42, 'B has own proto props after inherit');
|
||||
ok(new B().constructor === B, 'new B!@@ is B');
|
||||
});
|
||||
test('Function.isFunction', function(){
|
||||
var isFunction;
|
||||
var isFunction, i$, x$, ref$, len$;
|
||||
isFunction = Function.isFunction;
|
||||
ok(typeof isFunction === 'function');
|
||||
ok(isFunction(function(){}));
|
||||
ok(!isFunction(void 8));
|
||||
ok(!isFunction(null));
|
||||
ok(!isFunction(1));
|
||||
ok(!isFunction(''));
|
||||
ok(!isFunction(false));
|
||||
ok(!isFunction({}));
|
||||
ok(!isFunction(function(){
|
||||
ok(typeof isFunction === 'function', 'Function.isFunction is function');
|
||||
ok(isFunction(function(){}), 'isFunction function');
|
||||
for (i$ = 0, len$ = (ref$ = [void 8, null, 1, '', false, {}, fn$(), [], /./]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(!isFunction(x$), "not isFunction " + toString$.call(x$).slice(8, -1));
|
||||
}
|
||||
function fn$(){
|
||||
return arguments;
|
||||
}()));
|
||||
ok(!isFunction([1]));
|
||||
ok(!isFunction(/./));
|
||||
}
|
||||
});
|
||||
test('Function.isNative', function(){
|
||||
var isNative;
|
||||
var isNative, i$, x$, ref$, len$;
|
||||
isNative = Function.isNative;
|
||||
ok(isFunction(isNative));
|
||||
ok(isNative(Object.prototype.hasOwnProperty));
|
||||
ok(!isNative(void 8));
|
||||
ok(!isNative(null));
|
||||
ok(!isNative(1));
|
||||
ok(!isNative(''));
|
||||
ok(!isNative(false));
|
||||
ok(!isNative({}));
|
||||
ok(!isNative(function(){
|
||||
ok(isFunction(isNative), 'Function.isNative is function');
|
||||
ok(isNative(Object.prototype.hasOwnProperty), 'isNative native function');
|
||||
for (i$ = 0, len$ = (ref$ = [fn$, void 8, null, 1, '', false, {}, fn1$(), [], /./]).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(!isNative(x$), "not isNative " + toString$.call(x$).slice(8, -1));
|
||||
}
|
||||
function fn$(){}
|
||||
function fn1$(){
|
||||
return arguments;
|
||||
}()));
|
||||
ok(!isNative([1]));
|
||||
ok(!isNative(/./));
|
||||
ok(!isNative(function(){}));
|
||||
}
|
||||
});
|
||||
test('Function::methodize', function(){
|
||||
var num;
|
||||
@@ -2445,85 +2375,19 @@
|
||||
return it === 7 || it === 8 || it === 9 || it === 10;
|
||||
})));
|
||||
});
|
||||
/*
|
||||
test 'Number::isOdd' !->
|
||||
ok isFunction Number::isOdd
|
||||
ok 1.isOdd!
|
||||
ok 111.isOdd!
|
||||
ok (-1)isOdd!
|
||||
ok not NaN.isOdd!
|
||||
ok not Infinity.isOdd!
|
||||
ok not (-1.5)isOdd!
|
||||
ok not (1.5)isOdd!
|
||||
ok not 2.isOdd!
|
||||
ok not 222.isOdd!
|
||||
test 'Number::isEven' !->
|
||||
ok isFunction Number::isEven
|
||||
ok 2.isEven!
|
||||
ok 222.isEven!
|
||||
ok (-2)isEven!
|
||||
ok not NaN.isEven!
|
||||
ok not Infinity.isEven!
|
||||
ok not (-1.5)isEven!
|
||||
ok not (1.5)isEven!
|
||||
ok not 1.isEven!
|
||||
ok not 111.isEven!
|
||||
test 'Number::format' !->
|
||||
ok isFunction Number::format
|
||||
ok NaN.format! is \NaN
|
||||
ok (-Infinity)format! is \-Infinity
|
||||
ok 123.format! is \123
|
||||
ok (-123)format! is \-123
|
||||
ok 123.45.format! is \123
|
||||
ok (-123.45)format! is \-123
|
||||
ok NaN.format(3) is \NaN
|
||||
ok (-Infinity)format(3) is \-Infinity
|
||||
ok NaN.format(7 ', ' '. ') is \NaN
|
||||
ok (-Infinity)format(7 ', ' '. ') is \-Infinity
|
||||
ok 123.format(3) is '123.000'
|
||||
ok (-123)format(3) is '-123.000'
|
||||
ok 123.45678.format(3) is '123.457'
|
||||
ok (-123.45678)format(3) is '-123.457'
|
||||
ok 1234.format(7 ', ' '. ') is '1, 234. 000, 000, 0'
|
||||
ok (-1234)format(7 ', ' '. ') is '-1, 234. 000, 000, 0'
|
||||
ok 1234.45678.format(7 ', ' '. ') is '1, 234. 456, 780, 0'
|
||||
ok (-1234.45678)format(7 ', ' '. ') is '-1, 234. 456, 780, 0'
|
||||
ok (-1234.45678)format(null ', ' '. ') is '-1, 234'
|
||||
ok (0.1 ^ 10)format(6 \. \,) is '0,000.000'
|
||||
*/
|
||||
test('Number:: <<< Math', function(){
|
||||
ok(isFunction(Number.prototype.round));
|
||||
ok(isFunction(Number.prototype.floor));
|
||||
ok(isFunction(Number.prototype.ceil));
|
||||
ok(isFunction(Number.prototype.abs));
|
||||
ok(isFunction(Number.prototype.sin));
|
||||
ok(isFunction(Number.prototype.asin));
|
||||
ok(isFunction(Number.prototype.cos));
|
||||
ok(isFunction(Number.prototype.acos));
|
||||
ok(isFunction(Number.prototype.tan));
|
||||
ok(isFunction(Number.prototype.atan));
|
||||
ok(isFunction(Number.prototype.exp));
|
||||
ok(isFunction(Number.prototype.pow));
|
||||
ok(isFunction(Number.prototype.sqrt));
|
||||
ok(isFunction(Number.prototype.max));
|
||||
ok(isFunction(Number.prototype.min));
|
||||
ok(isFunction(Number.prototype.pow));
|
||||
ok(isFunction(Number.prototype.atan2));
|
||||
ok(isFunction(Number.prototype.acosh));
|
||||
ok(isFunction(Number.prototype.asinh));
|
||||
ok(isFunction(Number.prototype.atanh));
|
||||
ok(isFunction(Number.prototype.cbrt));
|
||||
ok(isFunction(Number.prototype.cosh));
|
||||
ok(isFunction(Number.prototype.expm1));
|
||||
ok(isFunction(Number.prototype.hypot));
|
||||
ok(isFunction(Number.prototype.imul));
|
||||
ok(isFunction(Number.prototype.log1p));
|
||||
ok(isFunction(Number.prototype.log10));
|
||||
ok(isFunction(Number.prototype.log2));
|
||||
ok(isFunction(Number.prototype.sign));
|
||||
ok(isFunction(Number.prototype.sinh));
|
||||
ok(isFunction(Number.prototype.tanh));
|
||||
ok(isFunction(Number.prototype.trunc));
|
||||
test('Number::{Math}', function(){
|
||||
var i$, x$, ref$, len$, y$;
|
||||
for (i$ = 0, len$ = (ref$ = ['round', 'floor', 'ceil', 'abs', 'sin', 'asin', 'cos', 'acos', 'tan', 'atan', 'exp', 'sqrt', 'max', 'min', 'pow', 'atan2']).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
ok(isFunction(Number.prototype[x$]), "Number::" + x$ + " is function (ES3)");
|
||||
}
|
||||
for (i$ = 0, len$ = (ref$ = ['acosh', 'asinh', 'atanh', 'cbrt', 'cosh', 'expm1', 'hypot', 'imul', 'log1p', 'log10', 'log2', 'sign', 'sinh', 'tanh', 'trunc']).length; i$ < len$; ++i$) {
|
||||
y$ = ref$[i$];
|
||||
ok(isFunction(Number.prototype[y$]), "Number::" + y$ + " is function (ES6)");
|
||||
}
|
||||
ok(3 .max(2) === 3, 'context is argument of Number::{Math}');
|
||||
ok(3 .min(2) === 2, 'Number::{Math} works with first argument');
|
||||
ok(1 .max(2, 3, 4, 5, 6, 7) === 7, 'Number::{Math} works with various arguments length');
|
||||
});
|
||||
}).call(this);
|
||||
|
||||
@@ -3307,6 +3171,29 @@
|
||||
b.x = b;
|
||||
ok(isEqual(a, b));
|
||||
});
|
||||
test('Object.symbol', function(){
|
||||
var symbol;
|
||||
symbol = Object.symbol;
|
||||
ok(isFunction(symbol), 'Object.symbol is function');
|
||||
ok(typeof symbol('foo') === 'string', "symbol('foo') return string");
|
||||
ok(symbol('foo') !== symbol('foo'), "symbol('foo') !== symbol('foo')");
|
||||
ok(symbol('foo').slice(0, 6) === '@@foo_', "symbol('foo') begin from @@foo_");
|
||||
ok(symbol('foo').length > 15, "symbol('foo')length > 15");
|
||||
});
|
||||
test('Object.hidden', function(){
|
||||
var hidden, o, desc;
|
||||
hidden = Object.hidden;
|
||||
ok(isFunction(hidden), 'Object.hidden is function');
|
||||
o = {};
|
||||
ok(hidden(o, 'key', 42) === o, 'hidden return target');
|
||||
ok(o.key === 42, 'hidden define property');
|
||||
if (isNative(getOwnPropertyDescriptor)) {
|
||||
desc = getOwnPropertyDescriptor(o, 'key');
|
||||
ok(!desc.enumerable, 'hidden define not enumerable property');
|
||||
ok(desc.writable, 'hidden define writable property');
|
||||
ok(desc.configurable, 'hidden define configurable property');
|
||||
}
|
||||
});
|
||||
function clone$(it){
|
||||
function fun(){} fun.prototype = it;
|
||||
return new fun;
|
||||
|
||||
+44
-125
@@ -4,150 +4,69 @@ same = Object.is
|
||||
epsilon = (a, b)-> Math.abs(a - b) <= Number.EPSILON
|
||||
test 'Object.assign' !->
|
||||
{assign} = Object
|
||||
ok isFunction assign
|
||||
ok isFunction(assign), 'Object.assign is function'
|
||||
foo = q:1
|
||||
ok foo is assign foo, w:2
|
||||
ok foo.w is 2
|
||||
ok foo is assign(foo, bar: 2), 'assign return target'
|
||||
ok foo.bar is 2, 'assign define properties'
|
||||
if isNative getOwnPropertyDescriptor
|
||||
foo = q:1
|
||||
foo2 = defineProperty {}, \w, get: -> @q + 1
|
||||
assign foo, foo2
|
||||
ok foo.w is void
|
||||
foo = baz: 1
|
||||
assign foo, defineProperty {}, \bar, get: -> @baz + 1
|
||||
ok foo.bar is void, "assign don't copy descriptors"
|
||||
test 'Object.is' !->
|
||||
ok isFunction same
|
||||
ok same 1 1
|
||||
ok same NaN, NaN
|
||||
ok not same 0 -0
|
||||
ok not same {} {}
|
||||
ok isFunction(same), 'Object.is is function'
|
||||
ok same(1 1), '1 is 1'
|
||||
ok same(NaN, NaN), '1 is 1'
|
||||
ok not same(0 -0), '0 isnt -0'
|
||||
ok not same({} {}), '{} isnt {}'
|
||||
if Object.setPrototypeOf
|
||||
test 'Object.setPrototypeOf' !->
|
||||
{setPrototypeOf} = Object
|
||||
ok isFunction setPrototypeOf
|
||||
ok \apply of setPrototypeOf {} Function::
|
||||
ok setPrototypeOf(a:2, {b: -> @a^2})b! is 4
|
||||
ok setPrototypeOf(tmp = {}, {a: 1}) is tmp
|
||||
ok !(\toString of setPrototypeOf {} null)
|
||||
ok isFunction(setPrototypeOf), 'Object.setPrototypeOf is function'
|
||||
ok \apply of setPrototypeOf({} Function::), 'Parent properties in target'
|
||||
ok setPrototypeOf(a:2, {b: -> @a^2})b! is 4, 'Child and parent properties in target'
|
||||
ok setPrototypeOf(tmp = {}, {a: 1}) is tmp, 'setPrototypeOf return target'
|
||||
ok !(\toString of setPrototypeOf {} null), 'Can set null as prototype'
|
||||
test 'Number.EPSILON' !->
|
||||
ok \EPSILON of Number
|
||||
ok Number.EPSILON is 2.220446049250313e-16
|
||||
ok 1 isnt 1 + Number.EPSILON
|
||||
ok 1 is 1 + Number.EPSILON / 2
|
||||
{EPSILON} = Number
|
||||
ok \EPSILON of Number, 'EPSILON in Number'
|
||||
ok EPSILON is 2^-52, 'Number.EPSILON is 2^-52'
|
||||
ok 1 isnt 1 + EPSILON, '1 isnt 1 + EPSILON'
|
||||
ok 1 is 1 + EPSILON / 2, '1 is 1 + EPSILON / 2'
|
||||
test 'Number.isFinite' !->
|
||||
{isFinite} = Number
|
||||
ok isFunction isFinite
|
||||
ok isFinite 1
|
||||
ok isFinite 0.1
|
||||
ok isFinite -1
|
||||
ok isFinite 2^16
|
||||
ok isFinite 2^16 - 1
|
||||
ok isFinite 2^31
|
||||
ok isFinite 2^31 - 1
|
||||
ok isFinite 2^32
|
||||
ok isFinite 2^32 - 1
|
||||
ok isFinite -0
|
||||
ok not isFinite NaN
|
||||
ok not isFinite Infinity
|
||||
ok not isFinite 'NaN'
|
||||
ok not isFinite '5'
|
||||
ok not isFinite no
|
||||
ok not isFinite new Number NaN
|
||||
ok not isFinite new Number Infinity
|
||||
ok not isFinite new Number 5
|
||||
ok not isFinite new Number 0.1
|
||||
ok not isFinite void
|
||||
ok not isFinite null
|
||||
ok not isFinite {}
|
||||
ok not isFinite ->
|
||||
ok isFunction(isFinite), 'Number.isFinite is function'
|
||||
for [1 0.1 -1 2^16 2^16 - 1 2^31 2^31 - 1 2^32 2^32 - 1 -0]
|
||||
ok isFinite(..), "isFinite #{typeof ..} #{..}"
|
||||
for [NaN, Infinity, \NaN, \5, no, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void, null, {}, ->]
|
||||
ok not isFinite(..), "not isFinite #{typeof ..} #{..}"
|
||||
test 'Number.isInteger' !->
|
||||
{isInteger} = Number
|
||||
ok isFunction isInteger
|
||||
ok isInteger 1
|
||||
ok isInteger -1
|
||||
ok isInteger 2^16
|
||||
ok isInteger 2^16 - 1
|
||||
ok isInteger 2^31
|
||||
ok isInteger 2^31 - 1
|
||||
ok isInteger 2^32
|
||||
ok isInteger 2^32 - 1
|
||||
ok not isInteger NaN
|
||||
ok not isInteger 0.1
|
||||
ok not isInteger Infinity
|
||||
ok not isInteger \NaN
|
||||
ok not isInteger \5
|
||||
ok not isInteger no
|
||||
ok not isInteger new Number NaN
|
||||
ok not isInteger new Number Infinity
|
||||
ok not isInteger new Number 5
|
||||
ok not isInteger new Number 0.1
|
||||
ok not isInteger void
|
||||
ok not isInteger null
|
||||
ok not isInteger {}
|
||||
ok not isInteger ->
|
||||
ok isInteger -0
|
||||
ok isFunction(isInteger), 'Number.isInteger is function'
|
||||
for [1 -1 2^16 2^16 - 1 2^31 2^31 - 1 2^32 2^32 - 1 -0]
|
||||
ok isInteger(..), "isInteger #{typeof ..} #{..}"
|
||||
for [NaN, 0.1, Infinity, \NaN, \5, no, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void, null, {}, ->]
|
||||
ok not isInteger(..), "not isInteger #{typeof ..} #{..}"
|
||||
test 'Number.isNaN' !->
|
||||
{isNaN} = Number
|
||||
ok isFunction isNaN
|
||||
ok isNaN NaN
|
||||
ok not isNaN 1
|
||||
ok not isNaN 0.1
|
||||
ok not isNaN -1
|
||||
ok not isNaN 2^16
|
||||
ok not isNaN 2^16 - 1
|
||||
ok not isNaN 2^31
|
||||
ok not isNaN 2^31 - 1
|
||||
ok not isNaN 2^32
|
||||
ok not isNaN 2^32 - 1
|
||||
ok not isNaN Infinity
|
||||
ok not isNaN 'NaN'
|
||||
ok not isNaN '5'
|
||||
ok not isNaN no
|
||||
ok not isNaN new Number NaN
|
||||
ok not isNaN new Number Infinity
|
||||
ok not isNaN new Number 5
|
||||
ok not isNaN new Number 0.1
|
||||
ok not isNaN void
|
||||
ok not isNaN null
|
||||
ok not isNaN {}
|
||||
ok not isNaN ->
|
||||
ok not isNaN -0
|
||||
ok isFunction(isNaN), 'Number.isNaN is function'
|
||||
ok isNaN(NaN), 'Number.isNaN NaN'
|
||||
for [1 0.1 -1 2^16 2^16 - 1 2^31 2^31 - 1 2^32 2^32 - 1 -0 Infinity, \NaN, \5, no, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void, null, {}, ->]
|
||||
ok not isNaN(..), "not Number.isNaN #{typeof ..} #{..}"
|
||||
test 'Number.isSafeInteger' !->
|
||||
{isSafeInteger} = Number
|
||||
ok isFunction isSafeInteger
|
||||
ok isSafeInteger 1
|
||||
ok isSafeInteger -1
|
||||
ok isSafeInteger 2^16
|
||||
ok isSafeInteger 2^16 - 1
|
||||
ok isSafeInteger 2^31
|
||||
ok isSafeInteger 2^31 - 1
|
||||
ok isSafeInteger 2^32
|
||||
ok isSafeInteger 2^32 - 1
|
||||
ok isSafeInteger 16~1fffffffffffff
|
||||
ok isSafeInteger -16~1fffffffffffff
|
||||
ok isSafeInteger -0
|
||||
ok not isSafeInteger NaN
|
||||
ok not isSafeInteger 0.1
|
||||
ok not isSafeInteger 16~20000000000000
|
||||
ok not isSafeInteger -16~20000000000000
|
||||
ok not isSafeInteger Infinity
|
||||
ok not isSafeInteger 'NaN'
|
||||
ok not isSafeInteger '5'
|
||||
ok not isSafeInteger no
|
||||
ok not isSafeInteger new Number NaN
|
||||
ok not isSafeInteger new Number Infinity
|
||||
ok not isSafeInteger new Number 5
|
||||
ok not isSafeInteger new Number 0.1
|
||||
ok not isSafeInteger void
|
||||
ok not isSafeInteger null
|
||||
ok not isSafeInteger {}
|
||||
ok not isSafeInteger ->
|
||||
ok isFunction(isSafeInteger), 'Number.isSafeInteger is function'
|
||||
for [1 -1 2^16 2^16 - 1 2^31 2^31 - 1 2^32 2^32 - 1 -0 16~1fffffffffffff -16~1fffffffffffff]
|
||||
ok isSafeInteger(..), "isSafeInteger #{typeof ..} #{..}"
|
||||
for [16~20000000000000 -16~20000000000000 NaN, 0.1, Infinity, \NaN, \5, no, new Number(NaN), new Number(Infinity), new Number(5), new Number(0.1), void, null, {}, ->]
|
||||
ok not isSafeInteger(..), "not isSafeInteger #{typeof ..} #{..}"
|
||||
test 'Number.MAX_SAFE_INTEGER' !->
|
||||
ok Number.MAX_SAFE_INTEGER is 16~1fffffffffffff
|
||||
ok Number.MAX_SAFE_INTEGER is 2^53 - 1, 'Number.MAX_SAFE_INTEGER is 2^53 - 1'
|
||||
test 'Number.MIN_SAFE_INTEGER' !->
|
||||
ok Number.MIN_SAFE_INTEGER is -16~1fffffffffffff
|
||||
ok Number.MIN_SAFE_INTEGER is -2^53 + 1, 'Number.MIN_SAFE_INTEGER is -2^53 + 1'
|
||||
test 'Number.parseFloat' !->
|
||||
ok isFunction Number.parseFloat
|
||||
ok isFunction(Number.parseFloat), 'Number.parseFloat is function'
|
||||
test 'Number.parseInt' !->
|
||||
ok isFunction Number.parseInt
|
||||
ok isFunction(Number.parseInt), 'Number.parseInt is function'
|
||||
test 'Math.acosh' !->
|
||||
# Returns an implementation-dependent approximation to the inverse hyperbolic cosine of x.
|
||||
{acosh} = Math
|
||||
|
||||
+14
-29
@@ -2,42 +2,27 @@
|
||||
{isFunction} = Function
|
||||
test 'Function.inherits' !->
|
||||
{inherits} = Function
|
||||
ok isFunction inherits
|
||||
ok isFunction(inherits), 'Function.inherits is function'
|
||||
A = ->
|
||||
B = ->
|
||||
B::prop = 42
|
||||
B::foo = 42
|
||||
inherits B, A
|
||||
ok new B instanceof B
|
||||
ok new B instanceof A
|
||||
ok new B!prop is 42
|
||||
ok new B!@@ is B
|
||||
ok new B instanceof B, 'new B instanceof B'
|
||||
ok new B instanceof A, 'new B instanceof A'
|
||||
ok new B!foo is 42, 'B has own proto props after inherit'
|
||||
ok new B!@@ is B, 'new B!@@ is B'
|
||||
test 'Function.isFunction' !->
|
||||
{isFunction} = Function
|
||||
ok typeof isFunction is \function
|
||||
ok isFunction ->
|
||||
ok not isFunction void
|
||||
ok not isFunction null
|
||||
ok not isFunction 1
|
||||
ok not isFunction ''
|
||||
ok not isFunction no
|
||||
ok not isFunction {}
|
||||
ok not isFunction do -> &
|
||||
ok not isFunction [1]
|
||||
ok not isFunction /./
|
||||
ok typeof isFunction is \function, 'Function.isFunction is function'
|
||||
ok isFunction(->), 'isFunction function'
|
||||
for [void, null, 1, '', no, {}, do -> &, [], /./]
|
||||
ok not isFunction(..), "not isFunction #{typeof! ..}"
|
||||
test 'Function.isNative' !->
|
||||
{isNative} = Function
|
||||
ok isFunction isNative
|
||||
ok isNative Object::hasOwnProperty
|
||||
ok not isNative void
|
||||
ok not isNative null
|
||||
ok not isNative 1
|
||||
ok not isNative ''
|
||||
ok not isNative no
|
||||
ok not isNative {}
|
||||
ok not isNative do -> &
|
||||
ok not isNative [1]
|
||||
ok not isNative /./
|
||||
ok not isNative ->
|
||||
ok isFunction(isNative), 'Function.isNative is function'
|
||||
ok isNative(Object::hasOwnProperty), 'isNative native function'
|
||||
for [->, void, null, 1, '', no, {}, do -> &, [], /./]
|
||||
ok not isNative(..), "not isNative #{typeof! ..}"
|
||||
test 'Function::methodize' !->
|
||||
ok isFunction Function::methodize
|
||||
ok {a: 42, fn: (-> it.a)methodize!}fn! is 42
|
||||
|
||||
+9
-80
@@ -27,83 +27,12 @@ test 'Number::rand' !->
|
||||
ok 100.times(-> 10.rand!)every (in [to 10])
|
||||
ok 100.times(-> 10.rand 7)every (in [7 to 10])
|
||||
ok 100.times(-> 7.rand 10)every (in [7 to 10])
|
||||
/*
|
||||
test 'Number::isOdd' !->
|
||||
ok isFunction Number::isOdd
|
||||
ok 1.isOdd!
|
||||
ok 111.isOdd!
|
||||
ok (-1)isOdd!
|
||||
ok not NaN.isOdd!
|
||||
ok not Infinity.isOdd!
|
||||
ok not (-1.5)isOdd!
|
||||
ok not (1.5)isOdd!
|
||||
ok not 2.isOdd!
|
||||
ok not 222.isOdd!
|
||||
test 'Number::isEven' !->
|
||||
ok isFunction Number::isEven
|
||||
ok 2.isEven!
|
||||
ok 222.isEven!
|
||||
ok (-2)isEven!
|
||||
ok not NaN.isEven!
|
||||
ok not Infinity.isEven!
|
||||
ok not (-1.5)isEven!
|
||||
ok not (1.5)isEven!
|
||||
ok not 1.isEven!
|
||||
ok not 111.isEven!
|
||||
test 'Number::format' !->
|
||||
ok isFunction Number::format
|
||||
ok NaN.format! is \NaN
|
||||
ok (-Infinity)format! is \-Infinity
|
||||
ok 123.format! is \123
|
||||
ok (-123)format! is \-123
|
||||
ok 123.45.format! is \123
|
||||
ok (-123.45)format! is \-123
|
||||
ok NaN.format(3) is \NaN
|
||||
ok (-Infinity)format(3) is \-Infinity
|
||||
ok NaN.format(7 ', ' '. ') is \NaN
|
||||
ok (-Infinity)format(7 ', ' '. ') is \-Infinity
|
||||
ok 123.format(3) is '123.000'
|
||||
ok (-123)format(3) is '-123.000'
|
||||
ok 123.45678.format(3) is '123.457'
|
||||
ok (-123.45678)format(3) is '-123.457'
|
||||
ok 1234.format(7 ', ' '. ') is '1, 234. 000, 000, 0'
|
||||
ok (-1234)format(7 ', ' '. ') is '-1, 234. 000, 000, 0'
|
||||
ok 1234.45678.format(7 ', ' '. ') is '1, 234. 456, 780, 0'
|
||||
ok (-1234.45678)format(7 ', ' '. ') is '-1, 234. 456, 780, 0'
|
||||
ok (-1234.45678)format(null ', ' '. ') is '-1, 234'
|
||||
ok (0.1 ^ 10)format(6 \. \,) is '0,000.000'
|
||||
*/
|
||||
test 'Number:: <<< Math' !->
|
||||
# TODO
|
||||
ok isFunction Number::round
|
||||
ok isFunction Number::floor
|
||||
ok isFunction Number::ceil
|
||||
ok isFunction Number::abs
|
||||
ok isFunction Number::sin
|
||||
ok isFunction Number::asin
|
||||
ok isFunction Number::cos
|
||||
ok isFunction Number::acos
|
||||
ok isFunction Number::tan
|
||||
ok isFunction Number::atan
|
||||
ok isFunction Number::exp
|
||||
ok isFunction Number::pow
|
||||
ok isFunction Number::sqrt
|
||||
ok isFunction Number::max
|
||||
ok isFunction Number::min
|
||||
ok isFunction Number::pow
|
||||
ok isFunction Number::atan2
|
||||
ok isFunction Number::acosh
|
||||
ok isFunction Number::asinh
|
||||
ok isFunction Number::atanh
|
||||
ok isFunction Number::cbrt
|
||||
ok isFunction Number::cosh
|
||||
ok isFunction Number::expm1
|
||||
ok isFunction Number::hypot
|
||||
ok isFunction Number::imul
|
||||
ok isFunction Number::log1p
|
||||
ok isFunction Number::log10
|
||||
ok isFunction Number::log2
|
||||
ok isFunction Number::sign
|
||||
ok isFunction Number::sinh
|
||||
ok isFunction Number::tanh
|
||||
ok isFunction Number::trunc
|
||||
test 'Number::{Math}' !->
|
||||
for <[round floor ceil abs sin asin cos acos tan atan exp sqrt max min pow atan2]>
|
||||
ok isFunction(Number::[..]), "Number::#{..} is function (ES3)"
|
||||
for <[acosh asinh atanh cbrt cosh expm1 hypot imul log1p log10 log2 sign sinh tanh trunc]>
|
||||
ok isFunction(Number::[..]), "Number::#{..} is function (ES6)"
|
||||
ok 3.max(2) is 3, 'context is argument of Number::{Math}'
|
||||
ok 3.min(2) is 2, 'Number::{Math} works with first argument'
|
||||
ok 1.max(2 3 4 5 6 7) is 7, 'Number::{Math} works with various arguments length'
|
||||
|
||||
+19
-1
@@ -392,4 +392,22 @@ test 'Object.isEqual' !->
|
||||
a.x = a
|
||||
b = {y:1}
|
||||
b.x = b
|
||||
ok isEqual a, b
|
||||
ok isEqual a, b
|
||||
test 'Object.symbol' !->
|
||||
{symbol} = Object
|
||||
ok isFunction(symbol), 'Object.symbol is function'
|
||||
ok typeof symbol('foo') is 'string', "symbol('foo') return string"
|
||||
ok symbol('foo') isnt symbol('foo'), "symbol('foo') !== symbol('foo')"
|
||||
ok symbol('foo')slice(0 6) is '@@foo_', "symbol('foo') begin from @@foo_"
|
||||
ok symbol('foo')length > 15, "symbol('foo')length > 15"
|
||||
test 'Object.hidden' !->
|
||||
{hidden} = Object
|
||||
ok isFunction(hidden), 'Object.hidden is function'
|
||||
o = {}
|
||||
ok hidden(o, \key 42) is o, 'hidden return target'
|
||||
ok o.key is 42, 'hidden define property'
|
||||
if isNative getOwnPropertyDescriptor
|
||||
desc = getOwnPropertyDescriptor o, \key
|
||||
ok not desc.enumerable, 'hidden define not enumerable property'
|
||||
ok desc.writable, 'hidden define writable property'
|
||||
ok desc.configurable, 'hidden define configurable property'
|
||||
Reference in New Issue
Block a user