es5-shim-rails 2.0.5.1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWVlZGM0ODM4MGM3MjVkYjcwNzE0NWIxZTQ1NDg1MjlhMmIyNzU4Zg==
5
+ data.tar.gz: !binary |-
6
+ YjMzNGJhZGVhNGQ1MzVlZTJjNDg2MWNjMGRjNzAzM2FjZTdlMzI0Mw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzU5YWJiYzIwYjE0NzM4ZjE1YTYzMDhlOTRkN2NiOTM0OGUyNWEyNTc1OGQ1
10
+ NmNkYjQxYzNmODZlNjlhMzcyYjFkNmMwYmYyMjJjM2MxMTliNWNmZjQ1NzU0
11
+ ODdmYjQxNjQzOTBjNWY4NjQzNTlkYzczZTBlZmY2ZDgzNDg5YzY=
12
+ data.tar.gz: !binary |-
13
+ ZWNlNzM2ZDE4M2Y5NjIzYTRmNGM3NDNjOWZhMGEwMTc5OWRkMmY1OWEzOTA5
14
+ ZmNmMGFjNDhkNjFkNTYwZDU0NDQ1MmFmNmRkYzY2MWM1OTIxN2U5MjcyYWYz
15
+ ZDdlZTAyOWMxMzg5ZTYwNWE1OWM4MGRlZjlmYTA3MzI0YzY3ZjU=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # es5-shim asset gem for Rails
2
2
 
3
- This asset gem packages [es5-shim](https://github.com/kriskowal/es5-shim) for the Rails asset pipeline.
3
+ This asset gem packages [es5-shim](https://github.com/es-shims/es5-shim) for the Rails asset pipeline.
4
4
 
5
5
  ## Installation
6
6
 
@@ -37,7 +37,7 @@ Add one of the folllwing lines to your application.js manifest:
37
37
 
38
38
  ```
39
39
 
40
- Currently this version tracks es5-shim 2.0.5 [commit 6221329363](https://github.com/msievers/es5-shim-rails/commit/62213293633462d04770e658c6e8e4427c67d96a).
40
+ Currently this version tracks es5-shim 4.0.1 [commit 734e4dd](https://github.com/msievers/es5-shim-rails/commit/734e4dd80a1e4cbbd3bb6947c79084e86cb1793b).
41
41
 
42
42
  ## Contributing
43
43
 
@@ -1,7 +1,7 @@
1
1
  module Es5
2
2
  module Shim
3
3
  module Rails
4
- VERSION = "2.0.5.1"
4
+ VERSION = "4.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,44 +1,114 @@
1
- // Copyright 2009-2012 by contributors, MIT License
1
+ /*!
2
+ * https://github.com/es-shims/es5-shim
3
+ * @license es5-shim Copyright 2009-2014 by contributors, MIT License
4
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
5
+ */
6
+
2
7
  // vim: ts=4 sts=4 sw=4 expandtab
3
8
 
4
- // Module systems magic dance
5
- (function (definition) {
6
- // RequireJS
7
- if (typeof define == "function") {
8
- define(definition);
9
- // YUI3
10
- } else if (typeof YUI == "function") {
11
- YUI.add("es5-sham", definition);
12
- // CommonJS and <script>
9
+ //Add semicolon to prevent IIFE from being passed as argument to concated code.
10
+ ;
11
+
12
+ // UMD (Universal Module Definition)
13
+ // see https://github.com/umdjs/umd/blob/master/returnExports.js
14
+ (function (root, factory) {
15
+ if (typeof define === 'function' && define.amd) {
16
+ // AMD. Register as an anonymous module.
17
+ define(factory);
18
+ } else if (typeof exports === 'object') {
19
+ // Node. Does not work with strict CommonJS, but
20
+ // only CommonJS-like enviroments that support module.exports,
21
+ // like Node.
22
+ module.exports = factory();
13
23
  } else {
14
- definition();
15
- }
16
- })(function () {
24
+ // Browser globals (root is window)
25
+ root.returnExports = factory();
26
+ }
27
+ }(this, function () {
28
+
29
+ var call = Function.prototype.call;
30
+ var prototypeOfObject = Object.prototype;
31
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
32
+
33
+ // If JS engine supports accessors creating shortcuts.
34
+ var defineGetter;
35
+ var defineSetter;
36
+ var lookupGetter;
37
+ var lookupSetter;
38
+ var supportsAccessors = owns(prototypeOfObject, "__defineGetter__");
39
+ if (supportsAccessors) {
40
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
41
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
42
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
43
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
44
+ }
17
45
 
18
46
  // ES5 15.2.3.2
19
47
  // http://es5.github.com/#x15.2.3.2
20
48
  if (!Object.getPrototypeOf) {
21
- // https://github.com/kriskowal/es5-shim/issues#issue/2
49
+ // https://github.com/es-shims/es5-shim/issues#issue/2
22
50
  // http://ejohn.org/blog/objectgetprototypeof/
23
51
  // recommended by fschaefer on github
52
+ //
53
+ // sure, and webreflection says ^_^
54
+ // ... this will nerever possibly return null
55
+ // ... Opera Mini breaks here with infinite loops
24
56
  Object.getPrototypeOf = function getPrototypeOf(object) {
25
- return object.__proto__ || (
26
- object.constructor
27
- ? object.constructor.prototype
28
- : prototypeOfObject
29
- );
57
+ var proto = object.__proto__;
58
+ if (proto || proto === null) {
59
+ return proto;
60
+ } else if (object.constructor) {
61
+ return object.constructor.prototype;
62
+ } else {
63
+ return prototypeOfObject;
64
+ }
30
65
  };
31
66
  }
32
67
 
33
- // ES5 15.2.3.3
34
- // http://es5.github.com/#x15.2.3.3
35
- if (!Object.getOwnPropertyDescriptor) {
68
+ //ES5 15.2.3.3
69
+ //http://es5.github.com/#x15.2.3.3
70
+
71
+ function doesGetOwnPropertyDescriptorWork(object) {
72
+ try {
73
+ object.sentinel = 0;
74
+ return Object.getOwnPropertyDescriptor(
75
+ object,
76
+ "sentinel"
77
+ ).value === 0;
78
+ } catch (exception) {
79
+ // returns falsy
80
+ }
81
+ }
82
+
83
+ //check whether getOwnPropertyDescriptor works if it's given. Otherwise,
84
+ //shim partially.
85
+ if (Object.defineProperty) {
86
+ var getOwnPropertyDescriptorWorksOnObject = doesGetOwnPropertyDescriptorWork({});
87
+ var getOwnPropertyDescriptorWorksOnDom = typeof document === "undefined" ||
88
+ doesGetOwnPropertyDescriptorWork(document.createElement("div"));
89
+ if (!getOwnPropertyDescriptorWorksOnDom || !getOwnPropertyDescriptorWorksOnObject) {
90
+ var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
91
+ }
92
+ }
93
+
94
+ if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
36
95
  var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: ";
37
96
 
38
97
  Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
39
- if ((typeof object != "object" && typeof object != "function") || object === null) {
98
+ if ((typeof object !== "object" && typeof object !== "function") || object === null) {
40
99
  throw new TypeError(ERR_NON_OBJECT + object);
41
100
  }
101
+
102
+ // make a valiant attempt to use the real getOwnPropertyDescriptor
103
+ // for I8's DOM elements.
104
+ if (getOwnPropertyDescriptorFallback) {
105
+ try {
106
+ return getOwnPropertyDescriptorFallback.call(Object, object, property);
107
+ } catch (exception) {
108
+ // try the shim if the real one doesn't work
109
+ }
110
+ }
111
+
42
112
  // If object does not owns property return undefined immediately.
43
113
  if (!owns(object, property)) {
44
114
  return;
@@ -57,13 +127,21 @@ if (!Object.getOwnPropertyDescriptor) {
57
127
  // `__proto__` so that `__lookupGetter__` will return getter only
58
128
  // if it's owned by an object.
59
129
  var prototype = object.__proto__;
60
- object.__proto__ = prototypeOfObject;
130
+ var notPrototypeOfObject = object !== prototypeOfObject;
131
+ // avoid recursion problem, breaking in Opera Mini when
132
+ // Object.getOwnPropertyDescriptor(Object.prototype, 'toString')
133
+ // or any other Object.prototype accessor
134
+ if (notPrototypeOfObject) {
135
+ object.__proto__ = prototypeOfObject;
136
+ }
61
137
 
62
138
  var getter = lookupGetter(object, property);
63
139
  var setter = lookupSetter(object, property);
64
140
 
65
- // Once we have getter and setter we can put values back.
66
- object.__proto__ = prototype;
141
+ if (notPrototypeOfObject) {
142
+ // Once we have getter and setter we can put values back.
143
+ object.__proto__ = prototype;
144
+ }
67
145
 
68
146
  if (getter || setter) {
69
147
  if (getter) {
@@ -81,6 +159,7 @@ if (!Object.getOwnPropertyDescriptor) {
81
159
  // If we got this far we know that object has an own property that is
82
160
  // not an accessor so we set it as a value and return descriptor.
83
161
  descriptor.value = object[property];
162
+ descriptor.writable = true;
84
163
  return descriptor;
85
164
  };
86
165
  }
@@ -99,8 +178,11 @@ if (!Object.create) {
99
178
 
100
179
  // Contributed by Brandon Benvie, October, 2012
101
180
  var createEmpty;
102
- var supportsProto = Object.prototype.__proto__ === null;
103
- if (supportsProto || typeof document == 'undefined') {
181
+ var supportsProto = !({__proto__:null} instanceof Object);
182
+ // the following produces false positives
183
+ // in Opera Mini => not a reliable check
184
+ // Object.prototype.__proto__ === null
185
+ if (supportsProto || typeof document === 'undefined') {
104
186
  createEmpty = function () {
105
187
  return { "__proto__": null };
106
188
  };
@@ -110,7 +192,7 @@ if (!Object.create) {
110
192
  // aside from Object.prototype itself. Instead, create a new global
111
193
  // object and *steal* its Object.prototype and strip it bare. This is
112
194
  // used as the prototype to create nullary objects.
113
- createEmpty = (function () {
195
+ createEmpty = function () {
114
196
  var iframe = document.createElement('iframe');
115
197
  var parent = document.body || document.documentElement;
116
198
  iframe.style.display = 'none';
@@ -130,11 +212,12 @@ if (!Object.create) {
130
212
 
131
213
  function Empty() {}
132
214
  Empty.prototype = empty;
133
-
134
- return function () {
215
+ // short-circuit future calls
216
+ createEmpty = function () {
135
217
  return new Empty();
136
218
  };
137
- })();
219
+ return new Empty();
220
+ };
138
221
  }
139
222
 
140
223
  Object.create = function create(prototype, properties) {
@@ -175,7 +258,7 @@ if (!Object.create) {
175
258
 
176
259
  // Patch for WebKit and IE8 standard mode
177
260
  // Designed by hax <hax.github.com>
178
- // related issue: https://github.com/kriskowal/es5-shim/issues#issue/5
261
+ // related issue: https://github.com/es-shims/es5-shim/issues#issue/5
179
262
  // IE8 Reference:
180
263
  // http://msdn.microsoft.com/en-us/library/dd282900.aspx
181
264
  // http://msdn.microsoft.com/en-us/library/dd229916.aspx
@@ -195,7 +278,7 @@ function doesDefinePropertyWork(object) {
195
278
  // shim partially.
196
279
  if (Object.defineProperty) {
197
280
  var definePropertyWorksOnObject = doesDefinePropertyWork({});
198
- var definePropertyWorksOnDom = typeof document == "undefined" ||
281
+ var definePropertyWorksOnDom = typeof document === "undefined" ||
199
282
  doesDefinePropertyWork(document.createElement("div"));
200
283
  if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
201
284
  var definePropertyFallback = Object.defineProperty,
@@ -210,10 +293,10 @@ if (!Object.defineProperty || definePropertyFallback) {
210
293
  "on this javascript engine";
211
294
 
212
295
  Object.defineProperty = function defineProperty(object, property, descriptor) {
213
- if ((typeof object != "object" && typeof object != "function") || object === null) {
296
+ if ((typeof object !== "object" && typeof object !== "function") || object === null) {
214
297
  throw new TypeError(ERR_NON_OBJECT_TARGET + object);
215
298
  }
216
- if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null) {
299
+ if ((typeof descriptor !== "object" && typeof descriptor !== "function") || descriptor === null) {
217
300
  throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
218
301
  }
219
302
  // make a valiant attempt to use the real defineProperty
@@ -289,9 +372,9 @@ if (!Object.defineProperties || definePropertiesFallback) {
289
372
  // try the shim if the real one doesn't work
290
373
  }
291
374
  }
292
-
375
+
293
376
  for (var property in properties) {
294
- if (owns(properties, property) && property != "__proto__") {
377
+ if (owns(properties, property) && property !== "__proto__") {
295
378
  Object.defineProperty(object, property, properties[property]);
296
379
  }
297
380
  }
@@ -327,7 +410,7 @@ try {
327
410
  } catch (exception) {
328
411
  Object.freeze = (function freeze(freezeObject) {
329
412
  return function freeze(object) {
330
- if (typeof object == "function") {
413
+ if (typeof object === "function") {
331
414
  return object;
332
415
  } else {
333
416
  return freezeObject(object);
@@ -383,4 +466,5 @@ if (!Object.isExtensible) {
383
466
  };
384
467
  }
385
468
 
386
- });
469
+ }));
470
+
@@ -1,7 +1,7 @@
1
- (function(f){"function"==typeof define?define(f):"function"==typeof YUI?YUI.add("es5-sham",f):f()})(function(){function f(a){try{return Object.defineProperty(a,"sentinel",{}),"sentinel"in a}catch(b){}}Object.getPrototypeOf||(Object.getPrototypeOf=function(a){return a.__proto__||(a.constructor?a.constructor.prototype:prototypeOfObject)});Object.getOwnPropertyDescriptor||(Object.getOwnPropertyDescriptor=function(a,b){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object: "+
2
- a);if(owns(a,b)){var d={enumerable:true,configurable:true};if(supportsAccessors){var l=a.__proto__;a.__proto__=prototypeOfObject;var c=lookupGetter(a,b),e=lookupSetter(a,b);a.__proto__=l;if(c||e){if(c)d.get=c;if(e)d.set=e;return d}}d.value=a[b];return d}});Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(a){return Object.keys(a)});if(!Object.create){var h;if(null===Object.prototype.__proto__||"undefined"==typeof document)h=function(){return{__proto__:null}};else{var k=function(){},
3
- e=document.createElement("iframe"),g=document.body||document.documentElement;e.style.display="none";g.appendChild(e);e.src="javascript:";var c=e.contentWindow.Object.prototype;g.removeChild(e);e=null;delete c.constructor;delete c.hasOwnProperty;delete c.propertyIsEnumerable;delete c.isPrototypeOf;delete c.toLocaleString;delete c.toString;delete c.valueOf;c.__proto__=null;k.prototype=c;h=function(){return new k}}Object.create=function(a,b){function d(){}var c;if(a===null)c=h();else{if(typeof a!=="object"&&
4
- typeof a!=="function")throw new TypeError("Object prototype may only be an Object or null");d.prototype=a;c=new d;c.__proto__=a}b!==void 0&&Object.defineProperties(c,b);return c}}if(Object.defineProperty&&(e=f({}),g="undefined"==typeof document||f(document.createElement("div")),!e||!g))var i=Object.defineProperty,j=Object.defineProperties;if(!Object.defineProperty||i)Object.defineProperty=function(a,b,d){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("Object.defineProperty called on non-object: "+
5
- a);if(typeof d!="object"&&typeof d!="function"||d===null)throw new TypeError("Property description must be an object: "+d);if(i)try{return i.call(Object,a,b,d)}catch(c){}if(owns(d,"value"))if(supportsAccessors&&(lookupGetter(a,b)||lookupSetter(a,b))){var e=a.__proto__;a.__proto__=prototypeOfObject;delete a[b];a[b]=d.value;a.__proto__=e}else a[b]=d.value;else{if(!supportsAccessors)throw new TypeError("getters & setters can not be defined on this javascript engine");owns(d,"get")&&defineGetter(a,b,
6
- d.get);owns(d,"set")&&defineSetter(a,b,d.set)}return a};if(!Object.defineProperties||j)Object.defineProperties=function(a,b){if(j)try{return j.call(Object,a,b)}catch(d){}for(var c in b)owns(b,c)&&c!="__proto__"&&Object.defineProperty(a,c,b[c]);return a};Object.seal||(Object.seal=function(a){return a});Object.freeze||(Object.freeze=function(a){return a});try{Object.freeze(function(){})}catch(n){var m=Object.freeze;Object.freeze=function(a){return typeof a=="function"?a:m(a)}}Object.preventExtensions||
7
- (Object.preventExtensions=function(a){return a});Object.isSealed||(Object.isSealed=function(){return false});Object.isFrozen||(Object.isFrozen=function(){return false});Object.isExtensible||(Object.isExtensible=function(a){if(Object(a)!==a)throw new TypeError;for(var b="";owns(a,b);)b=b+"?";a[b]=true;var c=owns(a,b);delete a[b];return c})});
1
+ /*!
2
+ * https://github.com/es-shims/es5-shim
3
+ * @license es5-shim Copyright 2009-2014 by contributors, MIT License
4
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
5
+ */
6
+ (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}}});
7
+ //# sourceMappingURL=es5-sham.map
@@ -1,19 +1,30 @@
1
- // Copyright 2009-2012 by contributors, MIT License
1
+ /*!
2
+ * https://github.com/es-shims/es5-shim
3
+ * @license es5-shim Copyright 2009-2014 by contributors, MIT License
4
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
5
+ */
6
+
2
7
  // vim: ts=4 sts=4 sw=4 expandtab
3
8
 
4
- // Module systems magic dance
5
- (function (definition) {
6
- // RequireJS
7
- if (typeof define == "function") {
8
- define(definition);
9
- // YUI3
10
- } else if (typeof YUI == "function") {
11
- YUI.add("es5", definition);
12
- // CommonJS and <script>
9
+ //Add semicolon to prevent IIFE from being passed as argument to concated code.
10
+ ;
11
+
12
+ // UMD (Universal Module Definition)
13
+ // see https://github.com/umdjs/umd/blob/master/returnExports.js
14
+ (function (root, factory) {
15
+ if (typeof define === 'function' && define.amd) {
16
+ // AMD. Register as an anonymous module.
17
+ define(factory);
18
+ } else if (typeof exports === 'object') {
19
+ // Node. Does not work with strict CommonJS, but
20
+ // only CommonJS-like enviroments that support module.exports,
21
+ // like Node.
22
+ module.exports = factory();
13
23
  } else {
14
- definition();
24
+ // Browser globals (root is window)
25
+ root.returnExports = factory();
15
26
  }
16
- })(function () {
27
+ }(this, function () {
17
28
 
18
29
  /**
19
30
  * Brings an environment as close to ECMAScript 5 compliance
@@ -24,6 +35,149 @@
24
35
  * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
25
36
  */
26
37
 
38
+ // Shortcut to an often accessed properties, in order to avoid multiple
39
+ // dereference that costs universally.
40
+ var ArrayPrototype = Array.prototype;
41
+ var ObjectPrototype = Object.prototype;
42
+ var FunctionPrototype = Function.prototype;
43
+ var StringPrototype = String.prototype;
44
+ var NumberPrototype = Number.prototype;
45
+ var _Array_slice_ = ArrayPrototype.slice;
46
+ var array_splice = ArrayPrototype.splice;
47
+ var array_push = ArrayPrototype.push;
48
+ var array_unshift = ArrayPrototype.unshift;
49
+ var call = FunctionPrototype.call;
50
+
51
+ // Having a toString local variable name breaks in Opera so use _toString.
52
+ var _toString = ObjectPrototype.toString;
53
+
54
+ var isFunction = function (val) {
55
+ return ObjectPrototype.toString.call(val) === '[object Function]';
56
+ };
57
+ var isRegex = function (val) {
58
+ return ObjectPrototype.toString.call(val) === '[object RegExp]';
59
+ };
60
+ var isArray = function isArray(obj) {
61
+ return _toString.call(obj) === "[object Array]";
62
+ };
63
+ var isString = function isString(obj) {
64
+ return _toString.call(obj) === "[object String]";
65
+ };
66
+ var isArguments = function isArguments(value) {
67
+ var str = _toString.call(value);
68
+ var isArgs = str === '[object Arguments]';
69
+ if (!isArgs) {
70
+ isArgs = !isArray(value)
71
+ && value !== null
72
+ && typeof value === 'object'
73
+ && typeof value.length === 'number'
74
+ && value.length >= 0
75
+ && isFunction(value.callee);
76
+ }
77
+ return isArgs;
78
+ };
79
+
80
+ var supportsDescriptors = Object.defineProperty && (function () {
81
+ try {
82
+ Object.defineProperty({}, 'x', {});
83
+ return true;
84
+ } catch (e) { /* this is ES3 */
85
+ return false;
86
+ }
87
+ }());
88
+
89
+ // Define configurable, writable and non-enumerable props
90
+ // if they don't exist.
91
+ var defineProperty;
92
+ if (supportsDescriptors) {
93
+ defineProperty = function (object, name, method, forceAssign) {
94
+ if (!forceAssign && (name in object)) { return; }
95
+ Object.defineProperty(object, name, {
96
+ configurable: true,
97
+ enumerable: false,
98
+ writable: true,
99
+ value: method
100
+ });
101
+ };
102
+ } else {
103
+ defineProperty = function (object, name, method, forceAssign) {
104
+ if (!forceAssign && (name in object)) { return; }
105
+ object[name] = method;
106
+ };
107
+ }
108
+ var defineProperties = function (object, map, forceAssign) {
109
+ for (var name in map) {
110
+ if (ObjectPrototype.hasOwnProperty.call(map, name)) {
111
+ defineProperty(object, name, map[name], forceAssign);
112
+ }
113
+ }
114
+ };
115
+
116
+ //
117
+ // Util
118
+ // ======
119
+ //
120
+
121
+ // ES5 9.4
122
+ // http://es5.github.com/#x9.4
123
+ // http://jsperf.com/to-integer
124
+
125
+ function toInteger(n) {
126
+ n = +n;
127
+ if (n !== n) { // isNaN
128
+ n = 0;
129
+ } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
130
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
131
+ }
132
+ return n;
133
+ }
134
+
135
+ function isPrimitive(input) {
136
+ var type = typeof input;
137
+ return (
138
+ input === null ||
139
+ type === "undefined" ||
140
+ type === "boolean" ||
141
+ type === "number" ||
142
+ type === "string"
143
+ );
144
+ }
145
+
146
+ function toPrimitive(input) {
147
+ var val, valueOf, toStr;
148
+ if (isPrimitive(input)) {
149
+ return input;
150
+ }
151
+ valueOf = input.valueOf;
152
+ if (isFunction(valueOf)) {
153
+ val = valueOf.call(input);
154
+ if (isPrimitive(val)) {
155
+ return val;
156
+ }
157
+ }
158
+ toStr = input.toString;
159
+ if (isFunction(toStr)) {
160
+ val = toStr.call(input);
161
+ if (isPrimitive(val)) {
162
+ return val;
163
+ }
164
+ }
165
+ throw new TypeError();
166
+ }
167
+
168
+ // ES5 9.9
169
+ // http://es5.github.com/#x9.9
170
+ var toObject = function (o) {
171
+ if (o == null) { // this matches both null and undefined
172
+ throw new TypeError("can't convert " + o + " to object");
173
+ }
174
+ return Object(o);
175
+ };
176
+
177
+ var ToUint32 = function ToUint32(x) {
178
+ return x >>> 0;
179
+ };
180
+
27
181
  //
28
182
  // Function
29
183
  // ========
@@ -34,18 +188,18 @@
34
188
 
35
189
  function Empty() {}
36
190
 
37
- if (!Function.prototype.bind) {
38
- Function.prototype.bind = function bind(that) { // .length is 1
191
+ defineProperties(FunctionPrototype, {
192
+ bind: function bind(that) { // .length is 1
39
193
  // 1. Let Target be the this value.
40
194
  var target = this;
41
195
  // 2. If IsCallable(Target) is false, throw a TypeError exception.
42
- if (typeof target != "function") {
196
+ if (!isFunction(target)) {
43
197
  throw new TypeError("Function.prototype.bind called on incompatible " + target);
44
198
  }
45
199
  // 3. Let A be a new (possibly empty) internal list of all of the
46
200
  // argument values provided after thisArg (arg1, arg2 etc), in order.
47
201
  // XXX slicedArgs will stand in for "A" if used
48
- var args = slice.call(arguments, 1); // for normal call
202
+ var args = _Array_slice_.call(arguments, 1); // for normal call
49
203
  // 4. Let F be a new native ECMAScript object.
50
204
  // 11. Set the [[Prototype]] internal property of F to the standard
51
205
  // built-in Function prototype object as specified in 15.3.3.1.
@@ -55,7 +209,7 @@ if (!Function.prototype.bind) {
55
209
  // 15.3.4.5.2.
56
210
  // 14. Set the [[HasInstance]] internal property of F as described in
57
211
  // 15.3.4.5.3.
58
- var bound = function () {
212
+ var binder = function () {
59
213
 
60
214
  if (this instanceof bound) {
61
215
  // 15.3.4.5.2 [[Construct]]
@@ -76,7 +230,7 @@ if (!Function.prototype.bind) {
76
230
 
77
231
  var result = target.apply(
78
232
  this,
79
- args.concat(slice.call(arguments))
233
+ args.concat(_Array_slice_.call(arguments))
80
234
  );
81
235
  if (Object(result) === result) {
82
236
  return result;
@@ -105,27 +259,42 @@ if (!Function.prototype.bind) {
105
259
  // equiv: target.call(this, ...boundArgs, ...args)
106
260
  return target.apply(
107
261
  that,
108
- args.concat(slice.call(arguments))
262
+ args.concat(_Array_slice_.call(arguments))
109
263
  );
110
264
 
111
265
  }
112
266
 
113
267
  };
114
- if(target.prototype) {
115
- Empty.prototype = target.prototype;
116
- bound.prototype = new Empty();
117
- // Clean up dangling references.
118
- Empty.prototype = null;
119
- }
120
- // XXX bound.length is never writable, so don't even try
121
- //
268
+
122
269
  // 15. If the [[Class]] internal property of Target is "Function", then
123
270
  // a. Let L be the length property of Target minus the length of A.
124
271
  // b. Set the length own property of F to either 0 or L, whichever is
125
272
  // larger.
126
273
  // 16. Else set the length own property of F to 0.
274
+
275
+ var boundLength = Math.max(0, target.length - args.length);
276
+
127
277
  // 17. Set the attributes of the length own property of F to the values
128
278
  // specified in 15.3.5.1.
279
+ var boundArgs = [];
280
+ for (var i = 0; i < boundLength; i++) {
281
+ boundArgs.push("$" + i);
282
+ }
283
+
284
+ // XXX Build a dynamic function with desired amount of arguments is the only
285
+ // way to set the length property of a function.
286
+ // In environments where Content Security Policies enabled (Chrome extensions,
287
+ // for ex.) all use of eval or Function costructor throws an exception.
288
+ // However in all of these environments Function.prototype.bind exists
289
+ // and so this code will never be executed.
290
+ var bound = Function("binder", "return function (" + boundArgs.join(",") + "){return binder.apply(this,arguments)}")(binder);
291
+
292
+ if (target.prototype) {
293
+ Empty.prototype = target.prototype;
294
+ bound.prototype = new Empty();
295
+ // Clean up dangling references.
296
+ Empty.prototype = null;
297
+ }
129
298
 
130
299
  // TODO
131
300
  // 18. Set the [[Extensible]] internal property of F to true.
@@ -149,20 +318,12 @@ if (!Function.prototype.bind) {
149
318
 
150
319
  // 22. Return F.
151
320
  return bound;
152
- };
153
- }
321
+ }
322
+ });
154
323
 
155
- // Shortcut to an often accessed properties, in order to avoid multiple
156
- // dereference that costs universally.
157
324
  // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
158
325
  // us it in defining shortcuts.
159
- var call = Function.prototype.call;
160
- var prototypeOfArray = Array.prototype;
161
- var prototypeOfObject = Object.prototype;
162
- var slice = prototypeOfArray.slice;
163
- // Having a toString local variable name breaks in Opera so use _toString.
164
- var _toString = call.bind(prototypeOfObject.toString);
165
- var owns = call.bind(prototypeOfObject.hasOwnProperty);
326
+ var owns = call.bind(ObjectPrototype.hasOwnProperty);
166
327
 
167
328
  // If JS engine supports accessors creating shortcuts.
168
329
  var defineGetter;
@@ -170,11 +331,11 @@ var defineSetter;
170
331
  var lookupGetter;
171
332
  var lookupSetter;
172
333
  var supportsAccessors;
173
- if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
174
- defineGetter = call.bind(prototypeOfObject.__defineGetter__);
175
- defineSetter = call.bind(prototypeOfObject.__defineSetter__);
176
- lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
177
- lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
334
+ if ((supportsAccessors = owns(ObjectPrototype, "__defineGetter__"))) {
335
+ defineGetter = call.bind(ObjectPrototype.__defineGetter__);
336
+ defineSetter = call.bind(ObjectPrototype.__defineSetter__);
337
+ lookupGetter = call.bind(ObjectPrototype.__lookupGetter__);
338
+ lookupSetter = call.bind(ObjectPrototype.__lookupSetter__);
178
339
  }
179
340
 
180
341
  //
@@ -184,44 +345,61 @@ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
184
345
 
185
346
  // ES5 15.4.4.12
186
347
  // http://es5.github.com/#x15.4.4.12
187
- // Default value for second param
188
- // [bugfix, ielt9, old browsers]
189
- // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
190
- if ([1,2].splice(0).length != 2) {
191
- var array_splice = Array.prototype.splice;
192
- Array.prototype.splice = function(start, deleteCount) {
193
- if (!arguments.length) {
348
+ var spliceNoopReturnsEmptyArray = (function () {
349
+ var a = [1, 2];
350
+ var result = a.splice();
351
+ return a.length === 2 && isArray(result) && result.length === 0;
352
+ }());
353
+ defineProperties(ArrayPrototype, {
354
+ // Safari 5.0 bug where .splice() returns undefined
355
+ splice: function splice(start, deleteCount) {
356
+ if (arguments.length === 0) {
194
357
  return [];
195
358
  } else {
196
- return array_splice.apply(this, [
197
- start === void 0 ? 0 : start,
198
- deleteCount === void 0 ? (this.length - start) : deleteCount
199
- ].concat(slice.call(arguments, 2)))
359
+ return array_splice.apply(this, arguments);
200
360
  }
201
- };
202
- }
361
+ }
362
+ }, spliceNoopReturnsEmptyArray);
363
+
364
+ var spliceWorksWithEmptyObject = (function () {
365
+ var obj = {};
366
+ ArrayPrototype.splice.call(obj, 0, 0, 1);
367
+ return obj.length === 1;
368
+ }());
369
+ defineProperties(ArrayPrototype, {
370
+ splice: function splice(start, deleteCount) {
371
+ if (arguments.length === 0) { return []; }
372
+ var args = arguments;
373
+ this.length = Math.max(toInteger(this.length), 0);
374
+ if (arguments.length > 0 && typeof deleteCount !== 'number') {
375
+ args = _Array_slice_.call(arguments);
376
+ if (args.length < 2) {
377
+ args.push(this.length - start);
378
+ } else {
379
+ args[1] = toInteger(deleteCount);
380
+ }
381
+ }
382
+ return array_splice.apply(this, args);
383
+ }
384
+ }, !spliceWorksWithEmptyObject);
203
385
 
204
386
  // ES5 15.4.4.12
205
387
  // http://es5.github.com/#x15.4.4.13
206
388
  // Return len+argCount.
207
389
  // [bugfix, ielt8]
208
- // IE < 8 bug: [].unshift(0) == undefined but should be "1"
209
- if ([].unshift(0) != 1) {
210
- var array_unshift = Array.prototype.unshift;
211
- Array.prototype.unshift = function() {
390
+ // IE < 8 bug: [].unshift(0) === undefined but should be "1"
391
+ var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
392
+ defineProperties(ArrayPrototype, {
393
+ unshift: function () {
212
394
  array_unshift.apply(this, arguments);
213
395
  return this.length;
214
- };
215
- }
396
+ }
397
+ }, hasUnshiftReturnValueBug);
216
398
 
217
399
  // ES5 15.4.3.2
218
400
  // http://es5.github.com/#x15.4.3.2
219
401
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
220
- if (!Array.isArray) {
221
- Array.isArray = function isArray(obj) {
222
- return _toString(obj) == "[object Array]";
223
- };
224
- }
402
+ defineProperties(Array, { isArray: isArray });
225
403
 
226
404
  // The IsCallable() check in the Array functions
227
405
  // has been replaced with a strict check on the
@@ -241,21 +419,36 @@ if (!Array.isArray) {
241
419
 
242
420
  // Check failure of by-index access of string characters (IE < 9)
243
421
  // and failure of `0 in boxedString` (Rhino)
244
- var boxedString = Object("a"),
245
- splitString = boxedString[0] != "a" || !(0 in boxedString);
422
+ var boxedString = Object("a");
423
+ var splitString = boxedString[0] !== "a" || !(0 in boxedString);
424
+
425
+ var properlyBoxesContext = function properlyBoxed(method) {
426
+ // Check node 0.6.21 bug where third parameter is not boxed
427
+ var properlyBoxesNonStrict = true;
428
+ var properlyBoxesStrict = true;
429
+ if (method) {
430
+ method.call('foo', function (_, __, context) {
431
+ if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
432
+ });
433
+
434
+ method.call([1], function () {
435
+ 'use strict';
436
+ properlyBoxesStrict = typeof this === 'string';
437
+ }, 'x');
438
+ }
439
+ return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
440
+ };
246
441
 
247
- if (!Array.prototype.forEach) {
248
- Array.prototype.forEach = function forEach(fun /*, thisp*/) {
442
+ defineProperties(ArrayPrototype, {
443
+ forEach: function forEach(fun /*, thisp*/) {
249
444
  var object = toObject(this),
250
- self = splitString && _toString(this) == "[object String]" ?
251
- this.split("") :
252
- object,
445
+ self = splitString && isString(this) ? this.split('') : object,
253
446
  thisp = arguments[1],
254
447
  i = -1,
255
448
  length = self.length >>> 0;
256
449
 
257
450
  // If no callback function or if callback is not a callable function
258
- if (_toString(fun) != "[object Function]") {
451
+ if (!isFunction(fun)) {
259
452
  throw new TypeError(); // TODO message
260
453
  }
261
454
 
@@ -267,51 +460,48 @@ if (!Array.prototype.forEach) {
267
460
  fun.call(thisp, self[i], i, object);
268
461
  }
269
462
  }
270
- };
271
- }
463
+ }
464
+ }, !properlyBoxesContext(ArrayPrototype.forEach));
272
465
 
273
466
  // ES5 15.4.4.19
274
467
  // http://es5.github.com/#x15.4.4.19
275
468
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
276
- if (!Array.prototype.map) {
277
- Array.prototype.map = function map(fun /*, thisp*/) {
469
+ defineProperties(ArrayPrototype, {
470
+ map: function map(fun /*, thisp*/) {
278
471
  var object = toObject(this),
279
- self = splitString && _toString(this) == "[object String]" ?
280
- this.split("") :
281
- object,
472
+ self = splitString && isString(this) ? this.split('') : object,
282
473
  length = self.length >>> 0,
283
474
  result = Array(length),
284
475
  thisp = arguments[1];
285
476
 
286
477
  // If no callback function or if callback is not a callable function
287
- if (_toString(fun) != "[object Function]") {
478
+ if (!isFunction(fun)) {
288
479
  throw new TypeError(fun + " is not a function");
289
480
  }
290
481
 
291
482
  for (var i = 0; i < length; i++) {
292
- if (i in self)
483
+ if (i in self) {
293
484
  result[i] = fun.call(thisp, self[i], i, object);
485
+ }
294
486
  }
295
487
  return result;
296
- };
297
- }
488
+ }
489
+ }, !properlyBoxesContext(ArrayPrototype.map));
298
490
 
299
491
  // ES5 15.4.4.20
300
492
  // http://es5.github.com/#x15.4.4.20
301
493
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
302
- if (!Array.prototype.filter) {
303
- Array.prototype.filter = function filter(fun /*, thisp */) {
494
+ defineProperties(ArrayPrototype, {
495
+ filter: function filter(fun /*, thisp */) {
304
496
  var object = toObject(this),
305
- self = splitString && _toString(this) == "[object String]" ?
306
- this.split("") :
307
- object,
497
+ self = splitString && isString(this) ? this.split('') : object,
308
498
  length = self.length >>> 0,
309
499
  result = [],
310
500
  value,
311
501
  thisp = arguments[1];
312
502
 
313
503
  // If no callback function or if callback is not a callable function
314
- if (_toString(fun) != "[object Function]") {
504
+ if (!isFunction(fun)) {
315
505
  throw new TypeError(fun + " is not a function");
316
506
  }
317
507
 
@@ -324,23 +514,21 @@ if (!Array.prototype.filter) {
324
514
  }
325
515
  }
326
516
  return result;
327
- };
328
- }
517
+ }
518
+ }, !properlyBoxesContext(ArrayPrototype.filter));
329
519
 
330
520
  // ES5 15.4.4.16
331
521
  // http://es5.github.com/#x15.4.4.16
332
522
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
333
- if (!Array.prototype.every) {
334
- Array.prototype.every = function every(fun /*, thisp */) {
523
+ defineProperties(ArrayPrototype, {
524
+ every: function every(fun /*, thisp */) {
335
525
  var object = toObject(this),
336
- self = splitString && _toString(this) == "[object String]" ?
337
- this.split("") :
338
- object,
526
+ self = splitString && isString(this) ? this.split('') : object,
339
527
  length = self.length >>> 0,
340
528
  thisp = arguments[1];
341
529
 
342
530
  // If no callback function or if callback is not a callable function
343
- if (_toString(fun) != "[object Function]") {
531
+ if (!isFunction(fun)) {
344
532
  throw new TypeError(fun + " is not a function");
345
533
  }
346
534
 
@@ -350,23 +538,21 @@ if (!Array.prototype.every) {
350
538
  }
351
539
  }
352
540
  return true;
353
- };
354
- }
541
+ }
542
+ }, !properlyBoxesContext(ArrayPrototype.every));
355
543
 
356
544
  // ES5 15.4.4.17
357
545
  // http://es5.github.com/#x15.4.4.17
358
546
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
359
- if (!Array.prototype.some) {
360
- Array.prototype.some = function some(fun /*, thisp */) {
547
+ defineProperties(ArrayPrototype, {
548
+ some: function some(fun /*, thisp */) {
361
549
  var object = toObject(this),
362
- self = splitString && _toString(this) == "[object String]" ?
363
- this.split("") :
364
- object,
550
+ self = splitString && isString(this) ? this.split('') : object,
365
551
  length = self.length >>> 0,
366
552
  thisp = arguments[1];
367
553
 
368
554
  // If no callback function or if callback is not a callable function
369
- if (_toString(fun) != "[object Function]") {
555
+ if (!isFunction(fun)) {
370
556
  throw new TypeError(fun + " is not a function");
371
557
  }
372
558
 
@@ -376,27 +562,29 @@ if (!Array.prototype.some) {
376
562
  }
377
563
  }
378
564
  return false;
379
- };
380
- }
565
+ }
566
+ }, !properlyBoxesContext(ArrayPrototype.some));
381
567
 
382
568
  // ES5 15.4.4.21
383
569
  // http://es5.github.com/#x15.4.4.21
384
570
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
385
- if (!Array.prototype.reduce) {
386
- Array.prototype.reduce = function reduce(fun /*, initial*/) {
571
+ var reduceCoercesToObject = false;
572
+ if (ArrayPrototype.reduce) {
573
+ reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object';
574
+ }
575
+ defineProperties(ArrayPrototype, {
576
+ reduce: function reduce(fun /*, initial*/) {
387
577
  var object = toObject(this),
388
- self = splitString && _toString(this) == "[object String]" ?
389
- this.split("") :
390
- object,
578
+ self = splitString && isString(this) ? this.split('') : object,
391
579
  length = self.length >>> 0;
392
580
 
393
581
  // If no callback function or if callback is not a callable function
394
- if (_toString(fun) != "[object Function]") {
582
+ if (!isFunction(fun)) {
395
583
  throw new TypeError(fun + " is not a function");
396
584
  }
397
585
 
398
586
  // no value to return if no initial value and an empty array
399
- if (!length && arguments.length == 1) {
587
+ if (!length && arguments.length === 1) {
400
588
  throw new TypeError("reduce of empty array with no initial value");
401
589
  }
402
590
 
@@ -425,27 +613,29 @@ if (!Array.prototype.reduce) {
425
613
  }
426
614
 
427
615
  return result;
428
- };
429
- }
616
+ }
617
+ }, !reduceCoercesToObject);
430
618
 
431
619
  // ES5 15.4.4.22
432
620
  // http://es5.github.com/#x15.4.4.22
433
621
  // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
434
- if (!Array.prototype.reduceRight) {
435
- Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
622
+ var reduceRightCoercesToObject = false;
623
+ if (ArrayPrototype.reduceRight) {
624
+ reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object';
625
+ }
626
+ defineProperties(ArrayPrototype, {
627
+ reduceRight: function reduceRight(fun /*, initial*/) {
436
628
  var object = toObject(this),
437
- self = splitString && _toString(this) == "[object String]" ?
438
- this.split("") :
439
- object,
629
+ self = splitString && isString(this) ? this.split('') : object,
440
630
  length = self.length >>> 0;
441
631
 
442
632
  // If no callback function or if callback is not a callable function
443
- if (_toString(fun) != "[object Function]") {
633
+ if (!isFunction(fun)) {
444
634
  throw new TypeError(fun + " is not a function");
445
635
  }
446
636
 
447
637
  // no value to return if no initial value, empty array
448
- if (!length && arguments.length == 1) {
638
+ if (!length && arguments.length === 1) {
449
639
  throw new TypeError("reduceRight of empty array with no initial value");
450
640
  }
451
641
 
@@ -466,24 +656,27 @@ if (!Array.prototype.reduceRight) {
466
656
  } while (true);
467
657
  }
468
658
 
659
+ if (i < 0) {
660
+ return result;
661
+ }
662
+
469
663
  do {
470
- if (i in this) {
664
+ if (i in self) {
471
665
  result = fun.call(void 0, result, self[i], i, object);
472
666
  }
473
667
  } while (i--);
474
668
 
475
669
  return result;
476
- };
477
- }
670
+ }
671
+ }, !reduceRightCoercesToObject);
478
672
 
479
673
  // ES5 15.4.4.14
480
674
  // http://es5.github.com/#x15.4.4.14
481
675
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
482
- if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
483
- Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
484
- var self = splitString && _toString(this) == "[object String]" ?
485
- this.split("") :
486
- toObject(this),
676
+ var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
677
+ defineProperties(ArrayPrototype, {
678
+ indexOf: function indexOf(sought /*, fromIndex */ ) {
679
+ var self = splitString && isString(this) ? this.split('') : toObject(this),
487
680
  length = self.length >>> 0;
488
681
 
489
682
  if (!length) {
@@ -503,17 +696,16 @@ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
503
696
  }
504
697
  }
505
698
  return -1;
506
- };
507
- }
699
+ }
700
+ }, hasFirefox2IndexOfBug);
508
701
 
509
702
  // ES5 15.4.4.15
510
703
  // http://es5.github.com/#x15.4.4.15
511
704
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
512
- if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
513
- Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
514
- var self = splitString && _toString(this) == "[object String]" ?
515
- this.split("") :
516
- toObject(this),
705
+ var hasFirefox2LastIndexOfBug = Array.prototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
706
+ defineProperties(ArrayPrototype, {
707
+ lastIndexOf: function lastIndexOf(sought /*, fromIndex */) {
708
+ var self = splitString && isString(this) ? this.split('') : toObject(this),
517
709
  length = self.length >>> 0;
518
710
 
519
711
  if (!length) {
@@ -531,8 +723,8 @@ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
531
723
  }
532
724
  }
533
725
  return -1;
534
- };
535
- }
726
+ }
727
+ }, hasFirefox2LastIndexOfBug);
536
728
 
537
729
  //
538
730
  // Object
@@ -541,52 +733,74 @@ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
541
733
 
542
734
  // ES5 15.2.3.14
543
735
  // http://es5.github.com/#x15.2.3.14
544
- if (!Object.keys) {
545
- // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
546
- var hasDontEnumBug = true,
547
- dontEnums = [
548
- "toString",
549
- "toLocaleString",
550
- "valueOf",
551
- "hasOwnProperty",
552
- "isPrototypeOf",
553
- "propertyIsEnumerable",
554
- "constructor"
555
- ],
556
- dontEnumsLength = dontEnums.length;
557
-
558
- for (var key in {"toString": null}) {
559
- hasDontEnumBug = false;
560
- }
561
-
562
- Object.keys = function keys(object) {
563
736
 
564
- if (
565
- (typeof object != "object" && typeof object != "function") ||
566
- object === null
567
- ) {
737
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
738
+ var hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'),
739
+ hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
740
+ dontEnums = [
741
+ "toString",
742
+ "toLocaleString",
743
+ "valueOf",
744
+ "hasOwnProperty",
745
+ "isPrototypeOf",
746
+ "propertyIsEnumerable",
747
+ "constructor"
748
+ ],
749
+ dontEnumsLength = dontEnums.length;
750
+
751
+ defineProperties(Object, {
752
+ keys: function keys(object) {
753
+ var isFn = isFunction(object),
754
+ isArgs = isArguments(object),
755
+ isObject = object !== null && typeof object === 'object',
756
+ isStr = isObject && isString(object);
757
+
758
+ if (!isObject && !isFn && !isArgs) {
568
759
  throw new TypeError("Object.keys called on a non-object");
569
760
  }
570
761
 
571
- var keys = [];
572
- for (var name in object) {
573
- if (owns(object, name)) {
574
- keys.push(name);
762
+ var theKeys = [];
763
+ var skipProto = hasProtoEnumBug && isFn;
764
+ if (isStr || isArgs) {
765
+ for (var i = 0; i < object.length; ++i) {
766
+ theKeys.push(String(i));
767
+ }
768
+ } else {
769
+ for (var name in object) {
770
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
771
+ theKeys.push(String(name));
772
+ }
575
773
  }
576
774
  }
577
775
 
578
776
  if (hasDontEnumBug) {
579
- for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
580
- var dontEnum = dontEnums[i];
581
- if (owns(object, dontEnum)) {
582
- keys.push(dontEnum);
777
+ var ctor = object.constructor,
778
+ skipConstructor = ctor && ctor.prototype === object;
779
+ for (var j = 0; j < dontEnumsLength; j++) {
780
+ var dontEnum = dontEnums[j];
781
+ if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
782
+ theKeys.push(dontEnum);
583
783
  }
584
784
  }
585
785
  }
586
- return keys;
587
- };
786
+ return theKeys;
787
+ }
788
+ });
588
789
 
589
- }
790
+ var keysWorksWithArguments = Object.keys && (function () {
791
+ // Safari 5.0 bug
792
+ return Object.keys(arguments).length === 2;
793
+ }(1, 2));
794
+ var originalKeys = Object.keys;
795
+ defineProperties(Object, {
796
+ keys: function keys(object) {
797
+ if (isArguments(object)) {
798
+ return originalKeys(ArrayPrototype.slice.call(object));
799
+ } else {
800
+ return originalKeys(object);
801
+ }
802
+ }
803
+ }, !keysWorksWithArguments);
590
804
 
591
805
  //
592
806
  // Date
@@ -600,13 +814,12 @@ if (!Object.keys) {
600
814
  // string format defined in 15.9.1.15. All fields are present in the String.
601
815
  // The time zone is always UTC, denoted by the suffix Z. If the time value of
602
816
  // this object is not a finite Number a RangeError exception is thrown.
603
- var negativeDate = -62198755200000,
604
- negativeYearString = "-000001";
605
- if (
606
- !Date.prototype.toISOString ||
607
- (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
608
- ) {
609
- Date.prototype.toISOString = function toISOString() {
817
+ var negativeDate = -62198755200000;
818
+ var negativeYearString = "-000001";
819
+ var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
820
+
821
+ defineProperties(Date.prototype, {
822
+ toISOString: function toISOString() {
610
823
  var result, length, value, year, month;
611
824
  if (!isFinite(this)) {
612
825
  throw new RangeError("Date.prototype.toISOString called on non-finite value.");
@@ -615,17 +828,15 @@ if (
615
828
  year = this.getUTCFullYear();
616
829
 
617
830
  month = this.getUTCMonth();
618
- // see https://github.com/kriskowal/es5-shim/issues/111
831
+ // see https://github.com/es-shims/es5-shim/issues/111
619
832
  year += Math.floor(month / 12);
620
833
  month = (month % 12 + 12) % 12;
621
834
 
622
835
  // the date time string format is specified in 15.9.1.15.
623
- result = [month + 1, this.getUTCDate(),
624
- this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
836
+ result = [month + 1, this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
625
837
  year = (
626
838
  (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
627
- ("00000" + Math.abs(year))
628
- .slice(0 <= year && year <= 9999 ? -4 : -6)
839
+ ("00000" + Math.abs(year)).slice(0 <= year && year <= 9999 ? -4 : -6)
629
840
  );
630
841
 
631
842
  length = result.length;
@@ -643,8 +854,8 @@ if (
643
854
  "T" + result.slice(2).join(":") + "." +
644
855
  ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
645
856
  );
646
- };
647
- }
857
+ }
858
+ }, hasNegativeDateBug);
648
859
 
649
860
 
650
861
  // ES5 15.9.5.44
@@ -684,7 +895,7 @@ if (!dateToJSONIsSupported) {
684
895
  // O with argument "toISOString".
685
896
  toISO = o.toISOString;
686
897
  // 5. If IsCallable(toISO) is false, throw a TypeError exception.
687
- if (typeof toISO != "function") {
898
+ if (typeof toISO !== "function") {
688
899
  throw new TypeError("toISOString property is not callable");
689
900
  }
690
901
  // 6. Return the result of calling the [[Call]] internal method of
@@ -706,16 +917,19 @@ if (!dateToJSONIsSupported) {
706
917
  // http://es5.github.com/#x15.9.4.2
707
918
  // based on work shared by Daniel Friesen (dantman)
708
919
  // http://gist.github.com/303249
709
- if (!Date.parse || "Date.parse is buggy") {
920
+ var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
921
+ var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z'));
922
+ var doesNotParseY2KNewYear = isNaN(Date.parse("2000-01-01T00:00:00.000Z"));
923
+ if (!Date.parse || doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
710
924
  // XXX global assignment won't work in embeddings that use
711
925
  // an alternate object for the context.
712
- Date = (function(NativeDate) {
926
+ Date = (function (NativeDate) {
713
927
 
714
928
  // Date.length === 7
715
929
  function Date(Y, M, D, h, m, s, ms) {
716
930
  var length = arguments.length;
717
931
  if (this instanceof NativeDate) {
718
- var date = length == 1 && String(Y) === Y ? // isString(Y)
932
+ var date = length === 1 && String(Y) === Y ? // isString(Y)
719
933
  // We explicitly pass it through parse:
720
934
  new NativeDate(Date.parse(Y)) :
721
935
  // We have to manually make calls depending on argument
@@ -733,7 +947,7 @@ if (!Date.parse || "Date.parse is buggy") {
733
947
  return date;
734
948
  }
735
949
  return NativeDate.apply(this, arguments);
736
- };
950
+ }
737
951
 
738
952
  // 15.9.1.15 Date Time String Format.
739
953
  var isoDateExpression = new RegExp("^" +
@@ -746,7 +960,7 @@ if (!Date.parse || "Date.parse is buggy") {
746
960
  ":(\\d{2})" + // minutes capture
747
961
  "(?:" + // optional :seconds.milliseconds
748
962
  ":(\\d{2})" + // seconds capture
749
- "(?:\\.(\\d{3}))?" + // milliseconds capture
963
+ "(?:(\\.\\d{1,}))?" + // milliseconds capture
750
964
  ")?" +
751
965
  "(" + // capture UTC offset component
752
966
  "Z|" + // UTC capture
@@ -773,6 +987,10 @@ if (!Date.parse || "Date.parse is buggy") {
773
987
  );
774
988
  }
775
989
 
990
+ function toUTC(t) {
991
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
992
+ }
993
+
776
994
  // Copy any custom methods a 3rd party library may have added
777
995
  for (var key in NativeDate) {
778
996
  Date[key] = NativeDate[key];
@@ -797,12 +1015,11 @@ if (!Date.parse || "Date.parse is buggy") {
797
1015
  hour = Number(match[4] || 0),
798
1016
  minute = Number(match[5] || 0),
799
1017
  second = Number(match[6] || 0),
800
- millisecond = Number(match[7] || 0),
1018
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
801
1019
  // When time zone is missed, local offset should be used
802
1020
  // (ES 5.1 bug)
803
1021
  // see https://bugs.ecmascript.org/show_bug.cgi?id=112
804
- offset = !match[4] || match[8] ?
805
- 0 : Number(new NativeDate(1970, 0)),
1022
+ isLocalTime = Boolean(match[4] && !match[8]),
806
1023
  signOffset = match[9] === "-" ? 1 : -1,
807
1024
  hourOffset = Number(match[10] || 0),
808
1025
  minuteOffset = Number(match[11] || 0),
@@ -829,7 +1046,10 @@ if (!Date.parse || "Date.parse is buggy") {
829
1046
  result = (
830
1047
  (result + minute + minuteOffset * signOffset) * 60 +
831
1048
  second
832
- ) * 1000 + millisecond + offset;
1049
+ ) * 1000 + millisecond;
1050
+ if (isLocalTime) {
1051
+ result = toUTC(result);
1052
+ }
833
1053
  if (-8.64e15 <= result && result <= 8.64e15) {
834
1054
  return result;
835
1055
  }
@@ -853,129 +1073,359 @@ if (!Date.now) {
853
1073
 
854
1074
 
855
1075
  //
856
- // String
1076
+ // Number
857
1077
  // ======
858
1078
  //
859
1079
 
1080
+ // ES5.1 15.7.4.5
1081
+ // http://es5.github.com/#x15.7.4.5
1082
+ var hasToFixedBugs = NumberPrototype.toFixed && (
1083
+ (0.00008).toFixed(3) !== '0.000'
1084
+ || (0.9).toFixed(0) !== '1'
1085
+ || (1.255).toFixed(2) !== '1.25'
1086
+ || (1000000000000000128).toFixed(0) !== "1000000000000000128"
1087
+ );
1088
+
1089
+ var toFixedHelpers = {
1090
+ base: 1e7,
1091
+ size: 6,
1092
+ data: [0, 0, 0, 0, 0, 0],
1093
+ multiply: function multiply(n, c) {
1094
+ var i = -1;
1095
+ while (++i < toFixedHelpers.size) {
1096
+ c += n * toFixedHelpers.data[i];
1097
+ toFixedHelpers.data[i] = c % toFixedHelpers.base;
1098
+ c = Math.floor(c / toFixedHelpers.base);
1099
+ }
1100
+ },
1101
+ divide: function divide(n) {
1102
+ var i = toFixedHelpers.size, c = 0;
1103
+ while (--i >= 0) {
1104
+ c += toFixedHelpers.data[i];
1105
+ toFixedHelpers.data[i] = Math.floor(c / n);
1106
+ c = (c % n) * toFixedHelpers.base;
1107
+ }
1108
+ },
1109
+ numToString: function numToString() {
1110
+ var i = toFixedHelpers.size;
1111
+ var s = '';
1112
+ while (--i >= 0) {
1113
+ if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
1114
+ var t = String(toFixedHelpers.data[i]);
1115
+ if (s === '') {
1116
+ s = t;
1117
+ } else {
1118
+ s += '0000000'.slice(0, 7 - t.length) + t;
1119
+ }
1120
+ }
1121
+ }
1122
+ return s;
1123
+ },
1124
+ pow: function pow(x, n, acc) {
1125
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1126
+ },
1127
+ log: function log(x) {
1128
+ var n = 0;
1129
+ while (x >= 4096) {
1130
+ n += 12;
1131
+ x /= 4096;
1132
+ }
1133
+ while (x >= 2) {
1134
+ n += 1;
1135
+ x /= 2;
1136
+ }
1137
+ return n;
1138
+ }
1139
+ };
1140
+
1141
+ defineProperties(NumberPrototype, {
1142
+ toFixed: function toFixed(fractionDigits) {
1143
+ var f, x, s, m, e, z, j, k;
1144
+
1145
+ // Test for NaN and round fractionDigits down
1146
+ f = Number(fractionDigits);
1147
+ f = f !== f ? 0 : Math.floor(f);
1148
+
1149
+ if (f < 0 || f > 20) {
1150
+ throw new RangeError("Number.toFixed called with invalid number of decimals");
1151
+ }
1152
+
1153
+ x = Number(this);
1154
+
1155
+ // Test for NaN
1156
+ if (x !== x) {
1157
+ return "NaN";
1158
+ }
1159
+
1160
+ // If it is too big or small, return the string value of the number
1161
+ if (x <= -1e21 || x >= 1e21) {
1162
+ return String(x);
1163
+ }
1164
+
1165
+ s = "";
1166
+
1167
+ if (x < 0) {
1168
+ s = "-";
1169
+ x = -x;
1170
+ }
1171
+
1172
+ m = "0";
1173
+
1174
+ if (x > 1e-21) {
1175
+ // 1e-21 < x < 1e21
1176
+ // -70 < log2(x) < 70
1177
+ e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
1178
+ z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
1179
+ z *= 0x10000000000000; // Math.pow(2, 52);
1180
+ e = 52 - e;
1181
+
1182
+ // -18 < e < 122
1183
+ // x = z / 2 ^ e
1184
+ if (e > 0) {
1185
+ toFixedHelpers.multiply(0, z);
1186
+ j = f;
1187
+
1188
+ while (j >= 7) {
1189
+ toFixedHelpers.multiply(1e7, 0);
1190
+ j -= 7;
1191
+ }
1192
+
1193
+ toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
1194
+ j = e - 1;
1195
+
1196
+ while (j >= 23) {
1197
+ toFixedHelpers.divide(1 << 23);
1198
+ j -= 23;
1199
+ }
1200
+
1201
+ toFixedHelpers.divide(1 << j);
1202
+ toFixedHelpers.multiply(1, 1);
1203
+ toFixedHelpers.divide(2);
1204
+ m = toFixedHelpers.numToString();
1205
+ } else {
1206
+ toFixedHelpers.multiply(0, z);
1207
+ toFixedHelpers.multiply(1 << (-e), 0);
1208
+ m = toFixedHelpers.numToString() + '0.00000000000000000000'.slice(2, 2 + f);
1209
+ }
1210
+ }
1211
+
1212
+ if (f > 0) {
1213
+ k = m.length;
1214
+
1215
+ if (k <= f) {
1216
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1217
+ } else {
1218
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1219
+ }
1220
+ } else {
1221
+ m = s + m;
1222
+ }
1223
+
1224
+ return m;
1225
+ }
1226
+ }, hasToFixedBugs);
1227
+
1228
+
1229
+ //
1230
+ // String
1231
+ // ======
1232
+ //
860
1233
 
861
1234
  // ES5 15.5.4.14
862
1235
  // http://es5.github.com/#x15.5.4.14
1236
+
1237
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1238
+ // Many browsers do not split properly with regular expressions or they
1239
+ // do not perform the split correctly under obscure conditions.
1240
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1241
+ // I've tested in many browsers and this seems to cover the deviant ones:
1242
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1243
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1244
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1245
+ // [undefined, "t", undefined, "e", ...]
1246
+ // ''.split(/.?/) should be [], not [""]
1247
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1248
+
1249
+ var string_split = StringPrototype.split;
1250
+ if (
1251
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1252
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1253
+ 'tesst'.split(/(s)*/)[1] === "t" ||
1254
+ 'test'.split(/(?:)/, -1).length !== 4 ||
1255
+ ''.split(/.?/).length ||
1256
+ '.'.split(/()()/).length > 1
1257
+ ) {
1258
+ (function () {
1259
+ var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1260
+
1261
+ StringPrototype.split = function (separator, limit) {
1262
+ var string = this;
1263
+ if (separator === void 0 && limit === 0) {
1264
+ return [];
1265
+ }
1266
+
1267
+ // If `separator` is not a regex, use native split
1268
+ if (_toString.call(separator) !== "[object RegExp]") {
1269
+ return string_split.call(this, separator, limit);
1270
+ }
1271
+
1272
+ var output = [],
1273
+ flags = (separator.ignoreCase ? "i" : "") +
1274
+ (separator.multiline ? "m" : "") +
1275
+ (separator.extended ? "x" : "") + // Proposed for ES6
1276
+ (separator.sticky ? "y" : ""), // Firefox 3+
1277
+ lastLastIndex = 0,
1278
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1279
+ separator2, match, lastIndex, lastLength;
1280
+ separator = new RegExp(separator.source, flags + "g");
1281
+ string += ""; // Type-convert
1282
+ if (!compliantExecNpcg) {
1283
+ // Doesn't need flags gy, but they don't hurt
1284
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1285
+ }
1286
+ /* Values for `limit`, per the spec:
1287
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1288
+ * If 0, Infinity, or NaN: 0
1289
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1290
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1291
+ * If other: Type-convert, then use the above rules
1292
+ */
1293
+ limit = limit === void 0 ?
1294
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1295
+ ToUint32(limit);
1296
+ while (match = separator.exec(string)) {
1297
+ // `separator.lastIndex` is not reliable cross-browser
1298
+ lastIndex = match.index + match[0].length;
1299
+ if (lastIndex > lastLastIndex) {
1300
+ output.push(string.slice(lastLastIndex, match.index));
1301
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1302
+ // nonparticipating capturing groups
1303
+ if (!compliantExecNpcg && match.length > 1) {
1304
+ match[0].replace(separator2, function () {
1305
+ for (var i = 1; i < arguments.length - 2; i++) {
1306
+ if (arguments[i] === void 0) {
1307
+ match[i] = void 0;
1308
+ }
1309
+ }
1310
+ });
1311
+ }
1312
+ if (match.length > 1 && match.index < string.length) {
1313
+ ArrayPrototype.push.apply(output, match.slice(1));
1314
+ }
1315
+ lastLength = match[0].length;
1316
+ lastLastIndex = lastIndex;
1317
+ if (output.length >= limit) {
1318
+ break;
1319
+ }
1320
+ }
1321
+ if (separator.lastIndex === match.index) {
1322
+ separator.lastIndex++; // Avoid an infinite loop
1323
+ }
1324
+ }
1325
+ if (lastLastIndex === string.length) {
1326
+ if (lastLength || !separator.test("")) {
1327
+ output.push("");
1328
+ }
1329
+ } else {
1330
+ output.push(string.slice(lastLastIndex));
1331
+ }
1332
+ return output.length > limit ? output.slice(0, limit) : output;
1333
+ };
1334
+ }());
1335
+
863
1336
  // [bugfix, chrome]
864
1337
  // If separator is undefined, then the result array contains just one String,
865
1338
  // which is the this value (converted to a String). If limit is not undefined,
866
1339
  // then the output array is truncated so that it contains no more than limit
867
1340
  // elements.
868
1341
  // "0".split(undefined, 0) -> []
869
- if("0".split(void 0, 0).length) {
870
- var string_split = String.prototype.split;
871
- String.prototype.split = function(separator, limit) {
872
- if(separator === void 0 && limit === 0)return [];
873
- return string_split.apply(this, arguments);
874
- }
1342
+ } else if ("0".split(void 0, 0).length) {
1343
+ StringPrototype.split = function split(separator, limit) {
1344
+ if (separator === void 0 && limit === 0) { return []; }
1345
+ return string_split.call(this, separator, limit);
1346
+ };
1347
+ }
1348
+
1349
+ var str_replace = StringPrototype.replace;
1350
+ var replaceReportsGroupsCorrectly = (function () {
1351
+ var groups = [];
1352
+ 'x'.replace(/x(.)?/g, function (match, group) {
1353
+ groups.push(group);
1354
+ });
1355
+ return groups.length === 1 && typeof groups[0] === 'undefined';
1356
+ }());
1357
+
1358
+ if (!replaceReportsGroupsCorrectly) {
1359
+ StringPrototype.replace = function replace(searchValue, replaceValue) {
1360
+ var isFn = isFunction(replaceValue);
1361
+ var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
1362
+ if (!isFn || !hasCapturingGroups) {
1363
+ return str_replace.call(this, searchValue, replaceValue);
1364
+ } else {
1365
+ var wrappedReplaceValue = function (match) {
1366
+ var length = arguments.length;
1367
+ var originalLastIndex = searchValue.lastIndex;
1368
+ searchValue.lastIndex = 0;
1369
+ var args = searchValue.exec(match);
1370
+ searchValue.lastIndex = originalLastIndex;
1371
+ args.push(arguments[length - 2], arguments[length - 1]);
1372
+ return replaceValue.apply(this, args);
1373
+ };
1374
+ return str_replace.call(this, searchValue, wrappedReplaceValue);
1375
+ }
1376
+ };
875
1377
  }
876
1378
 
877
1379
  // ECMA-262, 3rd B.2.3
878
- // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
1380
+ // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
879
1381
  // non-normative section suggesting uniform semantics and it should be
880
1382
  // normalized across all browsers
881
1383
  // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
882
- if("".substr && "0b".substr(-1) !== "b") {
883
- var string_substr = String.prototype.substr;
884
- /**
885
- * Get the substring of a string
886
- * @param {integer} start where to start the substring
887
- * @param {integer} length how many characters to return
888
- * @return {string}
889
- */
890
- String.prototype.substr = function(start, length) {
1384
+ var string_substr = StringPrototype.substr;
1385
+ var hasNegativeSubstrBug = "".substr && "0b".substr(-1) !== "b";
1386
+ defineProperties(StringPrototype, {
1387
+ substr: function substr(start, length) {
891
1388
  return string_substr.call(
892
1389
  this,
893
1390
  start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
894
1391
  length
895
1392
  );
896
1393
  }
897
- }
1394
+ }, hasNegativeSubstrBug);
898
1395
 
899
1396
  // ES5 15.5.4.20
900
- // http://es5.github.com/#x15.5.4.20
1397
+ // whitespace from: http://es5.github.io/#x15.5.4.20
901
1398
  var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
902
1399
  "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
903
1400
  "\u2029\uFEFF";
904
- if (!String.prototype.trim || ws.trim()) {
1401
+ var zeroWidth = '\u200b';
1402
+ var wsRegexChars = "[" + ws + "]";
1403
+ var trimBeginRegexp = new RegExp("^" + wsRegexChars + wsRegexChars + "*");
1404
+ var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + "*$");
1405
+ var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
1406
+ defineProperties(StringPrototype, {
905
1407
  // http://blog.stevenlevithan.com/archives/faster-trim-javascript
906
1408
  // http://perfectionkills.com/whitespace-deviations/
907
- ws = "[" + ws + "]";
908
- var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
909
- trimEndRegexp = new RegExp(ws + ws + "*$");
910
- String.prototype.trim = function trim() {
911
- if (this === undefined || this === null) {
912
- throw new TypeError("can't convert "+this+" to object");
913
- }
914
- return String(this)
915
- .replace(trimBeginRegexp, "")
916
- .replace(trimEndRegexp, "");
917
- };
918
- }
919
-
920
- //
921
- // Util
922
- // ======
923
- //
924
-
925
- // ES5 9.4
926
- // http://es5.github.com/#x9.4
927
- // http://jsperf.com/to-integer
928
-
929
- function toInteger(n) {
930
- n = +n;
931
- if (n !== n) { // isNaN
932
- n = 0;
933
- } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
934
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
935
- }
936
- return n;
937
- }
938
-
939
- function isPrimitive(input) {
940
- var type = typeof input;
941
- return (
942
- input === null ||
943
- type === "undefined" ||
944
- type === "boolean" ||
945
- type === "number" ||
946
- type === "string"
947
- );
948
- }
949
-
950
- function toPrimitive(input) {
951
- var val, valueOf, toString;
952
- if (isPrimitive(input)) {
953
- return input;
954
- }
955
- valueOf = input.valueOf;
956
- if (typeof valueOf === "function") {
957
- val = valueOf.call(input);
958
- if (isPrimitive(val)) {
959
- return val;
1409
+ trim: function trim() {
1410
+ if (this === void 0 || this === null) {
1411
+ throw new TypeError("can't convert " + this + " to object");
960
1412
  }
1413
+ return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
961
1414
  }
962
- toString = input.toString;
963
- if (typeof toString === "function") {
964
- val = toString.call(input);
965
- if (isPrimitive(val)) {
966
- return val;
967
- }
968
- }
969
- throw new TypeError();
1415
+ }, hasTrimWhitespaceBug);
1416
+
1417
+ // ES-5 15.1.2.2
1418
+ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
1419
+ parseInt = (function (origParseInt) {
1420
+ var hexRegex = /^0[xX]/;
1421
+ return function parseIntES5(str, radix) {
1422
+ str = String(str).trim();
1423
+ if (!Number(radix)) {
1424
+ radix = hexRegex.test(str) ? 16 : 10;
1425
+ }
1426
+ return origParseInt(str, radix);
1427
+ };
1428
+ }(parseInt));
970
1429
  }
971
1430
 
972
- // ES5 9.9
973
- // http://es5.github.com/#x9.9
974
- var toObject = function (o) {
975
- if (o == null) { // this matches both null and undefined
976
- throw new TypeError("can't convert "+o+" to object");
977
- }
978
- return Object(o);
979
- };
980
-
981
- });
1431
+ }));