es5-shim-rails 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/es5-shim-rails.gemspec +19 -0
- data/lib/es5-shim-rails.rb +10 -0
- data/lib/es5-shim-rails/version.rb +7 -0
- data/vendor/assets/javascripts/es5-shim/es5-sham-min.js +1 -0
- data/vendor/assets/javascripts/es5-shim/es5-sham.js +1 -0
- data/vendor/assets/javascripts/es5-shim/es5-shim-min.js +1 -0
- data/vendor/assets/javascripts/es5-shim/es5-shim.js +1 -0
- data/vendor/assets/javascripts/es5-shim/shims/es5-sham.js +386 -0
- data/vendor/assets/javascripts/es5-shim/shims/es5-sham.min.js +7 -0
- data/vendor/assets/javascripts/es5-shim/shims/es5-shim.js +981 -0
- data/vendor/assets/javascripts/es5-shim/shims/es5-shim.min.js +17 -0
- metadata +61 -0
@@ -0,0 +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})});
|
@@ -0,0 +1,981 @@
|
|
1
|
+
// Copyright 2009-2012 by contributors, MIT License
|
2
|
+
// vim: ts=4 sts=4 sw=4 expandtab
|
3
|
+
|
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>
|
13
|
+
} else {
|
14
|
+
definition();
|
15
|
+
}
|
16
|
+
})(function () {
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Brings an environment as close to ECMAScript 5 compliance
|
20
|
+
* as is possible with the facilities of erstwhile engines.
|
21
|
+
*
|
22
|
+
* Annotated ES5: http://es5.github.com/ (specific links below)
|
23
|
+
* ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
|
24
|
+
* Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
|
25
|
+
*/
|
26
|
+
|
27
|
+
//
|
28
|
+
// Function
|
29
|
+
// ========
|
30
|
+
//
|
31
|
+
|
32
|
+
// ES-5 15.3.4.5
|
33
|
+
// http://es5.github.com/#x15.3.4.5
|
34
|
+
|
35
|
+
function Empty() {}
|
36
|
+
|
37
|
+
if (!Function.prototype.bind) {
|
38
|
+
Function.prototype.bind = function bind(that) { // .length is 1
|
39
|
+
// 1. Let Target be the this value.
|
40
|
+
var target = this;
|
41
|
+
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
42
|
+
if (typeof target != "function") {
|
43
|
+
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
44
|
+
}
|
45
|
+
// 3. Let A be a new (possibly empty) internal list of all of the
|
46
|
+
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
47
|
+
// XXX slicedArgs will stand in for "A" if used
|
48
|
+
var args = slice.call(arguments, 1); // for normal call
|
49
|
+
// 4. Let F be a new native ECMAScript object.
|
50
|
+
// 11. Set the [[Prototype]] internal property of F to the standard
|
51
|
+
// built-in Function prototype object as specified in 15.3.3.1.
|
52
|
+
// 12. Set the [[Call]] internal property of F as described in
|
53
|
+
// 15.3.4.5.1.
|
54
|
+
// 13. Set the [[Construct]] internal property of F as described in
|
55
|
+
// 15.3.4.5.2.
|
56
|
+
// 14. Set the [[HasInstance]] internal property of F as described in
|
57
|
+
// 15.3.4.5.3.
|
58
|
+
var bound = function () {
|
59
|
+
|
60
|
+
if (this instanceof bound) {
|
61
|
+
// 15.3.4.5.2 [[Construct]]
|
62
|
+
// When the [[Construct]] internal method of a function object,
|
63
|
+
// F that was created using the bind function is called with a
|
64
|
+
// list of arguments ExtraArgs, the following steps are taken:
|
65
|
+
// 1. Let target be the value of F's [[TargetFunction]]
|
66
|
+
// internal property.
|
67
|
+
// 2. If target has no [[Construct]] internal method, a
|
68
|
+
// TypeError exception is thrown.
|
69
|
+
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
70
|
+
// property.
|
71
|
+
// 4. Let args be a new list containing the same values as the
|
72
|
+
// list boundArgs in the same order followed by the same
|
73
|
+
// values as the list ExtraArgs in the same order.
|
74
|
+
// 5. Return the result of calling the [[Construct]] internal
|
75
|
+
// method of target providing args as the arguments.
|
76
|
+
|
77
|
+
var result = target.apply(
|
78
|
+
this,
|
79
|
+
args.concat(slice.call(arguments))
|
80
|
+
);
|
81
|
+
if (Object(result) === result) {
|
82
|
+
return result;
|
83
|
+
}
|
84
|
+
return this;
|
85
|
+
|
86
|
+
} else {
|
87
|
+
// 15.3.4.5.1 [[Call]]
|
88
|
+
// When the [[Call]] internal method of a function object, F,
|
89
|
+
// which was created using the bind function is called with a
|
90
|
+
// this value and a list of arguments ExtraArgs, the following
|
91
|
+
// steps are taken:
|
92
|
+
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
93
|
+
// property.
|
94
|
+
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
95
|
+
// property.
|
96
|
+
// 3. Let target be the value of F's [[TargetFunction]] internal
|
97
|
+
// property.
|
98
|
+
// 4. Let args be a new list containing the same values as the
|
99
|
+
// list boundArgs in the same order followed by the same
|
100
|
+
// values as the list ExtraArgs in the same order.
|
101
|
+
// 5. Return the result of calling the [[Call]] internal method
|
102
|
+
// of target providing boundThis as the this value and
|
103
|
+
// providing args as the arguments.
|
104
|
+
|
105
|
+
// equiv: target.call(this, ...boundArgs, ...args)
|
106
|
+
return target.apply(
|
107
|
+
that,
|
108
|
+
args.concat(slice.call(arguments))
|
109
|
+
);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
};
|
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
|
+
//
|
122
|
+
// 15. If the [[Class]] internal property of Target is "Function", then
|
123
|
+
// a. Let L be the length property of Target minus the length of A.
|
124
|
+
// b. Set the length own property of F to either 0 or L, whichever is
|
125
|
+
// larger.
|
126
|
+
// 16. Else set the length own property of F to 0.
|
127
|
+
// 17. Set the attributes of the length own property of F to the values
|
128
|
+
// specified in 15.3.5.1.
|
129
|
+
|
130
|
+
// TODO
|
131
|
+
// 18. Set the [[Extensible]] internal property of F to true.
|
132
|
+
|
133
|
+
// TODO
|
134
|
+
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
135
|
+
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
136
|
+
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
137
|
+
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
138
|
+
// false.
|
139
|
+
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
140
|
+
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
141
|
+
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
142
|
+
// and false.
|
143
|
+
|
144
|
+
// TODO
|
145
|
+
// NOTE Function objects created using Function.prototype.bind do not
|
146
|
+
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
147
|
+
// [[Scope]] internal properties.
|
148
|
+
// XXX can't delete prototype in pure-js.
|
149
|
+
|
150
|
+
// 22. Return F.
|
151
|
+
return bound;
|
152
|
+
};
|
153
|
+
}
|
154
|
+
|
155
|
+
// Shortcut to an often accessed properties, in order to avoid multiple
|
156
|
+
// dereference that costs universally.
|
157
|
+
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
158
|
+
// 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);
|
166
|
+
|
167
|
+
// If JS engine supports accessors creating shortcuts.
|
168
|
+
var defineGetter;
|
169
|
+
var defineSetter;
|
170
|
+
var lookupGetter;
|
171
|
+
var lookupSetter;
|
172
|
+
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__);
|
178
|
+
}
|
179
|
+
|
180
|
+
//
|
181
|
+
// Array
|
182
|
+
// =====
|
183
|
+
//
|
184
|
+
|
185
|
+
// ES5 15.4.4.12
|
186
|
+
// 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) {
|
194
|
+
return [];
|
195
|
+
} 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)))
|
200
|
+
}
|
201
|
+
};
|
202
|
+
}
|
203
|
+
|
204
|
+
// ES5 15.4.4.12
|
205
|
+
// http://es5.github.com/#x15.4.4.13
|
206
|
+
// Return len+argCount.
|
207
|
+
// [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() {
|
212
|
+
array_unshift.apply(this, arguments);
|
213
|
+
return this.length;
|
214
|
+
};
|
215
|
+
}
|
216
|
+
|
217
|
+
// ES5 15.4.3.2
|
218
|
+
// http://es5.github.com/#x15.4.3.2
|
219
|
+
// 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
|
+
}
|
225
|
+
|
226
|
+
// The IsCallable() check in the Array functions
|
227
|
+
// has been replaced with a strict check on the
|
228
|
+
// internal class of the object to trap cases where
|
229
|
+
// the provided function was actually a regular
|
230
|
+
// expression literal, which in V8 and
|
231
|
+
// JavaScriptCore is a typeof "function". Only in
|
232
|
+
// V8 are regular expression literals permitted as
|
233
|
+
// reduce parameters, so it is desirable in the
|
234
|
+
// general case for the shim to match the more
|
235
|
+
// strict and common behavior of rejecting regular
|
236
|
+
// expressions.
|
237
|
+
|
238
|
+
// ES5 15.4.4.18
|
239
|
+
// http://es5.github.com/#x15.4.4.18
|
240
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
|
241
|
+
|
242
|
+
// Check failure of by-index access of string characters (IE < 9)
|
243
|
+
// and failure of `0 in boxedString` (Rhino)
|
244
|
+
var boxedString = Object("a"),
|
245
|
+
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
246
|
+
|
247
|
+
if (!Array.prototype.forEach) {
|
248
|
+
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
249
|
+
var object = toObject(this),
|
250
|
+
self = splitString && _toString(this) == "[object String]" ?
|
251
|
+
this.split("") :
|
252
|
+
object,
|
253
|
+
thisp = arguments[1],
|
254
|
+
i = -1,
|
255
|
+
length = self.length >>> 0;
|
256
|
+
|
257
|
+
// If no callback function or if callback is not a callable function
|
258
|
+
if (_toString(fun) != "[object Function]") {
|
259
|
+
throw new TypeError(); // TODO message
|
260
|
+
}
|
261
|
+
|
262
|
+
while (++i < length) {
|
263
|
+
if (i in self) {
|
264
|
+
// Invoke the callback function with call, passing arguments:
|
265
|
+
// context, property value, property key, thisArg object
|
266
|
+
// context
|
267
|
+
fun.call(thisp, self[i], i, object);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
};
|
271
|
+
}
|
272
|
+
|
273
|
+
// ES5 15.4.4.19
|
274
|
+
// http://es5.github.com/#x15.4.4.19
|
275
|
+
// 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*/) {
|
278
|
+
var object = toObject(this),
|
279
|
+
self = splitString && _toString(this) == "[object String]" ?
|
280
|
+
this.split("") :
|
281
|
+
object,
|
282
|
+
length = self.length >>> 0,
|
283
|
+
result = Array(length),
|
284
|
+
thisp = arguments[1];
|
285
|
+
|
286
|
+
// If no callback function or if callback is not a callable function
|
287
|
+
if (_toString(fun) != "[object Function]") {
|
288
|
+
throw new TypeError(fun + " is not a function");
|
289
|
+
}
|
290
|
+
|
291
|
+
for (var i = 0; i < length; i++) {
|
292
|
+
if (i in self)
|
293
|
+
result[i] = fun.call(thisp, self[i], i, object);
|
294
|
+
}
|
295
|
+
return result;
|
296
|
+
};
|
297
|
+
}
|
298
|
+
|
299
|
+
// ES5 15.4.4.20
|
300
|
+
// http://es5.github.com/#x15.4.4.20
|
301
|
+
// 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 */) {
|
304
|
+
var object = toObject(this),
|
305
|
+
self = splitString && _toString(this) == "[object String]" ?
|
306
|
+
this.split("") :
|
307
|
+
object,
|
308
|
+
length = self.length >>> 0,
|
309
|
+
result = [],
|
310
|
+
value,
|
311
|
+
thisp = arguments[1];
|
312
|
+
|
313
|
+
// If no callback function or if callback is not a callable function
|
314
|
+
if (_toString(fun) != "[object Function]") {
|
315
|
+
throw new TypeError(fun + " is not a function");
|
316
|
+
}
|
317
|
+
|
318
|
+
for (var i = 0; i < length; i++) {
|
319
|
+
if (i in self) {
|
320
|
+
value = self[i];
|
321
|
+
if (fun.call(thisp, value, i, object)) {
|
322
|
+
result.push(value);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
return result;
|
327
|
+
};
|
328
|
+
}
|
329
|
+
|
330
|
+
// ES5 15.4.4.16
|
331
|
+
// http://es5.github.com/#x15.4.4.16
|
332
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
333
|
+
if (!Array.prototype.every) {
|
334
|
+
Array.prototype.every = function every(fun /*, thisp */) {
|
335
|
+
var object = toObject(this),
|
336
|
+
self = splitString && _toString(this) == "[object String]" ?
|
337
|
+
this.split("") :
|
338
|
+
object,
|
339
|
+
length = self.length >>> 0,
|
340
|
+
thisp = arguments[1];
|
341
|
+
|
342
|
+
// If no callback function or if callback is not a callable function
|
343
|
+
if (_toString(fun) != "[object Function]") {
|
344
|
+
throw new TypeError(fun + " is not a function");
|
345
|
+
}
|
346
|
+
|
347
|
+
for (var i = 0; i < length; i++) {
|
348
|
+
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
349
|
+
return false;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
return true;
|
353
|
+
};
|
354
|
+
}
|
355
|
+
|
356
|
+
// ES5 15.4.4.17
|
357
|
+
// http://es5.github.com/#x15.4.4.17
|
358
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
359
|
+
if (!Array.prototype.some) {
|
360
|
+
Array.prototype.some = function some(fun /*, thisp */) {
|
361
|
+
var object = toObject(this),
|
362
|
+
self = splitString && _toString(this) == "[object String]" ?
|
363
|
+
this.split("") :
|
364
|
+
object,
|
365
|
+
length = self.length >>> 0,
|
366
|
+
thisp = arguments[1];
|
367
|
+
|
368
|
+
// If no callback function or if callback is not a callable function
|
369
|
+
if (_toString(fun) != "[object Function]") {
|
370
|
+
throw new TypeError(fun + " is not a function");
|
371
|
+
}
|
372
|
+
|
373
|
+
for (var i = 0; i < length; i++) {
|
374
|
+
if (i in self && fun.call(thisp, self[i], i, object)) {
|
375
|
+
return true;
|
376
|
+
}
|
377
|
+
}
|
378
|
+
return false;
|
379
|
+
};
|
380
|
+
}
|
381
|
+
|
382
|
+
// ES5 15.4.4.21
|
383
|
+
// http://es5.github.com/#x15.4.4.21
|
384
|
+
// 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*/) {
|
387
|
+
var object = toObject(this),
|
388
|
+
self = splitString && _toString(this) == "[object String]" ?
|
389
|
+
this.split("") :
|
390
|
+
object,
|
391
|
+
length = self.length >>> 0;
|
392
|
+
|
393
|
+
// If no callback function or if callback is not a callable function
|
394
|
+
if (_toString(fun) != "[object Function]") {
|
395
|
+
throw new TypeError(fun + " is not a function");
|
396
|
+
}
|
397
|
+
|
398
|
+
// no value to return if no initial value and an empty array
|
399
|
+
if (!length && arguments.length == 1) {
|
400
|
+
throw new TypeError("reduce of empty array with no initial value");
|
401
|
+
}
|
402
|
+
|
403
|
+
var i = 0;
|
404
|
+
var result;
|
405
|
+
if (arguments.length >= 2) {
|
406
|
+
result = arguments[1];
|
407
|
+
} else {
|
408
|
+
do {
|
409
|
+
if (i in self) {
|
410
|
+
result = self[i++];
|
411
|
+
break;
|
412
|
+
}
|
413
|
+
|
414
|
+
// if array contains no values, no initial value to return
|
415
|
+
if (++i >= length) {
|
416
|
+
throw new TypeError("reduce of empty array with no initial value");
|
417
|
+
}
|
418
|
+
} while (true);
|
419
|
+
}
|
420
|
+
|
421
|
+
for (; i < length; i++) {
|
422
|
+
if (i in self) {
|
423
|
+
result = fun.call(void 0, result, self[i], i, object);
|
424
|
+
}
|
425
|
+
}
|
426
|
+
|
427
|
+
return result;
|
428
|
+
};
|
429
|
+
}
|
430
|
+
|
431
|
+
// ES5 15.4.4.22
|
432
|
+
// http://es5.github.com/#x15.4.4.22
|
433
|
+
// 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*/) {
|
436
|
+
var object = toObject(this),
|
437
|
+
self = splitString && _toString(this) == "[object String]" ?
|
438
|
+
this.split("") :
|
439
|
+
object,
|
440
|
+
length = self.length >>> 0;
|
441
|
+
|
442
|
+
// If no callback function or if callback is not a callable function
|
443
|
+
if (_toString(fun) != "[object Function]") {
|
444
|
+
throw new TypeError(fun + " is not a function");
|
445
|
+
}
|
446
|
+
|
447
|
+
// no value to return if no initial value, empty array
|
448
|
+
if (!length && arguments.length == 1) {
|
449
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
450
|
+
}
|
451
|
+
|
452
|
+
var result, i = length - 1;
|
453
|
+
if (arguments.length >= 2) {
|
454
|
+
result = arguments[1];
|
455
|
+
} else {
|
456
|
+
do {
|
457
|
+
if (i in self) {
|
458
|
+
result = self[i--];
|
459
|
+
break;
|
460
|
+
}
|
461
|
+
|
462
|
+
// if array contains no values, no initial value to return
|
463
|
+
if (--i < 0) {
|
464
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
465
|
+
}
|
466
|
+
} while (true);
|
467
|
+
}
|
468
|
+
|
469
|
+
do {
|
470
|
+
if (i in this) {
|
471
|
+
result = fun.call(void 0, result, self[i], i, object);
|
472
|
+
}
|
473
|
+
} while (i--);
|
474
|
+
|
475
|
+
return result;
|
476
|
+
};
|
477
|
+
}
|
478
|
+
|
479
|
+
// ES5 15.4.4.14
|
480
|
+
// http://es5.github.com/#x15.4.4.14
|
481
|
+
// 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),
|
487
|
+
length = self.length >>> 0;
|
488
|
+
|
489
|
+
if (!length) {
|
490
|
+
return -1;
|
491
|
+
}
|
492
|
+
|
493
|
+
var i = 0;
|
494
|
+
if (arguments.length > 1) {
|
495
|
+
i = toInteger(arguments[1]);
|
496
|
+
}
|
497
|
+
|
498
|
+
// handle negative indices
|
499
|
+
i = i >= 0 ? i : Math.max(0, length + i);
|
500
|
+
for (; i < length; i++) {
|
501
|
+
if (i in self && self[i] === sought) {
|
502
|
+
return i;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
return -1;
|
506
|
+
};
|
507
|
+
}
|
508
|
+
|
509
|
+
// ES5 15.4.4.15
|
510
|
+
// http://es5.github.com/#x15.4.4.15
|
511
|
+
// 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),
|
517
|
+
length = self.length >>> 0;
|
518
|
+
|
519
|
+
if (!length) {
|
520
|
+
return -1;
|
521
|
+
}
|
522
|
+
var i = length - 1;
|
523
|
+
if (arguments.length > 1) {
|
524
|
+
i = Math.min(i, toInteger(arguments[1]));
|
525
|
+
}
|
526
|
+
// handle negative indices
|
527
|
+
i = i >= 0 ? i : length - Math.abs(i);
|
528
|
+
for (; i >= 0; i--) {
|
529
|
+
if (i in self && sought === self[i]) {
|
530
|
+
return i;
|
531
|
+
}
|
532
|
+
}
|
533
|
+
return -1;
|
534
|
+
};
|
535
|
+
}
|
536
|
+
|
537
|
+
//
|
538
|
+
// Object
|
539
|
+
// ======
|
540
|
+
//
|
541
|
+
|
542
|
+
// ES5 15.2.3.14
|
543
|
+
// 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
|
+
|
564
|
+
if (
|
565
|
+
(typeof object != "object" && typeof object != "function") ||
|
566
|
+
object === null
|
567
|
+
) {
|
568
|
+
throw new TypeError("Object.keys called on a non-object");
|
569
|
+
}
|
570
|
+
|
571
|
+
var keys = [];
|
572
|
+
for (var name in object) {
|
573
|
+
if (owns(object, name)) {
|
574
|
+
keys.push(name);
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
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);
|
583
|
+
}
|
584
|
+
}
|
585
|
+
}
|
586
|
+
return keys;
|
587
|
+
};
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
//
|
592
|
+
// Date
|
593
|
+
// ====
|
594
|
+
//
|
595
|
+
|
596
|
+
// ES5 15.9.5.43
|
597
|
+
// http://es5.github.com/#x15.9.5.43
|
598
|
+
// This function returns a String value represent the instance in time
|
599
|
+
// represented by this Date object. The format of the String is the Date Time
|
600
|
+
// string format defined in 15.9.1.15. All fields are present in the String.
|
601
|
+
// The time zone is always UTC, denoted by the suffix Z. If the time value of
|
602
|
+
// 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() {
|
610
|
+
var result, length, value, year, month;
|
611
|
+
if (!isFinite(this)) {
|
612
|
+
throw new RangeError("Date.prototype.toISOString called on non-finite value.");
|
613
|
+
}
|
614
|
+
|
615
|
+
year = this.getUTCFullYear();
|
616
|
+
|
617
|
+
month = this.getUTCMonth();
|
618
|
+
// see https://github.com/kriskowal/es5-shim/issues/111
|
619
|
+
year += Math.floor(month / 12);
|
620
|
+
month = (month % 12 + 12) % 12;
|
621
|
+
|
622
|
+
// 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()];
|
625
|
+
year = (
|
626
|
+
(year < 0 ? "-" : (year > 9999 ? "+" : "")) +
|
627
|
+
("00000" + Math.abs(year))
|
628
|
+
.slice(0 <= year && year <= 9999 ? -4 : -6)
|
629
|
+
);
|
630
|
+
|
631
|
+
length = result.length;
|
632
|
+
while (length--) {
|
633
|
+
value = result[length];
|
634
|
+
// pad months, days, hours, minutes, and seconds to have two
|
635
|
+
// digits.
|
636
|
+
if (value < 10) {
|
637
|
+
result[length] = "0" + value;
|
638
|
+
}
|
639
|
+
}
|
640
|
+
// pad milliseconds to have three digits.
|
641
|
+
return (
|
642
|
+
year + "-" + result.slice(0, 2).join("-") +
|
643
|
+
"T" + result.slice(2).join(":") + "." +
|
644
|
+
("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
|
645
|
+
);
|
646
|
+
};
|
647
|
+
}
|
648
|
+
|
649
|
+
|
650
|
+
// ES5 15.9.5.44
|
651
|
+
// http://es5.github.com/#x15.9.5.44
|
652
|
+
// This function provides a String representation of a Date object for use by
|
653
|
+
// JSON.stringify (15.12.3).
|
654
|
+
var dateToJSONIsSupported = false;
|
655
|
+
try {
|
656
|
+
dateToJSONIsSupported = (
|
657
|
+
Date.prototype.toJSON &&
|
658
|
+
new Date(NaN).toJSON() === null &&
|
659
|
+
new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
|
660
|
+
Date.prototype.toJSON.call({ // generic
|
661
|
+
toISOString: function () {
|
662
|
+
return true;
|
663
|
+
}
|
664
|
+
})
|
665
|
+
);
|
666
|
+
} catch (e) {
|
667
|
+
}
|
668
|
+
if (!dateToJSONIsSupported) {
|
669
|
+
Date.prototype.toJSON = function toJSON(key) {
|
670
|
+
// When the toJSON method is called with argument key, the following
|
671
|
+
// steps are taken:
|
672
|
+
|
673
|
+
// 1. Let O be the result of calling ToObject, giving it the this
|
674
|
+
// value as its argument.
|
675
|
+
// 2. Let tv be toPrimitive(O, hint Number).
|
676
|
+
var o = Object(this),
|
677
|
+
tv = toPrimitive(o),
|
678
|
+
toISO;
|
679
|
+
// 3. If tv is a Number and is not finite, return null.
|
680
|
+
if (typeof tv === "number" && !isFinite(tv)) {
|
681
|
+
return null;
|
682
|
+
}
|
683
|
+
// 4. Let toISO be the result of calling the [[Get]] internal method of
|
684
|
+
// O with argument "toISOString".
|
685
|
+
toISO = o.toISOString;
|
686
|
+
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
|
687
|
+
if (typeof toISO != "function") {
|
688
|
+
throw new TypeError("toISOString property is not callable");
|
689
|
+
}
|
690
|
+
// 6. Return the result of calling the [[Call]] internal method of
|
691
|
+
// toISO with O as the this value and an empty argument list.
|
692
|
+
return toISO.call(o);
|
693
|
+
|
694
|
+
// NOTE 1 The argument is ignored.
|
695
|
+
|
696
|
+
// NOTE 2 The toJSON function is intentionally generic; it does not
|
697
|
+
// require that its this value be a Date object. Therefore, it can be
|
698
|
+
// transferred to other kinds of objects for use as a method. However,
|
699
|
+
// it does require that any such object have a toISOString method. An
|
700
|
+
// object is free to use the argument key to filter its
|
701
|
+
// stringification.
|
702
|
+
};
|
703
|
+
}
|
704
|
+
|
705
|
+
// ES5 15.9.4.2
|
706
|
+
// http://es5.github.com/#x15.9.4.2
|
707
|
+
// based on work shared by Daniel Friesen (dantman)
|
708
|
+
// http://gist.github.com/303249
|
709
|
+
if (!Date.parse || "Date.parse is buggy") {
|
710
|
+
// XXX global assignment won't work in embeddings that use
|
711
|
+
// an alternate object for the context.
|
712
|
+
Date = (function(NativeDate) {
|
713
|
+
|
714
|
+
// Date.length === 7
|
715
|
+
function Date(Y, M, D, h, m, s, ms) {
|
716
|
+
var length = arguments.length;
|
717
|
+
if (this instanceof NativeDate) {
|
718
|
+
var date = length == 1 && String(Y) === Y ? // isString(Y)
|
719
|
+
// We explicitly pass it through parse:
|
720
|
+
new NativeDate(Date.parse(Y)) :
|
721
|
+
// We have to manually make calls depending on argument
|
722
|
+
// length here
|
723
|
+
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
|
724
|
+
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
|
725
|
+
length >= 5 ? new NativeDate(Y, M, D, h, m) :
|
726
|
+
length >= 4 ? new NativeDate(Y, M, D, h) :
|
727
|
+
length >= 3 ? new NativeDate(Y, M, D) :
|
728
|
+
length >= 2 ? new NativeDate(Y, M) :
|
729
|
+
length >= 1 ? new NativeDate(Y) :
|
730
|
+
new NativeDate();
|
731
|
+
// Prevent mixups with unfixed Date object
|
732
|
+
date.constructor = Date;
|
733
|
+
return date;
|
734
|
+
}
|
735
|
+
return NativeDate.apply(this, arguments);
|
736
|
+
};
|
737
|
+
|
738
|
+
// 15.9.1.15 Date Time String Format.
|
739
|
+
var isoDateExpression = new RegExp("^" +
|
740
|
+
"(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
|
741
|
+
// 6-digit extended year
|
742
|
+
"(?:-(\\d{2})" + // optional month capture
|
743
|
+
"(?:-(\\d{2})" + // optional day capture
|
744
|
+
"(?:" + // capture hours:minutes:seconds.milliseconds
|
745
|
+
"T(\\d{2})" + // hours capture
|
746
|
+
":(\\d{2})" + // minutes capture
|
747
|
+
"(?:" + // optional :seconds.milliseconds
|
748
|
+
":(\\d{2})" + // seconds capture
|
749
|
+
"(?:\\.(\\d{3}))?" + // milliseconds capture
|
750
|
+
")?" +
|
751
|
+
"(" + // capture UTC offset component
|
752
|
+
"Z|" + // UTC capture
|
753
|
+
"(?:" + // offset specifier +/-hours:minutes
|
754
|
+
"([-+])" + // sign capture
|
755
|
+
"(\\d{2})" + // hours offset capture
|
756
|
+
":(\\d{2})" + // minutes offset capture
|
757
|
+
")" +
|
758
|
+
")?)?)?)?" +
|
759
|
+
"$");
|
760
|
+
|
761
|
+
var months = [
|
762
|
+
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
|
763
|
+
];
|
764
|
+
|
765
|
+
function dayFromMonth(year, month) {
|
766
|
+
var t = month > 1 ? 1 : 0;
|
767
|
+
return (
|
768
|
+
months[month] +
|
769
|
+
Math.floor((year - 1969 + t) / 4) -
|
770
|
+
Math.floor((year - 1901 + t) / 100) +
|
771
|
+
Math.floor((year - 1601 + t) / 400) +
|
772
|
+
365 * (year - 1970)
|
773
|
+
);
|
774
|
+
}
|
775
|
+
|
776
|
+
// Copy any custom methods a 3rd party library may have added
|
777
|
+
for (var key in NativeDate) {
|
778
|
+
Date[key] = NativeDate[key];
|
779
|
+
}
|
780
|
+
|
781
|
+
// Copy "native" methods explicitly; they may be non-enumerable
|
782
|
+
Date.now = NativeDate.now;
|
783
|
+
Date.UTC = NativeDate.UTC;
|
784
|
+
Date.prototype = NativeDate.prototype;
|
785
|
+
Date.prototype.constructor = Date;
|
786
|
+
|
787
|
+
// Upgrade Date.parse to handle simplified ISO 8601 strings
|
788
|
+
Date.parse = function parse(string) {
|
789
|
+
var match = isoDateExpression.exec(string);
|
790
|
+
if (match) {
|
791
|
+
// parse months, days, hours, minutes, seconds, and milliseconds
|
792
|
+
// provide default values if necessary
|
793
|
+
// parse the UTC offset component
|
794
|
+
var year = Number(match[1]),
|
795
|
+
month = Number(match[2] || 1) - 1,
|
796
|
+
day = Number(match[3] || 1) - 1,
|
797
|
+
hour = Number(match[4] || 0),
|
798
|
+
minute = Number(match[5] || 0),
|
799
|
+
second = Number(match[6] || 0),
|
800
|
+
millisecond = Number(match[7] || 0),
|
801
|
+
// When time zone is missed, local offset should be used
|
802
|
+
// (ES 5.1 bug)
|
803
|
+
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
|
804
|
+
offset = !match[4] || match[8] ?
|
805
|
+
0 : Number(new NativeDate(1970, 0)),
|
806
|
+
signOffset = match[9] === "-" ? 1 : -1,
|
807
|
+
hourOffset = Number(match[10] || 0),
|
808
|
+
minuteOffset = Number(match[11] || 0),
|
809
|
+
result;
|
810
|
+
if (
|
811
|
+
hour < (
|
812
|
+
minute > 0 || second > 0 || millisecond > 0 ?
|
813
|
+
24 : 25
|
814
|
+
) &&
|
815
|
+
minute < 60 && second < 60 && millisecond < 1000 &&
|
816
|
+
month > -1 && month < 12 && hourOffset < 24 &&
|
817
|
+
minuteOffset < 60 && // detect invalid offsets
|
818
|
+
day > -1 &&
|
819
|
+
day < (
|
820
|
+
dayFromMonth(year, month + 1) -
|
821
|
+
dayFromMonth(year, month)
|
822
|
+
)
|
823
|
+
) {
|
824
|
+
result = (
|
825
|
+
(dayFromMonth(year, month) + day) * 24 +
|
826
|
+
hour +
|
827
|
+
hourOffset * signOffset
|
828
|
+
) * 60;
|
829
|
+
result = (
|
830
|
+
(result + minute + minuteOffset * signOffset) * 60 +
|
831
|
+
second
|
832
|
+
) * 1000 + millisecond + offset;
|
833
|
+
if (-8.64e15 <= result && result <= 8.64e15) {
|
834
|
+
return result;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
return NaN;
|
838
|
+
}
|
839
|
+
return NativeDate.parse.apply(this, arguments);
|
840
|
+
};
|
841
|
+
|
842
|
+
return Date;
|
843
|
+
})(Date);
|
844
|
+
}
|
845
|
+
|
846
|
+
// ES5 15.9.4.4
|
847
|
+
// http://es5.github.com/#x15.9.4.4
|
848
|
+
if (!Date.now) {
|
849
|
+
Date.now = function now() {
|
850
|
+
return new Date().getTime();
|
851
|
+
};
|
852
|
+
}
|
853
|
+
|
854
|
+
|
855
|
+
//
|
856
|
+
// String
|
857
|
+
// ======
|
858
|
+
//
|
859
|
+
|
860
|
+
|
861
|
+
// ES5 15.5.4.14
|
862
|
+
// http://es5.github.com/#x15.5.4.14
|
863
|
+
// [bugfix, chrome]
|
864
|
+
// If separator is undefined, then the result array contains just one String,
|
865
|
+
// which is the this value (converted to a String). If limit is not undefined,
|
866
|
+
// then the output array is truncated so that it contains no more than limit
|
867
|
+
// elements.
|
868
|
+
// "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
|
+
}
|
875
|
+
}
|
876
|
+
|
877
|
+
// ECMA-262, 3rd B.2.3
|
878
|
+
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a
|
879
|
+
// non-normative section suggesting uniform semantics and it should be
|
880
|
+
// normalized across all browsers
|
881
|
+
// [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) {
|
891
|
+
return string_substr.call(
|
892
|
+
this,
|
893
|
+
start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
|
894
|
+
length
|
895
|
+
);
|
896
|
+
}
|
897
|
+
}
|
898
|
+
|
899
|
+
// ES5 15.5.4.20
|
900
|
+
// http://es5.github.com/#x15.5.4.20
|
901
|
+
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
902
|
+
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
903
|
+
"\u2029\uFEFF";
|
904
|
+
if (!String.prototype.trim || ws.trim()) {
|
905
|
+
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
906
|
+
// 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;
|
960
|
+
}
|
961
|
+
}
|
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();
|
970
|
+
}
|
971
|
+
|
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
|
+
});
|