Comparing version 1.1.0 to 1.1.1
@@ -9,2 +9,8 @@ /*! Jahcode v1.1.0 | jahcode.com | Copyright 2011-2013 by Florian Buecklers | MIT license */ | ||
if (!Function.prototype.extend) { | ||
/** | ||
* Extends the target with the properties of props and return target | ||
* @param {*=} target The target to extends or thisArg, if it is not set | ||
* @param {Object} props The properties to extend | ||
* @returns {*} The extended target | ||
*/ | ||
Function.prototype.extend = function(target, props) { | ||
@@ -16,3 +22,3 @@ if (!props) { | ||
for (name in props) { | ||
for (var name in props) { | ||
if (props.hasOwnProperty(name)) { | ||
@@ -27,4 +33,16 @@ target[name] = props[name]; | ||
Object.extend(Function.prototype, { | ||
Object.extend(Function.prototype, /** @lends Function.prototype */ { | ||
/** | ||
* The linearized type hierarchy of this class | ||
* @type Function[] | ||
*/ | ||
linearizedTypes : [Object], | ||
/** | ||
* Inherits this constructor and extends it by additional properties and methods. Optional there can be mixined | ||
* additional Traits | ||
* @param {Trait...} traits Additional traits to mixin | ||
* @param {Object} classDescriptor The descriptor of the class properties and methods | ||
* @returns {Function} The new created child class | ||
*/ | ||
inherit : function() { | ||
@@ -74,2 +92,8 @@ var klass = function(toCast) { | ||
}, | ||
/** | ||
* Indicates if the object is an instance of this class | ||
* @param obj The object to check for | ||
* @returns {boolean} <code>true</code> if the object is defined and | ||
*/ | ||
isInstance : function(obj) { | ||
@@ -81,2 +105,9 @@ if (obj === null || obj === undefined) | ||
}, | ||
/** | ||
* Checks if the object is an instance of this class and returns the object or try to convert the | ||
* object to an instance of this class by calling {@link #conv} | ||
* @param obj The object to check | ||
* @returns {*} The typed object or null, if the object can't be typed to an instance of this class | ||
*/ | ||
asInstance : function(obj) { | ||
@@ -89,3 +120,9 @@ if (this.isInstance(obj)) { | ||
}, | ||
conv : function() { | ||
/** | ||
* Converts the given value to an instance of this class, or returns null, if the value can't be converted | ||
* @param {*} value The value to convert | ||
* @returns {null} The converted value or null | ||
*/ | ||
conv : function(value) { | ||
return null; | ||
@@ -95,3 +132,3 @@ } | ||
Object.extend({ | ||
Object.extend( /** @lends Object **/ { | ||
properties : {}, | ||
@@ -209,2 +246,8 @@ cloneOwnProperties : function(target, src) { | ||
/** | ||
* Returns the constructor of the given object, works for objects and primitive types | ||
* @param {*} object The constructor to return for | ||
* @returns {Function} The constructor of the object | ||
* @global | ||
*/ | ||
var classOf = function(object) { | ||
@@ -214,5 +257,15 @@ return Object.getPrototypeOf(Object(object)).constructor; | ||
/** | ||
* @mixin Trait | ||
* @global | ||
*/ | ||
var Trait = Object.inherit({}); | ||
/** | ||
* @extends Trait | ||
* @mixin Bind | ||
* @global | ||
*/ | ||
var Bind = Trait.inherit({ | ||
/** @lends Bind */ | ||
extend : { | ||
@@ -251,2 +304,10 @@ initialize : function() { | ||
}, | ||
/** | ||
* Creates a bind proxy for the given object | ||
* Each method of the given object is reflected on the proxy and | ||
* bound to the object context | ||
* @param {*} obj The object which will be bound | ||
* @returns {Bind} The bound proxy | ||
*/ | ||
create : function(obj) { | ||
@@ -294,2 +355,7 @@ if (!obj.constructor.Bind) { | ||
} | ||
/** | ||
* @type Bind | ||
* @name Bind.prototype.bind | ||
*/ | ||
}); | ||
@@ -319,4 +385,6 @@ | ||
Error.prototype.initialize = function(message) { | ||
Object.extend(this, new Error()); | ||
var stack = new Error().stack || 'Error'; | ||
stack = stack.substring(stack.indexOf('\n') + 1); | ||
this.stack = message + '\n' + stack; | ||
this.message = message; | ||
@@ -323,0 +391,0 @@ }; |
@@ -26,1 +26,3 @@ | ||
- Steven Levithan Copyright (C) 2012 MIT License | ||
- Jordan Harband (C) 2013 MIT License | ||
@@ -1,19 +0,29 @@ | ||
// Copyright 2009-2012 by contributors, MIT License | ||
/*! | ||
* https://github.com/es-shims/es5-shim | ||
* @license es5-shim Copyright 2009-2014 by contributors, MIT License | ||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE | ||
*/ | ||
// vim: ts=4 sts=4 sw=4 expandtab | ||
// Module systems magic dance | ||
(function (definition) { | ||
// RequireJS | ||
if (typeof define == "function") { | ||
define(definition); | ||
// YUI3 | ||
} else if (typeof YUI == "function") { | ||
YUI.add("es5-sham", definition); | ||
// CommonJS and <script> | ||
//Add semicolon to prevent IIFE from being passed as argument to concated code. | ||
; | ||
// UMD (Universal Module Definition) | ||
// see https://github.com/umdjs/umd/blob/master/returnExports.js | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(factory); | ||
} else if (typeof exports === 'object') { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like enviroments that support module.exports, | ||
// like Node. | ||
module.exports = factory(); | ||
} else { | ||
definition(); | ||
} | ||
})(function () { | ||
// Browser globals (root is window) | ||
root.returnExports = factory(); | ||
} | ||
}(this, function () { | ||
var call = Function.prototype.call; | ||
@@ -28,4 +38,4 @@ var prototypeOfObject = Object.prototype; | ||
var lookupSetter; | ||
var supportsAccessors; | ||
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { | ||
var supportsAccessors = owns(prototypeOfObject, "__defineGetter__"); | ||
if (supportsAccessors) { | ||
defineGetter = call.bind(prototypeOfObject.__defineGetter__); | ||
@@ -40,11 +50,18 @@ defineSetter = call.bind(prototypeOfObject.__defineSetter__); | ||
if (!Object.getPrototypeOf) { | ||
// https://github.com/kriskowal/es5-shim/issues#issue/2 | ||
// https://github.com/es-shims/es5-shim/issues#issue/2 | ||
// http://ejohn.org/blog/objectgetprototypeof/ | ||
// recommended by fschaefer on github | ||
// | ||
// sure, and webreflection says ^_^ | ||
// ... this will nerever possibly return null | ||
// ... Opera Mini breaks here with infinite loops | ||
Object.getPrototypeOf = function getPrototypeOf(object) { | ||
return object.__proto__ || ( | ||
object.constructor | ||
? object.constructor.prototype | ||
: prototypeOfObject | ||
); | ||
var proto = object.__proto__; | ||
if (proto || proto === null) { | ||
return proto; | ||
} else if (object.constructor) { | ||
return object.constructor.prototype; | ||
} else { | ||
return prototypeOfObject; | ||
} | ||
}; | ||
@@ -71,9 +88,6 @@ } | ||
if (Object.defineProperty) { | ||
var getOwnPropertyDescriptorWorksOnObject = | ||
doesGetOwnPropertyDescriptorWork({}); | ||
var getOwnPropertyDescriptorWorksOnDom = typeof document == "undefined" || | ||
var getOwnPropertyDescriptorWorksOnObject = doesGetOwnPropertyDescriptorWork({}); | ||
var getOwnPropertyDescriptorWorksOnDom = typeof document === "undefined" || | ||
doesGetOwnPropertyDescriptorWork(document.createElement("div")); | ||
if (!getOwnPropertyDescriptorWorksOnDom || | ||
!getOwnPropertyDescriptorWorksOnObject | ||
) { | ||
if (!getOwnPropertyDescriptorWorksOnDom || !getOwnPropertyDescriptorWorksOnObject) { | ||
var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor; | ||
@@ -87,3 +101,3 @@ } | ||
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { | ||
if ((typeof object != "object" && typeof object != "function") || object === null) { | ||
if ((typeof object !== "object" && typeof object !== "function") || object === null) { | ||
throw new TypeError(ERR_NON_OBJECT + object); | ||
@@ -120,3 +134,9 @@ } | ||
var prototype = object.__proto__; | ||
object.__proto__ = prototypeOfObject; | ||
var notPrototypeOfObject = object !== prototypeOfObject; | ||
// avoid recursion problem, breaking in Opera Mini when | ||
// Object.getOwnPropertyDescriptor(Object.prototype, 'toString') | ||
// or any other Object.prototype accessor | ||
if (notPrototypeOfObject) { | ||
object.__proto__ = prototypeOfObject; | ||
} | ||
@@ -126,4 +146,6 @@ var getter = lookupGetter(object, property); | ||
// Once we have getter and setter we can put values back. | ||
object.__proto__ = prototype; | ||
if (notPrototypeOfObject) { | ||
// Once we have getter and setter we can put values back. | ||
object.__proto__ = prototype; | ||
} | ||
@@ -165,4 +187,7 @@ if (getter || setter) { | ||
var createEmpty; | ||
var supportsProto = Object.prototype.__proto__ === null; | ||
if (supportsProto || typeof document == 'undefined') { | ||
var supportsProto = !({__proto__:null} instanceof Object); | ||
// the following produces false positives | ||
// in Opera Mini => not a reliable check | ||
// Object.prototype.__proto__ === null | ||
if (supportsProto || typeof document === 'undefined') { | ||
createEmpty = function () { | ||
@@ -243,3 +268,3 @@ return { "__proto__": null }; | ||
// Designed by hax <hax.github.com> | ||
// related issue: https://github.com/kriskowal/es5-shim/issues#issue/5 | ||
// related issue: https://github.com/es-shims/es5-shim/issues#issue/5 | ||
// IE8 Reference: | ||
@@ -264,3 +289,3 @@ // http://msdn.microsoft.com/en-us/library/dd282900.aspx | ||
var definePropertyWorksOnObject = doesDefinePropertyWork({}); | ||
var definePropertyWorksOnDom = typeof document == "undefined" || | ||
var definePropertyWorksOnDom = typeof document === "undefined" || | ||
doesDefinePropertyWork(document.createElement("div")); | ||
@@ -280,6 +305,6 @@ if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) { | ||
Object.defineProperty = function defineProperty(object, property, descriptor) { | ||
if ((typeof object != "object" && typeof object != "function") || object === null) { | ||
if ((typeof object !== "object" && typeof object !== "function") || object === null) { | ||
throw new TypeError(ERR_NON_OBJECT_TARGET + object); | ||
} | ||
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null) { | ||
if ((typeof descriptor !== "object" && typeof descriptor !== "function") || descriptor === null) { | ||
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor); | ||
@@ -362,3 +387,3 @@ } | ||
for (var property in properties) { | ||
if (owns(properties, property) && property != "__proto__") { | ||
if (owns(properties, property) && property !== "__proto__") { | ||
Object.defineProperty(object, property, properties[property]); | ||
@@ -399,3 +424,3 @@ } | ||
return function freeze(object) { | ||
if (typeof object == "function") { | ||
if (typeof object === "function") { | ||
return object; | ||
@@ -456,2 +481,3 @@ } else { | ||
}); | ||
})); | ||
@@ -1,4 +0,7 @@ | ||
(function(definition){if(typeof define=="function"){define(definition)}else if(typeof YUI=="function"){YUI.add("es5-sham",definition)}else{definition()}})(function(){var call=Function.prototype.call;var prototypeOfObject=Object.prototype;var owns=call.bind(prototypeOfObject.hasOwnProperty);var defineGetter;var defineSetter;var lookupGetter;var lookupSetter;var supportsAccessors;if(supportsAccessors=owns(prototypeOfObject,"__defineGetter__")){defineGetter=call.bind(prototypeOfObject.__defineGetter__);defineSetter=call.bind(prototypeOfObject.__defineSetter__);lookupGetter=call.bind(prototypeOfObject.__lookupGetter__);lookupSetter=call.bind(prototypeOfObject.__lookupSetter__)}if(!Object.getPrototypeOf){Object.getPrototypeOf=function getPrototypeOf(object){return object.__proto__||(object.constructor?object.constructor.prototype:prototypeOfObject)}}function doesGetOwnPropertyDescriptorWork(object){try{object.sentinel=0;return Object.getOwnPropertyDescriptor(object,"sentinel").value===0}catch(exception){}}if(Object.defineProperty){var getOwnPropertyDescriptorWorksOnObject=doesGetOwnPropertyDescriptorWork({});var getOwnPropertyDescriptorWorksOnDom=typeof document=="undefined"||doesGetOwnPropertyDescriptorWork(document.createElement("div"));if(!getOwnPropertyDescriptorWorksOnDom||!getOwnPropertyDescriptorWorksOnObject){var getOwnPropertyDescriptorFallback=Object.getOwnPropertyDescriptor}}if(!Object.getOwnPropertyDescriptor||getOwnPropertyDescriptorFallback){var ERR_NON_OBJECT="Object.getOwnPropertyDescriptor called on a non-object: ";Object.getOwnPropertyDescriptor=function getOwnPropertyDescriptor(object,property){if(typeof object!="object"&&typeof object!="function"||object===null){throw new TypeError(ERR_NON_OBJECT+object)}if(getOwnPropertyDescriptorFallback){try{return getOwnPropertyDescriptorFallback.call(Object,object,property)}catch(exception){}}if(!owns(object,property)){return}var descriptor={enumerable:true,configurable:true};if(supportsAccessors){var prototype=object.__proto__;object.__proto__=prototypeOfObject;var getter=lookupGetter(object,property);var setter=lookupSetter(object,property);object.__proto__=prototype;if(getter||setter){if(getter){descriptor.get=getter}if(setter){descriptor.set=setter}return descriptor}}descriptor.value=object[property];descriptor.writable=true;return descriptor}}if(!Object.getOwnPropertyNames){Object.getOwnPropertyNames=function getOwnPropertyNames(object){return Object.keys(object)}}if(!Object.create){var createEmpty;var supportsProto=Object.prototype.__proto__===null;if(supportsProto||typeof document=="undefined"){createEmpty=function(){return{__proto__:null}}}else{createEmpty=function(){var iframe=document.createElement("iframe");var parent=document.body||document.documentElement;iframe.style.display="none";parent.appendChild(iframe);iframe.src="javascript:";var empty=iframe.contentWindow.Object.prototype;parent.removeChild(iframe);iframe=null;delete empty.constructor;delete empty.hasOwnProperty;delete empty.propertyIsEnumerable;delete empty.isPrototypeOf;delete empty.toLocaleString;delete empty.toString;delete empty.valueOf;empty.__proto__=null;function Empty(){}Empty.prototype=empty;createEmpty=function(){return new Empty};return new Empty}}Object.create=function create(prototype,properties){var object;function Type(){}if(prototype===null){object=createEmpty()}else{if(typeof prototype!=="object"&&typeof prototype!=="function"){throw new TypeError("Object prototype may only be an Object or null")}Type.prototype=prototype;object=new Type;object.__proto__=prototype}if(properties!==void 0){Object.defineProperties(object,properties)}return object}}function doesDefinePropertyWork(object){try{Object.defineProperty(object,"sentinel",{});return"sentinel"in object}catch(exception){}}if(Object.defineProperty){var definePropertyWorksOnObject=doesDefinePropertyWork({});var definePropertyWorksOnDom=typeof document=="undefined"||doesDefinePropertyWork(document.createElement("div"));if(!definePropertyWorksOnObject||!definePropertyWorksOnDom){var definePropertyFallback=Object.defineProperty,definePropertiesFallback=Object.defineProperties}}if(!Object.defineProperty||definePropertyFallback){var ERR_NON_OBJECT_DESCRIPTOR="Property description must be an object: ";var ERR_NON_OBJECT_TARGET="Object.defineProperty called on non-object: ";var ERR_ACCESSORS_NOT_SUPPORTED="getters & setters can not be defined "+"on this javascript engine";Object.defineProperty=function defineProperty(object,property,descriptor){if(typeof object!="object"&&typeof object!="function"||object===null){throw new TypeError(ERR_NON_OBJECT_TARGET+object)}if(typeof descriptor!="object"&&typeof descriptor!="function"||descriptor===null){throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR+descriptor)}if(definePropertyFallback){try{return definePropertyFallback.call(Object,object,property,descriptor)}catch(exception){}}if(owns(descriptor,"value")){if(supportsAccessors&&(lookupGetter(object,property)||lookupSetter(object,property))){var prototype=object.__proto__;object.__proto__=prototypeOfObject;delete object[property];object[property]=descriptor.value;object.__proto__=prototype}else{object[property]=descriptor.value}}else{if(!supportsAccessors){throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED)}if(owns(descriptor,"get")){defineGetter(object,property,descriptor.get)}if(owns(descriptor,"set")){defineSetter(object,property,descriptor.set)}}return object}}if(!Object.defineProperties||definePropertiesFallback){Object.defineProperties=function defineProperties(object,properties){if(definePropertiesFallback){try{return definePropertiesFallback.call(Object,object,properties)}catch(exception){}}for(var property in properties){if(owns(properties,property)&&property!="__proto__"){Object.defineProperty(object,property,properties[property])}}return object}}if(!Object.seal){Object.seal=function seal(object){return object}}if(!Object.freeze){Object.freeze=function freeze(object){return object}}try{Object.freeze(function(){})}catch(exception){Object.freeze=function freeze(freezeObject){return function freeze(object){if(typeof object=="function"){return object}else{return freezeObject(object)}}}(Object.freeze)}if(!Object.preventExtensions){Object.preventExtensions=function preventExtensions(object){return object}}if(!Object.isSealed){Object.isSealed=function isSealed(object){return false}}if(!Object.isFrozen){Object.isFrozen=function isFrozen(object){return false}}if(!Object.isExtensible){Object.isExtensible=function isExtensible(object){if(Object(object)!==object){throw new TypeError}var name="";while(owns(object,name)){name+="?"}object[name]=true;var returnValue=owns(object,name);delete object[name];return returnValue}}}); | ||
/* | ||
//@ sourceMappingURL=es5-sham.map | ||
*/ | ||
/*! | ||
* https://github.com/es-shims/es5-shim | ||
* @license es5-shim Copyright 2009-2014 by contributors, MIT License | ||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE | ||
*/ | ||
(function(e,t){if(typeof define==="function"&&define.amd){define(t)}else if(typeof exports==="object"){module.exports=t()}else{e.returnExports=t()}})(this,function(){var e=Function.prototype.call;var t=Object.prototype;var r=e.bind(t.hasOwnProperty);var n;var o;var i;var c;var f=r(t,"__defineGetter__");if(f){n=e.bind(t.__defineGetter__);o=e.bind(t.__defineSetter__);i=e.bind(t.__lookupGetter__);c=e.bind(t.__lookupSetter__)}if(!Object.getPrototypeOf){Object.getPrototypeOf=function g(e){var r=e.__proto__;if(r||r===null){return r}else if(e.constructor){return e.constructor.prototype}else{return t}}}function u(e){try{e.sentinel=0;return Object.getOwnPropertyDescriptor(e,"sentinel").value===0}catch(t){}}if(Object.defineProperty){var p=u({});var a=typeof document==="undefined"||u(document.createElement("div"));if(!a||!p){var l=Object.getOwnPropertyDescriptor}}if(!Object.getOwnPropertyDescriptor||l){var b="Object.getOwnPropertyDescriptor called on a non-object: ";Object.getOwnPropertyDescriptor=function E(e,n){if(typeof e!=="object"&&typeof e!=="function"||e===null){throw new TypeError(b+e)}if(l){try{return l.call(Object,e,n)}catch(o){}}if(!r(e,n)){return}var u={enumerable:true,configurable:true};if(f){var p=e.__proto__;var a=e!==t;if(a){e.__proto__=t}var _=i(e,n);var s=c(e,n);if(a){e.__proto__=p}if(_||s){if(_){u.get=_}if(s){u.set=s}return u}}u.value=e[n];u.writable=true;return u}}if(!Object.getOwnPropertyNames){Object.getOwnPropertyNames=function x(e){return Object.keys(e)}}if(!Object.create){var _;var s=!({__proto__:null}instanceof Object);if(s||typeof document==="undefined"){_=function(){return{__proto__:null}}}else{_=function(){var e=document.createElement("iframe");var t=document.body||document.documentElement;e.style.display="none";t.appendChild(e);e.src="javascript:";var r=e.contentWindow.Object.prototype;t.removeChild(e);e=null;delete r.constructor;delete r.hasOwnProperty;delete r.propertyIsEnumerable;delete r.isPrototypeOf;delete r.toLocaleString;delete r.toString;delete r.valueOf;r.__proto__=null;function n(){}n.prototype=r;_=function(){return new n};return new n}}Object.create=function z(e,t){var r;function n(){}if(e===null){r=_()}else{if(typeof e!=="object"&&typeof e!=="function"){throw new TypeError("Object prototype may only be an Object or null")}n.prototype=e;r=new n;r.__proto__=e}if(t!==void 0){Object.defineProperties(r,t)}return r}}function d(e){try{Object.defineProperty(e,"sentinel",{});return"sentinel"in e}catch(t){}}if(Object.defineProperty){var y=d({});var O=typeof document==="undefined"||d(document.createElement("div"));if(!y||!O){var j=Object.defineProperty,v=Object.defineProperties}}if(!Object.defineProperty||j){var w="Property description must be an object: ";var P="Object.defineProperty called on non-object: ";var m="getters & setters can not be defined "+"on this javascript engine";Object.defineProperty=function S(e,u,p){if(typeof e!=="object"&&typeof e!=="function"||e===null){throw new TypeError(P+e)}if(typeof p!=="object"&&typeof p!=="function"||p===null){throw new TypeError(w+p)}if(j){try{return j.call(Object,e,u,p)}catch(a){}}if(r(p,"value")){if(f&&(i(e,u)||c(e,u))){var l=e.__proto__;e.__proto__=t;delete e[u];e[u]=p.value;e.__proto__=l}else{e[u]=p.value}}else{if(!f){throw new TypeError(m)}if(r(p,"get")){n(e,u,p.get)}if(r(p,"set")){o(e,u,p.set)}}return e}}if(!Object.defineProperties||v){Object.defineProperties=function T(e,t){if(v){try{return v.call(Object,e,t)}catch(n){}}for(var o in t){if(r(t,o)&&o!=="__proto__"){Object.defineProperty(e,o,t[o])}}return e}}if(!Object.seal){Object.seal=function D(e){return e}}if(!Object.freeze){Object.freeze=function k(e){return e}}try{Object.freeze(function(){})}catch(h){Object.freeze=function F(e){return function t(r){if(typeof r==="function"){return r}else{return e(r)}}}(Object.freeze)}if(!Object.preventExtensions){Object.preventExtensions=function G(e){return e}}if(!Object.isSealed){Object.isSealed=function C(e){return false}}if(!Object.isFrozen){Object.isFrozen=function N(e){return false}}if(!Object.isExtensible){Object.isExtensible=function I(e){if(Object(e)!==e){throw new TypeError}var t="";while(r(e,t)){t+="?"}e[t]=true;var n=r(e,t);delete e[t];return n}}}); | ||
//# sourceMappingURL=es5-sham.map |
1079
lib/es5-shim.js
@@ -1,17 +0,28 @@ | ||
// Copyright 2009-2012 by contributors, MIT License | ||
/*! | ||
* https://github.com/es-shims/es5-shim | ||
* @license es5-shim Copyright 2009-2014 by contributors, MIT License | ||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE | ||
*/ | ||
// vim: ts=4 sts=4 sw=4 expandtab | ||
// Module systems magic dance | ||
(function (definition) { | ||
// RequireJS | ||
if (typeof define == "function") { | ||
define(definition); | ||
// YUI3 | ||
} else if (typeof YUI == "function") { | ||
YUI.add("es5", definition); | ||
// CommonJS and <script> | ||
//Add semicolon to prevent IIFE from being passed as argument to concated code. | ||
; | ||
// UMD (Universal Module Definition) | ||
// see https://github.com/umdjs/umd/blob/master/returnExports.js | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(factory); | ||
} else if (typeof exports === 'object') { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like enviroments that support module.exports, | ||
// like Node. | ||
module.exports = factory(); | ||
} else { | ||
definition(); | ||
// Browser globals (root is window) | ||
root.returnExports = factory(); | ||
} | ||
})(function () { | ||
}(this, function () { | ||
@@ -27,3 +38,146 @@ /** | ||
// Shortcut to an often accessed properties, in order to avoid multiple | ||
// dereference that costs universally. | ||
var ArrayPrototype = Array.prototype; | ||
var ObjectPrototype = Object.prototype; | ||
var FunctionPrototype = Function.prototype; | ||
var StringPrototype = String.prototype; | ||
var NumberPrototype = Number.prototype; | ||
var array_slice = ArrayPrototype.slice; | ||
var array_splice = ArrayPrototype.splice; | ||
var array_push = ArrayPrototype.push; | ||
var array_unshift = ArrayPrototype.unshift; | ||
var call = FunctionPrototype.call; | ||
// Having a toString local variable name breaks in Opera so use _toString. | ||
var _toString = ObjectPrototype.toString; | ||
var isFunction = function (val) { | ||
return ObjectPrototype.toString.call(val) === '[object Function]'; | ||
}; | ||
var isRegex = function (val) { | ||
return ObjectPrototype.toString.call(val) === '[object RegExp]'; | ||
}; | ||
var isArray = function isArray(obj) { | ||
return _toString.call(obj) === "[object Array]"; | ||
}; | ||
var isString = function isString(obj) { | ||
return _toString.call(obj) === "[object String]"; | ||
}; | ||
var isArguments = function isArguments(value) { | ||
var str = _toString.call(value); | ||
var isArgs = str === '[object Arguments]'; | ||
if (!isArgs) { | ||
isArgs = !isArray(value) | ||
&& value !== null | ||
&& typeof value === 'object' | ||
&& typeof value.length === 'number' | ||
&& value.length >= 0 | ||
&& isFunction(value.callee); | ||
} | ||
return isArgs; | ||
}; | ||
var supportsDescriptors = Object.defineProperty && (function () { | ||
try { | ||
Object.defineProperty({}, 'x', {}); | ||
return true; | ||
} catch (e) { /* this is ES3 */ | ||
return false; | ||
} | ||
}()); | ||
// Define configurable, writable and non-enumerable props | ||
// if they don't exist. | ||
var defineProperty; | ||
if (supportsDescriptors) { | ||
defineProperty = function (object, name, method, forceAssign) { | ||
if (!forceAssign && (name in object)) { return; } | ||
Object.defineProperty(object, name, { | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
value: method | ||
}); | ||
}; | ||
} else { | ||
defineProperty = function (object, name, method, forceAssign) { | ||
if (!forceAssign && (name in object)) { return; } | ||
object[name] = method; | ||
}; | ||
} | ||
var defineProperties = function (object, map, forceAssign) { | ||
for (var name in map) { | ||
if (ObjectPrototype.hasOwnProperty.call(map, name)) { | ||
defineProperty(object, name, map[name], forceAssign); | ||
} | ||
} | ||
}; | ||
// | ||
// Util | ||
// ====== | ||
// | ||
// ES5 9.4 | ||
// http://es5.github.com/#x9.4 | ||
// http://jsperf.com/to-integer | ||
function toInteger(n) { | ||
n = +n; | ||
if (n !== n) { // isNaN | ||
n = 0; | ||
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { | ||
n = (n > 0 || -1) * Math.floor(Math.abs(n)); | ||
} | ||
return n; | ||
} | ||
function isPrimitive(input) { | ||
var type = typeof input; | ||
return ( | ||
input === null || | ||
type === "undefined" || | ||
type === "boolean" || | ||
type === "number" || | ||
type === "string" | ||
); | ||
} | ||
function toPrimitive(input) { | ||
var val, valueOf, toStr; | ||
if (isPrimitive(input)) { | ||
return input; | ||
} | ||
valueOf = input.valueOf; | ||
if (isFunction(valueOf)) { | ||
val = valueOf.call(input); | ||
if (isPrimitive(val)) { | ||
return val; | ||
} | ||
} | ||
toStr = input.toString; | ||
if (isFunction(toStr)) { | ||
val = toStr.call(input); | ||
if (isPrimitive(val)) { | ||
return val; | ||
} | ||
} | ||
throw new TypeError(); | ||
} | ||
// ES5 9.9 | ||
// http://es5.github.com/#x9.9 | ||
var toObject = function (o) { | ||
if (o == null) { // this matches both null and undefined | ||
throw new TypeError("can't convert " + o + " to object"); | ||
} | ||
return Object(o); | ||
}; | ||
var ToUint32 = function ToUint32(x) { | ||
return x >>> 0; | ||
}; | ||
// | ||
// Function | ||
@@ -38,8 +192,8 @@ // ======== | ||
if (!Function.prototype.bind) { | ||
Function.prototype.bind = function bind(that) { // .length is 1 | ||
defineProperties(FunctionPrototype, { | ||
bind: function bind(that) { // .length is 1 | ||
// 1. Let Target be the this value. | ||
var target = this; | ||
// 2. If IsCallable(Target) is false, throw a TypeError exception. | ||
if (typeof target != "function") { | ||
if (!isFunction(target)) { | ||
throw new TypeError("Function.prototype.bind called on incompatible " + target); | ||
@@ -50,3 +204,3 @@ } | ||
// XXX slicedArgs will stand in for "A" if used | ||
var args = _Array_slice_.call(arguments, 1); // for normal call | ||
var args = array_slice.call(arguments, 1); // for normal call | ||
// 4. Let F be a new native ECMAScript object. | ||
@@ -61,3 +215,3 @@ // 11. Set the [[Prototype]] internal property of F to the standard | ||
// 15.3.4.5.3. | ||
var bound = function () { | ||
var binder = function () { | ||
@@ -83,3 +237,3 @@ if (this instanceof bound) { | ||
this, | ||
args.concat(_Array_slice_.call(arguments)) | ||
args.concat(array_slice.call(arguments)) | ||
); | ||
@@ -113,3 +267,3 @@ if (Object(result) === result) { | ||
that, | ||
args.concat(_Array_slice_.call(arguments)) | ||
args.concat(array_slice.call(arguments)) | ||
); | ||
@@ -120,10 +274,3 @@ | ||
}; | ||
if (target.prototype) { | ||
Empty.prototype = target.prototype; | ||
bound.prototype = new Empty(); | ||
// Clean up dangling references. | ||
Empty.prototype = null; | ||
} | ||
// XXX bound.length is never writable, so don't even try | ||
// | ||
// 15. If the [[Class]] internal property of Target is "Function", then | ||
@@ -134,5 +281,27 @@ // a. Let L be the length property of Target minus the length of A. | ||
// 16. Else set the length own property of F to 0. | ||
var boundLength = Math.max(0, target.length - args.length); | ||
// 17. Set the attributes of the length own property of F to the values | ||
// specified in 15.3.5.1. | ||
var boundArgs = []; | ||
for (var i = 0; i < boundLength; i++) { | ||
boundArgs.push("$" + i); | ||
} | ||
// XXX Build a dynamic function with desired amount of arguments is the only | ||
// way to set the length property of a function. | ||
// In environments where Content Security Policies enabled (Chrome extensions, | ||
// for ex.) all use of eval or Function costructor throws an exception. | ||
// However in all of these environments Function.prototype.bind exists | ||
// and so this code will never be executed. | ||
var bound = Function("binder", "return function (" + boundArgs.join(",") + "){return binder.apply(this,arguments)}")(binder); | ||
if (target.prototype) { | ||
Empty.prototype = target.prototype; | ||
bound.prototype = new Empty(); | ||
// Clean up dangling references. | ||
Empty.prototype = null; | ||
} | ||
// TODO | ||
@@ -160,16 +329,8 @@ // 18. Set the [[Extensible]] internal property of F to true. | ||
return bound; | ||
}; | ||
} | ||
} | ||
}); | ||
// Shortcut to an often accessed properties, in order to avoid multiple | ||
// dereference that costs universally. | ||
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we | ||
// us it in defining shortcuts. | ||
var call = Function.prototype.call; | ||
var prototypeOfArray = Array.prototype; | ||
var prototypeOfObject = Object.prototype; | ||
var _Array_slice_ = prototypeOfArray.slice; | ||
// Having a toString local variable name breaks in Opera so use _toString. | ||
var _toString = call.bind(prototypeOfObject.toString); | ||
var owns = call.bind(prototypeOfObject.hasOwnProperty); | ||
var owns = call.bind(ObjectPrototype.hasOwnProperty); | ||
@@ -182,7 +343,7 @@ // If JS engine supports accessors creating shortcuts. | ||
var supportsAccessors; | ||
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { | ||
defineGetter = call.bind(prototypeOfObject.__defineGetter__); | ||
defineSetter = call.bind(prototypeOfObject.__defineSetter__); | ||
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__); | ||
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__); | ||
if ((supportsAccessors = owns(ObjectPrototype, "__defineGetter__"))) { | ||
defineGetter = call.bind(ObjectPrototype.__defineGetter__); | ||
defineSetter = call.bind(ObjectPrototype.__defineSetter__); | ||
lookupGetter = call.bind(ObjectPrototype.__lookupGetter__); | ||
lookupSetter = call.bind(ObjectPrototype.__lookupSetter__); | ||
} | ||
@@ -197,94 +358,39 @@ | ||
// http://es5.github.com/#x15.4.4.12 | ||
// Default value for second param | ||
// [bugfix, ielt9, old browsers] | ||
// IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12" | ||
if ([1,2].splice(0).length != 2) { | ||
var array_splice = Array.prototype.splice; | ||
if (function() { // test IE < 9 to splice bug - see issue #138 | ||
function makeArray(l) { | ||
var a = []; | ||
while (l--) { | ||
a.unshift(l) | ||
} | ||
return a | ||
var spliceNoopReturnsEmptyArray = (function () { | ||
var a = [1, 2]; | ||
var result = a.splice(); | ||
return a.length === 2 && isArray(result) && result.length === 0; | ||
}()); | ||
defineProperties(ArrayPrototype, { | ||
// Safari 5.0 bug where .splice() returns undefined | ||
splice: function splice(start, deleteCount) { | ||
if (arguments.length === 0) { | ||
return []; | ||
} else { | ||
return array_splice.apply(this, arguments); | ||
} | ||
} | ||
}, spliceNoopReturnsEmptyArray); | ||
var array = [] | ||
, lengthBefore | ||
; | ||
array.splice.bind(array, 0, 0).apply(null, makeArray(20)); | ||
array.splice.bind(array, 0, 0).apply(null, makeArray(26)); | ||
lengthBefore = array.length; //20 | ||
array.splice(5, 0, "XXX"); // add one element | ||
if (lengthBefore + 1 == array.length) { | ||
return true;// has right splice implementation without bugs | ||
} | ||
// else { | ||
// IE8 bug | ||
// } | ||
}()) {//IE 6/7 | ||
Array.prototype.splice = function(start, deleteCount) { | ||
if (!arguments.length) { | ||
return []; | ||
var spliceWorksWithEmptyObject = (function () { | ||
var obj = {}; | ||
ArrayPrototype.splice.call(obj, 0, 0, 1); | ||
return obj.length === 1; | ||
}()); | ||
defineProperties(ArrayPrototype, { | ||
splice: function splice(start, deleteCount) { | ||
if (arguments.length === 0) { return []; } | ||
var args = arguments; | ||
this.length = Math.max(toInteger(this.length), 0); | ||
if (arguments.length > 0 && typeof deleteCount !== 'number') { | ||
args = array_slice.call(arguments); | ||
if (args.length < 2) { | ||
args.push(this.length - start); | ||
} else { | ||
return array_splice.apply(this, [ | ||
start === void 0 ? 0 : start, | ||
deleteCount === void 0 ? (this.length - start) : deleteCount | ||
].concat(_Array_slice_.call(arguments, 2))) | ||
args[1] = toInteger(deleteCount); | ||
} | ||
}; | ||
} | ||
else {//IE8 | ||
Array.prototype.splice = function(start, deleteCount) { | ||
var result | ||
, args = _Array_slice_.call(arguments, 2) | ||
, addElementsCount = args.length | ||
; | ||
if (!arguments.length) { | ||
return []; | ||
} | ||
if (start === void 0) { // default | ||
start = 0; | ||
} | ||
if (deleteCount === void 0) { // default | ||
deleteCount = this.length - start; | ||
} | ||
if (addElementsCount > 0) { | ||
if (deleteCount <= 0) { | ||
if (start == this.length) { // tiny optimisation #1 | ||
this.push.apply(this, args); | ||
return []; | ||
} | ||
if (start == 0) { // tiny optimisation #2 | ||
this.unshift.apply(this, args); | ||
return []; | ||
} | ||
} | ||
// Array.prototype.splice implementation | ||
result = _Array_slice_.call(this, start, start + deleteCount);// delete part | ||
args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part | ||
args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part | ||
// delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part' | ||
args.unshift(0, this.length); | ||
array_splice.apply(this, args); | ||
return result; | ||
} | ||
return array_splice.call(this, start, deleteCount); | ||
} | ||
return array_splice.apply(this, args); | ||
} | ||
} | ||
}, !spliceWorksWithEmptyObject); | ||
@@ -295,10 +401,10 @@ // ES5 15.4.4.12 | ||
// [bugfix, ielt8] | ||
// IE < 8 bug: [].unshift(0) == undefined but should be "1" | ||
if ([].unshift(0) != 1) { | ||
var array_unshift = Array.prototype.unshift; | ||
Array.prototype.unshift = function() { | ||
// IE < 8 bug: [].unshift(0) === undefined but should be "1" | ||
var hasUnshiftReturnValueBug = [].unshift(0) !== 1; | ||
defineProperties(ArrayPrototype, { | ||
unshift: function () { | ||
array_unshift.apply(this, arguments); | ||
return this.length; | ||
}; | ||
} | ||
} | ||
}, hasUnshiftReturnValueBug); | ||
@@ -308,7 +414,3 @@ // ES5 15.4.3.2 | ||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray | ||
if (!Array.isArray) { | ||
Array.isArray = function isArray(obj) { | ||
return _toString(obj) == "[object Array]"; | ||
}; | ||
} | ||
defineProperties(Array, { isArray: isArray }); | ||
@@ -333,11 +435,26 @@ // The IsCallable() check in the Array functions | ||
// and failure of `0 in boxedString` (Rhino) | ||
var boxedString = Object("a"), | ||
splitString = boxedString[0] != "a" || !(0 in boxedString); | ||
var boxedString = Object("a"); | ||
var splitString = boxedString[0] !== "a" || !(0 in boxedString); | ||
if (!Array.prototype.forEach) { | ||
Array.prototype.forEach = function forEach(fun /*, thisp*/) { | ||
var properlyBoxesContext = function properlyBoxed(method) { | ||
// Check node 0.6.21 bug where third parameter is not boxed | ||
var properlyBoxesNonStrict = true; | ||
var properlyBoxesStrict = true; | ||
if (method) { | ||
method.call('foo', function (_, __, context) { | ||
if (typeof context !== 'object') { properlyBoxesNonStrict = false; } | ||
}); | ||
method.call([1], function () { | ||
'use strict'; | ||
properlyBoxesStrict = typeof this === 'string'; | ||
}, 'x'); | ||
} | ||
return !!method && properlyBoxesNonStrict && properlyBoxesStrict; | ||
}; | ||
defineProperties(ArrayPrototype, { | ||
forEach: function forEach(fun /*, thisp*/) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
thisp = arguments[1], | ||
@@ -348,3 +465,3 @@ i = -1, | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(); // TODO message | ||
@@ -361,4 +478,4 @@ } | ||
} | ||
}; | ||
} | ||
} | ||
}, !properlyBoxesContext(ArrayPrototype.forEach)); | ||
@@ -368,8 +485,6 @@ // ES5 15.4.4.19 | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map | ||
if (!Array.prototype.map) { | ||
Array.prototype.map = function map(fun /*, thisp*/) { | ||
defineProperties(ArrayPrototype, { | ||
map: function map(fun /*, thisp*/) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0, | ||
@@ -380,3 +495,3 @@ result = Array(length), | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -386,8 +501,9 @@ } | ||
for (var i = 0; i < length; i++) { | ||
if (i in self) | ||
if (i in self) { | ||
result[i] = fun.call(thisp, self[i], i, object); | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
} | ||
}, !properlyBoxesContext(ArrayPrototype.map)); | ||
@@ -397,8 +513,6 @@ // ES5 15.4.4.20 | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter | ||
if (!Array.prototype.filter) { | ||
Array.prototype.filter = function filter(fun /*, thisp */) { | ||
defineProperties(ArrayPrototype, { | ||
filter: function filter(fun /*, thisp */) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0, | ||
@@ -410,3 +524,3 @@ result = [], | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -424,4 +538,4 @@ } | ||
return result; | ||
}; | ||
} | ||
} | ||
}, !properlyBoxesContext(ArrayPrototype.filter)); | ||
@@ -431,8 +545,6 @@ // ES5 15.4.4.16 | ||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every | ||
if (!Array.prototype.every) { | ||
Array.prototype.every = function every(fun /*, thisp */) { | ||
defineProperties(ArrayPrototype, { | ||
every: function every(fun /*, thisp */) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0, | ||
@@ -442,3 +554,3 @@ thisp = arguments[1]; | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -453,4 +565,4 @@ } | ||
return true; | ||
}; | ||
} | ||
} | ||
}, !properlyBoxesContext(ArrayPrototype.every)); | ||
@@ -460,8 +572,6 @@ // ES5 15.4.4.17 | ||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some | ||
if (!Array.prototype.some) { | ||
Array.prototype.some = function some(fun /*, thisp */) { | ||
defineProperties(ArrayPrototype, { | ||
some: function some(fun /*, thisp */) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0, | ||
@@ -471,3 +581,3 @@ thisp = arguments[1]; | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -482,4 +592,4 @@ } | ||
return false; | ||
}; | ||
} | ||
} | ||
}, !properlyBoxesContext(ArrayPrototype.some)); | ||
@@ -489,12 +599,14 @@ // ES5 15.4.4.21 | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce | ||
if (!Array.prototype.reduce) { | ||
Array.prototype.reduce = function reduce(fun /*, initial*/) { | ||
var reduceCoercesToObject = false; | ||
if (ArrayPrototype.reduce) { | ||
reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object'; | ||
} | ||
defineProperties(ArrayPrototype, { | ||
reduce: function reduce(fun /*, initial*/) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0; | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -504,3 +616,3 @@ } | ||
// no value to return if no initial value and an empty array | ||
if (!length && arguments.length == 1) { | ||
if (!length && arguments.length === 1) { | ||
throw new TypeError("reduce of empty array with no initial value"); | ||
@@ -534,4 +646,4 @@ } | ||
return result; | ||
}; | ||
} | ||
} | ||
}, !reduceCoercesToObject); | ||
@@ -541,12 +653,14 @@ // ES5 15.4.4.22 | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight | ||
if (!Array.prototype.reduceRight) { | ||
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) { | ||
var reduceRightCoercesToObject = false; | ||
if (ArrayPrototype.reduceRight) { | ||
reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object'; | ||
} | ||
defineProperties(ArrayPrototype, { | ||
reduceRight: function reduceRight(fun /*, initial*/) { | ||
var object = toObject(this), | ||
self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
object, | ||
self = splitString && isString(this) ? this.split('') : object, | ||
length = self.length >>> 0; | ||
// If no callback function or if callback is not a callable function | ||
if (_toString(fun) != "[object Function]") { | ||
if (!isFunction(fun)) { | ||
throw new TypeError(fun + " is not a function"); | ||
@@ -556,3 +670,3 @@ } | ||
// no value to return if no initial value, empty array | ||
if (!length && arguments.length == 1) { | ||
if (!length && arguments.length === 1) { | ||
throw new TypeError("reduceRight of empty array with no initial value"); | ||
@@ -583,3 +697,3 @@ } | ||
do { | ||
if (i in this) { | ||
if (i in self) { | ||
result = fun.call(void 0, result, self[i], i, object); | ||
@@ -590,4 +704,4 @@ } | ||
return result; | ||
}; | ||
} | ||
} | ||
}, !reduceRightCoercesToObject); | ||
@@ -597,7 +711,6 @@ // ES5 15.4.4.14 | ||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf | ||
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) { | ||
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) { | ||
var self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
toObject(this), | ||
var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1; | ||
defineProperties(ArrayPrototype, { | ||
indexOf: function indexOf(sought /*, fromIndex */ ) { | ||
var self = splitString && isString(this) ? this.split('') : toObject(this), | ||
length = self.length >>> 0; | ||
@@ -622,4 +735,4 @@ | ||
return -1; | ||
}; | ||
} | ||
} | ||
}, hasFirefox2IndexOfBug); | ||
@@ -629,7 +742,6 @@ // ES5 15.4.4.15 | ||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf | ||
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) { | ||
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) { | ||
var self = splitString && _toString(this) == "[object String]" ? | ||
this.split("") : | ||
toObject(this), | ||
var hasFirefox2LastIndexOfBug = Array.prototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1; | ||
defineProperties(ArrayPrototype, { | ||
lastIndexOf: function lastIndexOf(sought /*, fromIndex */) { | ||
var self = splitString && isString(this) ? this.split('') : toObject(this), | ||
length = self.length >>> 0; | ||
@@ -652,4 +764,4 @@ | ||
return -1; | ||
}; | ||
} | ||
} | ||
}, hasFirefox2LastIndexOfBug); | ||
@@ -663,48 +775,70 @@ // | ||
// http://es5.github.com/#x15.2.3.14 | ||
if (!Object.keys) { | ||
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation | ||
var hasDontEnumBug = true, | ||
dontEnums = [ | ||
"toString", | ||
"toLocaleString", | ||
"valueOf", | ||
"hasOwnProperty", | ||
"isPrototypeOf", | ||
"propertyIsEnumerable", | ||
"constructor" | ||
], | ||
dontEnumsLength = dontEnums.length; | ||
for (var key in {"toString": null}) { | ||
hasDontEnumBug = false; | ||
} | ||
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation | ||
var hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'), | ||
hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'), | ||
dontEnums = [ | ||
"toString", | ||
"toLocaleString", | ||
"valueOf", | ||
"hasOwnProperty", | ||
"isPrototypeOf", | ||
"propertyIsEnumerable", | ||
"constructor" | ||
], | ||
dontEnumsLength = dontEnums.length; | ||
Object.keys = function keys(object) { | ||
defineProperties(Object, { | ||
keys: function keys(object) { | ||
var isFn = isFunction(object), | ||
isArgs = isArguments(object), | ||
isObject = object !== null && typeof object === 'object', | ||
isStr = isObject && isString(object); | ||
if ( | ||
(typeof object != "object" && typeof object != "function") || | ||
object === null | ||
) { | ||
if (!isObject && !isFn && !isArgs) { | ||
throw new TypeError("Object.keys called on a non-object"); | ||
} | ||
var keys = []; | ||
for (var name in object) { | ||
if (owns(object, name)) { | ||
keys.push(name); | ||
var theKeys = []; | ||
var skipProto = hasProtoEnumBug && isFn; | ||
if (isStr || isArgs) { | ||
for (var i = 0; i < object.length; ++i) { | ||
theKeys.push(String(i)); | ||
} | ||
} else { | ||
for (var name in object) { | ||
if (!(skipProto && name === 'prototype') && owns(object, name)) { | ||
theKeys.push(String(name)); | ||
} | ||
} | ||
} | ||
if (hasDontEnumBug) { | ||
for (var i = 0, ii = dontEnumsLength; i < ii; i++) { | ||
var dontEnum = dontEnums[i]; | ||
if (owns(object, dontEnum)) { | ||
keys.push(dontEnum); | ||
var ctor = object.constructor, | ||
skipConstructor = ctor && ctor.prototype === object; | ||
for (var j = 0; j < dontEnumsLength; j++) { | ||
var dontEnum = dontEnums[j]; | ||
if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) { | ||
theKeys.push(dontEnum); | ||
} | ||
} | ||
} | ||
return keys; | ||
}; | ||
return theKeys; | ||
} | ||
}); | ||
} | ||
var keysWorksWithArguments = Object.keys && (function () { | ||
// Safari 5.0 bug | ||
return Object.keys(arguments).length === 2; | ||
}(1, 2)); | ||
var originalKeys = Object.keys; | ||
defineProperties(Object, { | ||
keys: function keys(object) { | ||
if (isArguments(object)) { | ||
return originalKeys(ArrayPrototype.slice.call(object)); | ||
} else { | ||
return originalKeys(object); | ||
} | ||
} | ||
}, !keysWorksWithArguments); | ||
@@ -723,9 +857,8 @@ // | ||
// this object is not a finite Number a RangeError exception is thrown. | ||
var negativeDate = -62198755200000, | ||
negativeYearString = "-000001"; | ||
if ( | ||
!Date.prototype.toISOString || | ||
(new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1) | ||
) { | ||
Date.prototype.toISOString = function toISOString() { | ||
var negativeDate = -62198755200000; | ||
var negativeYearString = "-000001"; | ||
var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1; | ||
defineProperties(Date.prototype, { | ||
toISOString: function toISOString() { | ||
var result, length, value, year, month; | ||
@@ -739,3 +872,3 @@ if (!isFinite(this)) { | ||
month = this.getUTCMonth(); | ||
// see https://github.com/kriskowal/es5-shim/issues/111 | ||
// see https://github.com/es-shims/es5-shim/issues/111 | ||
year += Math.floor(month / 12); | ||
@@ -745,8 +878,6 @@ month = (month % 12 + 12) % 12; | ||
// the date time string format is specified in 15.9.1.15. | ||
result = [month + 1, this.getUTCDate(), | ||
this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()]; | ||
result = [month + 1, this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()]; | ||
year = ( | ||
(year < 0 ? "-" : (year > 9999 ? "+" : "")) + | ||
("00000" + Math.abs(year)) | ||
.slice(0 <= year && year <= 9999 ? -4 : -6) | ||
("00000" + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6) | ||
); | ||
@@ -769,4 +900,4 @@ | ||
); | ||
}; | ||
} | ||
} | ||
}, hasNegativeDateBug); | ||
@@ -811,3 +942,3 @@ | ||
// 5. If IsCallable(toISO) is false, throw a TypeError exception. | ||
if (typeof toISO != "function") { | ||
if (typeof toISO !== "function") { | ||
throw new TypeError("toISOString property is not callable"); | ||
@@ -834,6 +965,9 @@ } | ||
// http://gist.github.com/303249 | ||
if (!Date.parse || "Date.parse is buggy") { | ||
var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15; | ||
var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')); | ||
var doesNotParseY2KNewYear = isNaN(Date.parse("2000-01-01T00:00:00.000Z")); | ||
if (!Date.parse || doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) { | ||
// XXX global assignment won't work in embeddings that use | ||
// an alternate object for the context. | ||
Date = (function(NativeDate) { | ||
Date = (function (NativeDate) { | ||
@@ -844,3 +978,3 @@ // Date.length === 7 | ||
if (this instanceof NativeDate) { | ||
var date = length == 1 && String(Y) === Y ? // isString(Y) | ||
var date = length === 1 && String(Y) === Y ? // isString(Y) | ||
// We explicitly pass it through parse: | ||
@@ -863,3 +997,3 @@ new NativeDate(Date.parse(Y)) : | ||
return NativeDate.apply(this, arguments); | ||
}; | ||
} | ||
@@ -996,150 +1130,149 @@ // 15.9.1.15 Date Time String Format. | ||
// http://es5.github.com/#x15.7.4.5 | ||
if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") { | ||
// Hide these variables and functions | ||
(function () { | ||
var base, size, data, i; | ||
var hasToFixedBugs = NumberPrototype.toFixed && ( | ||
(0.00008).toFixed(3) !== '0.000' | ||
|| (0.9).toFixed(0) !== '1' | ||
|| (1.255).toFixed(2) !== '1.25' | ||
|| (1000000000000000128).toFixed(0) !== "1000000000000000128" | ||
); | ||
base = 1e7; | ||
size = 6; | ||
data = [0, 0, 0, 0, 0, 0]; | ||
var toFixedHelpers = { | ||
base: 1e7, | ||
size: 6, | ||
data: [0, 0, 0, 0, 0, 0], | ||
multiply: function multiply(n, c) { | ||
var i = -1; | ||
while (++i < toFixedHelpers.size) { | ||
c += n * toFixedHelpers.data[i]; | ||
toFixedHelpers.data[i] = c % toFixedHelpers.base; | ||
c = Math.floor(c / toFixedHelpers.base); | ||
} | ||
}, | ||
divide: function divide(n) { | ||
var i = toFixedHelpers.size, c = 0; | ||
while (--i >= 0) { | ||
c += toFixedHelpers.data[i]; | ||
toFixedHelpers.data[i] = Math.floor(c / n); | ||
c = (c % n) * toFixedHelpers.base; | ||
} | ||
}, | ||
numToString: function numToString() { | ||
var i = toFixedHelpers.size; | ||
var s = ''; | ||
while (--i >= 0) { | ||
if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) { | ||
var t = String(toFixedHelpers.data[i]); | ||
if (s === '') { | ||
s = t; | ||
} else { | ||
s += '0000000'.slice(0, 7 - t.length) + t; | ||
} | ||
} | ||
} | ||
return s; | ||
}, | ||
pow: function pow(x, n, acc) { | ||
return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc))); | ||
}, | ||
log: function log(x) { | ||
var n = 0; | ||
while (x >= 4096) { | ||
n += 12; | ||
x /= 4096; | ||
} | ||
while (x >= 2) { | ||
n += 1; | ||
x /= 2; | ||
} | ||
return n; | ||
} | ||
}; | ||
function multiply(n, c) { | ||
var i = -1; | ||
while (++i < size) { | ||
c += n * data[i]; | ||
data[i] = c % base; | ||
c = Math.floor(c / base); | ||
} | ||
} | ||
defineProperties(NumberPrototype, { | ||
toFixed: function toFixed(fractionDigits) { | ||
var f, x, s, m, e, z, j, k; | ||
function divide(n) { | ||
var i = size, c = 0; | ||
while (--i >= 0) { | ||
c += data[i]; | ||
data[i] = Math.floor(c / n); | ||
c = (c % n) * base; | ||
} | ||
} | ||
// Test for NaN and round fractionDigits down | ||
f = Number(fractionDigits); | ||
f = f !== f ? 0 : Math.floor(f); | ||
function toString() { | ||
var i = size; | ||
var s = ''; | ||
while (--i >= 0) { | ||
if (s !== '' || i === 0 || data[i] !== 0) { | ||
var t = String(data[i]); | ||
if (s === '') { | ||
s = t; | ||
} else { | ||
s += '0000000'.slice(0, 7 - t.length) + t; | ||
} | ||
} | ||
} | ||
return s; | ||
if (f < 0 || f > 20) { | ||
throw new RangeError("Number.toFixed called with invalid number of decimals"); | ||
} | ||
function pow(x, n, acc) { | ||
return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc))); | ||
x = Number(this); | ||
// Test for NaN | ||
if (x !== x) { | ||
return "NaN"; | ||
} | ||
function log(x) { | ||
var n = 0; | ||
while (x >= 4096) { | ||
n += 12; | ||
x /= 4096; | ||
} | ||
while (x >= 2) { | ||
n += 1; | ||
x /= 2; | ||
} | ||
return n; | ||
// If it is too big or small, return the string value of the number | ||
if (x <= -1e21 || x >= 1e21) { | ||
return String(x); | ||
} | ||
Number.prototype.toFixed = function (fractionDigits) { | ||
var f, x, s, m, e, z, j, k; | ||
s = ""; | ||
// Test for NaN and round fractionDigits down | ||
f = Number(fractionDigits); | ||
f = f !== f ? 0 : Math.floor(f); | ||
if (x < 0) { | ||
s = "-"; | ||
x = -x; | ||
} | ||
if (f < 0 || f > 20) { | ||
throw new RangeError("Number.toFixed called with invalid number of decimals"); | ||
} | ||
m = "0"; | ||
x = Number(this); | ||
if (x > 1e-21) { | ||
// 1e-21 < x < 1e21 | ||
// -70 < log2(x) < 70 | ||
e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69; | ||
z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1)); | ||
z *= 0x10000000000000; // Math.pow(2, 52); | ||
e = 52 - e; | ||
// Test for NaN | ||
if (x !== x) { | ||
return "NaN"; | ||
} | ||
// -18 < e < 122 | ||
// x = z / 2 ^ e | ||
if (e > 0) { | ||
toFixedHelpers.multiply(0, z); | ||
j = f; | ||
// If it is too big or small, return the string value of the number | ||
if (x <= -1e21 || x >= 1e21) { | ||
return String(x); | ||
} | ||
while (j >= 7) { | ||
toFixedHelpers.multiply(1e7, 0); | ||
j -= 7; | ||
} | ||
s = ""; | ||
toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0); | ||
j = e - 1; | ||
if (x < 0) { | ||
s = "-"; | ||
x = -x; | ||
} | ||
while (j >= 23) { | ||
toFixedHelpers.divide(1 << 23); | ||
j -= 23; | ||
} | ||
m = "0"; | ||
if (x > 1e-21) { | ||
// 1e-21 < x < 1e21 | ||
// -70 < log2(x) < 70 | ||
e = log(x * pow(2, 69, 1)) - 69; | ||
z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1)); | ||
z *= 0x10000000000000; // Math.pow(2, 52); | ||
e = 52 - e; | ||
// -18 < e < 122 | ||
// x = z / 2 ^ e | ||
if (e > 0) { | ||
multiply(0, z); | ||
j = f; | ||
while (j >= 7) { | ||
multiply(1e7, 0); | ||
j -= 7; | ||
} | ||
multiply(pow(10, j, 1), 0); | ||
j = e - 1; | ||
while (j >= 23) { | ||
divide(1 << 23); | ||
j -= 23; | ||
} | ||
divide(1 << j); | ||
multiply(1, 1); | ||
divide(2); | ||
m = toString(); | ||
} else { | ||
multiply(0, z); | ||
multiply(1 << (-e), 0); | ||
m = toString() + '0.00000000000000000000'.slice(2, 2 + f); | ||
} | ||
toFixedHelpers.divide(1 << j); | ||
toFixedHelpers.multiply(1, 1); | ||
toFixedHelpers.divide(2); | ||
m = toFixedHelpers.numToString(); | ||
} else { | ||
toFixedHelpers.multiply(0, z); | ||
toFixedHelpers.multiply(1 << (-e), 0); | ||
m = toFixedHelpers.numToString() + '0.00000000000000000000'.slice(2, 2 + f); | ||
} | ||
} | ||
if (f > 0) { | ||
k = m.length; | ||
if (f > 0) { | ||
k = m.length; | ||
if (k <= f) { | ||
m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m; | ||
} else { | ||
m = s + m.slice(0, k - f) + '.' + m.slice(k - f); | ||
} | ||
if (k <= f) { | ||
m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m; | ||
} else { | ||
m = s + m; | ||
m = s + m.slice(0, k - f) + '.' + m.slice(k - f); | ||
} | ||
return m; | ||
} else { | ||
m = s + m; | ||
} | ||
}()); | ||
} | ||
return m; | ||
} | ||
}, hasToFixedBugs); | ||
// | ||
@@ -1150,3 +1283,2 @@ // String | ||
// ES5 15.5.4.14 | ||
@@ -1167,3 +1299,3 @@ // http://es5.github.com/#x15.5.4.14 | ||
var string_split = String.prototype.split; | ||
var string_split = StringPrototype.split; | ||
if ( | ||
@@ -1173,2 +1305,3 @@ 'ab'.split(/(?:ab)*/).length !== 2 || | ||
'tesst'.split(/(s)*/)[1] === "t" || | ||
'test'.split(/(?:)/, -1).length !== 4 || | ||
''.split(/.?/).length || | ||
@@ -1180,10 +1313,11 @@ '.'.split(/()()/).length > 1 | ||
String.prototype.split = function (separator, limit) { | ||
StringPrototype.split = function (separator, limit) { | ||
var string = this; | ||
if (separator === void 0 && limit === 0) | ||
if (separator === void 0 && limit === 0) { | ||
return []; | ||
} | ||
// If `separator` is not a regex, use native split | ||
if (Object.prototype.toString.call(separator) !== "[object RegExp]") { | ||
return string_split.apply(this, arguments); | ||
if (_toString.call(separator) !== "[object RegExp]") { | ||
return string_split.call(this, separator, limit); | ||
} | ||
@@ -1198,4 +1332,4 @@ | ||
// Make `global` and avoid `lastIndex` issues by working with a copy | ||
separator = new RegExp(separator.source, flags + "g"), | ||
separator2, match, lastIndex, lastLength; | ||
separator = new RegExp(separator.source, flags + "g"); | ||
string += ""; // Type-convert | ||
@@ -1215,3 +1349,3 @@ if (!compliantExecNpcg) { | ||
-1 >>> 0 : // Math.pow(2, 32) - 1 | ||
limit >>> 0; // ToUint32(limit) | ||
ToUint32(limit); | ||
while (match = separator.exec(string)) { | ||
@@ -1234,3 +1368,3 @@ // `separator.lastIndex` is not reliable cross-browser | ||
if (match.length > 1 && match.index < string.length) { | ||
Array.prototype.push.apply(output, match.slice(1)); | ||
ArrayPrototype.push.apply(output, match.slice(1)); | ||
} | ||
@@ -1265,23 +1399,47 @@ lastLength = match[0].length; | ||
} else if ("0".split(void 0, 0).length) { | ||
String.prototype.split = function(separator, limit) { | ||
if (separator === void 0 && limit === 0) return []; | ||
return string_split.apply(this, arguments); | ||
} | ||
StringPrototype.split = function split(separator, limit) { | ||
if (separator === void 0 && limit === 0) { return []; } | ||
return string_split.call(this, separator, limit); | ||
}; | ||
} | ||
var str_replace = StringPrototype.replace; | ||
var replaceReportsGroupsCorrectly = (function () { | ||
var groups = []; | ||
'x'.replace(/x(.)?/g, function (match, group) { | ||
groups.push(group); | ||
}); | ||
return groups.length === 1 && typeof groups[0] === 'undefined'; | ||
}()); | ||
if (!replaceReportsGroupsCorrectly) { | ||
StringPrototype.replace = function replace(searchValue, replaceValue) { | ||
var isFn = isFunction(replaceValue); | ||
var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source); | ||
if (!isFn || !hasCapturingGroups) { | ||
return str_replace.call(this, searchValue, replaceValue); | ||
} else { | ||
var wrappedReplaceValue = function (match) { | ||
var length = arguments.length; | ||
var originalLastIndex = searchValue.lastIndex; | ||
searchValue.lastIndex = 0; | ||
var args = searchValue.exec(match); | ||
searchValue.lastIndex = originalLastIndex; | ||
args.push(arguments[length - 2], arguments[length - 1]); | ||
return replaceValue.apply(this, args); | ||
}; | ||
return str_replace.call(this, searchValue, wrappedReplaceValue); | ||
} | ||
}; | ||
} | ||
// ECMA-262, 3rd B.2.3 | ||
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a | ||
// Not an ECMAScript standard, although ECMAScript 3rd Edition has a | ||
// non-normative section suggesting uniform semantics and it should be | ||
// normalized across all browsers | ||
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE | ||
if ("".substr && "0b".substr(-1) !== "b") { | ||
var string_substr = String.prototype.substr; | ||
/** | ||
* Get the substring of a string | ||
* @param {integer} start where to start the substring | ||
* @param {integer} length how many characters to return | ||
* @return {string} | ||
*/ | ||
String.prototype.substr = function(start, length) { | ||
var string_substr = StringPrototype.substr; | ||
var hasNegativeSubstrBug = "".substr && "0b".substr(-1) !== "b"; | ||
defineProperties(StringPrototype, { | ||
substr: function substr(start, length) { | ||
return string_substr.call( | ||
@@ -1293,86 +1451,39 @@ this, | ||
} | ||
} | ||
}, hasNegativeSubstrBug); | ||
// ES5 15.5.4.20 | ||
// http://es5.github.com/#x15.5.4.20 | ||
// whitespace from: http://es5.github.io/#x15.5.4.20 | ||
var ws = "\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"; | ||
if (!String.prototype.trim || ws.trim()) { | ||
var zeroWidth = '\u200b'; | ||
var wsRegexChars = "[" + ws + "]"; | ||
var trimBeginRegexp = new RegExp("^" + wsRegexChars + wsRegexChars + "*"); | ||
var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + "*$"); | ||
var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim()); | ||
defineProperties(StringPrototype, { | ||
// http://blog.stevenlevithan.com/archives/faster-trim-javascript | ||
// http://perfectionkills.com/whitespace-deviations/ | ||
ws = "[" + ws + "]"; | ||
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"), | ||
trimEndRegexp = new RegExp(ws + ws + "*$"); | ||
String.prototype.trim = function trim() { | ||
trim: function trim() { | ||
if (this === void 0 || this === null) { | ||
throw new TypeError("can't convert "+this+" to object"); | ||
throw new TypeError("can't convert " + this + " to object"); | ||
} | ||
return String(this) | ||
.replace(trimBeginRegexp, "") | ||
.replace(trimEndRegexp, ""); | ||
}; | ||
} | ||
// | ||
// Util | ||
// ====== | ||
// | ||
// ES5 9.4 | ||
// http://es5.github.com/#x9.4 | ||
// http://jsperf.com/to-integer | ||
function toInteger(n) { | ||
n = +n; | ||
if (n !== n) { // isNaN | ||
n = 0; | ||
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) { | ||
n = (n > 0 || -1) * Math.floor(Math.abs(n)); | ||
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, ""); | ||
} | ||
return n; | ||
} | ||
}, hasTrimWhitespaceBug); | ||
function isPrimitive(input) { | ||
var type = typeof input; | ||
return ( | ||
input === null || | ||
type === "undefined" || | ||
type === "boolean" || | ||
type === "number" || | ||
type === "string" | ||
); | ||
// ES-5 15.1.2.2 | ||
if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) { | ||
parseInt = (function (origParseInt) { | ||
var hexRegex = /^0[xX]/; | ||
return function parseIntES5(str, radix) { | ||
str = String(str).trim(); | ||
if (!Number(radix)) { | ||
radix = hexRegex.test(str) ? 16 : 10; | ||
} | ||
return origParseInt(str, radix); | ||
}; | ||
}(parseInt)); | ||
} | ||
function toPrimitive(input) { | ||
var val, valueOf, toString; | ||
if (isPrimitive(input)) { | ||
return input; | ||
} | ||
valueOf = input.valueOf; | ||
if (typeof valueOf === "function") { | ||
val = valueOf.call(input); | ||
if (isPrimitive(val)) { | ||
return val; | ||
} | ||
} | ||
toString = input.toString; | ||
if (typeof toString === "function") { | ||
val = toString.call(input); | ||
if (isPrimitive(val)) { | ||
return val; | ||
} | ||
} | ||
throw new TypeError(); | ||
} | ||
// ES5 9.9 | ||
// http://es5.github.com/#x9.9 | ||
var toObject = function (o) { | ||
if (o == null) { // this matches both null and undefined | ||
throw new TypeError("can't convert "+o+" to object"); | ||
} | ||
return Object(o); | ||
}; | ||
}); | ||
})); |
@@ -1,4 +0,7 @@ | ||
(function(definition){if(typeof define=="function"){define(definition)}else if(typeof YUI=="function"){YUI.add("es5",definition)}else{definition()}})(function(){function Empty(){}if(!Function.prototype.bind){Function.prototype.bind=function bind(that){var target=this;if(typeof target!="function"){throw new TypeError("Function.prototype.bind called on incompatible "+target)}var args=_Array_slice_.call(arguments,1);var bound=function(){if(this instanceof bound){var result=target.apply(this,args.concat(_Array_slice_.call(arguments)));if(Object(result)===result){return result}return this}else{return target.apply(that,args.concat(_Array_slice_.call(arguments)))}};if(target.prototype){Empty.prototype=target.prototype;bound.prototype=new Empty;Empty.prototype=null}return bound}}var call=Function.prototype.call;var prototypeOfArray=Array.prototype;var prototypeOfObject=Object.prototype;var _Array_slice_=prototypeOfArray.slice;var _toString=call.bind(prototypeOfObject.toString);var owns=call.bind(prototypeOfObject.hasOwnProperty);var defineGetter;var defineSetter;var lookupGetter;var lookupSetter;var supportsAccessors;if(supportsAccessors=owns(prototypeOfObject,"__defineGetter__")){defineGetter=call.bind(prototypeOfObject.__defineGetter__);defineSetter=call.bind(prototypeOfObject.__defineSetter__);lookupGetter=call.bind(prototypeOfObject.__lookupGetter__);lookupSetter=call.bind(prototypeOfObject.__lookupSetter__)}if([1,2].splice(0).length!=2){var array_splice=Array.prototype.splice;if(function(){function makeArray(l){var a=[];while(l--){a.unshift(l)}return a}var array=[],lengthBefore;array.splice.bind(array,0,0).apply(null,makeArray(20));array.splice.bind(array,0,0).apply(null,makeArray(26));lengthBefore=array.length;array.splice(5,0,"XXX");if(lengthBefore+1==array.length){return true}}()){Array.prototype.splice=function(start,deleteCount){if(!arguments.length){return[]}else{return array_splice.apply(this,[start===void 0?0:start,deleteCount===void 0?this.length-start:deleteCount].concat(_Array_slice_.call(arguments,2)))}}}else{Array.prototype.splice=function(start,deleteCount){var result,args=_Array_slice_.call(arguments,2),addElementsCount=args.length;if(!arguments.length){return[]}if(start===void 0){start=0}if(deleteCount===void 0){deleteCount=this.length-start}if(addElementsCount>0){if(deleteCount<=0){if(start==this.length){this.push.apply(this,args);return[]}if(start==0){this.unshift.apply(this,args);return[]}}result=_Array_slice_.call(this,start,start+deleteCount);args.push.apply(args,_Array_slice_.call(this,start+deleteCount,this.length));args.unshift.apply(args,_Array_slice_.call(this,0,start));args.unshift(0,this.length);array_splice.apply(this,args);return result}return array_splice.call(this,start,deleteCount)}}}if([].unshift(0)!=1){var array_unshift=Array.prototype.unshift;Array.prototype.unshift=function(){array_unshift.apply(this,arguments);return this.length}}if(!Array.isArray){Array.isArray=function isArray(obj){return _toString(obj)=="[object Array]"}}var boxedString=Object("a"),splitString=boxedString[0]!="a"||!(0 in boxedString);if(!Array.prototype.forEach){Array.prototype.forEach=function forEach(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,thisp=arguments[1],i=-1,length=self.length>>>0;if(_toString(fun)!="[object Function]"){throw new TypeError}while(++i<length){if(i in self){fun.call(thisp,self[i],i,object)}}}}if(!Array.prototype.map){Array.prototype.map=function map(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0,result=Array(length),thisp=arguments[1];if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}for(var i=0;i<length;i++){if(i in self)result[i]=fun.call(thisp,self[i],i,object)}return result}}if(!Array.prototype.filter){Array.prototype.filter=function filter(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0,result=[],value,thisp=arguments[1];if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}for(var i=0;i<length;i++){if(i in self){value=self[i];if(fun.call(thisp,value,i,object)){result.push(value)}}}return result}}if(!Array.prototype.every){Array.prototype.every=function every(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0,thisp=arguments[1];if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}for(var i=0;i<length;i++){if(i in self&&!fun.call(thisp,self[i],i,object)){return false}}return true}}if(!Array.prototype.some){Array.prototype.some=function some(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0,thisp=arguments[1];if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}for(var i=0;i<length;i++){if(i in self&&fun.call(thisp,self[i],i,object)){return true}}return false}}if(!Array.prototype.reduce){Array.prototype.reduce=function reduce(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0;if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}if(!length&&arguments.length==1){throw new TypeError("reduce of empty array with no initial value")}var i=0;var result;if(arguments.length>=2){result=arguments[1]}else{do{if(i in self){result=self[i++];break}if(++i>=length){throw new TypeError("reduce of empty array with no initial value")}}while(true)}for(;i<length;i++){if(i in self){result=fun.call(void 0,result,self[i],i,object)}}return result}}if(!Array.prototype.reduceRight){Array.prototype.reduceRight=function reduceRight(fun){var object=toObject(this),self=splitString&&_toString(this)=="[object String]"?this.split(""):object,length=self.length>>>0;if(_toString(fun)!="[object Function]"){throw new TypeError(fun+" is not a function")}if(!length&&arguments.length==1){throw new TypeError("reduceRight of empty array with no initial value")}var result,i=length-1;if(arguments.length>=2){result=arguments[1]}else{do{if(i in self){result=self[i--];break}if(--i<0){throw new TypeError("reduceRight of empty array with no initial value")}}while(true)}if(i<0){return result}do{if(i in this){result=fun.call(void 0,result,self[i],i,object)}}while(i--);return result}}if(!Array.prototype.indexOf||[0,1].indexOf(1,2)!=-1){Array.prototype.indexOf=function indexOf(sought){var self=splitString&&_toString(this)=="[object String]"?this.split(""):toObject(this),length=self.length>>>0;if(!length){return-1}var i=0;if(arguments.length>1){i=toInteger(arguments[1])}i=i>=0?i:Math.max(0,length+i);for(;i<length;i++){if(i in self&&self[i]===sought){return i}}return-1}}if(!Array.prototype.lastIndexOf||[0,1].lastIndexOf(0,-3)!=-1){Array.prototype.lastIndexOf=function lastIndexOf(sought){var self=splitString&&_toString(this)=="[object String]"?this.split(""):toObject(this),length=self.length>>>0;if(!length){return-1}var i=length-1;if(arguments.length>1){i=Math.min(i,toInteger(arguments[1]))}i=i>=0?i:length-Math.abs(i);for(;i>=0;i--){if(i in self&&sought===self[i]){return i}}return-1}}if(!Object.keys){var hasDontEnumBug=true,dontEnums=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],dontEnumsLength=dontEnums.length;for(var key in{toString:null}){hasDontEnumBug=false}Object.keys=function keys(object){if(typeof object!="object"&&typeof object!="function"||object===null){throw new TypeError("Object.keys called on a non-object")}var keys=[];for(var name in object){if(owns(object,name)){keys.push(name)}}if(hasDontEnumBug){for(var i=0,ii=dontEnumsLength;i<ii;i++){var dontEnum=dontEnums[i];if(owns(object,dontEnum)){keys.push(dontEnum)}}}return keys}}var negativeDate=-621987552e5,negativeYearString="-000001";if(!Date.prototype.toISOString||new Date(negativeDate).toISOString().indexOf(negativeYearString)===-1){Date.prototype.toISOString=function toISOString(){var result,length,value,year,month;if(!isFinite(this)){throw new RangeError("Date.prototype.toISOString called on non-finite value.")}year=this.getUTCFullYear();month=this.getUTCMonth();year+=Math.floor(month/12);month=(month%12+12)%12;result=[month+1,this.getUTCDate(),this.getUTCHours(),this.getUTCMinutes(),this.getUTCSeconds()];year=(year<0?"-":year>9999?"+":"")+("00000"+Math.abs(year)).slice(0<=year&&year<=9999?-4:-6);length=result.length;while(length--){value=result[length];if(value<10){result[length]="0"+value}}return year+"-"+result.slice(0,2).join("-")+"T"+result.slice(2).join(":")+"."+("000"+this.getUTCMilliseconds()).slice(-3)+"Z"}}var dateToJSONIsSupported=false;try{dateToJSONIsSupported=Date.prototype.toJSON&&new Date(NaN).toJSON()===null&&new Date(negativeDate).toJSON().indexOf(negativeYearString)!==-1&&Date.prototype.toJSON.call({toISOString:function(){return true}})}catch(e){}if(!dateToJSONIsSupported){Date.prototype.toJSON=function toJSON(key){var o=Object(this),tv=toPrimitive(o),toISO;if(typeof tv==="number"&&!isFinite(tv)){return null}toISO=o.toISOString;if(typeof toISO!="function"){throw new TypeError("toISOString property is not callable")}return toISO.call(o)}}if(!Date.parse||"Date.parse is buggy"){Date=function(NativeDate){function Date(Y,M,D,h,m,s,ms){var length=arguments.length;if(this instanceof NativeDate){var date=length==1&&String(Y)===Y?new NativeDate(Date.parse(Y)):length>=7?new NativeDate(Y,M,D,h,m,s,ms):length>=6?new NativeDate(Y,M,D,h,m,s):length>=5?new NativeDate(Y,M,D,h,m):length>=4?new NativeDate(Y,M,D,h):length>=3?new NativeDate(Y,M,D):length>=2?new NativeDate(Y,M):length>=1?new NativeDate(Y):new NativeDate;date.constructor=Date;return date}return NativeDate.apply(this,arguments)}var isoDateExpression=new RegExp("^"+"(\\d{4}|[+-]\\d{6})"+"(?:-(\\d{2})"+"(?:-(\\d{2})"+"(?:"+"T(\\d{2})"+":(\\d{2})"+"(?:"+":(\\d{2})"+"(?:(\\.\\d{1,}))?"+")?"+"("+"Z|"+"(?:"+"([-+])"+"(\\d{2})"+":(\\d{2})"+")"+")?)?)?)?"+"$");var months=[0,31,59,90,120,151,181,212,243,273,304,334,365];function dayFromMonth(year,month){var t=month>1?1:0;return months[month]+Math.floor((year-1969+t)/4)-Math.floor((year-1901+t)/100)+Math.floor((year-1601+t)/400)+365*(year-1970)}for(var key in NativeDate){Date[key]=NativeDate[key]}Date.now=NativeDate.now;Date.UTC=NativeDate.UTC;Date.prototype=NativeDate.prototype;Date.prototype.constructor=Date;Date.parse=function parse(string){var match=isoDateExpression.exec(string);if(match){var year=Number(match[1]),month=Number(match[2]||1)-1,day=Number(match[3]||1)-1,hour=Number(match[4]||0),minute=Number(match[5]||0),second=Number(match[6]||0),millisecond=Math.floor(Number(match[7]||0)*1e3),offset=!match[4]||match[8]?0:Number(new NativeDate(1970,0)),signOffset=match[9]==="-"?1:-1,hourOffset=Number(match[10]||0),minuteOffset=Number(match[11]||0),result;if(hour<(minute>0||second>0||millisecond>0?24:25)&&minute<60&&second<60&&millisecond<1e3&&month>-1&&month<12&&hourOffset<24&&minuteOffset<60&&day>-1&&day<dayFromMonth(year,month+1)-dayFromMonth(year,month)){result=((dayFromMonth(year,month)+day)*24+hour+hourOffset*signOffset)*60;result=((result+minute+minuteOffset*signOffset)*60+second)*1e3+millisecond+offset;if(-864e13<=result&&result<=864e13){return result}}return NaN}return NativeDate.parse.apply(this,arguments)};return Date}(Date)}if(!Date.now){Date.now=function now(){return(new Date).getTime()}}if(!Number.prototype.toFixed||8e-5.toFixed(3)!=="0.000"||.9.toFixed(0)==="0"||1.255.toFixed(2)!=="1.25"||0xde0b6b3a7640080.toFixed(0)!=="1000000000000000128"){(function(){var base,size,data,i;base=1e7;size=6;data=[0,0,0,0,0,0];function multiply(n,c){var i=-1;while(++i<size){c+=n*data[i];data[i]=c%base;c=Math.floor(c/base)}}function divide(n){var i=size,c=0;while(--i>=0){c+=data[i];data[i]=Math.floor(c/n);c=c%n*base}}function toString(){var i=size;var s="";while(--i>=0){if(s!==""||i===0||data[i]!==0){var t=String(data[i]);if(s===""){s=t}else{s+="0000000".slice(0,7-t.length)+t}}}return s}function pow(x,n,acc){return n===0?acc:n%2===1?pow(x,n-1,acc*x):pow(x*x,n/2,acc)}function log(x){var n=0;while(x>=4096){n+=12;x/=4096}while(x>=2){n+=1;x/=2}return n}Number.prototype.toFixed=function(fractionDigits){var f,x,s,m,e,z,j,k;f=Number(fractionDigits);f=f!==f?0:Math.floor(f);if(f<0||f>20){throw new RangeError("Number.toFixed called with invalid number of decimals")}x=Number(this);if(x!==x){return"NaN"}if(x<=-1e21||x>=1e21){return String(x)}s="";if(x<0){s="-";x=-x}m="0";if(x>1e-21){e=log(x*pow(2,69,1))-69;z=e<0?x*pow(2,-e,1):x/pow(2,e,1);z*=4503599627370496;e=52-e;if(e>0){multiply(0,z);j=f;while(j>=7){multiply(1e7,0);j-=7}multiply(pow(10,j,1),0);j=e-1;while(j>=23){divide(1<<23);j-=23}divide(1<<j);multiply(1,1);divide(2);m=toString()}else{multiply(0,z);multiply(1<<-e,0);m=toString()+"0.00000000000000000000".slice(2,2+f)}}if(f>0){k=m.length;if(k<=f){m=s+"0.0000000000000000000".slice(0,f-k+2)+m}else{m=s+m.slice(0,k-f)+"."+m.slice(k-f)}}else{m=s+m}return m}})()}var string_split=String.prototype.split;if("ab".split(/(?:ab)*/).length!==2||".".split(/(.?)(.?)/).length!==4||"tesst".split(/(s)*/)[1]==="t"||"".split(/.?/).length===0||".".split(/()()/).length>1){(function(){var compliantExecNpcg=/()??/.exec("")[1]===void 0;String.prototype.split=function(separator,limit){var string=this;if(separator===void 0&&limit===0)return[];if(Object.prototype.toString.call(separator)!=="[object RegExp]"){return string_split.apply(this,arguments)}var output=[],flags=(separator.ignoreCase?"i":"")+(separator.multiline?"m":"")+(separator.extended?"x":"")+(separator.sticky?"y":""),lastLastIndex=0,separator=new RegExp(separator.source,flags+"g"),separator2,match,lastIndex,lastLength;string+="";if(!compliantExecNpcg){separator2=new RegExp("^"+separator.source+"$(?!\\s)",flags)}limit=limit===void 0?-1>>>0:limit>>>0;while(match=separator.exec(string)){lastIndex=match.index+match[0].length;if(lastIndex>lastLastIndex){output.push(string.slice(lastLastIndex,match.index));if(!compliantExecNpcg&&match.length>1){match[0].replace(separator2,function(){for(var i=1;i<arguments.length-2;i++){if(arguments[i]===void 0){match[i]=void 0}}})}if(match.length>1&&match.index<string.length){Array.prototype.push.apply(output,match.slice(1))}lastLength=match[0].length;lastLastIndex=lastIndex;if(output.length>=limit){break}}if(separator.lastIndex===match.index){separator.lastIndex++}}if(lastLastIndex===string.length){if(lastLength||!separator.test("")){output.push("")}}else{output.push(string.slice(lastLastIndex))}return output.length>limit?output.slice(0,limit):output}})()}else if("0".split(void 0,0).length){String.prototype.split=function(separator,limit){if(separator===void 0&&limit===0)return[];return string_split.apply(this,arguments)}}if("".substr&&"0b".substr(-1)!=="b"){var string_substr=String.prototype.substr;String.prototype.substr=function(start,length){return string_substr.call(this,start<0?(start=this.length+start)<0?0:start:start,length)}}var ws=" \n\f\r \xa0\u1680\u180e\u2000\u2001\u2002\u2003"+"\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028"+"\u2029\ufeff";if(!String.prototype.trim||ws.trim()){ws="["+ws+"]";var trimBeginRegexp=new RegExp("^"+ws+ws+"*"),trimEndRegexp=new RegExp(ws+ws+"*$");String.prototype.trim=function trim(){if(this===void 0||this===null){throw new TypeError("can't convert "+this+" to object")}return String(this).replace(trimBeginRegexp,"").replace(trimEndRegexp,"")}}function toInteger(n){n=+n;if(n!==n){n=0}else if(n!==0&&n!==1/0&&n!==-(1/0)){n=(n>0||-1)*Math.floor(Math.abs(n))}return n}function isPrimitive(input){var type=typeof input;return input===null||type==="undefined"||type==="boolean"||type==="number"||type==="string"}function toPrimitive(input){var val,valueOf,toString;if(isPrimitive(input)){return input}valueOf=input.valueOf;if(typeof valueOf==="function"){val=valueOf.call(input);if(isPrimitive(val)){return val}}toString=input.toString;if(typeof toString==="function"){val=toString.call(input);if(isPrimitive(val)){return val}}throw new TypeError}var toObject=function(o){if(o==null){throw new TypeError("can't convert "+o+" to object")}return Object(o)}}); | ||
/* | ||
//@ sourceMappingURL=es5-shim.map | ||
*/ | ||
/*! | ||
* https://github.com/es-shims/es5-shim | ||
* @license es5-shim Copyright 2009-2014 by contributors, MIT License | ||
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE | ||
*/ | ||
(function(t,e){if(typeof define==="function"&&define.amd){define(e)}else if(typeof exports==="object"){module.exports=e()}else{t.returnExports=e()}})(this,function(){var t=Array.prototype;var e=Object.prototype;var r=Function.prototype;var n=String.prototype;var i=Number.prototype;var a=t.slice;var o=t.splice;var l=t.push;var u=t.unshift;var s=r.call;var f=e.toString;var c=function(t){return e.toString.call(t)==="[object Function]"};var h=function(t){return e.toString.call(t)==="[object RegExp]"};var p=function ve(t){return f.call(t)==="[object Array]"};var v=function ge(t){return f.call(t)==="[object String]"};var g=function ye(t){var e=f.call(t);var r=e==="[object Arguments]";if(!r){r=!p(t)&&t!==null&&typeof t==="object"&&typeof t.length==="number"&&t.length>=0&&c(t.callee)}return r};var y=Object.defineProperty&&function(){try{Object.defineProperty({},"x",{});return true}catch(t){return false}}();var d;if(y){d=function(t,e,r,n){if(!n&&e in t){return}Object.defineProperty(t,e,{configurable:true,enumerable:false,writable:true,value:r})}}else{d=function(t,e,r,n){if(!n&&e in t){return}t[e]=r}}var m=function(t,r,n){for(var i in r){if(e.hasOwnProperty.call(r,i)){d(t,i,r[i],n)}}};function w(t){t=+t;if(t!==t){t=0}else if(t!==0&&t!==1/0&&t!==-(1/0)){t=(t>0||-1)*Math.floor(Math.abs(t))}return t}function b(t){var e=typeof t;return t===null||e==="undefined"||e==="boolean"||e==="number"||e==="string"}function x(t){var e,r,n;if(b(t)){return t}r=t.valueOf;if(c(r)){e=r.call(t);if(b(e)){return e}}n=t.toString;if(c(n)){e=n.call(t);if(b(e)){return e}}throw new TypeError}var S=function(t){if(t==null){throw new TypeError("can't convert "+t+" to object")}return Object(t)};var O=function de(t){return t>>>0};function T(){}m(r,{bind:function me(t){var e=this;if(!c(e)){throw new TypeError("Function.prototype.bind called on incompatible "+e)}var r=a.call(arguments,1);var n=function(){if(this instanceof u){var n=e.apply(this,r.concat(a.call(arguments)));if(Object(n)===n){return n}return this}else{return e.apply(t,r.concat(a.call(arguments)))}};var i=Math.max(0,e.length-r.length);var o=[];for(var l=0;l<i;l++){o.push("$"+l)}var u=Function("binder","return function ("+o.join(",")+"){return binder.apply(this,arguments)}")(n);if(e.prototype){T.prototype=e.prototype;u.prototype=new T;T.prototype=null}return u}});var j=s.bind(e.hasOwnProperty);var E;var N;var I;var D;var _;if(_=j(e,"__defineGetter__")){E=s.bind(e.__defineGetter__);N=s.bind(e.__defineSetter__);I=s.bind(e.__lookupGetter__);D=s.bind(e.__lookupSetter__)}var M=function(){var t=[1,2];var e=t.splice();return t.length===2&&p(e)&&e.length===0}();m(t,{splice:function we(t,e){if(arguments.length===0){return[]}else{return o.apply(this,arguments)}}},M);var F=function(){var e={};t.splice.call(e,0,0,1);return e.length===1}();m(t,{splice:function be(t,e){if(arguments.length===0){return[]}var r=arguments;this.length=Math.max(w(this.length),0);if(arguments.length>0&&typeof e!=="number"){r=a.call(arguments);if(r.length<2){r.push(this.length-t)}else{r[1]=w(e)}}return o.apply(this,r)}},!F);var R=[].unshift(0)!==1;m(t,{unshift:function(){u.apply(this,arguments);return this.length}},R);m(Array,{isArray:p});var k=Object("a");var C=k[0]!=="a"||!(0 in k);var U=function xe(t){var e=true;var r=true;if(t){t.call("foo",function(t,r,n){if(typeof n!=="object"){e=false}});t.call([1],function(){"use strict";r=typeof this==="string"},"x")}return!!t&&e&&r};m(t,{forEach:function Se(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=arguments[1],i=-1,a=r.length>>>0;if(!c(t)){throw new TypeError}while(++i<a){if(i in r){t.call(n,r[i],i,e)}}}},!U(t.forEach));m(t,{map:function Oe(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0,i=Array(n),a=arguments[1];if(!c(t)){throw new TypeError(t+" is not a function")}for(var o=0;o<n;o++){if(o in r){i[o]=t.call(a,r[o],o,e)}}return i}},!U(t.map));m(t,{filter:function Te(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0,i=[],a,o=arguments[1];if(!c(t)){throw new TypeError(t+" is not a function")}for(var l=0;l<n;l++){if(l in r){a=r[l];if(t.call(o,a,l,e)){i.push(a)}}}return i}},!U(t.filter));m(t,{every:function je(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0,i=arguments[1];if(!c(t)){throw new TypeError(t+" is not a function")}for(var a=0;a<n;a++){if(a in r&&!t.call(i,r[a],a,e)){return false}}return true}},!U(t.every));m(t,{some:function Ee(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0,i=arguments[1];if(!c(t)){throw new TypeError(t+" is not a function")}for(var a=0;a<n;a++){if(a in r&&t.call(i,r[a],a,e)){return true}}return false}},!U(t.some));var A=false;if(t.reduce){A=typeof t.reduce.call("es5",function(t,e,r,n){return n})==="object"}m(t,{reduce:function Ne(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0;if(!c(t)){throw new TypeError(t+" is not a function")}if(!n&&arguments.length===1){throw new TypeError("reduce of empty array with no initial value")}var i=0;var a;if(arguments.length>=2){a=arguments[1]}else{do{if(i in r){a=r[i++];break}if(++i>=n){throw new TypeError("reduce of empty array with no initial value")}}while(true)}for(;i<n;i++){if(i in r){a=t.call(void 0,a,r[i],i,e)}}return a}},!A);var P=false;if(t.reduceRight){P=typeof t.reduceRight.call("es5",function(t,e,r,n){return n})==="object"}m(t,{reduceRight:function Ie(t){var e=S(this),r=C&&v(this)?this.split(""):e,n=r.length>>>0;if(!c(t)){throw new TypeError(t+" is not a function")}if(!n&&arguments.length===1){throw new TypeError("reduceRight of empty array with no initial value")}var i,a=n-1;if(arguments.length>=2){i=arguments[1]}else{do{if(a in r){i=r[a--];break}if(--a<0){throw new TypeError("reduceRight of empty array with no initial value")}}while(true)}if(a<0){return i}do{if(a in r){i=t.call(void 0,i,r[a],a,e)}}while(a--);return i}},!P);var Z=Array.prototype.indexOf&&[0,1].indexOf(1,2)!==-1;m(t,{indexOf:function De(t){var e=C&&v(this)?this.split(""):S(this),r=e.length>>>0;if(!r){return-1}var n=0;if(arguments.length>1){n=w(arguments[1])}n=n>=0?n:Math.max(0,r+n);for(;n<r;n++){if(n in e&&e[n]===t){return n}}return-1}},Z);var J=Array.prototype.lastIndexOf&&[0,1].lastIndexOf(0,-3)!==-1;m(t,{lastIndexOf:function _e(t){var e=C&&v(this)?this.split(""):S(this),r=e.length>>>0;if(!r){return-1}var n=r-1;if(arguments.length>1){n=Math.min(n,w(arguments[1]))}n=n>=0?n:r-Math.abs(n);for(;n>=0;n--){if(n in e&&t===e[n]){return n}}return-1}},J);var z=!{toString:null}.propertyIsEnumerable("toString"),$=function(){}.propertyIsEnumerable("prototype"),G=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],B=G.length;m(Object,{keys:function Me(t){var e=c(t),r=g(t),n=t!==null&&typeof t==="object",i=n&&v(t);if(!n&&!e&&!r){throw new TypeError("Object.keys called on a non-object")}var a=[];var o=$&&e;if(i||r){for(var l=0;l<t.length;++l){a.push(String(l))}}else{for(var u in t){if(!(o&&u==="prototype")&&j(t,u)){a.push(String(u))}}}if(z){var s=t.constructor,f=s&&s.prototype===t;for(var h=0;h<B;h++){var p=G[h];if(!(f&&p==="constructor")&&j(t,p)){a.push(p)}}}return a}});var H=Object.keys&&function(){return Object.keys(arguments).length===2}(1,2);var L=Object.keys;m(Object,{keys:function Fe(e){if(g(e)){return L(t.slice.call(e))}else{return L(e)}}},!H);var X=-621987552e5;var Y="-000001";var q=Date.prototype.toISOString&&new Date(X).toISOString().indexOf(Y)===-1;m(Date.prototype,{toISOString:function Re(){var t,e,r,n,i;if(!isFinite(this)){throw new RangeError("Date.prototype.toISOString called on non-finite value.")}n=this.getUTCFullYear();i=this.getUTCMonth();n+=Math.floor(i/12);i=(i%12+12)%12;t=[i+1,this.getUTCDate(),this.getUTCHours(),this.getUTCMinutes(),this.getUTCSeconds()];n=(n<0?"-":n>9999?"+":"")+("00000"+Math.abs(n)).slice(0<=n&&n<=9999?-4:-6);e=t.length;while(e--){r=t[e];if(r<10){t[e]="0"+r}}return n+"-"+t.slice(0,2).join("-")+"T"+t.slice(2).join(":")+"."+("000"+this.getUTCMilliseconds()).slice(-3)+"Z"}},q);var K=false;try{K=Date.prototype.toJSON&&new Date(NaN).toJSON()===null&&new Date(X).toJSON().indexOf(Y)!==-1&&Date.prototype.toJSON.call({toISOString:function(){return true}})}catch(Q){}if(!K){Date.prototype.toJSON=function ke(t){var e=Object(this),r=x(e),n;if(typeof r==="number"&&!isFinite(r)){return null}n=e.toISOString;if(typeof n!=="function"){throw new TypeError("toISOString property is not callable")}return n.call(e)}}var V=Date.parse("+033658-09-27T01:46:40.000Z")===1e15;var W=!isNaN(Date.parse("2012-04-04T24:00:00.500Z"))||!isNaN(Date.parse("2012-11-31T23:59:59.000Z"));var te=isNaN(Date.parse("2000-01-01T00:00:00.000Z"));if(!Date.parse||te||W||!V){Date=function(t){function e(r,n,i,a,o,l,u){var s=arguments.length;if(this instanceof t){var f=s===1&&String(r)===r?new t(e.parse(r)):s>=7?new t(r,n,i,a,o,l,u):s>=6?new t(r,n,i,a,o,l):s>=5?new t(r,n,i,a,o):s>=4?new t(r,n,i,a):s>=3?new t(r,n,i):s>=2?new t(r,n):s>=1?new t(r):new t;f.constructor=e;return f}return t.apply(this,arguments)}var r=new RegExp("^"+"(\\d{4}|[+-]\\d{6})"+"(?:-(\\d{2})"+"(?:-(\\d{2})"+"(?:"+"T(\\d{2})"+":(\\d{2})"+"(?:"+":(\\d{2})"+"(?:(\\.\\d{1,}))?"+")?"+"("+"Z|"+"(?:"+"([-+])"+"(\\d{2})"+":(\\d{2})"+")"+")?)?)?)?"+"$");var n=[0,31,59,90,120,151,181,212,243,273,304,334,365];function i(t,e){var r=e>1?1:0;return n[e]+Math.floor((t-1969+r)/4)-Math.floor((t-1901+r)/100)+Math.floor((t-1601+r)/400)+365*(t-1970)}function a(e){return Number(new t(1970,0,1,0,0,0,e))}for(var o in t){e[o]=t[o]}e.now=t.now;e.UTC=t.UTC;e.prototype=t.prototype;e.prototype.constructor=e;e.parse=function l(e){var n=r.exec(e);if(n){var o=Number(n[1]),l=Number(n[2]||1)-1,u=Number(n[3]||1)-1,s=Number(n[4]||0),f=Number(n[5]||0),c=Number(n[6]||0),h=Math.floor(Number(n[7]||0)*1e3),p=Boolean(n[4]&&!n[8]),v=n[9]==="-"?1:-1,g=Number(n[10]||0),y=Number(n[11]||0),d;if(s<(f>0||c>0||h>0?24:25)&&f<60&&c<60&&h<1e3&&l>-1&&l<12&&g<24&&y<60&&u>-1&&u<i(o,l+1)-i(o,l)){d=((i(o,l)+u)*24+s+g*v)*60;d=((d+f+y*v)*60+c)*1e3+h;if(p){d=a(d)}if(-864e13<=d&&d<=864e13){return d}}return NaN}return t.parse.apply(this,arguments)};return e}(Date)}if(!Date.now){Date.now=function Ce(){return(new Date).getTime()}}var ee=i.toFixed&&(8e-5.toFixed(3)!=="0.000"||.9.toFixed(0)!=="1"||1.255.toFixed(2)!=="1.25"||0xde0b6b3a7640080.toFixed(0)!=="1000000000000000128");var re={base:1e7,size:6,data:[0,0,0,0,0,0],multiply:function Ue(t,e){var r=-1;while(++r<re.size){e+=t*re.data[r];re.data[r]=e%re.base;e=Math.floor(e/re.base)}},divide:function Ae(t){var e=re.size,r=0;while(--e>=0){r+=re.data[e];re.data[e]=Math.floor(r/t);r=r%t*re.base}},numToString:function Pe(){var t=re.size;var e="";while(--t>=0){if(e!==""||t===0||re.data[t]!==0){var r=String(re.data[t]);if(e===""){e=r}else{e+="0000000".slice(0,7-r.length)+r}}}return e},pow:function Ze(t,e,r){return e===0?r:e%2===1?Ze(t,e-1,r*t):Ze(t*t,e/2,r)},log:function Je(t){var e=0;while(t>=4096){e+=12;t/=4096}while(t>=2){e+=1;t/=2}return e}};m(i,{toFixed:function ze(t){var e,r,n,i,a,o,l,u;e=Number(t);e=e!==e?0:Math.floor(e);if(e<0||e>20){throw new RangeError("Number.toFixed called with invalid number of decimals")}r=Number(this);if(r!==r){return"NaN"}if(r<=-1e21||r>=1e21){return String(r)}n="";if(r<0){n="-";r=-r}i="0";if(r>1e-21){a=re.log(r*re.pow(2,69,1))-69;o=a<0?r*re.pow(2,-a,1):r/re.pow(2,a,1);o*=4503599627370496;a=52-a;if(a>0){re.multiply(0,o);l=e;while(l>=7){re.multiply(1e7,0);l-=7}re.multiply(re.pow(10,l,1),0);l=a-1;while(l>=23){re.divide(1<<23);l-=23}re.divide(1<<l);re.multiply(1,1);re.divide(2);i=re.numToString()}else{re.multiply(0,o);re.multiply(1<<-a,0);i=re.numToString()+"0.00000000000000000000".slice(2,2+e)}}if(e>0){u=i.length;if(u<=e){i=n+"0.0000000000000000000".slice(0,e-u+2)+i}else{i=n+i.slice(0,u-e)+"."+i.slice(u-e)}}else{i=n+i}return i}},ee);var ne=n.split;if("ab".split(/(?:ab)*/).length!==2||".".split(/(.?)(.?)/).length!==4||"tesst".split(/(s)*/)[1]==="t"||"test".split(/(?:)/,-1).length!==4||"".split(/.?/).length||".".split(/()()/).length>1){(function(){var e=/()??/.exec("")[1]===void 0;n.split=function(r,n){var i=this;if(r===void 0&&n===0){return[]}if(f.call(r)!=="[object RegExp]"){return ne.call(this,r,n)}var a=[],o=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.extended?"x":"")+(r.sticky?"y":""),l=0,u,s,c,h;r=new RegExp(r.source,o+"g");i+="";if(!e){u=new RegExp("^"+r.source+"$(?!\\s)",o)}n=n===void 0?-1>>>0:O(n);while(s=r.exec(i)){c=s.index+s[0].length;if(c>l){a.push(i.slice(l,s.index));if(!e&&s.length>1){s[0].replace(u,function(){for(var t=1;t<arguments.length-2;t++){if(arguments[t]===void 0){s[t]=void 0}}})}if(s.length>1&&s.index<i.length){t.push.apply(a,s.slice(1))}h=s[0].length;l=c;if(a.length>=n){break}}if(r.lastIndex===s.index){r.lastIndex++}}if(l===i.length){if(h||!r.test("")){a.push("")}}else{a.push(i.slice(l))}return a.length>n?a.slice(0,n):a}})()}else if("0".split(void 0,0).length){n.split=function $e(t,e){if(t===void 0&&e===0){return[]}return ne.call(this,t,e)}}var ie=n.replace;var ae=function(){var t=[];"x".replace(/x(.)?/g,function(e,r){t.push(r)});return t.length===1&&typeof t[0]==="undefined"}();if(!ae){n.replace=function Ge(t,e){var r=c(e);var n=h(t)&&/\)[*?]/.test(t.source);if(!r||!n){return ie.call(this,t,e)}else{var i=function(r){var n=arguments.length;var i=t.lastIndex;t.lastIndex=0;var a=t.exec(r);t.lastIndex=i;a.push(arguments[n-2],arguments[n-1]);return e.apply(this,a)};return ie.call(this,t,i)}}}var oe=n.substr;var le="".substr&&"0b".substr(-1)!=="b";m(n,{substr:function Be(t,e){return oe.call(this,t<0?(t=this.length+t)<0?0:t:t,e)}},le);var ue=" \n\f\r \xa0\u1680\u180e\u2000\u2001\u2002\u2003"+"\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028"+"\u2029\ufeff";var se="\u200b";var fe="["+ue+"]";var ce=new RegExp("^"+fe+fe+"*");var he=new RegExp(fe+fe+"*$");var pe=n.trim&&(ue.trim()||!se.trim());m(n,{trim:function He(){if(this===void 0||this===null){throw new TypeError("can't convert "+this+" to object")}return String(this).replace(ce,"").replace(he,"")}},pe);if(parseInt(ue+"08")!==8||parseInt(ue+"0x16")!==22){parseInt=function(t){var e=/^0[xX]/;return function r(n,i){n=String(n).trim();if(!Number(i)){i=e.test(n)?16:10}return t(n,i)}}(parseInt)}}); | ||
//# sourceMappingURL=es5-shim.map |
{ | ||
"name": "es5-shim", | ||
"version": "2.1.0", | ||
"description": "ES5 as implementable on previous engines", | ||
"homepage": "http://github.com/kriskowal/es5-shim/", | ||
"version": "4.0.1", | ||
"description": "ECMAScript 5 compatibility shims for legacy JavaScript engines", | ||
"homepage": "http://github.com/es-shims/es5-shim/", | ||
"contributors": [ | ||
@@ -11,7 +11,8 @@ "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)", | ||
"Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)", | ||
"Kit Cambridge <kitcambridge@gmail.com> (http://kitcambridge.github.com)" | ||
"Kit Cambridge <kitcambridge@gmail.com> (http://kitcambridge.github.com)", | ||
"Jordan Harband <ljharb@gmail.com> (https://github.com/ljharb/)" | ||
], | ||
"bugs": { | ||
"mail": "kris@cixar.com", | ||
"url": "http://github.com/kriskowal/es5-shim/issues" | ||
"mail": "ljharb@gmail.com", | ||
"url": "http://github.com/es-shims/es5-shim/issues" | ||
}, | ||
@@ -21,3 +22,3 @@ "licenses": [ | ||
"type": "MIT", | ||
"url": "http://github.com/kriskowal/es5-shim/raw/master/LICENSE" | ||
"url": "http://github.com/es-shims/es5-shim/raw/master/LICENSE" | ||
} | ||
@@ -28,10 +29,38 @@ ], | ||
"type": "git", | ||
"url": "http://github.com/kriskowal/es5-shim.git" | ||
"url": "http://github.com/es-shims/es5-shim.git" | ||
}, | ||
"scripts": { | ||
"minify": "uglifyjs es5-shim.js --source-map=es5-shim.map -b ascii_only=true,beautify=false > es5-shim.min.js; uglifyjs es5-sham.js --source-map=es5-sham.map -b ascii_only=true,beautify=false > es5-sham.min.js" | ||
"minify": "npm run minify-shim && npm run minify-sham", | ||
"minify-shim": "uglifyjs es5-shim.js --comments --source-map=es5-shim.map -m -b ascii_only=true,beautify=false > es5-shim.min.js", | ||
"minify-sham": "uglifyjs es5-sham.js --comments --source-map=es5-sham.map -m -b ascii_only=true,beautify=false > es5-sham.min.js", | ||
"test": "jasmine-node --matchall ./ tests/spec/", | ||
"test-native": "jasmine-node --matchall tests/spec/", | ||
"lint": "jscs tests/helpers/*.js tests/spec/*.js es5-shim.js es5-sham.js" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "~1.14.5", | ||
"jscs": "~1.5.8", | ||
"uglify-js": "~2.4.14" | ||
}, | ||
"engines": { | ||
"node": ">=0.2.0" | ||
"node": ">=0.4.0" | ||
}, | ||
"testling": { | ||
"browsers": [ | ||
"iexplore/6.0..latest", | ||
"firefox/3.0..6.0", | ||
"firefox/18.0..latest", | ||
"firefox/nightly", | ||
"chrome/4.0..10.0", | ||
"chrome/25.0..latest", | ||
"chrome/canary", | ||
"opera/10.0..latest", | ||
"opera/next", | ||
"safari/4.0..latest", | ||
"ipad/6.0..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2" | ||
] | ||
} | ||
} | ||
@@ -0,1 +1,7 @@ | ||
#es5-shim <sup>[![Version Badge][2]][1]</sup> | ||
[![npm badge][9]][1] | ||
[![Build Status][3]][4] [![dependency status][5]][6] [![dev dependency status][7]][8] | ||
`es5-shim.js` and `es5-shim.min.js` monkey-patch a JavaScript context to | ||
@@ -18,7 +24,2 @@ contain all EcmaScript 5 methods that can be faithfully emulated with a | ||
In order to run against the shim-code, the tests attempt to kill the current | ||
implementation of the missing methods. This happens in <root-folder>/tests/helpers/h-kill.js. | ||
So in order to run the tests against the built-in methods, invalidate that file somehow | ||
(comment-out, delete the file, delete the script-tag, etc.). | ||
## Shims | ||
@@ -41,3 +42,2 @@ | ||
* Function.prototype.bind | ||
* :warning: Caveat: the bound function's length is always 0. | ||
* :warning: Caveat: the bound function has a prototype property. | ||
@@ -52,4 +52,7 @@ * :warning: Caveat: bound functions do not try too hard to keep you | ||
* String.prototype.trim | ||
* String.prototype.replace | ||
* Firefox (through v29) natively handles capturing groups incorrectly. | ||
* Date.parse (for ISO parsing) | ||
* Date.prototype.toISOString | ||
* parseInt | ||
@@ -64,7 +67,2 @@ ## Shams | ||
:warning: Object.create(null) will work only in browsers that | ||
support prototype assignment. This creates an object that does not | ||
have any properties inherited from Object.prototype. It will | ||
silently fail otherwise. | ||
:warning: The second argument is passed to Object.defineProperties | ||
@@ -114,3 +112,3 @@ which will probably fail either silently or with extreme predudice. | ||
* :warning: Object.getOwnPropertyDescriptor | ||
The behavior of this shim does not conform to ES5. It should | ||
@@ -129,3 +127,3 @@ probably not be used at this time, until its behavior has been | ||
set "writable", "enumerable", and "configurable" properties. | ||
Providing a getter or setter with "get" or "set" on a descriptor | ||
@@ -135,3 +133,3 @@ will silently fail on engines that lack "__defineGetter__" and | ||
https://github.com/kriskowal/es5-shim/issues#issue/5 | ||
https://github.com/es-shims/es5-shim/issues#issue/5 | ||
@@ -163,1 +161,11 @@ * :warning: Object.defineProperties | ||
[1]: https://npmjs.org/package/es5-shim | ||
[2]: http://vb.teelaun.ch/es-shims/es5-shim.svg | ||
[3]: https://travis-ci.org/es-shims/es5-shim.png | ||
[4]: https://travis-ci.org/es-shims/es5-shim | ||
[5]: https://david-dm.org/es-shims/es5-shim.png | ||
[6]: https://david-dm.org/es-shims/es5-shim | ||
[7]: https://david-dm.org/es-shims/es5-shim/dev-status.png | ||
[8]: https://david-dm.org/es-shims/es5-shim#info=devDependencies | ||
[9]: https://nodei.co/npm/es5-shim.png?downloads=true&stars=true | ||
@@ -1,4 +0,4 @@ | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
this.addMatchers({ | ||
toExactlyMatch: function(expected) { | ||
toExactlyMatch: function (expected) { | ||
var a1, a2, | ||
@@ -8,7 +8,7 @@ l, i, | ||
actual = this.actual; | ||
var getKeys = function(o) { | ||
var a = []; | ||
for(key in o) { | ||
if(o.hasOwnProperty(key)) { | ||
var getKeys = function (o) { | ||
var key, a = []; | ||
for (key in o) { | ||
if (o.hasOwnProperty(key)) { | ||
a.push(key); | ||
@@ -18,11 +18,11 @@ } | ||
return a; | ||
} | ||
}; | ||
a1 = getKeys(actual); | ||
a2 = getKeys(expected); | ||
l = a1.length; | ||
if(l !== a2.length) { | ||
if (l !== a2.length) { | ||
return false; | ||
} | ||
for(i = 0; i < l; i++) { | ||
for (i = 0; i < l; i++) { | ||
key = a1[i]; | ||
@@ -32,6 +32,7 @@ expect(key).toEqual(a2[i]); | ||
} | ||
return true; | ||
} | ||
}) | ||
}); | ||
}); | ||
function implement() { | ||
throw 'Not implemented'; | ||
} | ||
} | ||
@@ -1,11 +0,18 @@ | ||
describe('Array', function() { | ||
var toString = Object.prototype.toString; | ||
var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false. | ||
var hasStrictMode = (function () { | ||
"use strict"; | ||
return !this; | ||
}()); | ||
describe('Array', function () { | ||
var testSubject; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
testSubject = [2, 3, undefined, true, 'hej', null, false, 0]; | ||
delete testSubject[1]; | ||
}); | ||
function createArrayLikeFromArray(arr) { | ||
var createArrayLikeFromArray = function createArrayLikeFromArray(arr) { | ||
var o = {}; | ||
Array.prototype.forEach.call(arr, function(e, i) { | ||
o[i]=e; | ||
Array.prototype.forEach.call(arr, function (e, i) { | ||
o[i] = e; | ||
}); | ||
@@ -16,11 +23,10 @@ o.length = arr.length; | ||
describe('forEach', function() { | ||
"use strict"; | ||
describe('forEach', function () { | ||
var expected, actual; | ||
beforeEach(function() { | ||
expected = {0:2, 2: undefined, 3:true, 4: 'hej', 5:null, 6:false, 7:0 }; | ||
beforeEach(function () { | ||
expected = {0: 2, 2: undefined, 3: true, 4: 'hej', 5: null, 6: false, 7: 0 }; | ||
actual = {}; | ||
}); | ||
it('should pass the right parameters', function() { | ||
it('should pass the right parameters', function () { | ||
var callback = jasmine.createSpy('callback'), | ||
@@ -31,8 +37,8 @@ array = ['1']; | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.forEach(function(a) { | ||
arr.forEach(function (a) { | ||
i++; | ||
arr.push(a+3); | ||
arr.push(a + 3); | ||
}); | ||
@@ -43,9 +49,9 @@ expect(arr).toEqual([1,2,3,4,5,6]); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
[1].forEach(function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
[1].forEach(function () { context = this; }); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should iterate all', function() { | ||
testSubject.forEach(function(obj, index) { | ||
it('should iterate all', function () { | ||
testSubject.forEach(function (obj, index) { | ||
actual[index] = obj; | ||
@@ -55,6 +61,6 @@ }); | ||
}); | ||
it('should iterate all using a context', function() { | ||
it('should iterate all using a context', function () { | ||
var o = { a: actual }; | ||
testSubject.forEach(function(obj, index) { | ||
testSubject.forEach(function (obj, index) { | ||
this.a[index] = obj; | ||
@@ -65,5 +71,5 @@ }, o); | ||
it('should iterate all in an array-like object', function() { | ||
it('should iterate all in an array-like object', function () { | ||
var ts = createArrayLikeFromArray(testSubject); | ||
Array.prototype.forEach.call(ts, function(obj, index) { | ||
Array.prototype.forEach.call(ts, function (obj, index) { | ||
actual[index] = obj; | ||
@@ -73,7 +79,7 @@ }); | ||
}); | ||
it('should iterate all in an array-like object using a context', function() { | ||
it('should iterate all in an array-like object using a context', function () { | ||
var ts = createArrayLikeFromArray(testSubject), | ||
o = { a: actual }; | ||
Array.prototype.forEach.call(ts, function(obj, index) { | ||
Array.prototype.forEach.call(ts, function (obj, index) { | ||
this.a[index] = obj; | ||
@@ -84,8 +90,7 @@ }, o); | ||
describe('strings', function() { | ||
var str = 'Hello, World!', | ||
toString = Object.prototype.toString; | ||
it('should iterate all in a string', function() { | ||
describe('strings', function () { | ||
var str = 'Hello, World!'; | ||
it('should iterate all in a string', function () { | ||
actual = []; | ||
Array.prototype.forEach.call(str, function(item, index) { | ||
Array.prototype.forEach.call(str, function (item, index) { | ||
actual[index] = item; | ||
@@ -95,6 +100,6 @@ }); | ||
}); | ||
it('should iterate all in a string using a context', function() { | ||
it('should iterate all in a string using a context', function () { | ||
actual = []; | ||
var o = { a: actual }; | ||
Array.prototype.forEach.call(str, function(item, index) { | ||
Array.prototype.forEach.call(str, function (item, index) { | ||
this.a[index] = item; | ||
@@ -104,16 +109,27 @@ }, o); | ||
}); | ||
it('should have String object for third argument of callback', function() { | ||
Array.prototype.forEach.call(str, function(item, index, obj) { | ||
actual = obj; | ||
}); | ||
expect(typeof actual).toBe("object"); | ||
expect(toString.call(actual)).toBe("[object String]"); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.forEach.call('foo', function (item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
if (hasStrictMode) { | ||
it('does not autobox the content in strict mode', function () { | ||
var actual; | ||
[1].forEach(function () { | ||
'use strict'; | ||
actual = this; | ||
}, 'x'); | ||
expect(typeof actual).toBe('string'); | ||
}); | ||
} | ||
}); | ||
describe('some', function() { | ||
describe('some', function () { | ||
var actual, expected, numberOfRuns; | ||
beforeEach(function() { | ||
expected = {0:2, 2: undefined, 3:true }; | ||
beforeEach(function () { | ||
expected = {0: 2, 2: undefined, 3: true }; | ||
actual = {}; | ||
@@ -123,3 +139,3 @@ numberOfRuns = 0; | ||
it('should pass the correct values along to the callback', function() { | ||
it('should pass the correct values along to the callback', function () { | ||
var callback = jasmine.createSpy('callback'); | ||
@@ -130,8 +146,8 @@ var array = ['1']; | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.some(function(a) { | ||
arr.some(function (a) { | ||
i++; | ||
arr.push(a+3); | ||
arr.push(a + 3); | ||
return i > 3; | ||
@@ -142,41 +158,35 @@ }); | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
[1].some(function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
[1].some(function () { context = this; }); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should return false if it runs to the end', function() { | ||
actual = testSubject.some(function() {}); | ||
it('should return false if it runs to the end', function () { | ||
actual = testSubject.some(function () {}); | ||
expect(actual).toBeFalsy(); | ||
}); | ||
it('should return true if it is stopped somewhere', function() { | ||
actual = testSubject.some(function() { return true; }); | ||
it('should return true if it is stopped somewhere', function () { | ||
actual = testSubject.some(function () { return true; }); | ||
expect(actual).toBeTruthy(); | ||
}); | ||
it('should return false if there are no elements', function() { | ||
actual = [].some(function() { return true; }); | ||
it('should return false if there are no elements', function () { | ||
actual = [].some(function () { return true; }); | ||
expect(actual).toBeFalsy(); | ||
}); | ||
it('should stop after 3 elements', function() { | ||
testSubject.some(function(obj, index) { | ||
it('should stop after 3 elements', function () { | ||
testSubject.some(function (obj, index) { | ||
actual[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return true; | ||
} | ||
return false; | ||
return numberOfRuns === 3; | ||
}); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should stop after 3 elements using a context', function() { | ||
it('should stop after 3 elements using a context', function () { | ||
var o = { a: actual }; | ||
testSubject.some(function(obj, index) { | ||
testSubject.some(function (obj, index) { | ||
this.a[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return true; | ||
} | ||
return false; | ||
return numberOfRuns === 3; | ||
}, o); | ||
@@ -186,33 +196,35 @@ expect(actual).toExactlyMatch(expected); | ||
it('should stop after 3 elements in an array-like object', function() { | ||
it('should stop after 3 elements in an array-like object', function () { | ||
var ts = createArrayLikeFromArray(testSubject); | ||
Array.prototype.some.call(ts, function(obj, index) { | ||
Array.prototype.some.call(ts, function (obj, index) { | ||
actual[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return true; | ||
} | ||
return false; | ||
return numberOfRuns === 3; | ||
}); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should stop after 3 elements in an array-like object using a context', function() { | ||
it('should stop after 3 elements in an array-like object using a context', function () { | ||
var ts = createArrayLikeFromArray(testSubject); | ||
var o = { a: actual }; | ||
Array.prototype.some.call(ts, function(obj, index) { | ||
Array.prototype.some.call(ts, function (obj, index) { | ||
this.a[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return true; | ||
} | ||
return false; | ||
return numberOfRuns === 3; | ||
}, o); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.some.call('foo', function (item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('every', function() { | ||
describe('every', function () { | ||
var actual, expected, numberOfRuns; | ||
beforeEach(function() { | ||
expected = {0:2, 2: undefined, 3:true }; | ||
beforeEach(function () { | ||
expected = { 0: 2, 2: undefined, 3: true }; | ||
actual = {}; | ||
@@ -222,3 +234,3 @@ numberOfRuns = 0; | ||
it('should pass the correct values along to the callback', function() { | ||
it('should pass the correct values along to the callback', function () { | ||
var callback = jasmine.createSpy('callback'); | ||
@@ -229,8 +241,8 @@ var array = ['1']; | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.every(function(a) { | ||
arr.every(function (a) { | ||
i++; | ||
arr.push(a+3); | ||
arr.push(a + 3); | ||
return i <= 3; | ||
@@ -241,44 +253,38 @@ }); | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
[1].every(function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
[1].every(function () {context = this;}); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should return true if the array is empty', function() { | ||
actual = [].every(function() { return true; }); | ||
it('should return true if the array is empty', function () { | ||
actual = [].every(function () { return true; }); | ||
expect(actual).toBeTruthy(); | ||
actual = [].every(function() { return false; }); | ||
actual = [].every(function () { return false; }); | ||
expect(actual).toBeTruthy(); | ||
}); | ||
it('should return true if it runs to the end', function() { | ||
actual = [1,2,3].every(function() { return true; }); | ||
it('should return true if it runs to the end', function () { | ||
actual = [1,2,3].every(function () { return true; }); | ||
expect(actual).toBeTruthy(); | ||
}); | ||
it('should return false if it is stopped before the end', function() { | ||
actual = [1,2,3].every(function() { return false; }); | ||
it('should return false if it is stopped before the end', function () { | ||
actual = [1,2,3].every(function () { return false; }); | ||
expect(actual).toBeFalsy(); | ||
}); | ||
it('should return after 3 elements', function() { | ||
testSubject.every(function(obj, index) { | ||
it('should return after 3 elements', function () { | ||
testSubject.every(function (obj, index) { | ||
actual[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return false; | ||
} | ||
return true; | ||
return numberOfRuns !== 3; | ||
}); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should stop after 3 elements using a context', function() { | ||
it('should stop after 3 elements using a context', function () { | ||
var o = { a: actual }; | ||
testSubject.every(function(obj, index) { | ||
testSubject.every(function (obj, index) { | ||
this.a[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return false; | ||
} | ||
return true; | ||
return numberOfRuns !== 3; | ||
}, o); | ||
@@ -288,34 +294,36 @@ expect(actual).toExactlyMatch(expected); | ||
it('should stop after 3 elements in an array-like object', function() { | ||
it('should stop after 3 elements in an array-like object', function () { | ||
var ts = createArrayLikeFromArray(testSubject); | ||
Array.prototype.every.call(ts, function(obj, index) { | ||
Array.prototype.every.call(ts, function (obj, index) { | ||
actual[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return false; | ||
} | ||
return true; | ||
return numberOfRuns !== 3; | ||
}); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should stop after 3 elements in an array-like object using a context', function() { | ||
it('should stop after 3 elements in an array-like object using a context', function () { | ||
var ts = createArrayLikeFromArray(testSubject); | ||
var o = { a: actual }; | ||
Array.prototype.every.call(ts, function(obj, index) { | ||
Array.prototype.every.call(ts, function (obj, index) { | ||
this.a[index] = obj; | ||
numberOfRuns += 1; | ||
if(numberOfRuns == 3) { | ||
return false; | ||
} | ||
return true; | ||
return numberOfRuns !== 3; | ||
}, o); | ||
expect(actual).toExactlyMatch(expected); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.every.call('foo', function (item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('indexOf', function() { | ||
describe('indexOf', function () { | ||
"use strict"; | ||
var actual, expected, testSubject; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
testSubject = [2, 3, undefined, true, 'hej', null, 2, false, 0]; | ||
@@ -326,43 +334,43 @@ delete testSubject[1]; | ||
it('should find the element', function() { | ||
it('should find the element', function () { | ||
expected = 4; | ||
actual = testSubject.indexOf('hej'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not find the element', function() { | ||
it('should not find the element', function () { | ||
expected = -1; | ||
actual = testSubject.indexOf('mus'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should find undefined as well', function() { | ||
it('should find undefined as well', function () { | ||
expected = -1; | ||
actual = testSubject.indexOf(undefined); | ||
expect(actual).not.toEqual(expected); | ||
expect(actual).not.toBe(expected); | ||
}); | ||
it('should skip unset indexes', function() { | ||
it('should skip unset indexes', function () { | ||
expected = 2; | ||
actual = testSubject.indexOf(undefined); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use a strict test', function() { | ||
it('should use a strict test', function () { | ||
actual = testSubject.indexOf(null); | ||
expect(actual).toEqual(5); | ||
expect(actual).toBe(5); | ||
actual = testSubject.indexOf('2'); | ||
expect(actual).toEqual(-1); | ||
expect(actual).toBe(-1); | ||
}); | ||
it('should skip the first if fromIndex is set', function() { | ||
expect(testSubject.indexOf(2, 2)).toEqual(6); | ||
expect(testSubject.indexOf(2, 0)).toEqual(0); | ||
expect(testSubject.indexOf(2, 6)).toEqual(6); | ||
it('should skip the first if fromIndex is set', function () { | ||
expect(testSubject.indexOf(2, 2)).toBe(6); | ||
expect(testSubject.indexOf(2, 0)).toBe(0); | ||
expect(testSubject.indexOf(2, 6)).toBe(6); | ||
}); | ||
it('should work with negative fromIndex', function() { | ||
expect(testSubject.indexOf(2, -3)).toEqual(6); | ||
expect(testSubject.indexOf(2, -9)).toEqual(0); | ||
it('should work with negative fromIndex', function () { | ||
expect(testSubject.indexOf(2, -3)).toBe(6); | ||
expect(testSubject.indexOf(2, -9)).toBe(0); | ||
}); | ||
it('should work with fromIndex being greater than the length', function() { | ||
expect(testSubject.indexOf(0, 20)).toEqual(-1); | ||
it('should work with fromIndex being greater than the length', function () { | ||
expect(testSubject.indexOf(0, 20)).toBe(-1); | ||
}); | ||
it('should work with fromIndex being negative and greater than the length', function() { | ||
expect(testSubject.indexOf('hej', -20)).toEqual(4); | ||
it('should work with fromIndex being negative and greater than the length', function () { | ||
expect(testSubject.indexOf('hej', -20)).toBe(4); | ||
}); | ||
@@ -381,51 +389,51 @@ | ||
}); | ||
it('should find the element (array-like)', function() { | ||
it('should find the element (array-like)', function () { | ||
expected = 4; | ||
actual = indexOf.call(testAL, 'hej'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not find the element (array-like)', function() { | ||
it('should not find the element (array-like)', function () { | ||
expected = -1; | ||
actual = indexOf.call(testAL, 'mus'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should find undefined as well (array-like)', function() { | ||
it('should find undefined as well (array-like)', function () { | ||
expected = -1; | ||
actual = indexOf.call(testAL, undefined); | ||
expect(actual).not.toEqual(expected); | ||
expect(actual).not.toBe(expected); | ||
}); | ||
it('should skip unset indexes (array-like)', function() { | ||
it('should skip unset indexes (array-like)', function () { | ||
expected = 2; | ||
actual = indexOf.call(testAL, undefined); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use a strict test (array-like)', function() { | ||
it('should use a strict test (array-like)', function () { | ||
actual = Array.prototype.indexOf.call(testAL, null); | ||
expect(actual).toEqual(5); | ||
expect(actual).toBe(5); | ||
actual = Array.prototype.indexOf.call(testAL, '2'); | ||
expect(actual).toEqual(-1); | ||
expect(actual).toBe(-1); | ||
}); | ||
it('should skip the first if fromIndex is set (array-like)', function() { | ||
expect(indexOf.call(testAL, 2, 2)).toEqual(6); | ||
expect(indexOf.call(testAL, 2, 0)).toEqual(0); | ||
expect(indexOf.call(testAL, 2, 6)).toEqual(6); | ||
it('should skip the first if fromIndex is set (array-like)', function () { | ||
expect(indexOf.call(testAL, 2, 2)).toBe(6); | ||
expect(indexOf.call(testAL, 2, 0)).toBe(0); | ||
expect(indexOf.call(testAL, 2, 6)).toBe(6); | ||
}); | ||
it('should work with negative fromIndex (array-like)', function() { | ||
expect(indexOf.call(testAL, 2, -3)).toEqual(6); | ||
expect(indexOf.call(testAL, 2, -9)).toEqual(0); | ||
it('should work with negative fromIndex (array-like)', function () { | ||
expect(indexOf.call(testAL, 2, -3)).toBe(6); | ||
expect(indexOf.call(testAL, 2, -9)).toBe(0); | ||
}); | ||
it('should work with fromIndex being greater than the length (array-like)', function() { | ||
expect(indexOf.call(testAL, 0, 20)).toEqual(-1); | ||
it('should work with fromIndex being greater than the length (array-like)', function () { | ||
expect(indexOf.call(testAL, 0, 20)).toBe(-1); | ||
}); | ||
it('should work with fromIndex being negative and greater than the length (array-like)', function() { | ||
expect(indexOf.call(testAL, 'hej', -20)).toEqual(4); | ||
it('should work with fromIndex being negative and greater than the length (array-like)', function () { | ||
expect(indexOf.call(testAL, 'hej', -20)).toBe(4); | ||
}); | ||
}); | ||
}); | ||
describe('lastIndexOf', function() { | ||
describe('lastIndexOf', function () { | ||
"use strict"; | ||
var actual, expected, testSubject, testAL; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
testSubject = [2, 3, undefined, true, 'hej', null, 2, 3, false, 0]; | ||
@@ -435,51 +443,51 @@ delete testSubject[1]; | ||
}); | ||
describe('Array', function() { | ||
it('should find the element', function() { | ||
describe('Array', function () { | ||
it('should find the element', function () { | ||
expected = 4; | ||
actual = testSubject.lastIndexOf('hej'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not find the element', function() { | ||
it('should not find the element', function () { | ||
expected = -1; | ||
actual = testSubject.lastIndexOf('mus'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should find undefined as well', function() { | ||
it('should find undefined as well', function () { | ||
expected = -1; | ||
actual = testSubject.lastIndexOf(undefined); | ||
expect(actual).not.toEqual(expected); | ||
expect(actual).not.toBe(expected); | ||
}); | ||
it('should skip unset indexes', function() { | ||
it('should skip unset indexes', function () { | ||
expected = 2; | ||
actual = testSubject.lastIndexOf(undefined); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use a strict test', function() { | ||
it('should use a strict test', function () { | ||
actual = testSubject.lastIndexOf(null); | ||
expect(actual).toEqual(5); | ||
expect(actual).toBe(5); | ||
actual = testSubject.lastIndexOf('2'); | ||
expect(actual).toEqual(-1); | ||
expect(actual).toBe(-1); | ||
}); | ||
it('should skip the first if fromIndex is set', function() { | ||
expect(testSubject.lastIndexOf(2, 2)).toEqual(0); | ||
expect(testSubject.lastIndexOf(2, 0)).toEqual(0); | ||
expect(testSubject.lastIndexOf(2, 6)).toEqual(6); | ||
it('should skip the first if fromIndex is set', function () { | ||
expect(testSubject.lastIndexOf(2, 2)).toBe(0); | ||
expect(testSubject.lastIndexOf(2, 0)).toBe(0); | ||
expect(testSubject.lastIndexOf(2, 6)).toBe(6); | ||
}); | ||
it('should work with negative fromIndex', function() { | ||
expect(testSubject.lastIndexOf(2, -3)).toEqual(6); | ||
expect(testSubject.lastIndexOf(2, -9)).toEqual(0); | ||
it('should work with negative fromIndex', function () { | ||
expect(testSubject.lastIndexOf(2, -3)).toBe(6); | ||
expect(testSubject.lastIndexOf(2, -9)).toBe(0); | ||
}); | ||
it('should work with fromIndex being greater than the length', function() { | ||
expect(testSubject.lastIndexOf(2, 20)).toEqual(6); | ||
it('should work with fromIndex being greater than the length', function () { | ||
expect(testSubject.lastIndexOf(2, 20)).toBe(6); | ||
}); | ||
it('should work with fromIndex being negative and greater than the length', function() { | ||
expect(testSubject.lastIndexOf(2, -20)).toEqual(-1); | ||
it('should work with fromIndex being negative and greater than the length', function () { | ||
expect(testSubject.lastIndexOf(2, -20)).toBe(-1); | ||
}); | ||
}); | ||
describe('Array like', function() { | ||
describe('Array like', function () { | ||
var lastIndexOf = Array.prototype.lastIndexOf, | ||
testAL; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
testAL = {}; | ||
@@ -491,43 +499,43 @@ testSubject.forEach(function (o,i) { | ||
}); | ||
it('should find the element (array-like)', function() { | ||
it('should find the element (array-like)', function () { | ||
expected = 4; | ||
actual = lastIndexOf.call(testAL, 'hej'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should not find the element (array-like)', function() { | ||
it('should not find the element (array-like)', function () { | ||
expected = -1; | ||
actual = lastIndexOf.call(testAL, 'mus'); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should find undefined as well (array-like)', function() { | ||
it('should find undefined as well (array-like)', function () { | ||
expected = -1; | ||
actual = lastIndexOf.call(testAL, undefined); | ||
expect(actual).not.toEqual(expected); | ||
expect(actual).not.toBe(expected); | ||
}); | ||
it('should skip unset indexes (array-like)', function() { | ||
it('should skip unset indexes (array-like)', function () { | ||
expected = 2; | ||
actual = lastIndexOf.call(testAL, undefined); | ||
expect(actual).toEqual(expected); | ||
expect(actual).toBe(expected); | ||
}); | ||
it('should use a strict test (array-like)', function() { | ||
it('should use a strict test (array-like)', function () { | ||
actual = lastIndexOf.call(testAL, null); | ||
expect(actual).toEqual(5); | ||
expect(actual).toBe(5); | ||
actual = lastIndexOf.call(testAL, '2'); | ||
expect(actual).toEqual(-1); | ||
expect(actual).toBe(-1); | ||
}); | ||
it('should skip the first if fromIndex is set', function() { | ||
expect(lastIndexOf.call(testAL, 2, 2)).toEqual(0); | ||
expect(lastIndexOf.call(testAL, 2, 0)).toEqual(0); | ||
expect(lastIndexOf.call(testAL, 2, 6)).toEqual(6); | ||
it('should skip the first if fromIndex is set', function () { | ||
expect(lastIndexOf.call(testAL, 2, 2)).toBe(0); | ||
expect(lastIndexOf.call(testAL, 2, 0)).toBe(0); | ||
expect(lastIndexOf.call(testAL, 2, 6)).toBe(6); | ||
}); | ||
it('should work with negative fromIndex', function() { | ||
expect(lastIndexOf.call(testAL, 2, -3)).toEqual(6); | ||
expect(lastIndexOf.call(testAL, 2, -9)).toEqual(0); | ||
it('should work with negative fromIndex', function () { | ||
expect(lastIndexOf.call(testAL, 2, -3)).toBe(6); | ||
expect(lastIndexOf.call(testAL, 2, -9)).toBe(0); | ||
}); | ||
it('should work with fromIndex being greater than the length', function() { | ||
expect(lastIndexOf.call(testAL, 2, 20)).toEqual(6); | ||
it('should work with fromIndex being greater than the length', function () { | ||
expect(lastIndexOf.call(testAL, 2, 20)).toBe(6); | ||
}); | ||
it('should work with fromIndex being negative and greater than the length', function() { | ||
expect(lastIndexOf.call(testAL, 2, -20)).toEqual(-1); | ||
it('should work with fromIndex being negative and greater than the length', function () { | ||
expect(lastIndexOf.call(testAL, 2, -20)).toBe(-1); | ||
}); | ||
@@ -537,11 +545,9 @@ }); | ||
describe('filter', function() { | ||
describe('filter', function () { | ||
var filteredArray, | ||
callback = function callback(o, i, arr) { | ||
return ( | ||
i != 3 && i != 5 | ||
); | ||
return i !== 3 && i !== 5; | ||
}; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
testSubject = [2, 3, undefined, true, 'hej', 3, null, false, 0]; | ||
@@ -551,5 +557,5 @@ delete testSubject[1]; | ||
}); | ||
describe('Array object', function() { | ||
describe('Array object', function () { | ||
it('should call the callback with the proper arguments', function() { | ||
it('should call the callback with the proper arguments', function () { | ||
var callback = jasmine.createSpy('callback'), | ||
@@ -560,9 +566,9 @@ arr = ['1']; | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.filter(function(a) { | ||
arr.filter(function (a) { | ||
i++; | ||
if(i <= 4) { | ||
arr.push(a+3); | ||
if (i <= 4) { | ||
arr.push(a + 3); | ||
} | ||
@@ -574,7 +580,7 @@ return true; | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
var passedValues = {}; | ||
testSubject = [1,2,3,4]; | ||
delete testSubject[1]; | ||
testSubject.filter(function(o, i) { | ||
testSubject.filter(function (o, i) { | ||
passedValues[i] = o; | ||
@@ -585,7 +591,7 @@ return true; | ||
}); | ||
it('should pass the right context to the filter', function() { | ||
it('should pass the right context to the filter', function () { | ||
var passedValues = {}; | ||
testSubject = [1,2,3,4]; | ||
delete testSubject[1]; | ||
testSubject.filter(function(o, i) { | ||
testSubject.filter(function (o, i) { | ||
this[i] = o; | ||
@@ -596,12 +602,12 @@ return true; | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
[1].filter(function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
[1].filter(function () {context = this;}); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should remove only the values for which the callback returns false', function() { | ||
it('should remove only the values for which the callback returns false', function () { | ||
var result = testSubject.filter(callback); | ||
expect(result).toExactlyMatch(filteredArray); | ||
}); | ||
it('should leave the original array untouched', function() { | ||
it('should leave the original array untouched', function () { | ||
var copy = testSubject.slice(); | ||
@@ -612,4 +618,3 @@ testSubject.filter(callback); | ||
it('should not be affected by same-index mutation', function () { | ||
var results = [1, 2, 3] | ||
.filter(function (value, index, array) { | ||
var results = [1, 2, 3].filter(function (value, index, array) { | ||
array[index] = 'a'; | ||
@@ -621,7 +626,7 @@ return true; | ||
}); | ||
describe('Array like', function() { | ||
beforeEach(function() { | ||
describe('Array like', function () { | ||
beforeEach(function () { | ||
testSubject = createArrayLikeFromArray(testSubject); | ||
}); | ||
it('should call the callback with the proper arguments', function() { | ||
it('should call the callback with the proper arguments', function () { | ||
var callback = jasmine.createSpy('callback'), | ||
@@ -632,9 +637,9 @@ arr = createArrayLikeFromArray(['1']); | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = createArrayLikeFromArray([1,2,3]), | ||
i = 0; | ||
Array.prototype.filter.call(arr, function(a) { | ||
Array.prototype.filter.call(arr, function (a) { | ||
i++; | ||
if(i <= 4) { | ||
arr[i+2] = a+3; | ||
if (i <= 4) { | ||
arr[i + 2] = a + 3; | ||
} | ||
@@ -647,7 +652,7 @@ return true; | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
var passedValues = {}; | ||
testSubject = createArrayLikeFromArray([1,2,3,4]); | ||
delete testSubject[1]; | ||
Array.prototype.filter.call(testSubject, function(o, i) { | ||
Array.prototype.filter.call(testSubject, function (o, i) { | ||
passedValues[i] = o; | ||
@@ -659,12 +664,12 @@ return true; | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
Array.prototype.filter.call(createArrayLikeFromArray([1]), function() {context = this;}, undefined); | ||
expect(context).toBe(function() {return this}.call()); | ||
Array.prototype.filter.call(createArrayLikeFromArray([1]), function () {context = this;}, undefined); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should pass the right context to the filter', function() { | ||
it('should pass the right context to the filter', function () { | ||
var passedValues = {}; | ||
testSubject = createArrayLikeFromArray([1,2,3,4]); | ||
delete testSubject[1]; | ||
Array.prototype.filter.call(testSubject, function(o, i) { | ||
Array.prototype.filter.call(testSubject, function (o, i) { | ||
this[i] = o; | ||
@@ -676,7 +681,7 @@ return true; | ||
}); | ||
it('should remove only the values for which the callback returns false', function() { | ||
it('should remove only the values for which the callback returns false', function () { | ||
var result = Array.prototype.filter.call(testSubject, callback); | ||
expect(result).toExactlyMatch(filteredArray); | ||
}); | ||
it('should leave the original array untouched', function() { | ||
it('should leave the original array untouched', function () { | ||
var copy = createArrayLikeFromArray(testSubject); | ||
@@ -687,13 +692,21 @@ Array.prototype.filter.call(testSubject, callback); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.filter.call('foo', function (item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('map', function() { | ||
describe('map', function () { | ||
var callback; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
var i = 0; | ||
callback = function() { | ||
callback = function () { | ||
return i++; | ||
}; | ||
}); | ||
describe('Array object', function() { | ||
it('should call callback with the right parameters', function() { | ||
describe('Array object', function () { | ||
it('should call callback with the right parameters', function () { | ||
var callback = jasmine.createSpy('callback'), | ||
@@ -704,5 +717,5 @@ array = [1]; | ||
}); | ||
it('should set the context correctly', function() { | ||
it('should set the context correctly', function () { | ||
var context = {}; | ||
testSubject.map(function(o,i) { | ||
testSubject.map(function (o,i) { | ||
this[i] = o; | ||
@@ -712,8 +725,8 @@ }, context); | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
[1].map(function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
[1].map(function () {context = this;}); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should not change the array it is called on', function() { | ||
it('should not change the array it is called on', function () { | ||
var copy = testSubject.slice(); | ||
@@ -723,24 +736,24 @@ testSubject.map(callback); | ||
}); | ||
it('should only run for the number of objects in the array when it started', function() { | ||
it('should only run for the number of objects in the array when it started', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.map(function(o) { | ||
arr.push(o+3); | ||
arr.map(function (o) { | ||
arr.push(o + 3); | ||
i++; | ||
return o; | ||
}); | ||
expect(arr).toExactlyMatch([1,2,3,4,5,6]); | ||
expect(arr).toExactlyMatch([1, 2, 3, 4, 5, 6]); | ||
expect(i).toBe(3); | ||
}); | ||
it('should properly translate the values as according to the callback', function() { | ||
it('should properly translate the values as according to the callback', function () { | ||
var result = testSubject.map(callback), | ||
expected = [0,0,1,2,3,4,5,6]; | ||
expected = [0, 0, 1, 2, 3, 4, 5, 6]; | ||
delete expected[1]; | ||
expect(result).toExactlyMatch(expected); | ||
}); | ||
it('should skip non-existing values', function() { | ||
var array = [1,2,3,4], | ||
it('should skip non-existing values', function () { | ||
var array = [1, 2, 3, 4], | ||
i = 0; | ||
delete array[2]; | ||
array.map(function() { | ||
array.map(function () { | ||
i++; | ||
@@ -751,7 +764,7 @@ }); | ||
}); | ||
describe('Array-like', function() { | ||
beforeEach(function() { | ||
describe('Array-like', function () { | ||
beforeEach(function () { | ||
testSubject = createArrayLikeFromArray(testSubject); | ||
}); | ||
it('should call callback with the right parameters', function() { | ||
it('should call callback with the right parameters', function () { | ||
var callback = jasmine.createSpy('callback'), | ||
@@ -762,5 +775,5 @@ array = createArrayLikeFromArray([1]); | ||
}); | ||
it('should set the context correctly', function() { | ||
it('should set the context correctly', function () { | ||
var context = {}; | ||
Array.prototype.map.call(testSubject, function(o,i) { | ||
Array.prototype.map.call(testSubject, function (o,i) { | ||
this[i] = o; | ||
@@ -771,8 +784,8 @@ }, context); | ||
}); | ||
it('should set the right context when given none', function() { | ||
it('should set the right context when given none', function () { | ||
var context; | ||
Array.prototype.map.call(createArrayLikeFromArray([1]), function() {context = this;}); | ||
expect(context).toBe(function() {return this}.call()); | ||
Array.prototype.map.call(createArrayLikeFromArray([1]), function () {context = this;}); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('should not change the array it is called on', function() { | ||
it('should not change the array it is called on', function () { | ||
var copy = createArrayLikeFromArray(testSubject); | ||
@@ -782,7 +795,7 @@ Array.prototype.map.call(testSubject, callback); | ||
}); | ||
it('should only run for the number of objects in the array when it started', function() { | ||
var arr = createArrayLikeFromArray([1,2,3]), | ||
it('should only run for the number of objects in the array when it started', function () { | ||
var arr = createArrayLikeFromArray([1, 2, 3]), | ||
i = 0; | ||
Array.prototype.map.call(arr, function(o) { | ||
Array.prototype.push.call(arr, o+3); | ||
Array.prototype.map.call(arr, function (o) { | ||
Array.prototype.push.call(arr, o + 3); | ||
i++; | ||
@@ -795,3 +808,3 @@ return o; | ||
}); | ||
it('should properly translate the values as according to the callback', function() { | ||
it('should properly translate the values as according to the callback', function () { | ||
var result = Array.prototype.map.call(testSubject, callback), | ||
@@ -802,7 +815,7 @@ expected = [0,0,1,2,3,4,5,6]; | ||
}); | ||
it('should skip non-existing values', function() { | ||
it('should skip non-existing values', function () { | ||
var array = createArrayLikeFromArray([1,2,3,4]), | ||
i = 0; | ||
delete array[2]; | ||
Array.prototype.map.call(array, function() { | ||
Array.prototype.map.call(array, function () { | ||
i++; | ||
@@ -813,11 +826,19 @@ }); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.map.call('foo', function (item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('reduce', function() { | ||
beforeEach(function() { | ||
describe('reduce', function () { | ||
beforeEach(function () { | ||
testSubject = [1,2,3]; | ||
}); | ||
describe('Array', function() { | ||
it('should pass the correct arguments to the callback', function() { | ||
describe('Array', function () { | ||
it('should pass the correct arguments to the callback', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -827,3 +848,3 @@ testSubject.reduce(spy); | ||
}); | ||
it('should start with the right initialValue', function() { | ||
it('should start with the right initialValue', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -833,10 +854,10 @@ testSubject.reduce(spy, 0); | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.reduce(function(a, b) { | ||
arr.reduce(function (a, b) { | ||
i++; | ||
if(i <= 4) { | ||
arr.push(a+3); | ||
}; | ||
if (i <= 4) { | ||
arr.push(a + 3); | ||
} | ||
return b; | ||
@@ -847,5 +868,5 @@ }); | ||
}); | ||
it('should work as expected for empty arrays', function() { | ||
it('should work as expected for empty arrays', function () { | ||
var spy = jasmine.createSpy(); | ||
expect(function() { | ||
expect(function () { | ||
[].reduce(spy); | ||
@@ -855,42 +876,40 @@ }).toThrow(); | ||
}); | ||
it('should throw correctly if no callback is given', function() { | ||
expect(function() { | ||
it('should throw correctly if no callback is given', function () { | ||
expect(function () { | ||
testSubject.reduce(); | ||
}).toThrow(); | ||
}); | ||
it('should return the expected result', function() { | ||
expect(testSubject.reduce(function(a,b) { | ||
return (a||'').toString()+(b||'').toString(); | ||
it('should return the expected result', function () { | ||
expect(testSubject.reduce(function (a, b) { | ||
return String(a || '') + String(b || ''); | ||
})).toEqual(testSubject.join('')); | ||
}); | ||
it('should not directly affect the passed array', function() { | ||
it('should not directly affect the passed array', function () { | ||
var copy = testSubject.slice(); | ||
testSubject.reduce(function(a,b) { | ||
return a+b; | ||
testSubject.reduce(function (a, b) { | ||
return a + b; | ||
}); | ||
expect(testSubject).toEqual(copy); | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
delete testSubject[1]; | ||
var visited = {}; | ||
testSubject.reduce(function(a,b) { | ||
if(a) | ||
visited[a] = true; | ||
if(b) | ||
visited[b] = true; | ||
testSubject.reduce(function (a, b) { | ||
if (a) { visited[a] = true; } | ||
if (b) { visited[b] = true; } | ||
return 0; | ||
}); | ||
expect(visited).toEqual({ '1': true, '3': true }); | ||
expect(visited).toEqual({ 1: true, 3: true }); | ||
}); | ||
it('should have the right length', function() { | ||
it('should have the right length', function () { | ||
expect(testSubject.reduce.length).toBe(1); | ||
}); | ||
}); | ||
describe('Array-like objects', function() { | ||
beforeEach(function() { | ||
describe('Array-like objects', function () { | ||
beforeEach(function () { | ||
testSubject = createArrayLikeFromArray(testSubject); | ||
testSubject.reduce = Array.prototype.reduce; | ||
}); | ||
it('should pass the correct arguments to the callback', function() { | ||
it('should pass the correct arguments to the callback', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -900,3 +919,3 @@ testSubject.reduce(spy); | ||
}); | ||
it('should start with the right initialValue', function() { | ||
it('should start with the right initialValue', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -906,10 +925,10 @@ testSubject.reduce(spy, 0); | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = createArrayLikeFromArray([1,2,3]), | ||
i = 0; | ||
Array.prototype.reduce.call(arr, function(a, b) { | ||
Array.prototype.reduce.call(arr, function (a, b) { | ||
i++; | ||
if(i <= 4) { | ||
arr[i+2] = a+3; | ||
}; | ||
if (i <= 4) { | ||
arr[i + 2] = a + 3; | ||
} | ||
return b; | ||
@@ -927,5 +946,5 @@ }); | ||
}); | ||
it('should work as expected for empty arrays', function() { | ||
it('should work as expected for empty arrays', function () { | ||
var spy = jasmine.createSpy(); | ||
expect(function() { | ||
expect(function () { | ||
Array.prototype.reduce.call({length: 0}, spy); | ||
@@ -935,16 +954,16 @@ }).toThrow(); | ||
}); | ||
it('should throw correctly if no callback is given', function() { | ||
expect(function() { | ||
it('should throw correctly if no callback is given', function () { | ||
expect(function () { | ||
testSubject.reduce(); | ||
}).toThrow(); | ||
}); | ||
it('should return the expected result', function() { | ||
expect(testSubject.reduce(function(a,b) { | ||
return (a||'').toString()+(b||'').toString(); | ||
it('should return the expected result', function () { | ||
expect(testSubject.reduce(function (a, b) { | ||
return String(a || '') + String(b || ''); | ||
})).toEqual('123'); | ||
}); | ||
it('should not directly affect the passed array', function() { | ||
it('should not directly affect the passed array', function () { | ||
var copy = createArrayLikeFromArray(testSubject); | ||
testSubject.reduce(function(a,b) { | ||
return a+b; | ||
testSubject.reduce(function (a, b) { | ||
return a + b; | ||
}); | ||
@@ -954,27 +973,33 @@ delete(testSubject.reduce); | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
delete testSubject[1]; | ||
var visited = {}; | ||
testSubject.reduce(function(a,b) { | ||
if(a) | ||
visited[a] = true; | ||
if(b) | ||
visited[b] = true; | ||
testSubject.reduce(function (a, b) { | ||
if (a) { visited[a] = true; } | ||
if (b) { visited[b] = true; } | ||
return 0; | ||
}); | ||
expect(visited).toEqual({ '1': true, '3': true }); | ||
expect(visited).toEqual({ 1: true, 3: true }); | ||
}); | ||
it('should have the right length', function() { | ||
it('should have the right length', function () { | ||
expect(testSubject.reduce.length).toBe(1); | ||
}); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.reduce.call('foo', function (accumulator, item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('reduceRight', function() { | ||
beforeEach(function() { | ||
describe('reduceRight', function () { | ||
beforeEach(function () { | ||
testSubject = [1,2,3]; | ||
}); | ||
describe('Array', function() { | ||
it('should pass the correct arguments to the callback', function() { | ||
describe('Array', function () { | ||
it('should pass the correct arguments to the callback', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -984,3 +1009,3 @@ testSubject.reduceRight(spy); | ||
}); | ||
it('should start with the right initialValue', function() { | ||
it('should start with the right initialValue', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -990,10 +1015,10 @@ testSubject.reduceRight(spy, 0); | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = [1,2,3], | ||
i = 0; | ||
arr.reduceRight(function(a, b) { | ||
arr.reduceRight(function (a, b) { | ||
i++; | ||
if(i <= 4) { | ||
arr.push(a+3); | ||
}; | ||
if (i <= 4) { | ||
arr.push(a + 3); | ||
} | ||
return b; | ||
@@ -1004,5 +1029,5 @@ }); | ||
}); | ||
it('should work as expected for empty arrays', function() { | ||
it('should work as expected for empty arrays', function () { | ||
var spy = jasmine.createSpy(); | ||
expect(function() { | ||
expect(function () { | ||
[].reduceRight(spy); | ||
@@ -1012,3 +1037,3 @@ }).toThrow(); | ||
}); | ||
it('should work as expected for empty arrays with an initial value', function() { | ||
it('should work as expected for empty arrays with an initial value', function () { | ||
var spy = jasmine.createSpy(), | ||
@@ -1021,42 +1046,40 @@ result; | ||
}); | ||
it('should throw correctly if no callback is given', function() { | ||
expect(function() { | ||
it('should throw correctly if no callback is given', function () { | ||
expect(function () { | ||
testSubject.reduceRight(); | ||
}).toThrow(); | ||
}); | ||
it('should return the expected result', function() { | ||
expect(testSubject.reduceRight(function(a,b) { | ||
return (a||'').toString()+(b||'').toString(); | ||
})).toEqual('321'); | ||
it('should return the expected result', function () { | ||
expect(testSubject.reduceRight(function (a, b) { | ||
return String(a || '') + String(b || ''); | ||
})).toBe('321'); | ||
}); | ||
it('should not directly affect the passed array', function() { | ||
it('should not directly affect the passed array', function () { | ||
var copy = testSubject.slice(); | ||
testSubject.reduceRight(function(a,b) { | ||
return a+b; | ||
testSubject.reduceRight(function (a, b) { | ||
return a + b; | ||
}); | ||
expect(testSubject).toEqual(copy); | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
delete testSubject[1]; | ||
var visited = {}; | ||
testSubject.reduceRight(function(a,b) { | ||
if(a) | ||
visited[a] = true; | ||
if(b) | ||
visited[b] = true; | ||
testSubject.reduceRight(function (a, b) { | ||
if (a) { visited[a] = true; } | ||
if (b) { visited[b] = true; } | ||
return 0; | ||
}); | ||
expect(visited).toEqual({ '1': true, '3': true }); | ||
expect(visited).toEqual({ 1: true, 3: true }); | ||
}); | ||
it('should have the right length', function() { | ||
it('should have the right length', function () { | ||
expect(testSubject.reduceRight.length).toBe(1); | ||
}); | ||
}); | ||
describe('Array-like objects', function() { | ||
beforeEach(function() { | ||
describe('Array-like objects', function () { | ||
beforeEach(function () { | ||
testSubject = createArrayLikeFromArray(testSubject); | ||
testSubject.reduceRight = Array.prototype.reduceRight; | ||
}); | ||
it('should pass the correct arguments to the callback', function() { | ||
it('should pass the correct arguments to the callback', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -1066,3 +1089,3 @@ testSubject.reduceRight(spy); | ||
}); | ||
it('should start with the right initialValue', function() { | ||
it('should start with the right initialValue', function () { | ||
var spy = jasmine.createSpy().andReturn(0); | ||
@@ -1072,10 +1095,10 @@ testSubject.reduceRight(spy, 0); | ||
}); | ||
it('should not affect elements added to the array after it has begun', function() { | ||
it('should not affect elements added to the array after it has begun', function () { | ||
var arr = createArrayLikeFromArray([1,2,3]), | ||
i = 0; | ||
Array.prototype.reduceRight.call(arr, function(a, b) { | ||
Array.prototype.reduceRight.call(arr, function (a, b) { | ||
i++; | ||
if(i <= 4) { | ||
arr[i+2] = a+3; | ||
}; | ||
if (i <= 4) { | ||
arr[i + 2] = a + 3; | ||
} | ||
return b; | ||
@@ -1093,5 +1116,5 @@ }); | ||
}); | ||
it('should work as expected for empty arrays', function() { | ||
it('should work as expected for empty arrays', function () { | ||
var spy = jasmine.createSpy(); | ||
expect(function() { | ||
expect(function () { | ||
Array.prototype.reduceRight.call({length:0}, spy); | ||
@@ -1101,16 +1124,16 @@ }).toThrow(); | ||
}); | ||
it('should throw correctly if no callback is given', function() { | ||
expect(function() { | ||
it('should throw correctly if no callback is given', function () { | ||
expect(function () { | ||
testSubject.reduceRight(); | ||
}).toThrow(); | ||
}); | ||
it('should return the expected result', function() { | ||
expect(testSubject.reduceRight(function(a,b) { | ||
return (a||'').toString()+(b||'').toString(); | ||
it('should return the expected result', function () { | ||
expect(testSubject.reduceRight(function (a, b) { | ||
return String(a || '') + String(b || ''); | ||
})).toEqual('321'); | ||
}); | ||
it('should not directly affect the passed array', function() { | ||
it('should not directly affect the passed array', function () { | ||
var copy = createArrayLikeFromArray(testSubject); | ||
testSubject.reduceRight(function(a,b) { | ||
return a+b; | ||
testSubject.reduceRight(function (a, b) { | ||
return a + b; | ||
}); | ||
@@ -1120,31 +1143,35 @@ delete(testSubject.reduceRight); | ||
}); | ||
it('should skip non-set values', function() { | ||
it('should skip non-set values', function () { | ||
delete testSubject[1]; | ||
var visited = {}; | ||
testSubject.reduceRight(function(a,b) { | ||
if(a) | ||
visited[a] = true; | ||
if(b) | ||
visited[b] = true; | ||
testSubject.reduceRight(function (a, b) { | ||
if (a) { visited[a] = true; } | ||
if (b) { visited[b] = true; } | ||
return 0; | ||
}); | ||
expect(visited).toEqual({ '1': true, '3': true }); | ||
expect(visited).toEqual({ 1: true, 3: true }); | ||
}); | ||
it('should have the right length', function() { | ||
it('should have the right length', function () { | ||
expect(testSubject.reduceRight.length).toBe(1); | ||
}); | ||
}); | ||
it('should have a boxed object as list argument of callback', function () { | ||
var actual; | ||
Array.prototype.reduceRight.call('foo', function (accumulator, item, index, list) { | ||
actual = list; | ||
}); | ||
expect(typeof actual).toBe('object'); | ||
expect(toString.call(actual)).toBe('[object String]'); | ||
}); | ||
}); | ||
describe('isArray', function () { | ||
it('should work for Array', function () { | ||
var ret = Array.isArray([]); | ||
expect(ret).toBe(true); | ||
it('should be true for Array', function () { | ||
expect(Array.isArray([])).toBe(true); | ||
}); | ||
it('should fail for other objects', function () { | ||
var objects = [ | ||
"someString", | ||
it('should be false for primitives', function () { | ||
var primitives = [ | ||
'foo', | ||
true, | ||
@@ -1154,8 +1181,21 @@ false, | ||
0, | ||
-0, | ||
NaN, | ||
Infinity, | ||
-Infinity | ||
]; | ||
primitives.forEach(function (v) { | ||
expect(Array.isArray(v)).toBe(false); | ||
}); | ||
}); | ||
it('should fail for other objects', function () { | ||
var objects = [ | ||
{}, | ||
Object.create && Object.create(null) || null, | ||
/foo/, | ||
arguments, | ||
document.getElementsByTagName("div") | ||
arguments | ||
]; | ||
if (Object.create) { | ||
objects.push(Object.create(null)); | ||
} | ||
@@ -1166,2 +1206,9 @@ objects.forEach(function (v) { | ||
}); | ||
if (typeof document !== 'undefined') { | ||
it('should be false for an HTML element', function () { | ||
var el = document.getElementsByTagName('div'); | ||
expect(Array.isArray(el)).toBe(false); | ||
}); | ||
} | ||
}); | ||
@@ -1171,3 +1218,3 @@ | ||
it('should return length', function () { | ||
expect([].unshift(0)).toEqual(1); | ||
expect([].unshift(0)).toBe(1); | ||
}); | ||
@@ -1181,18 +1228,31 @@ }); | ||
var makeArray = function(l, prefix) { | ||
var makeArray = function (l, prefix) { | ||
prefix = prefix || ""; | ||
var a = []; | ||
while (l--) { | ||
a.unshift(prefix + Array(l + 1).join(" ") + l) | ||
a.unshift(prefix + Array(l + 1).join(" ") + l); | ||
} | ||
return a | ||
return a; | ||
}; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
test = a.slice(0); | ||
}); | ||
it('has the right length', function () { | ||
expect(Array.prototype.splice.length).toBe(2); | ||
}); | ||
/* This test is disabled, because ES6 normalizes actual | ||
* browser behavior, contradicting ES5. | ||
*/ | ||
xit('treats undefined deleteCount as 0', function () { | ||
expect(test.splice(0).length).toBe(0); | ||
expect(test.splice(0)).toEqual(test.splice(0, 0)); | ||
}); | ||
it('basic implementation test 1', function () { | ||
expect(test.splice(0)).toEqual(a); | ||
expect(test.splice(0, 0)).toEqual([]); | ||
}); | ||
it('basic implementation test 2', function () { | ||
@@ -1204,63 +1264,57 @@ test.splice(0, 2); | ||
it('should return right result 1', function () { | ||
expect((function() { | ||
var array = []; | ||
var array = []; | ||
array.splice(0, 0, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); | ||
array.splice(1, 0, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26"); | ||
array.splice(5, 0, "XXX"); | ||
array.splice(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); | ||
array.splice(1, 0, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26"); | ||
array.splice(5, 0, "XXX"); | ||
return array.join("|"); | ||
}())).toBe("1|F1|F2|F3|F4|XXX|F5|F6|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|F25|F26|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20"); | ||
expect(array).toEqual([1, 'F1', 'F2', 'F3', 'F4', 'XXX', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24', 'F25', 'F26', 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]); | ||
}); | ||
it('should return right result 2', function () { | ||
expect((function() { | ||
var array = makeArray(6); | ||
var array = makeArray(6); | ||
array.splice(array.length - 1, 1, ""); | ||
array.splice(0, 1, 1,2,3,4); | ||
array.splice(0, 0, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21, 22, 23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45); | ||
array.splice(array.length - 1, 1, ""); | ||
array.splice(0, 1, 1, 2, 3, 4); | ||
array.splice(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45); | ||
array.splice(4, 0, "99999999999999"); | ||
return array.join("|"); | ||
}())).toBe("1|2|3|4|99999999999999|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|1|2|3|4| 1| 2| 3| 4|"); | ||
array.splice(4, 0, "99999999999999"); | ||
expect(array).toEqual([1, 2, 3, 4, '99999999999999', 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 1, 2, 3, 4, ' 1', ' 2', ' 3', ' 4', '']); | ||
}); | ||
it('should return right result 3', function () { | ||
expect((function() { | ||
var array = [1,2,3]; | ||
var array = [1, 2, 3]; | ||
array.splice(0); | ||
array.splice(0, 1, 1,2,3,4,5,6,7,8,9,10); | ||
array.splice(1, 1, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26"); | ||
array.splice(5, 1, "YYY", "XXX"); | ||
array.splice(0, 1); | ||
array.splice(0, 2); | ||
array.pop(); | ||
array.push.apply(array, makeArray(10, "-")); | ||
array.splice(array.length - 2, 10); | ||
array.splice(); | ||
array.splice(1, 1, 1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9); | ||
array.splice(1, 1, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26",1,23,4,5,6,7,8); | ||
array.splice(30, 10); | ||
array.splice(30, 1); | ||
array.splice(30, 0); | ||
array.splice(2, 5, 1,2,3,"P", "LLL", "CCC", "YYY", "XXX"); | ||
array.push(1,2,3,4,5,6); | ||
array.splice(1, 6, 1,2,3,4,5,6,7,8,9,4,5,6,7,8,9); | ||
array.splice(3, 7); | ||
array.unshift(7,8,9,10,11); | ||
array.pop(); | ||
array.splice(5, 2); | ||
array.pop(); | ||
array.unshift.apply(array, makeArray(8, "~")); | ||
array.pop(); | ||
array.splice(3, 1, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26",1,23,4,5,6,7,8); | ||
array.splice(4, 5, "P", "LLL", "CCC", "YYY", "XXX"); | ||
array.splice(0, array.length); | ||
array.splice(0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
array.splice(1, 1, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21","F22", "F23", "F24", "F25", "F26"); | ||
array.splice(5, 1, "YYY", "XXX"); | ||
array.splice(0, 1); | ||
array.splice(0, 2); | ||
array.pop(); | ||
array.push.apply(array, makeArray(10, "-")); | ||
array.splice(array.length - 2, 10); | ||
array.splice(); | ||
array.splice(1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9); | ||
array.splice(1, 1, 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24', 'F25', 'F26', 1, 23, 4, 5, 6, 7, 8); | ||
array.splice(30, 10); | ||
array.splice(30, 1); | ||
array.splice(30, 0); | ||
array.splice(2, 5, 1, 2, 3, 'P', 'LLL', 'CCC', 'YYY', 'XXX'); | ||
array.push(1, 2, 3, 4, 5, 6); | ||
array.splice(1, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9); | ||
array.splice(3, 7); | ||
array.unshift(7, 8, 9, 10, 11); | ||
array.pop(); | ||
array.splice(5, 2); | ||
array.pop(); | ||
array.unshift.apply(array, makeArray(8, '~')); | ||
array.pop(); | ||
array.splice(3, 1, 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21','F22', 'F23', 'F24', 'F25', 'F26', 1, 23, 4, 5, 6, 7, 8); | ||
array.splice(4, 5, 'P', 'LLL', 'CCC', 'YYY', 'XXX'); | ||
return array.join("|"); | ||
}())).toBe("~0|~ 1|~ 2|F1|P|LLL|CCC|YYY|XXX|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|F25|F26|1|23|4|5|6|7|8|~ 4|~ 5|~ 6|~ 7|7|8|9|10|11|2|4|5|6|7|8|9|CCC|YYY|XXX|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|F25|F26|1|23|4|9|10|1|2|3|4|5|6|7|8|9|YYY|XXX|F6|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|F25|F26|3|4|5|6|7|8|9|-0|- 1|- 2|- 3|- 4|- 5|- 6|- 7|1|2|3"); | ||
expect(array).toEqual(['~0', '~ 1', '~ 2', 'F1', 'P', 'LLL', 'CCC', 'YYY', 'XXX', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24', 'F25', 'F26', 1, 23, 4, 5, 6, 7, 8, '~ 4', '~ 5', '~ 6', '~ 7', 7, 8, 9, 10, 11, 2, 4, 5, 6, 7, 8, 9, 'CCC', 'YYY', 'XXX', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24', 'F25', 'F26', 1, 23, 4, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'YYY', 'XXX', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24', 'F25', 'F26', 3, 4, 5, 6, 7, 8, 9, '-0', '- 1', '- 2', '- 3', '- 4', '- 5', '- 6', '- 7', 1, 2, 3]); | ||
}); | ||
it('should do nothing if method called with no arguments', function () { | ||
@@ -1270,3 +1324,3 @@ expect(test.splice()).toEqual([]); | ||
}); | ||
//TODO:: Is this realy TRUE behavior? | ||
it('should set first argument to 0 if first argument is set but undefined', function () { | ||
@@ -1278,13 +1332,26 @@ var test2 = test.slice(0); | ||
it('should deleted and return all items after "start" when second argument is undefined', function () { | ||
expect(test.splice(0)).toEqual(a); | ||
expect(test).toEqual([]); | ||
it('should work with objects - adding 1', function () { | ||
var obj = {}; | ||
Array.prototype.splice.call(obj, 0, 0, 1, 2, 3); | ||
expect(obj.length).toBe(3); | ||
}); | ||
it('should deleted and return all items after "start" when second argument is undefined', function () { | ||
expect(test.splice(2)).toEqual([b]); | ||
expect(test).toEqual([1, "a"]); | ||
it('should work with objects - adding 2', function () { | ||
var obj = { 0: 1, length: 1 }; | ||
Array.prototype.splice.call(obj, 1, 0, 2, 3); | ||
expect(obj.length).toBe(3); | ||
}); | ||
it('runshould have the right length', function () { | ||
expect(test.splice.length).toBe(2); | ||
it('should work with objects - removing', function () { | ||
var obj = { 0: 1, 1: 2, 2: 3, length: 3 }; | ||
Array.prototype.splice.call(obj, 0, 3); | ||
expect(obj.length).toBe(0); | ||
}); | ||
it('should work with objects - replacing', function () { | ||
var obj = { 0: 99, length: 1 }; | ||
Array.prototype.splice.call(obj, 0, 1, 1, 2, 3); | ||
expect(obj.length).toBe(3); | ||
expect(obj[0]).toBe(1); | ||
}); | ||
}); | ||
@@ -1291,0 +1358,0 @@ |
describe('Date', function () { | ||
describe('now', function () { | ||
it('should be the current time', function () { | ||
expect(Date.now() === new Date().getTime()).toBe(true); | ||
var before = (new Date()).getTime(); | ||
var middle = Date.now(); | ||
var after = (new Date()).getTime(); | ||
expect(middle).not.toBeLessThan(before); | ||
expect(middle).not.toBeGreaterThan(after); | ||
}); | ||
@@ -13,3 +17,2 @@ }); | ||
it('should support extended years', function () { | ||
expect(Date.parse('0001-01-01T00:00:00Z')).toBe(-62135596800000); | ||
@@ -20,15 +23,8 @@ expect(Date.parse('+275760-09-13T00:00:00.000Z')).toBe(8.64e15); | ||
expect(Date.parse('+002009-12-15T00:00:00Z')).toBe(1260835200000); | ||
}); | ||
it('should work', function () { | ||
it('should be an invalid date', function () { | ||
//Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 | ||
expect(Date.parse("2012-11-31T23:59:59.000Z")).toBeFalsy(); //1354406399000 NaN NaN 1354406399000 NaN | ||
expect(Date.parse("2012-12-31T23:59:59.000Z")).toBe(1356998399000); //1356998399000 1356998399000 1356998399000 1356998399000 1356998399000 | ||
expect(Date.parse("2012-12-31T23:59:60.000Z")).toBeFalsy(); //NaN NaN NaN NaN 1356998400000 | ||
expect(Date.parse("2012-04-04T05:02:02.170Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.170999Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.17Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.1Z")).toBe(1333515722100); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T24:00:00.000Z")).toBe(1333584000000); //NaN 1333584000000 1333584000000 1333584000000 1333584000000 | ||
expect(Date.parse("2012-04-04T24:00:00.500Z")).toBeFalsy(); //NaN NaN 1333584000500 1333584000500 NaN | ||
@@ -44,7 +40,24 @@ expect(Date.parse("2012-12-31T10:08:60.000Z")).toBeFalsy(); //NaN NaN NaN NaN 1356948540000 | ||
expect(Date.parse("2012-12-00T23:59:59.000Z")).toBeFalsy(); //NaN NaN NaN NaN NaN | ||
expect(Date.parse("2011-02-29T12:00:00.000Z")).toBeFalsy(); //1298980800000 NaN NaN 1298980800000 NaN | ||
}); | ||
it('should work', function () { | ||
//Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 | ||
expect(Date.parse("2012-12-31T23:59:59.000Z")).toBe(1356998399000); //1356998399000 1356998399000 1356998399000 1356998399000 1356998399000 | ||
expect(Date.parse("2012-04-04T05:02:02.170Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.170999Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.17Z")).toBe(1333515722170); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T05:02:02.1Z")).toBe(1333515722100); //1333515722170 1333515722170 1333515722170 1333515722170 1333515722170 | ||
expect(Date.parse("2012-04-04T24:00:00.000Z")).toBe(1333584000000); //NaN 1333584000000 1333584000000 1333584000000 1333584000000 | ||
expect(Date.parse("2012-02-29T12:00:00.000Z")).toBe(1330516800000); //1330516800000 1330516800000 1330516800000 1330516800000 1330516800000 | ||
expect(Date.parse("2011-02-29T12:00:00.000Z")).toBeFalsy(); //1298980800000 NaN NaN 1298980800000 NaN | ||
expect(Date.parse("2011-03-01T12:00:00.000Z")).toBe(1298980800000); //1298980800000 1298980800000 1298980800000 1298980800000 1298980800000 | ||
// extended years: | ||
// https://github.com/es-shims/es5-shim/issues/80 Safari bug with leap day | ||
expect(Date.parse("2034-03-01T00:00:00.000Z") - | ||
Date.parse("2034-02-27T23:59:59.999Z")).toBe(86400001); //86400001 86400001 86400001 86400001 1 | ||
}); | ||
it('should support extended years', function () { | ||
//Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 | ||
expect(Date.parse("0000-01-01T00:00:00.000Z")).toBe(-621672192e5); //-621672192e5 -621672192e5 -621672192e5 -621672192e5 -621672192e5 | ||
@@ -55,8 +68,6 @@ expect(Date.parse("+275760-09-13T00:00:00.000Z")).toBe(8.64e15); //8.64e15 NaN 8.64e15 8.64e15 8.64e15 | ||
expect(Date.parse("-271821-04-19T23:59:59.999Z")).toBeFalsy(); //NaN NaN NaN -8.64e15 - 1 -8.6400000864e15 - 1 | ||
}); | ||
// https://github.com/kriskowal/es5-shim/issues/80 Safari bug with leap day | ||
expect(Date.parse("2034-03-01T00:00:00.000Z") - | ||
Date.parse("2034-02-27T23:59:59.999Z")).toBe(86400001); //86400001 86400001 86400001 86400001 1 | ||
// Time Zone Offset | ||
it('works with timezone offsets', function () { | ||
//Chrome 19 Opera 12 Firefox 11 IE 9 Safari 5.1.1 | ||
expect(Date.parse("2012-01-29T12:00:00.000+01:00")).toBe(132783480e4);//132783480e4 132783480e4 132783480e4 132783480e4 132783480e4 | ||
@@ -82,3 +93,3 @@ expect(Date.parse("2012-01-29T12:00:00.000-00:00")).toBe(132783840e4);//132783840e4 132783840e4 132783840e4 132783840e4 132783840e4 | ||
it("should be able to coerce to a number", function(){ | ||
it("should be able to coerce to a number", function () { | ||
var actual = Number(new Date(1970, 0)); | ||
@@ -93,8 +104,10 @@ var expected = parseInt(actual, 10); | ||
describe("toString", function(){ | ||
var actual = (new Date(1970, 0)).toString(); | ||
beforeEach(function(){ | ||
describe("toString", function () { | ||
var actual; | ||
beforeEach(function () { | ||
actual = (new Date(1970, 0)).toString(); | ||
}); | ||
it("should show correct date info for "+actual, function(){ | ||
it("should show correct date info for " + actual, function () { | ||
expect(actual).toMatch(/1970/); | ||
@@ -107,10 +120,19 @@ expect(actual).toMatch(/jan/i); | ||
describe("valueOf", function(){ | ||
var actual = (new Date(1970, 0)); | ||
beforeEach(function(){ | ||
describe("valueOf", function () { | ||
// Note that new Date(1970, 0).valueOf() is 0 in UTC timezone. | ||
// Check check that it's a number (and an int), not that it's "truthy". | ||
var actual; | ||
beforeEach(function () { | ||
actual = (new Date(1970, 0)).valueOf(); | ||
}); | ||
it("should give an int value", function(){ | ||
expect(parseInt(actual, 10)).toBeTruthy(); | ||
it("should give a numeric value", function () { | ||
expect(typeof actual).toBe("number"); | ||
}); | ||
it("should not be NaN", function () { | ||
expect(isNaN(actual)).toBe(false); | ||
}); | ||
it("should give an int value", function () { | ||
expect(actual).toBe(Math.floor(actual)); | ||
}); | ||
}); | ||
@@ -120,3 +142,3 @@ | ||
// TODO: write the rest of the test. | ||
it('should support extended years', function () { | ||
@@ -157,5 +179,5 @@ expect(new Date(-62198755200000).toISOString().indexOf('-000001-01-01')).toBe(0); | ||
expect(JSON.stringify(date.toISOString())).toBe(JSON.stringify(date)); | ||
}) | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,37 +1,48 @@ | ||
describe('Function', function () { | ||
"use strict"; | ||
describe('Function', function() { | ||
"use strict"; | ||
describe('bind', function() { | ||
var actual, expected, | ||
testSubject; | ||
testSubject = { | ||
push: function(o) { | ||
describe('apply', function () { | ||
it('works with arraylike objects', function () { | ||
var arrayLike = { length: 4, 0: 1, 2: 4, 3: true }; | ||
var expectedArray = [1, undefined, 4, true]; | ||
var actualArray; | ||
(function () { | ||
actualArray = Array.prototype.slice.apply(arguments); | ||
}).apply(null, arrayLike); | ||
expect(actualArray).toEqual(expectedArray); | ||
}); | ||
}); | ||
describe('bind', function () { | ||
var actual, expected; | ||
var testSubject = { | ||
push: function (o) { | ||
this.a.push(o); | ||
} | ||
}; | ||
function func() { | ||
Array.prototype.forEach.call(arguments, function(a) { | ||
Array.prototype.forEach.call(arguments, function (a) { | ||
this.push(a); | ||
}, this); | ||
return this; | ||
}; | ||
beforeEach(function() { | ||
} | ||
beforeEach(function () { | ||
actual = []; | ||
testSubject.a = []; | ||
}); | ||
it('binds properly without a context', function() { | ||
it('binds properly without a context', function () { | ||
var context; | ||
testSubject.func = function() { | ||
testSubject.func = function () { | ||
context = this; | ||
}.bind(); | ||
testSubject.func(); | ||
expect(context).toBe(function() {return this}.call()); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('binds properly without a context, and still supplies bound arguments', function() { | ||
it('binds properly without a context, and still supplies bound arguments', function () { | ||
var a, context; | ||
testSubject.func = function() { | ||
testSubject.func = function () { | ||
a = Array.prototype.slice.call(arguments); | ||
@@ -42,5 +53,5 @@ context = this; | ||
expect(a).toEqual([1,2,3,1,2,3]); | ||
expect(context).toBe(function() {return this}.call()); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('binds a context properly', function() { | ||
it('binds a context properly', function () { | ||
testSubject.func = func.bind(actual); | ||
@@ -51,3 +62,3 @@ testSubject.func(1,2,3); | ||
}); | ||
it('binds a context and supplies bound arguments', function() { | ||
it('binds a context and supplies bound arguments', function () { | ||
testSubject.func = func.bind(actual, 1,2,3); | ||
@@ -58,13 +69,13 @@ testSubject.func(4,5,6); | ||
}); | ||
it('returns properly without binding a context', function() { | ||
testSubject.func = function() { | ||
it('returns properly without binding a context', function () { | ||
testSubject.func = function () { | ||
return this; | ||
}.bind(); | ||
var context = testSubject.func(); | ||
expect(context).toBe(function() {return this}.call()); | ||
expect(context).toBe(function () { return this; }.call()); | ||
}); | ||
it('returns properly without binding a context, and still supplies bound arguments', function() { | ||
it('returns properly without binding a context, and still supplies bound arguments', function () { | ||
var context; | ||
testSubject.func = function() { | ||
testSubject.func = function () { | ||
context = this; | ||
@@ -74,6 +85,6 @@ return Array.prototype.slice.call(arguments); | ||
actual = testSubject.func(1,2,3); | ||
expect(context).toBe(function() {return this}.call()); | ||
expect(context).toBe(function () { return this; }.call()); | ||
expect(actual).toEqual([1,2,3,1,2,3]); | ||
}); | ||
it('returns properly while binding a context properly', function() { | ||
it('returns properly while binding a context properly', function () { | ||
var ret; | ||
@@ -85,3 +96,3 @@ testSubject.func = func.bind(actual); | ||
}); | ||
it('returns properly while binding a context and supplies bound arguments', function() { | ||
it('returns properly while binding a context and supplies bound arguments', function () { | ||
var ret; | ||
@@ -93,5 +104,14 @@ testSubject.func = func.bind(actual, 1,2,3); | ||
}); | ||
it('passes the correct arguments as a constructor', function() { | ||
it('has the new instance\'s context as a constructor', function () { | ||
var actualContext; | ||
var expectedContext = { foo: 'bar' }; | ||
testSubject.func = function () { | ||
actualContext = this; | ||
}.bind(expectedContext); | ||
var result = new testSubject.func(); | ||
expect(actualContext).not.toBe(expectedContext); | ||
}); | ||
it('passes the correct arguments as a constructor', function () { | ||
var ret, expected = { name: "Correct" }; | ||
testSubject.func = function(arg) { | ||
testSubject.func = function (arg) { | ||
return arg; | ||
@@ -104,51 +124,71 @@ }.bind({ name: "Incorrect" }); | ||
var oracle = [1, 2, 3]; | ||
var subject = function () { | ||
var Subject = function () { | ||
return oracle; | ||
}.bind(null); | ||
var result = new subject; | ||
var result = new Subject(); | ||
expect(result).toBe(oracle); | ||
}); | ||
it('returns the correct value if constructor returns primitive', function() { | ||
it('returns the correct value if constructor returns primitive', function () { | ||
var oracle = [1, 2, 3]; | ||
var subject = function () { | ||
var Subject = function () { | ||
return oracle; | ||
}.bind(null); | ||
var result = new subject; | ||
var result = new Subject(); | ||
expect(result).toBe(oracle); | ||
oracle = {}; | ||
result = new subject; | ||
result = new Subject(); | ||
expect(result).toBe(oracle); | ||
oracle = function(){}; | ||
result = new subject; | ||
oracle = function () {}; | ||
result = new Subject(); | ||
expect(result).toBe(oracle); | ||
oracle = "asdf"; | ||
result = new subject; | ||
result = new Subject(); | ||
expect(result).not.toBe(oracle); | ||
oracle = null; | ||
result = new subject; | ||
result = new Subject(); | ||
expect(result).not.toBe(oracle); | ||
oracle = true; | ||
result = new subject; | ||
result = new Subject(); | ||
expect(result).not.toBe(oracle); | ||
oracle = 1; | ||
result = new subject; | ||
result = new Subject(); | ||
expect(result).not.toBe(oracle); | ||
}); | ||
it('returns the value that instance of original "class" when called as a constructor', function() { | ||
var classA = function(x) { | ||
it('returns the value that instance of original "class" when called as a constructor', function () { | ||
var ClassA = function (x) { | ||
this.name = x || "A"; | ||
} | ||
var classB = classA.bind(null, "B"); | ||
var result = new classB; | ||
expect(result instanceof classA).toBe(true); | ||
expect(result instanceof classB).toBe(true); | ||
}; | ||
var ClassB = ClassA.bind(null, "B"); | ||
var result = new ClassB(); | ||
expect(result instanceof ClassA).toBe(true); | ||
expect(result instanceof ClassB).toBe(true); | ||
}); | ||
it('sets a correct length without thisArg', function () { | ||
var Subject = function (a, b, c) { return a + b + c; }.bind(); | ||
expect(Subject.length).toBe(3); | ||
}); | ||
it('sets a correct length with thisArg', function () { | ||
var Subject = function (a, b, c) { return a + b + c; }.bind({}); | ||
expect(Subject.length).toBe(3); | ||
}); | ||
it('sets a correct length with thisArg and first argument', function () { | ||
var Subject = function (a, b, c) { return a + b + c; }.bind({}, 1); | ||
expect(Subject.length).toBe(2); | ||
}); | ||
it('sets a correct length without thisArg and first argument', function () { | ||
var Subject = function (a, b, c) { return a + b + c; }.bind(undefined, 1); | ||
expect(Subject.length).toBe(2); | ||
}); | ||
it('sets a correct length without thisArg and too many argument', function () { | ||
var Subject = function (a, b, c) { return a + b + c; }.bind(undefined, 1, 2, 3, 4); | ||
expect(Subject.length).toBe(0); | ||
}); | ||
}); | ||
}); |
describe('Number', function () { | ||
'use strict'; | ||
describe('toFixed', function () { | ||
@@ -5,0 +5,0 @@ it('should convert numbers correctly', function () { |
@@ -6,9 +6,9 @@ describe('Object', function () { | ||
var obj = { | ||
"str": "boz", | ||
"obj": { }, | ||
"arr": [], | ||
"bool": true, | ||
"num": 42, | ||
str: "boz", | ||
obj: { }, | ||
arr: [], | ||
bool: true, | ||
num: 42, | ||
"null": null, | ||
"undefined": undefined | ||
undefined: undefined | ||
}; | ||
@@ -26,2 +26,24 @@ | ||
describe('arguments objects', function () { | ||
it('works with an arguments object', function () { | ||
(function () { | ||
expect(arguments.length).toBe(3); | ||
expect(Object.keys(arguments)).toEqual(['0', '1', '2']); | ||
}(1, 2, 3)); | ||
}); | ||
it('works with a legacy arguments object', function () { | ||
var FakeArguments = function (args) { | ||
args.forEach(function (arg, i) { | ||
this[i] = arg; | ||
}.bind(this)); | ||
}; | ||
FakeArguments.prototype.length = 3; | ||
FakeArguments.prototype.callee = function () {}; | ||
var fakeOldArguments = new FakeArguments(['a', 'b', 'c']); | ||
expect(Object.keys(fakeOldArguments)).toEqual(['0', '1', '2']); | ||
}); | ||
}); | ||
it('should return an Array', function () { | ||
@@ -53,5 +75,35 @@ expect(Array.isArray(keys)).toBe(true); | ||
}); | ||
describe('enumerating over non-enumerable properties', function () { | ||
it('has no enumerable keys on a Function', function () { | ||
var Foo = function () {}; | ||
expect(Object.keys(Foo.prototype)).toEqual([]); | ||
}); | ||
it('has no enumerable keys on a boolean', function () { | ||
expect(Object.keys(Boolean.prototype)).toEqual([]); | ||
}); | ||
it('has no enumerable keys on an object', function () { | ||
expect(Object.keys(Object.prototype)).toEqual([]); | ||
}); | ||
}); | ||
it('works with boxed primitives', function () { | ||
expect(Object.keys(new String('hello'))).toEqual(['0', '1', '2', '3', '4']); | ||
expect(Object.keys(Object('hello'))).toEqual(['0', '1', '2', '3', '4']); | ||
}); | ||
it('works with boxed primitives with extra properties', function () { | ||
var x = new String('x'); | ||
x.y = 1; | ||
var actual = Object.keys(x); | ||
var expected = ['0', 'y']; | ||
actual.sort(); | ||
expected.sort(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
describe("Object.isExtensible", function () { | ||
describe("Object.isExtensible", function () { | ||
var obj = { }; | ||
@@ -87,10 +139,10 @@ | ||
describe("Object.defineProperty", function () { | ||
describe("Object.defineProperty", function () { | ||
var obj; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
obj = {}; | ||
Object.defineProperty(obj, 'name', { | ||
value : 'Testing', | ||
value: 'Testing', | ||
configurable: true, | ||
@@ -123,3 +175,3 @@ enumerable: true, | ||
Object.defineProperty(child, 'name', { | ||
value : 'Other' | ||
value: 'Other' | ||
}); | ||
@@ -138,3 +190,3 @@ | ||
describe("Object.getOwnPropertyDescriptor", function () { | ||
describe("Object.getOwnPropertyDescriptor", function () { | ||
it('should return undefined because the object does not own the property', function () { | ||
@@ -165,3 +217,3 @@ var descr = Object.getOwnPropertyDescriptor({}, 'name'); | ||
name: { | ||
value : 'Testing', | ||
value: 'Testing', | ||
configurable: true, | ||
@@ -182,3 +234,3 @@ enumerable: true, | ||
it('should throw error for non object', function () { | ||
it('should throw error for non object', function () { | ||
expect(function () { | ||
@@ -185,0 +237,0 @@ Object.getOwnPropertyDescriptor(42, 'name'); |
@@ -1,16 +0,32 @@ | ||
describe('String', function() { | ||
describe('String', function () { | ||
"use strict"; | ||
describe("trim", function() { | ||
describe("trim", function () { | ||
var test = "\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\uFEFFHello, World!\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"; | ||
it('trims all ES5 whitespace', function() { | ||
it('trims all ES5 whitespace', function () { | ||
expect(test.trim()).toEqual("Hello, World!"); | ||
expect(test.trim().length).toEqual(13); | ||
expect(test.trim().length).toBe(13); | ||
}); | ||
it('does not trim the zero-width space', function () { | ||
expect('\u200b'.trim()).toBe('\u200b'); | ||
expect('\u200b'.trim().length).toBe(1); | ||
}); | ||
}); | ||
describe("split", function() { | ||
describe("replace", function () { | ||
it('returns undefined for non-capturing groups', function () { | ||
var groups = []; | ||
'x'.replace(/x(.)?/g,function (m, group) { | ||
groups.push(group); /* "" in FF, `undefined` in CH/WK/IE */ | ||
}); | ||
expect(groups.length).toBe(1); | ||
expect(groups[0]).toBeUndefined(); | ||
}); | ||
}); | ||
describe("split", function () { | ||
var test = "ab"; | ||
it('If "separator" is undefined must return Array with one String - "this" string', function() { | ||
it('If "separator" is undefined must return Array with one String - "this" string', function () { | ||
expect(test.split()).toEqual([test]); | ||
@@ -20,3 +36,3 @@ expect(test.split(void 0)).toEqual([test]); | ||
it('If "separator" is undefined and "limit" set to 0 must return Array[]', function() { | ||
it('If "separator" is undefined and "limit" set to 0 must return Array[]', function () { | ||
expect(test.split(void 0, 0)).toEqual([]); | ||
@@ -23,0 +39,0 @@ }); |
{ | ||
"name": "jahcode", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Scala like Classes and Traits in JavaScript", | ||
@@ -9,9 +9,16 @@ "author": { | ||
}, | ||
"contributors": [{ | ||
"name": "19 Finger | interactive development", | ||
"url": "http://www.19f.de" | ||
}, { | ||
"name": "redPlant - 3D Realtime Studio", | ||
"url": "http://www.redplant.de" | ||
}], | ||
"contributors": [ | ||
{ | ||
"name": "Baqend - Backend as a Service", | ||
"url": "http://baqend.com" | ||
}, | ||
{ | ||
"name": "19 Finger | interactive development", | ||
"url": "http://www.19f.de" | ||
}, | ||
{ | ||
"name": "redPlant - 3D Realtime Studio", | ||
"url": "http://www.redplant.de" | ||
} | ||
], | ||
"homepage": "http://jahcode.com", | ||
@@ -35,4 +42,10 @@ "licenses": [ | ||
"jasmine-node": "1.7.x", | ||
"uglify-js": "2.3.x" | ||
}, | ||
"uglify-js": "2.3.x", | ||
"karma": "^0.12.19", | ||
"karma-jasmine": "^0.1.5", | ||
"karma-ie-launcher": "^0.1.5", | ||
"karma-firefox-launcher": "^0.1.3", | ||
"karma-chrome-launcher": "^0.1.4", | ||
"karma-phantomjs-launcher": "^0.1.4" | ||
}, | ||
"scripts": { | ||
@@ -39,0 +52,0 @@ "test": "jasmine-node test", |
@@ -219,2 +219,3 @@ require('../jahcode.js'); | ||
expect(err.message).toBe("A test error"); | ||
expect(err.stack.indexOf("A test error")).toBe(0); | ||
@@ -221,0 +222,0 @@ expect(err).isInstanceOf(Error); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
52
391488
8
8080
1