less 1.7.0 → 1.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.grunt/grunt-contrib-jasmine/es5-shim.js +1360 -0
  2. package/.idea/jsLibraryMappings.xml +0 -1
  3. package/.idea/workspace.xml +182 -183
  4. package/.travis.yml +0 -1
  5. package/CHANGELOG.md +60 -2
  6. package/CONTRIBUTING.md +1 -1
  7. package/Gruntfile.js +12 -24
  8. package/LICENSE +0 -2
  9. package/README.md +5 -3
  10. package/benchmark/less-benchmark.js +1 -2
  11. package/bin/lessc +13 -11
  12. package/bower.json +2 -2
  13. package/build/rhino-modules.js +1 -1
  14. package/dist/less-1.7.0.js +59 -59
  15. package/dist/less-1.7.0.min.js +12 -12
  16. package/dist/less-1.7.1.js +7936 -0
  17. package/dist/less-1.7.1.min.js +16 -0
  18. package/dist/less-1.7.2.js +7938 -0
  19. package/dist/less-1.7.2.min.js +16 -0
  20. package/dist/less-1.7.3.js +7942 -0
  21. package/dist/less-1.7.3.min.js +16 -0
  22. package/dist/less-1.7.4.js +7979 -0
  23. package/dist/less-1.7.4.min.js +16 -0
  24. package/dist/less-1.7.5.js +8008 -0
  25. package/dist/less-1.7.5.min.js +16 -0
  26. package/dist/less-rhino-1.7.0.js +48 -48
  27. package/dist/less-rhino-1.7.1.js +9311 -0
  28. package/dist/less-rhino-1.7.2.js +9313 -0
  29. package/dist/less-rhino-1.7.3.js +9317 -0
  30. package/dist/less-rhino-1.7.4.js +9354 -0
  31. package/dist/less-rhino-1.7.5.js +9383 -0
  32. package/dist/lessc-rhino-1.7.0.js +2 -2
  33. package/dist/lessc-rhino-1.7.1.js +449 -0
  34. package/dist/lessc-rhino-1.7.2.js +449 -0
  35. package/dist/lessc-rhino-1.7.3.js +449 -0
  36. package/dist/lessc-rhino-1.7.4.js +449 -0
  37. package/dist/lessc-rhino-1.7.5.js +449 -0
  38. package/lib/less/browser.js +14 -9
  39. package/lib/less/env.js +2 -0
  40. package/lib/less/fs.js +10 -0
  41. package/lib/less/functions.js +41 -38
  42. package/lib/less/import-visitor.js +9 -7
  43. package/lib/less/index.js +30 -18
  44. package/lib/less/lessc_helper.js +1 -0
  45. package/lib/less/parser/parser.js.orig +1747 -0
  46. package/lib/less/parser.js +81 -40
  47. package/lib/less/rhino.js +3 -3
  48. package/lib/less/source-map-output.js +1 -1
  49. package/lib/less/to-css-visitor.js +3 -0
  50. package/lib/less/tree/anonymous.js +7 -3
  51. package/lib/less/tree/directive.js +6 -0
  52. package/lib/less/tree/element.js +6 -22
  53. package/lib/less/tree/import.js +1 -1
  54. package/lib/less/tree/mixin.js +4 -3
  55. package/lib/less/tree/quoted.js +12 -4
  56. package/lib/less/tree/rule.js +7 -4
  57. package/lib/less/tree/rule.js.orig +164 -0
  58. package/lib/less/tree/ruleset.js +27 -2
  59. package/lib/less/tree/selector.js +1 -1
  60. package/lib/less/tree.js +2 -2
  61. package/package.json +13 -12
  62. package/test/browser/less.js +7317 -6931
  63. package/test/css/comments.css +8 -0
  64. package/test/css/css-3.css +9 -0
  65. package/test/css/functions.css +8 -8
  66. package/test/css/import-inline.css +4 -1
  67. package/test/css/import.css +6 -0
  68. package/test/css/javascript.css +5 -0
  69. package/test/css/mixins-guards.css +14 -3
  70. package/test/css/mixins.css +3 -0
  71. package/test/css/property-name-interp.css +1 -0
  72. package/test/css/urls.css +6 -0
  73. package/test/index.js +1 -1
  74. package/test/less/comments.less +14 -1
  75. package/test/less/css-3.less +12 -1
  76. package/test/less/errors/color-invalid-hex-code.less +3 -0
  77. package/test/less/errors/color-invalid-hex-code.txt +4 -0
  78. package/test/less/errors/color-invalid-hex-code2.less +3 -0
  79. package/test/less/errors/color-invalid-hex-code2.txt +4 -0
  80. package/test/less/errors/import-malformed.less +1 -0
  81. package/test/less/errors/import-malformed.txt +3 -0
  82. package/test/less/errors/import-no-semi.txt +1 -1
  83. package/test/less/errors/javascript-error.less +1 -1
  84. package/test/less/errors/javascript-error.txt +2 -2
  85. package/test/less/import-inline.less +1 -0
  86. package/test/less/import.less +8 -1
  87. package/test/less/javascript.less +9 -0
  88. package/test/less/mixins-guards.less +17 -3
  89. package/test/less/mixins.less +4 -0
  90. package/test/less/property-name-interp.less +4 -1
  91. package/test/less/property-name-interp.less.orig +59 -0
  92. package/test/less/urls.less +12 -0
  93. package/test/less-test.js +7 -8
  94. package/test/modify-vars.js +17 -0
  95. package/test/sourcemaps/basic.json +1 -1
  96. package/tmp/browser/test-runner-main.html +4 -0
  97. package/tmp/less.js +8295 -0
  98. package/build/README.md +0 -51
  99. package/tmp/browser/test-postProcessor.html +0 -59
  100. package/tmp/browser/test-runner-browser.html +0 -59
  101. package/tmp/browser/test-runner-errors.html +0 -267
  102. package/tmp/browser/test-runner-global-vars.html +0 -59
  103. package/tmp/browser/test-runner-legacy.html +0 -59
  104. package/tmp/browser/test-runner-modify-vars.html +0 -59
  105. package/tmp/browser/test-runner-no-js-errors.html +0 -59
  106. package/tmp/browser/test-runner-production.html +0 -55
  107. package/tmp/browser/test-runner-relative-urls.html +0 -59
  108. package/tmp/browser/test-runner-rootpath-relative.html +0 -59
  109. package/tmp/browser/test-runner-rootpath.html +0 -59
@@ -0,0 +1,1360 @@
1
+ // Copyright 2009-2012 by contributors, MIT License
2
+ // vim: ts=4 sts=4 sw=4 expandtab
3
+
4
+ //Add semicolon to prevent IIFE from being passed as argument to concated code.
5
+ ;
6
+ // Module systems magic dance
7
+ (function (definition) {
8
+ // RequireJS
9
+ if (typeof define == "function") {
10
+ define(definition);
11
+ // YUI3
12
+ } else if (typeof YUI == "function") {
13
+ YUI.add("es5", definition);
14
+ // CommonJS and <script>
15
+ } else {
16
+ definition();
17
+ }
18
+ })(function () {
19
+
20
+ /**
21
+ * Brings an environment as close to ECMAScript 5 compliance
22
+ * as is possible with the facilities of erstwhile engines.
23
+ *
24
+ * Annotated ES5: http://es5.github.com/ (specific links below)
25
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
26
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
27
+ */
28
+
29
+ // ES-5 15.1.2.2
30
+ if (parseInt('08') !== 8) {
31
+ parseInt = (function (origParseInt) {
32
+ var hexRegex = /^0[xX]/;
33
+ return function parseIntES5(str, radix) {
34
+ str = String(str).trim();
35
+ if (!+radix) {
36
+ radix = hexRegex.test(str) ? 16 : 10;
37
+ }
38
+ return origParseInt(str, radix);
39
+ };
40
+ }(parseInt));
41
+ }
42
+
43
+ //
44
+ // Function
45
+ // ========
46
+ //
47
+
48
+ // ES-5 15.3.4.5
49
+ // http://es5.github.com/#x15.3.4.5
50
+
51
+ function Empty() {}
52
+
53
+ if (!Function.prototype.bind) {
54
+ Function.prototype.bind = function bind(that) { // .length is 1
55
+ // 1. Let Target be the this value.
56
+ var target = this;
57
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
58
+ if (typeof target != "function") {
59
+ throw new TypeError("Function.prototype.bind called on incompatible " + target);
60
+ }
61
+ // 3. Let A be a new (possibly empty) internal list of all of the
62
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
63
+ // XXX slicedArgs will stand in for "A" if used
64
+ var args = _Array_slice_.call(arguments, 1); // for normal call
65
+ // 4. Let F be a new native ECMAScript object.
66
+ // 11. Set the [[Prototype]] internal property of F to the standard
67
+ // built-in Function prototype object as specified in 15.3.3.1.
68
+ // 12. Set the [[Call]] internal property of F as described in
69
+ // 15.3.4.5.1.
70
+ // 13. Set the [[Construct]] internal property of F as described in
71
+ // 15.3.4.5.2.
72
+ // 14. Set the [[HasInstance]] internal property of F as described in
73
+ // 15.3.4.5.3.
74
+ var binder = function () {
75
+
76
+ if (this instanceof bound) {
77
+ // 15.3.4.5.2 [[Construct]]
78
+ // When the [[Construct]] internal method of a function object,
79
+ // F that was created using the bind function is called with a
80
+ // list of arguments ExtraArgs, the following steps are taken:
81
+ // 1. Let target be the value of F's [[TargetFunction]]
82
+ // internal property.
83
+ // 2. If target has no [[Construct]] internal method, a
84
+ // TypeError exception is thrown.
85
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
86
+ // property.
87
+ // 4. Let args be a new list containing the same values as the
88
+ // list boundArgs in the same order followed by the same
89
+ // values as the list ExtraArgs in the same order.
90
+ // 5. Return the result of calling the [[Construct]] internal
91
+ // method of target providing args as the arguments.
92
+
93
+ var result = target.apply(
94
+ this,
95
+ args.concat(_Array_slice_.call(arguments))
96
+ );
97
+ if (Object(result) === result) {
98
+ return result;
99
+ }
100
+ return this;
101
+
102
+ } else {
103
+ // 15.3.4.5.1 [[Call]]
104
+ // When the [[Call]] internal method of a function object, F,
105
+ // which was created using the bind function is called with a
106
+ // this value and a list of arguments ExtraArgs, the following
107
+ // steps are taken:
108
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
109
+ // property.
110
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
111
+ // property.
112
+ // 3. Let target be the value of F's [[TargetFunction]] internal
113
+ // property.
114
+ // 4. Let args be a new list containing the same values as the
115
+ // list boundArgs in the same order followed by the same
116
+ // values as the list ExtraArgs in the same order.
117
+ // 5. Return the result of calling the [[Call]] internal method
118
+ // of target providing boundThis as the this value and
119
+ // providing args as the arguments.
120
+
121
+ // equiv: target.call(this, ...boundArgs, ...args)
122
+ return target.apply(
123
+ that,
124
+ args.concat(_Array_slice_.call(arguments))
125
+ );
126
+
127
+ }
128
+
129
+ };
130
+
131
+ // 15. If the [[Class]] internal property of Target is "Function", then
132
+ // a. Let L be the length property of Target minus the length of A.
133
+ // b. Set the length own property of F to either 0 or L, whichever is
134
+ // larger.
135
+ // 16. Else set the length own property of F to 0.
136
+
137
+ var boundLength = Math.max(0, target.length - args.length);
138
+
139
+ // 17. Set the attributes of the length own property of F to the values
140
+ // specified in 15.3.5.1.
141
+ var boundArgs = [];
142
+ for (var i = 0; i < boundLength; i++) {
143
+ boundArgs.push("$" + i);
144
+ }
145
+
146
+ // XXX Build a dynamic function with desired amount of arguments is the only
147
+ // way to set the length property of a function.
148
+ // In environments where Content Security Policies enabled (Chrome extensions,
149
+ // for ex.) all use of eval or Function costructor throws an exception.
150
+ // However in all of these environments Function.prototype.bind exists
151
+ // and so this code will never be executed.
152
+ var bound = Function("binder", "return function(" + boundArgs.join(",") + "){return binder.apply(this,arguments)}")(binder);
153
+
154
+ if (target.prototype) {
155
+ Empty.prototype = target.prototype;
156
+ bound.prototype = new Empty();
157
+ // Clean up dangling references.
158
+ Empty.prototype = null;
159
+ }
160
+
161
+ // TODO
162
+ // 18. Set the [[Extensible]] internal property of F to true.
163
+
164
+ // TODO
165
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
166
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
167
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
168
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
169
+ // false.
170
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
171
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
172
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
173
+ // and false.
174
+
175
+ // TODO
176
+ // NOTE Function objects created using Function.prototype.bind do not
177
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
178
+ // [[Scope]] internal properties.
179
+ // XXX can't delete prototype in pure-js.
180
+
181
+ // 22. Return F.
182
+ return bound;
183
+ };
184
+ }
185
+
186
+ // Shortcut to an often accessed properties, in order to avoid multiple
187
+ // dereference that costs universally.
188
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
189
+ // us it in defining shortcuts.
190
+ var call = Function.prototype.call;
191
+ var prototypeOfArray = Array.prototype;
192
+ var prototypeOfObject = Object.prototype;
193
+ var _Array_slice_ = prototypeOfArray.slice;
194
+ // Having a toString local variable name breaks in Opera so use _toString.
195
+ var _toString = call.bind(prototypeOfObject.toString);
196
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
197
+
198
+ // If JS engine supports accessors creating shortcuts.
199
+ var defineGetter;
200
+ var defineSetter;
201
+ var lookupGetter;
202
+ var lookupSetter;
203
+ var supportsAccessors;
204
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
205
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
206
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
207
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
208
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
209
+ }
210
+
211
+ //
212
+ // Array
213
+ // =====
214
+ //
215
+
216
+ // ES5 15.4.4.12
217
+ // http://es5.github.com/#x15.4.4.12
218
+ // Default value for second param
219
+ // [bugfix, ielt9, old browsers]
220
+ // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
221
+ if ([1,2].splice(0).length != 2) {
222
+ var array_splice = Array.prototype.splice;
223
+ var array_push = Array.prototype.push;
224
+ var array_unshift = Array.prototype.unshift;
225
+
226
+ if (function() { // test IE < 9 to splice bug - see issue #138
227
+ function makeArray(l) {
228
+ var a = [];
229
+ while (l--) {
230
+ a.unshift(l)
231
+ }
232
+ return a
233
+ }
234
+
235
+ var array = []
236
+ , lengthBefore
237
+ ;
238
+
239
+ array.splice.bind(array, 0, 0).apply(null, makeArray(20));
240
+ array.splice.bind(array, 0, 0).apply(null, makeArray(26));
241
+
242
+ lengthBefore = array.length; //20
243
+ array.splice(5, 0, "XXX"); // add one element
244
+
245
+ if (lengthBefore + 1 == array.length) {
246
+ return true;// has right splice implementation without bugs
247
+ }
248
+ // else {
249
+ // IE8 bug
250
+ // }
251
+ }()) {//IE 6/7
252
+ Array.prototype.splice = function(start, deleteCount) {
253
+ if (!arguments.length) {
254
+ return [];
255
+ } else {
256
+ return array_splice.apply(this, [
257
+ start === void 0 ? 0 : start,
258
+ deleteCount === void 0 ? (this.length - start) : deleteCount
259
+ ].concat(_Array_slice_.call(arguments, 2)))
260
+ }
261
+ };
262
+ }
263
+ else {//IE8
264
+ Array.prototype.splice = function(start, deleteCount) {
265
+ var result
266
+ , args = _Array_slice_.call(arguments, 2)
267
+ , addElementsCount = args.length
268
+ ;
269
+
270
+ if (!arguments.length) {
271
+ return [];
272
+ }
273
+
274
+ if (start === void 0) { // default
275
+ start = 0;
276
+ }
277
+ if (deleteCount === void 0) { // default
278
+ deleteCount = this.length - start;
279
+ }
280
+
281
+ if (addElementsCount > 0) {
282
+ if (deleteCount <= 0) {
283
+ if (start == this.length) { // tiny optimisation #1
284
+ array_push.apply(this, args);
285
+ return [];
286
+ }
287
+
288
+ if (start == 0) { // tiny optimisation #2
289
+ array_unshift.apply(this, args);
290
+ return [];
291
+ }
292
+ }
293
+
294
+ // Array.prototype.splice implementation
295
+ result = _Array_slice_.call(this, start, start + deleteCount);// delete part
296
+ args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part
297
+ args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part
298
+
299
+ // delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part'
300
+ args.unshift(0, this.length);
301
+
302
+ array_splice.apply(this, args);
303
+
304
+ return result;
305
+ }
306
+
307
+ return array_splice.call(this, start, deleteCount);
308
+ }
309
+
310
+ }
311
+ }
312
+
313
+ // ES5 15.4.4.12
314
+ // http://es5.github.com/#x15.4.4.13
315
+ // Return len+argCount.
316
+ // [bugfix, ielt8]
317
+ // IE < 8 bug: [].unshift(0) == undefined but should be "1"
318
+ if ([].unshift(0) != 1) {
319
+ var array_unshift = Array.prototype.unshift;
320
+ Array.prototype.unshift = function() {
321
+ array_unshift.apply(this, arguments);
322
+ return this.length;
323
+ };
324
+ }
325
+
326
+ // ES5 15.4.3.2
327
+ // http://es5.github.com/#x15.4.3.2
328
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
329
+ if (!Array.isArray) {
330
+ Array.isArray = function isArray(obj) {
331
+ return _toString(obj) == "[object Array]";
332
+ };
333
+ }
334
+
335
+ // The IsCallable() check in the Array functions
336
+ // has been replaced with a strict check on the
337
+ // internal class of the object to trap cases where
338
+ // the provided function was actually a regular
339
+ // expression literal, which in V8 and
340
+ // JavaScriptCore is a typeof "function". Only in
341
+ // V8 are regular expression literals permitted as
342
+ // reduce parameters, so it is desirable in the
343
+ // general case for the shim to match the more
344
+ // strict and common behavior of rejecting regular
345
+ // expressions.
346
+
347
+ // ES5 15.4.4.18
348
+ // http://es5.github.com/#x15.4.4.18
349
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
350
+
351
+ // Check failure of by-index access of string characters (IE < 9)
352
+ // and failure of `0 in boxedString` (Rhino)
353
+ var boxedString = Object("a"),
354
+ splitString = boxedString[0] != "a" || !(0 in boxedString);
355
+ // Check node 0.6.21 bug where third parameter is not boxed
356
+ var boxedForEach = true;
357
+ if (Array.prototype.forEach) {
358
+ Array.prototype.forEach.call("foo", function(item, i, obj) {
359
+ if (typeof obj !== 'object') boxedForEach = false;
360
+ });
361
+ }
362
+
363
+ if (!Array.prototype.forEach || !boxedForEach) {
364
+ Array.prototype.forEach = function forEach(fun /*, thisp*/) {
365
+ var object = toObject(this),
366
+ self = splitString && _toString(this) == "[object String]" ?
367
+ this.split("") :
368
+ object,
369
+ thisp = arguments[1],
370
+ i = -1,
371
+ length = self.length >>> 0;
372
+
373
+ // If no callback function or if callback is not a callable function
374
+ if (_toString(fun) != "[object Function]") {
375
+ throw new TypeError(); // TODO message
376
+ }
377
+
378
+ while (++i < length) {
379
+ if (i in self) {
380
+ // Invoke the callback function with call, passing arguments:
381
+ // context, property value, property key, thisArg object
382
+ // context
383
+ fun.call(thisp, self[i], i, object);
384
+ }
385
+ }
386
+ };
387
+ }
388
+
389
+ // ES5 15.4.4.19
390
+ // http://es5.github.com/#x15.4.4.19
391
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
392
+ if (!Array.prototype.map) {
393
+ Array.prototype.map = function map(fun /*, thisp*/) {
394
+ var object = toObject(this),
395
+ self = splitString && _toString(this) == "[object String]" ?
396
+ this.split("") :
397
+ object,
398
+ length = self.length >>> 0,
399
+ result = Array(length),
400
+ thisp = arguments[1];
401
+
402
+ // If no callback function or if callback is not a callable function
403
+ if (_toString(fun) != "[object Function]") {
404
+ throw new TypeError(fun + " is not a function");
405
+ }
406
+
407
+ for (var i = 0; i < length; i++) {
408
+ if (i in self)
409
+ result[i] = fun.call(thisp, self[i], i, object);
410
+ }
411
+ return result;
412
+ };
413
+ }
414
+
415
+ // ES5 15.4.4.20
416
+ // http://es5.github.com/#x15.4.4.20
417
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
418
+ if (!Array.prototype.filter) {
419
+ Array.prototype.filter = function filter(fun /*, thisp */) {
420
+ var object = toObject(this),
421
+ self = splitString && _toString(this) == "[object String]" ?
422
+ this.split("") :
423
+ object,
424
+ length = self.length >>> 0,
425
+ result = [],
426
+ value,
427
+ thisp = arguments[1];
428
+
429
+ // If no callback function or if callback is not a callable function
430
+ if (_toString(fun) != "[object Function]") {
431
+ throw new TypeError(fun + " is not a function");
432
+ }
433
+
434
+ for (var i = 0; i < length; i++) {
435
+ if (i in self) {
436
+ value = self[i];
437
+ if (fun.call(thisp, value, i, object)) {
438
+ result.push(value);
439
+ }
440
+ }
441
+ }
442
+ return result;
443
+ };
444
+ }
445
+
446
+ // ES5 15.4.4.16
447
+ // http://es5.github.com/#x15.4.4.16
448
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
449
+ if (!Array.prototype.every) {
450
+ Array.prototype.every = function every(fun /*, thisp */) {
451
+ var object = toObject(this),
452
+ self = splitString && _toString(this) == "[object String]" ?
453
+ this.split("") :
454
+ object,
455
+ length = self.length >>> 0,
456
+ thisp = arguments[1];
457
+
458
+ // If no callback function or if callback is not a callable function
459
+ if (_toString(fun) != "[object Function]") {
460
+ throw new TypeError(fun + " is not a function");
461
+ }
462
+
463
+ for (var i = 0; i < length; i++) {
464
+ if (i in self && !fun.call(thisp, self[i], i, object)) {
465
+ return false;
466
+ }
467
+ }
468
+ return true;
469
+ };
470
+ }
471
+
472
+ // ES5 15.4.4.17
473
+ // http://es5.github.com/#x15.4.4.17
474
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
475
+ if (!Array.prototype.some) {
476
+ Array.prototype.some = function some(fun /*, thisp */) {
477
+ var object = toObject(this),
478
+ self = splitString && _toString(this) == "[object String]" ?
479
+ this.split("") :
480
+ object,
481
+ length = self.length >>> 0,
482
+ thisp = arguments[1];
483
+
484
+ // If no callback function or if callback is not a callable function
485
+ if (_toString(fun) != "[object Function]") {
486
+ throw new TypeError(fun + " is not a function");
487
+ }
488
+
489
+ for (var i = 0; i < length; i++) {
490
+ if (i in self && fun.call(thisp, self[i], i, object)) {
491
+ return true;
492
+ }
493
+ }
494
+ return false;
495
+ };
496
+ }
497
+
498
+ // ES5 15.4.4.21
499
+ // http://es5.github.com/#x15.4.4.21
500
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
501
+ if (!Array.prototype.reduce) {
502
+ Array.prototype.reduce = function reduce(fun /*, initial*/) {
503
+ var object = toObject(this),
504
+ self = splitString && _toString(this) == "[object String]" ?
505
+ this.split("") :
506
+ object,
507
+ length = self.length >>> 0;
508
+
509
+ // If no callback function or if callback is not a callable function
510
+ if (_toString(fun) != "[object Function]") {
511
+ throw new TypeError(fun + " is not a function");
512
+ }
513
+
514
+ // no value to return if no initial value and an empty array
515
+ if (!length && arguments.length == 1) {
516
+ throw new TypeError("reduce of empty array with no initial value");
517
+ }
518
+
519
+ var i = 0;
520
+ var result;
521
+ if (arguments.length >= 2) {
522
+ result = arguments[1];
523
+ } else {
524
+ do {
525
+ if (i in self) {
526
+ result = self[i++];
527
+ break;
528
+ }
529
+
530
+ // if array contains no values, no initial value to return
531
+ if (++i >= length) {
532
+ throw new TypeError("reduce of empty array with no initial value");
533
+ }
534
+ } while (true);
535
+ }
536
+
537
+ for (; i < length; i++) {
538
+ if (i in self) {
539
+ result = fun.call(void 0, result, self[i], i, object);
540
+ }
541
+ }
542
+
543
+ return result;
544
+ };
545
+ }
546
+
547
+ // ES5 15.4.4.22
548
+ // http://es5.github.com/#x15.4.4.22
549
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
550
+ if (!Array.prototype.reduceRight) {
551
+ Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
552
+ var object = toObject(this),
553
+ self = splitString && _toString(this) == "[object String]" ?
554
+ this.split("") :
555
+ object,
556
+ length = self.length >>> 0;
557
+
558
+ // If no callback function or if callback is not a callable function
559
+ if (_toString(fun) != "[object Function]") {
560
+ throw new TypeError(fun + " is not a function");
561
+ }
562
+
563
+ // no value to return if no initial value, empty array
564
+ if (!length && arguments.length == 1) {
565
+ throw new TypeError("reduceRight of empty array with no initial value");
566
+ }
567
+
568
+ var result, i = length - 1;
569
+ if (arguments.length >= 2) {
570
+ result = arguments[1];
571
+ } else {
572
+ do {
573
+ if (i in self) {
574
+ result = self[i--];
575
+ break;
576
+ }
577
+
578
+ // if array contains no values, no initial value to return
579
+ if (--i < 0) {
580
+ throw new TypeError("reduceRight of empty array with no initial value");
581
+ }
582
+ } while (true);
583
+ }
584
+
585
+ if (i < 0) {
586
+ return result;
587
+ }
588
+
589
+ do {
590
+ if (i in this) {
591
+ result = fun.call(void 0, result, self[i], i, object);
592
+ }
593
+ } while (i--);
594
+
595
+ return result;
596
+ };
597
+ }
598
+
599
+ // ES5 15.4.4.14
600
+ // http://es5.github.com/#x15.4.4.14
601
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
602
+ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
603
+ Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
604
+ var self = splitString && _toString(this) == "[object String]" ?
605
+ this.split("") :
606
+ toObject(this),
607
+ length = self.length >>> 0;
608
+
609
+ if (!length) {
610
+ return -1;
611
+ }
612
+
613
+ var i = 0;
614
+ if (arguments.length > 1) {
615
+ i = toInteger(arguments[1]);
616
+ }
617
+
618
+ // handle negative indices
619
+ i = i >= 0 ? i : Math.max(0, length + i);
620
+ for (; i < length; i++) {
621
+ if (i in self && self[i] === sought) {
622
+ return i;
623
+ }
624
+ }
625
+ return -1;
626
+ };
627
+ }
628
+
629
+ // ES5 15.4.4.15
630
+ // http://es5.github.com/#x15.4.4.15
631
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
632
+ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
633
+ Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
634
+ var self = splitString && _toString(this) == "[object String]" ?
635
+ this.split("") :
636
+ toObject(this),
637
+ length = self.length >>> 0;
638
+
639
+ if (!length) {
640
+ return -1;
641
+ }
642
+ var i = length - 1;
643
+ if (arguments.length > 1) {
644
+ i = Math.min(i, toInteger(arguments[1]));
645
+ }
646
+ // handle negative indices
647
+ i = i >= 0 ? i : length - Math.abs(i);
648
+ for (; i >= 0; i--) {
649
+ if (i in self && sought === self[i]) {
650
+ return i;
651
+ }
652
+ }
653
+ return -1;
654
+ };
655
+ }
656
+
657
+ //
658
+ // Object
659
+ // ======
660
+ //
661
+
662
+ // ES5 15.2.3.14
663
+ // http://es5.github.com/#x15.2.3.14
664
+ if (!Object.keys) {
665
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
666
+ var hasDontEnumBug = true,
667
+ dontEnums = [
668
+ "toString",
669
+ "toLocaleString",
670
+ "valueOf",
671
+ "hasOwnProperty",
672
+ "isPrototypeOf",
673
+ "propertyIsEnumerable",
674
+ "constructor"
675
+ ],
676
+ dontEnumsLength = dontEnums.length;
677
+
678
+ for (var key in {"toString": null}) {
679
+ hasDontEnumBug = false;
680
+ }
681
+
682
+ Object.keys = function keys(object) {
683
+
684
+ if (
685
+ (typeof object != "object" && typeof object != "function") ||
686
+ object === null
687
+ ) {
688
+ throw new TypeError("Object.keys called on a non-object");
689
+ }
690
+
691
+ var keys = [];
692
+ for (var name in object) {
693
+ if (owns(object, name)) {
694
+ keys.push(name);
695
+ }
696
+ }
697
+
698
+ if (hasDontEnumBug) {
699
+ for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
700
+ var dontEnum = dontEnums[i];
701
+ if (owns(object, dontEnum)) {
702
+ keys.push(dontEnum);
703
+ }
704
+ }
705
+ }
706
+ return keys;
707
+ };
708
+
709
+ }
710
+
711
+ //
712
+ // Date
713
+ // ====
714
+ //
715
+
716
+ // ES5 15.9.5.43
717
+ // http://es5.github.com/#x15.9.5.43
718
+ // This function returns a String value represent the instance in time
719
+ // represented by this Date object. The format of the String is the Date Time
720
+ // string format defined in 15.9.1.15. All fields are present in the String.
721
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
722
+ // this object is not a finite Number a RangeError exception is thrown.
723
+ var negativeDate = -62198755200000,
724
+ negativeYearString = "-000001";
725
+ if (
726
+ !Date.prototype.toISOString ||
727
+ (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
728
+ ) {
729
+ Date.prototype.toISOString = function toISOString() {
730
+ var result, length, value, year, month;
731
+ if (!isFinite(this)) {
732
+ throw new RangeError("Date.prototype.toISOString called on non-finite value.");
733
+ }
734
+
735
+ year = this.getUTCFullYear();
736
+
737
+ month = this.getUTCMonth();
738
+ // see https://github.com/es-shims/es5-shim/issues/111
739
+ year += Math.floor(month / 12);
740
+ month = (month % 12 + 12) % 12;
741
+
742
+ // the date time string format is specified in 15.9.1.15.
743
+ result = [month + 1, this.getUTCDate(),
744
+ this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
745
+ year = (
746
+ (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
747
+ ("00000" + Math.abs(year))
748
+ .slice(0 <= year && year <= 9999 ? -4 : -6)
749
+ );
750
+
751
+ length = result.length;
752
+ while (length--) {
753
+ value = result[length];
754
+ // pad months, days, hours, minutes, and seconds to have two
755
+ // digits.
756
+ if (value < 10) {
757
+ result[length] = "0" + value;
758
+ }
759
+ }
760
+ // pad milliseconds to have three digits.
761
+ return (
762
+ year + "-" + result.slice(0, 2).join("-") +
763
+ "T" + result.slice(2).join(":") + "." +
764
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
765
+ );
766
+ };
767
+ }
768
+
769
+
770
+ // ES5 15.9.5.44
771
+ // http://es5.github.com/#x15.9.5.44
772
+ // This function provides a String representation of a Date object for use by
773
+ // JSON.stringify (15.12.3).
774
+ var dateToJSONIsSupported = false;
775
+ try {
776
+ dateToJSONIsSupported = (
777
+ Date.prototype.toJSON &&
778
+ new Date(NaN).toJSON() === null &&
779
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
780
+ Date.prototype.toJSON.call({ // generic
781
+ toISOString: function () {
782
+ return true;
783
+ }
784
+ })
785
+ );
786
+ } catch (e) {
787
+ }
788
+ if (!dateToJSONIsSupported) {
789
+ Date.prototype.toJSON = function toJSON(key) {
790
+ // When the toJSON method is called with argument key, the following
791
+ // steps are taken:
792
+
793
+ // 1. Let O be the result of calling ToObject, giving it the this
794
+ // value as its argument.
795
+ // 2. Let tv be toPrimitive(O, hint Number).
796
+ var o = Object(this),
797
+ tv = toPrimitive(o),
798
+ toISO;
799
+ // 3. If tv is a Number and is not finite, return null.
800
+ if (typeof tv === "number" && !isFinite(tv)) {
801
+ return null;
802
+ }
803
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
804
+ // O with argument "toISOString".
805
+ toISO = o.toISOString;
806
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
807
+ if (typeof toISO != "function") {
808
+ throw new TypeError("toISOString property is not callable");
809
+ }
810
+ // 6. Return the result of calling the [[Call]] internal method of
811
+ // toISO with O as the this value and an empty argument list.
812
+ return toISO.call(o);
813
+
814
+ // NOTE 1 The argument is ignored.
815
+
816
+ // NOTE 2 The toJSON function is intentionally generic; it does not
817
+ // require that its this value be a Date object. Therefore, it can be
818
+ // transferred to other kinds of objects for use as a method. However,
819
+ // it does require that any such object have a toISOString method. An
820
+ // object is free to use the argument key to filter its
821
+ // stringification.
822
+ };
823
+ }
824
+
825
+ // ES5 15.9.4.2
826
+ // http://es5.github.com/#x15.9.4.2
827
+ // based on work shared by Daniel Friesen (dantman)
828
+ // http://gist.github.com/303249
829
+ if (!Date.parse || "Date.parse is buggy") {
830
+ // XXX global assignment won't work in embeddings that use
831
+ // an alternate object for the context.
832
+ Date = (function(NativeDate) {
833
+
834
+ // Date.length === 7
835
+ function Date(Y, M, D, h, m, s, ms) {
836
+ var length = arguments.length;
837
+ if (this instanceof NativeDate) {
838
+ var date = length == 1 && String(Y) === Y ? // isString(Y)
839
+ // We explicitly pass it through parse:
840
+ new NativeDate(Date.parse(Y)) :
841
+ // We have to manually make calls depending on argument
842
+ // length here
843
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
844
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
845
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
846
+ length >= 4 ? new NativeDate(Y, M, D, h) :
847
+ length >= 3 ? new NativeDate(Y, M, D) :
848
+ length >= 2 ? new NativeDate(Y, M) :
849
+ length >= 1 ? new NativeDate(Y) :
850
+ new NativeDate();
851
+ // Prevent mixups with unfixed Date object
852
+ date.constructor = Date;
853
+ return date;
854
+ }
855
+ return NativeDate.apply(this, arguments);
856
+ };
857
+
858
+ // 15.9.1.15 Date Time String Format.
859
+ var isoDateExpression = new RegExp("^" +
860
+ "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
861
+ // 6-digit extended year
862
+ "(?:-(\\d{2})" + // optional month capture
863
+ "(?:-(\\d{2})" + // optional day capture
864
+ "(?:" + // capture hours:minutes:seconds.milliseconds
865
+ "T(\\d{2})" + // hours capture
866
+ ":(\\d{2})" + // minutes capture
867
+ "(?:" + // optional :seconds.milliseconds
868
+ ":(\\d{2})" + // seconds capture
869
+ "(?:(\\.\\d{1,}))?" + // milliseconds capture
870
+ ")?" +
871
+ "(" + // capture UTC offset component
872
+ "Z|" + // UTC capture
873
+ "(?:" + // offset specifier +/-hours:minutes
874
+ "([-+])" + // sign capture
875
+ "(\\d{2})" + // hours offset capture
876
+ ":(\\d{2})" + // minutes offset capture
877
+ ")" +
878
+ ")?)?)?)?" +
879
+ "$");
880
+
881
+ var months = [
882
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
883
+ ];
884
+
885
+ function dayFromMonth(year, month) {
886
+ var t = month > 1 ? 1 : 0;
887
+ return (
888
+ months[month] +
889
+ Math.floor((year - 1969 + t) / 4) -
890
+ Math.floor((year - 1901 + t) / 100) +
891
+ Math.floor((year - 1601 + t) / 400) +
892
+ 365 * (year - 1970)
893
+ );
894
+ }
895
+
896
+ function toUTC(t) {
897
+ return Number(new NativeDate(1970, 0, 1, 0, 0, 0, t));
898
+ }
899
+
900
+ // Copy any custom methods a 3rd party library may have added
901
+ for (var key in NativeDate) {
902
+ Date[key] = NativeDate[key];
903
+ }
904
+
905
+ // Copy "native" methods explicitly; they may be non-enumerable
906
+ Date.now = NativeDate.now;
907
+ Date.UTC = NativeDate.UTC;
908
+ Date.prototype = NativeDate.prototype;
909
+ Date.prototype.constructor = Date;
910
+
911
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
912
+ Date.parse = function parse(string) {
913
+ var match = isoDateExpression.exec(string);
914
+ if (match) {
915
+ // parse months, days, hours, minutes, seconds, and milliseconds
916
+ // provide default values if necessary
917
+ // parse the UTC offset component
918
+ var year = Number(match[1]),
919
+ month = Number(match[2] || 1) - 1,
920
+ day = Number(match[3] || 1) - 1,
921
+ hour = Number(match[4] || 0),
922
+ minute = Number(match[5] || 0),
923
+ second = Number(match[6] || 0),
924
+ millisecond = Math.floor(Number(match[7] || 0) * 1000),
925
+ // When time zone is missed, local offset should be used
926
+ // (ES 5.1 bug)
927
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
928
+ isLocalTime = Boolean(match[4] && !match[8]),
929
+ signOffset = match[9] === "-" ? 1 : -1,
930
+ hourOffset = Number(match[10] || 0),
931
+ minuteOffset = Number(match[11] || 0),
932
+ result;
933
+ if (
934
+ hour < (
935
+ minute > 0 || second > 0 || millisecond > 0 ?
936
+ 24 : 25
937
+ ) &&
938
+ minute < 60 && second < 60 && millisecond < 1000 &&
939
+ month > -1 && month < 12 && hourOffset < 24 &&
940
+ minuteOffset < 60 && // detect invalid offsets
941
+ day > -1 &&
942
+ day < (
943
+ dayFromMonth(year, month + 1) -
944
+ dayFromMonth(year, month)
945
+ )
946
+ ) {
947
+ result = (
948
+ (dayFromMonth(year, month) + day) * 24 +
949
+ hour +
950
+ hourOffset * signOffset
951
+ ) * 60;
952
+ result = (
953
+ (result + minute + minuteOffset * signOffset) * 60 +
954
+ second
955
+ ) * 1000 + millisecond;
956
+ if (isLocalTime) {
957
+ result = toUTC(result);
958
+ }
959
+ if (-8.64e15 <= result && result <= 8.64e15) {
960
+ return result;
961
+ }
962
+ }
963
+ return NaN;
964
+ }
965
+ return NativeDate.parse.apply(this, arguments);
966
+ };
967
+
968
+ return Date;
969
+ })(Date);
970
+ }
971
+
972
+ // ES5 15.9.4.4
973
+ // http://es5.github.com/#x15.9.4.4
974
+ if (!Date.now) {
975
+ Date.now = function now() {
976
+ return new Date().getTime();
977
+ };
978
+ }
979
+
980
+
981
+ //
982
+ // Number
983
+ // ======
984
+ //
985
+
986
+ // ES5.1 15.7.4.5
987
+ // http://es5.github.com/#x15.7.4.5
988
+ if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") {
989
+ // Hide these variables and functions
990
+ (function () {
991
+ var base, size, data, i;
992
+
993
+ base = 1e7;
994
+ size = 6;
995
+ data = [0, 0, 0, 0, 0, 0];
996
+
997
+ function multiply(n, c) {
998
+ var i = -1;
999
+ while (++i < size) {
1000
+ c += n * data[i];
1001
+ data[i] = c % base;
1002
+ c = Math.floor(c / base);
1003
+ }
1004
+ }
1005
+
1006
+ function divide(n) {
1007
+ var i = size, c = 0;
1008
+ while (--i >= 0) {
1009
+ c += data[i];
1010
+ data[i] = Math.floor(c / n);
1011
+ c = (c % n) * base;
1012
+ }
1013
+ }
1014
+
1015
+ function toString() {
1016
+ var i = size;
1017
+ var s = '';
1018
+ while (--i >= 0) {
1019
+ if (s !== '' || i === 0 || data[i] !== 0) {
1020
+ var t = String(data[i]);
1021
+ if (s === '') {
1022
+ s = t;
1023
+ } else {
1024
+ s += '0000000'.slice(0, 7 - t.length) + t;
1025
+ }
1026
+ }
1027
+ }
1028
+ return s;
1029
+ }
1030
+
1031
+ function pow(x, n, acc) {
1032
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1033
+ }
1034
+
1035
+ function log(x) {
1036
+ var n = 0;
1037
+ while (x >= 4096) {
1038
+ n += 12;
1039
+ x /= 4096;
1040
+ }
1041
+ while (x >= 2) {
1042
+ n += 1;
1043
+ x /= 2;
1044
+ }
1045
+ return n;
1046
+ }
1047
+
1048
+ Number.prototype.toFixed = function (fractionDigits) {
1049
+ var f, x, s, m, e, z, j, k;
1050
+
1051
+ // Test for NaN and round fractionDigits down
1052
+ f = Number(fractionDigits);
1053
+ f = f !== f ? 0 : Math.floor(f);
1054
+
1055
+ if (f < 0 || f > 20) {
1056
+ throw new RangeError("Number.toFixed called with invalid number of decimals");
1057
+ }
1058
+
1059
+ x = Number(this);
1060
+
1061
+ // Test for NaN
1062
+ if (x !== x) {
1063
+ return "NaN";
1064
+ }
1065
+
1066
+ // If it is too big or small, return the string value of the number
1067
+ if (x <= -1e21 || x >= 1e21) {
1068
+ return String(x);
1069
+ }
1070
+
1071
+ s = "";
1072
+
1073
+ if (x < 0) {
1074
+ s = "-";
1075
+ x = -x;
1076
+ }
1077
+
1078
+ m = "0";
1079
+
1080
+ if (x > 1e-21) {
1081
+ // 1e-21 < x < 1e21
1082
+ // -70 < log2(x) < 70
1083
+ e = log(x * pow(2, 69, 1)) - 69;
1084
+ z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
1085
+ z *= 0x10000000000000; // Math.pow(2, 52);
1086
+ e = 52 - e;
1087
+
1088
+ // -18 < e < 122
1089
+ // x = z / 2 ^ e
1090
+ if (e > 0) {
1091
+ multiply(0, z);
1092
+ j = f;
1093
+
1094
+ while (j >= 7) {
1095
+ multiply(1e7, 0);
1096
+ j -= 7;
1097
+ }
1098
+
1099
+ multiply(pow(10, j, 1), 0);
1100
+ j = e - 1;
1101
+
1102
+ while (j >= 23) {
1103
+ divide(1 << 23);
1104
+ j -= 23;
1105
+ }
1106
+
1107
+ divide(1 << j);
1108
+ multiply(1, 1);
1109
+ divide(2);
1110
+ m = toString();
1111
+ } else {
1112
+ multiply(0, z);
1113
+ multiply(1 << (-e), 0);
1114
+ m = toString() + '0.00000000000000000000'.slice(2, 2 + f);
1115
+ }
1116
+ }
1117
+
1118
+ if (f > 0) {
1119
+ k = m.length;
1120
+
1121
+ if (k <= f) {
1122
+ m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
1123
+ } else {
1124
+ m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
1125
+ }
1126
+ } else {
1127
+ m = s + m;
1128
+ }
1129
+
1130
+ return m;
1131
+ }
1132
+ }());
1133
+ }
1134
+
1135
+
1136
+ //
1137
+ // String
1138
+ // ======
1139
+ //
1140
+
1141
+
1142
+ // ES5 15.5.4.14
1143
+ // http://es5.github.com/#x15.5.4.14
1144
+
1145
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1146
+ // Many browsers do not split properly with regular expressions or they
1147
+ // do not perform the split correctly under obscure conditions.
1148
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1149
+ // I've tested in many browsers and this seems to cover the deviant ones:
1150
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1151
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1152
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1153
+ // [undefined, "t", undefined, "e", ...]
1154
+ // ''.split(/.?/) should be [], not [""]
1155
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1156
+
1157
+ var string_split = String.prototype.split;
1158
+ if (
1159
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1160
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1161
+ 'tesst'.split(/(s)*/)[1] === "t" ||
1162
+ ''.split(/.?/).length ||
1163
+ '.'.split(/()()/).length > 1
1164
+ ) {
1165
+ (function () {
1166
+ var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
1167
+
1168
+ String.prototype.split = function (separator, limit) {
1169
+ var string = this;
1170
+ if (separator === void 0 && limit === 0)
1171
+ return [];
1172
+
1173
+ // If `separator` is not a regex, use native split
1174
+ if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
1175
+ return string_split.apply(this, arguments);
1176
+ }
1177
+
1178
+ var output = [],
1179
+ flags = (separator.ignoreCase ? "i" : "") +
1180
+ (separator.multiline ? "m" : "") +
1181
+ (separator.extended ? "x" : "") + // Proposed for ES6
1182
+ (separator.sticky ? "y" : ""), // Firefox 3+
1183
+ lastLastIndex = 0,
1184
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1185
+ separator = new RegExp(separator.source, flags + "g"),
1186
+ separator2, match, lastIndex, lastLength;
1187
+ string += ""; // Type-convert
1188
+ if (!compliantExecNpcg) {
1189
+ // Doesn't need flags gy, but they don't hurt
1190
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
1191
+ }
1192
+ /* Values for `limit`, per the spec:
1193
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
1194
+ * If 0, Infinity, or NaN: 0
1195
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1196
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1197
+ * If other: Type-convert, then use the above rules
1198
+ */
1199
+ limit = limit === void 0 ?
1200
+ -1 >>> 0 : // Math.pow(2, 32) - 1
1201
+ limit >>> 0; // ToUint32(limit)
1202
+ while (match = separator.exec(string)) {
1203
+ // `separator.lastIndex` is not reliable cross-browser
1204
+ lastIndex = match.index + match[0].length;
1205
+ if (lastIndex > lastLastIndex) {
1206
+ output.push(string.slice(lastLastIndex, match.index));
1207
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1208
+ // nonparticipating capturing groups
1209
+ if (!compliantExecNpcg && match.length > 1) {
1210
+ match[0].replace(separator2, function () {
1211
+ for (var i = 1; i < arguments.length - 2; i++) {
1212
+ if (arguments[i] === void 0) {
1213
+ match[i] = void 0;
1214
+ }
1215
+ }
1216
+ });
1217
+ }
1218
+ if (match.length > 1 && match.index < string.length) {
1219
+ Array.prototype.push.apply(output, match.slice(1));
1220
+ }
1221
+ lastLength = match[0].length;
1222
+ lastLastIndex = lastIndex;
1223
+ if (output.length >= limit) {
1224
+ break;
1225
+ }
1226
+ }
1227
+ if (separator.lastIndex === match.index) {
1228
+ separator.lastIndex++; // Avoid an infinite loop
1229
+ }
1230
+ }
1231
+ if (lastLastIndex === string.length) {
1232
+ if (lastLength || !separator.test("")) {
1233
+ output.push("");
1234
+ }
1235
+ } else {
1236
+ output.push(string.slice(lastLastIndex));
1237
+ }
1238
+ return output.length > limit ? output.slice(0, limit) : output;
1239
+ };
1240
+ }());
1241
+
1242
+ // [bugfix, chrome]
1243
+ // If separator is undefined, then the result array contains just one String,
1244
+ // which is the this value (converted to a String). If limit is not undefined,
1245
+ // then the output array is truncated so that it contains no more than limit
1246
+ // elements.
1247
+ // "0".split(undefined, 0) -> []
1248
+ } else if ("0".split(void 0, 0).length) {
1249
+ String.prototype.split = function(separator, limit) {
1250
+ if (separator === void 0 && limit === 0) return [];
1251
+ return string_split.apply(this, arguments);
1252
+ }
1253
+ }
1254
+
1255
+
1256
+ // ECMA-262, 3rd B.2.3
1257
+ // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
1258
+ // non-normative section suggesting uniform semantics and it should be
1259
+ // normalized across all browsers
1260
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1261
+ if ("".substr && "0b".substr(-1) !== "b") {
1262
+ var string_substr = String.prototype.substr;
1263
+ /**
1264
+ * Get the substring of a string
1265
+ * @param {integer} start where to start the substring
1266
+ * @param {integer} length how many characters to return
1267
+ * @return {string}
1268
+ */
1269
+ String.prototype.substr = function(start, length) {
1270
+ return string_substr.call(
1271
+ this,
1272
+ start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
1273
+ length
1274
+ );
1275
+ }
1276
+ }
1277
+
1278
+ // ES5 15.5.4.20
1279
+ // http://es5.github.com/#x15.5.4.20
1280
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
1281
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
1282
+ "\u2029\uFEFF";
1283
+ if (!String.prototype.trim || ws.trim()) {
1284
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1285
+ // http://perfectionkills.com/whitespace-deviations/
1286
+ ws = "[" + ws + "]";
1287
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
1288
+ trimEndRegexp = new RegExp(ws + ws + "*$");
1289
+ String.prototype.trim = function trim() {
1290
+ if (this === void 0 || this === null) {
1291
+ throw new TypeError("can't convert "+this+" to object");
1292
+ }
1293
+ return String(this)
1294
+ .replace(trimBeginRegexp, "")
1295
+ .replace(trimEndRegexp, "");
1296
+ };
1297
+ }
1298
+
1299
+ //
1300
+ // Util
1301
+ // ======
1302
+ //
1303
+
1304
+ // ES5 9.4
1305
+ // http://es5.github.com/#x9.4
1306
+ // http://jsperf.com/to-integer
1307
+
1308
+ function toInteger(n) {
1309
+ n = +n;
1310
+ if (n !== n) { // isNaN
1311
+ n = 0;
1312
+ } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
1313
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
1314
+ }
1315
+ return n;
1316
+ }
1317
+
1318
+ function isPrimitive(input) {
1319
+ var type = typeof input;
1320
+ return (
1321
+ input === null ||
1322
+ type === "undefined" ||
1323
+ type === "boolean" ||
1324
+ type === "number" ||
1325
+ type === "string"
1326
+ );
1327
+ }
1328
+
1329
+ function toPrimitive(input) {
1330
+ var val, valueOf, toString;
1331
+ if (isPrimitive(input)) {
1332
+ return input;
1333
+ }
1334
+ valueOf = input.valueOf;
1335
+ if (typeof valueOf === "function") {
1336
+ val = valueOf.call(input);
1337
+ if (isPrimitive(val)) {
1338
+ return val;
1339
+ }
1340
+ }
1341
+ toString = input.toString;
1342
+ if (typeof toString === "function") {
1343
+ val = toString.call(input);
1344
+ if (isPrimitive(val)) {
1345
+ return val;
1346
+ }
1347
+ }
1348
+ throw new TypeError();
1349
+ }
1350
+
1351
+ // ES5 9.9
1352
+ // http://es5.github.com/#x9.9
1353
+ var toObject = function (o) {
1354
+ if (o == null) { // this matches both null and undefined
1355
+ throw new TypeError("can't convert "+o+" to object");
1356
+ }
1357
+ return Object(o);
1358
+ };
1359
+
1360
+ });