resin 0.3.0 → 0.3.1

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 (50) hide show
  1. data/amber/bin/amberc +4 -3
  2. data/amber/js/IDE.deploy.js +147 -45
  3. data/amber/js/IDE.js +155 -53
  4. data/amber/js/Kernel-Classes.deploy.js +20 -14
  5. data/amber/js/Kernel-Classes.js +29 -18
  6. data/amber/js/Kernel-Collections.deploy.js +82 -0
  7. data/amber/js/Kernel-Collections.js +102 -0
  8. data/amber/js/Kernel-Methods.deploy.js +374 -261
  9. data/amber/js/Kernel-Methods.js +417 -269
  10. data/amber/js/Kernel-Objects.deploy.js +90 -28
  11. data/amber/js/Kernel-Objects.js +121 -34
  12. data/amber/js/Kernel-Tests.deploy.js +35 -0
  13. data/amber/js/Kernel-Tests.js +45 -0
  14. data/amber/js/SUnit.deploy.js +175 -17
  15. data/amber/js/SUnit.js +237 -24
  16. data/amber/js/amber.js +2 -1
  17. data/amber/js/boot.js +74 -18
  18. data/amber/js/lib/es5-shim-2.0.2/CHANGES +93 -0
  19. data/amber/js/lib/es5-shim-2.0.2/CONTRIBUTORS.md +25 -0
  20. data/amber/js/lib/es5-shim-2.0.2/LICENSE +19 -0
  21. data/amber/js/lib/es5-shim-2.0.2/README.md +161 -0
  22. data/amber/js/lib/es5-shim-2.0.2/es5-sham.js +348 -0
  23. data/amber/js/lib/es5-shim-2.0.2/es5-sham.min.js +6 -0
  24. data/amber/js/lib/es5-shim-2.0.2/es5-shim.js +963 -0
  25. data/amber/js/lib/es5-shim-2.0.2/es5-shim.min.js +16 -0
  26. data/amber/js/lib/es5-shim-2.0.2/minify +2 -0
  27. data/amber/js/lib/es5-shim-2.0.2/package.json +31 -0
  28. data/amber/js/lib/es5-shim-2.0.2/tests/helpers/h-kill.js +59 -0
  29. data/amber/js/lib/es5-shim-2.0.2/tests/helpers/h-matchers.js +34 -0
  30. data/amber/js/lib/es5-shim-2.0.2/tests/helpers/h.js +3 -0
  31. data/amber/js/lib/es5-shim-2.0.2/tests/index.html +62 -0
  32. data/amber/js/lib/es5-shim-2.0.2/tests/lib/jasmine-html.js +190 -0
  33. data/amber/js/lib/es5-shim-2.0.2/tests/lib/jasmine.css +166 -0
  34. data/amber/js/lib/es5-shim-2.0.2/tests/lib/jasmine.js +2477 -0
  35. data/amber/js/lib/es5-shim-2.0.2/tests/lib/jasmine_favicon.png +0 -0
  36. data/amber/js/lib/es5-shim-2.0.2/tests/lib/json2.js +478 -0
  37. data/amber/js/lib/es5-shim-2.0.2/tests/spec/s-array.js +1138 -0
  38. data/amber/js/lib/es5-shim-2.0.2/tests/spec/s-date.js +117 -0
  39. data/amber/js/lib/es5-shim-2.0.2/tests/spec/s-function.js +147 -0
  40. data/amber/js/lib/es5-shim-2.0.2/tests/spec/s-object.js +84 -0
  41. data/amber/js/lib/es5-shim-2.0.2/tests/spec/s-string.js +24 -0
  42. data/amber/st/IDE.st +15 -16
  43. data/amber/st/Kernel-Classes.st +9 -9
  44. data/amber/st/Kernel-Collections.st +37 -0
  45. data/amber/st/Kernel-Methods.st +63 -8
  46. data/amber/st/Kernel-Objects.st +34 -7
  47. data/amber/st/Kernel-Tests.st +10 -0
  48. data/amber/st/SUnit.st +86 -9
  49. metadata +44 -21
  50. data/amber/js/compat.js +0 -22
@@ -0,0 +1,348 @@
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-sham", definition);
12
+ // CommonJS and <script>
13
+ } else {
14
+ definition();
15
+ }
16
+ })(function () {
17
+
18
+ // ES5 15.2.3.2
19
+ // http://es5.github.com/#x15.2.3.2
20
+ if (!Object.getPrototypeOf) {
21
+ // https://github.com/kriskowal/es5-shim/issues#issue/2
22
+ // http://ejohn.org/blog/objectgetprototypeof/
23
+ // recommended by fschaefer on github
24
+ Object.getPrototypeOf = function getPrototypeOf(object) {
25
+ return object.__proto__ || (
26
+ object.constructor
27
+ ? object.constructor.prototype
28
+ : prototypeOfObject
29
+ );
30
+ };
31
+ }
32
+
33
+
34
+ var call = Function.prototype.call;
35
+ var prototypeOfObject = Object.prototype;
36
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
37
+ var supportsAccessors;
38
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
39
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
40
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
41
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
42
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
43
+ }
44
+
45
+
46
+ // ES5 15.2.3.3
47
+ // http://es5.github.com/#x15.2.3.3
48
+ if (!Object.getOwnPropertyDescriptor) {
49
+ var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: ";
50
+
51
+ Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
52
+ if ((typeof object != "object" && typeof object != "function") || object === null) {
53
+ throw new TypeError(ERR_NON_OBJECT + object);
54
+ }
55
+ // If object does not owns property return undefined immediately.
56
+ if (!owns(object, property)) {
57
+ return;
58
+ }
59
+
60
+ // If object has a property then it's for sure both `enumerable` and
61
+ // `configurable`.
62
+ var descriptor = { enumerable: true, configurable: true };
63
+
64
+ // If JS engine supports accessor properties then property may be a
65
+ // getter or setter.
66
+ if (supportsAccessors) {
67
+ // Unfortunately `__lookupGetter__` will return a getter even
68
+ // if object has own non getter property along with a same named
69
+ // inherited getter. To avoid misbehavior we temporary remove
70
+ // `__proto__` so that `__lookupGetter__` will return getter only
71
+ // if it's owned by an object.
72
+ var prototype = object.__proto__;
73
+ object.__proto__ = prototypeOfObject;
74
+
75
+ var getter = lookupGetter(object, property);
76
+ var setter = lookupSetter(object, property);
77
+
78
+ // Once we have getter and setter we can put values back.
79
+ object.__proto__ = prototype;
80
+
81
+ if (getter || setter) {
82
+ if (getter) {
83
+ descriptor.get = getter;
84
+ }
85
+ if (setter) {
86
+ descriptor.set = setter;
87
+ }
88
+ // If it was accessor property we're done and return here
89
+ // in order to avoid adding `value` to the descriptor.
90
+ return descriptor;
91
+ }
92
+ }
93
+
94
+ // If we got this far we know that object has an own property that is
95
+ // not an accessor so we set it as a value and return descriptor.
96
+ descriptor.value = object[property];
97
+ return descriptor;
98
+ };
99
+ }
100
+
101
+ // ES5 15.2.3.4
102
+ // http://es5.github.com/#x15.2.3.4
103
+ if (!Object.getOwnPropertyNames) {
104
+ Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
105
+ return Object.keys(object);
106
+ };
107
+ }
108
+
109
+ // ES5 15.2.3.5
110
+ // http://es5.github.com/#x15.2.3.5
111
+ if (!Object.create) {
112
+ Object.create = function create(prototype, properties) {
113
+
114
+ var object;
115
+ function Type() {} // An empty constructor.
116
+
117
+ if (prototype === null) {
118
+ object = { "__proto__": null };
119
+ } else {
120
+ if (typeof prototype !== "object" && typeof prototype !== "function") {
121
+ // In the native implementation `parent` can be `null`
122
+ // OR *any* `instanceof Object` (Object|Function|Array|RegExp|etc)
123
+ // Use `typeof` tho, b/c in old IE, DOM elements are not `instanceof Object`
124
+ // like they are in modern browsers. Using `Object.create` on DOM elements
125
+ // is...err...probably inappropriate, but the native version allows for it.
126
+ throw new TypeError("Object prototype may only be an Object or null"); // same msg as Chrome
127
+ }
128
+ Type.prototype = prototype;
129
+ object = new Type();
130
+ // IE has no built-in implementation of `Object.getPrototypeOf`
131
+ // neither `__proto__`, but this manually setting `__proto__` will
132
+ // guarantee that `Object.getPrototypeOf` will work as expected with
133
+ // objects created using `Object.create`
134
+ object.__proto__ = prototype;
135
+ }
136
+
137
+ if (properties !== void 0) {
138
+ Object.defineProperties(object, properties);
139
+ }
140
+
141
+ return object;
142
+ };
143
+ }
144
+
145
+ // ES5 15.2.3.6
146
+ // http://es5.github.com/#x15.2.3.6
147
+
148
+ // Patch for WebKit and IE8 standard mode
149
+ // Designed by hax <hax.github.com>
150
+ // related issue: https://github.com/kriskowal/es5-shim/issues#issue/5
151
+ // IE8 Reference:
152
+ // http://msdn.microsoft.com/en-us/library/dd282900.aspx
153
+ // http://msdn.microsoft.com/en-us/library/dd229916.aspx
154
+ // WebKit Bugs:
155
+ // https://bugs.webkit.org/show_bug.cgi?id=36423
156
+
157
+ function doesDefinePropertyWork(object) {
158
+ try {
159
+ Object.defineProperty(object, "sentinel", {});
160
+ return "sentinel" in object;
161
+ } catch (exception) {
162
+ // returns falsy
163
+ }
164
+ }
165
+
166
+ // check whether defineProperty works if it's given. Otherwise,
167
+ // shim partially.
168
+ if (Object.defineProperty) {
169
+ var definePropertyWorksOnObject = doesDefinePropertyWork({});
170
+ var definePropertyWorksOnDom = typeof document == "undefined" ||
171
+ doesDefinePropertyWork(document.createElement("div"));
172
+ if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
173
+ var definePropertyFallback = Object.defineProperty;
174
+ }
175
+ }
176
+
177
+ if (!Object.defineProperty || definePropertyFallback) {
178
+ var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
179
+ var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
180
+ var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
181
+ "on this javascript engine";
182
+
183
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
184
+ if ((typeof object != "object" && typeof object != "function") || object === null) {
185
+ throw new TypeError(ERR_NON_OBJECT_TARGET + object);
186
+ }
187
+ if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null) {
188
+ throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
189
+ }
190
+ // make a valiant attempt to use the real defineProperty
191
+ // for I8's DOM elements.
192
+ if (definePropertyFallback) {
193
+ try {
194
+ return definePropertyFallback.call(Object, object, property, descriptor);
195
+ } catch (exception) {
196
+ // try the shim if the real one doesn't work
197
+ }
198
+ }
199
+
200
+ // If it's a data property.
201
+ if (owns(descriptor, "value")) {
202
+ // fail silently if "writable", "enumerable", or "configurable"
203
+ // are requested but not supported
204
+ /*
205
+ // alternate approach:
206
+ if ( // can't implement these features; allow false but not true
207
+ !(owns(descriptor, "writable") ? descriptor.writable : true) ||
208
+ !(owns(descriptor, "enumerable") ? descriptor.enumerable : true) ||
209
+ !(owns(descriptor, "configurable") ? descriptor.configurable : true)
210
+ )
211
+ throw new RangeError(
212
+ "This implementation of Object.defineProperty does not " +
213
+ "support configurable, enumerable, or writable."
214
+ );
215
+ */
216
+
217
+ if (supportsAccessors && (lookupGetter(object, property) ||
218
+ lookupSetter(object, property)))
219
+ {
220
+ // As accessors are supported only on engines implementing
221
+ // `__proto__` we can safely override `__proto__` while defining
222
+ // a property to make sure that we don't hit an inherited
223
+ // accessor.
224
+ var prototype = object.__proto__;
225
+ object.__proto__ = prototypeOfObject;
226
+ // Deleting a property anyway since getter / setter may be
227
+ // defined on object itself.
228
+ delete object[property];
229
+ object[property] = descriptor.value;
230
+ // Setting original `__proto__` back now.
231
+ object.__proto__ = prototype;
232
+ } else {
233
+ object[property] = descriptor.value;
234
+ }
235
+ } else {
236
+ if (!supportsAccessors) {
237
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
238
+ }
239
+ // If we got that far then getters and setters can be defined !!
240
+ if (owns(descriptor, "get")) {
241
+ defineGetter(object, property, descriptor.get);
242
+ }
243
+ if (owns(descriptor, "set")) {
244
+ defineSetter(object, property, descriptor.set);
245
+ }
246
+ }
247
+ return object;
248
+ };
249
+ }
250
+
251
+ // ES5 15.2.3.7
252
+ // http://es5.github.com/#x15.2.3.7
253
+ if (!Object.defineProperties) {
254
+ Object.defineProperties = function defineProperties(object, properties) {
255
+ for (var property in properties) {
256
+ if (owns(properties, property) && property != "__proto__") {
257
+ Object.defineProperty(object, property, properties[property]);
258
+ }
259
+ }
260
+ return object;
261
+ };
262
+ }
263
+
264
+ // ES5 15.2.3.8
265
+ // http://es5.github.com/#x15.2.3.8
266
+ if (!Object.seal) {
267
+ Object.seal = function seal(object) {
268
+ // this is misleading and breaks feature-detection, but
269
+ // allows "securable" code to "gracefully" degrade to working
270
+ // but insecure code.
271
+ return object;
272
+ };
273
+ }
274
+
275
+ // ES5 15.2.3.9
276
+ // http://es5.github.com/#x15.2.3.9
277
+ if (!Object.freeze) {
278
+ Object.freeze = function freeze(object) {
279
+ // this is misleading and breaks feature-detection, but
280
+ // allows "securable" code to "gracefully" degrade to working
281
+ // but insecure code.
282
+ return object;
283
+ };
284
+ }
285
+
286
+ // detect a Rhino bug and patch it
287
+ try {
288
+ Object.freeze(function () {});
289
+ } catch (exception) {
290
+ Object.freeze = (function freeze(freezeObject) {
291
+ return function freeze(object) {
292
+ if (typeof object == "function") {
293
+ return object;
294
+ } else {
295
+ return freezeObject(object);
296
+ }
297
+ };
298
+ })(Object.freeze);
299
+ }
300
+
301
+ // ES5 15.2.3.10
302
+ // http://es5.github.com/#x15.2.3.10
303
+ if (!Object.preventExtensions) {
304
+ Object.preventExtensions = function preventExtensions(object) {
305
+ // this is misleading and breaks feature-detection, but
306
+ // allows "securable" code to "gracefully" degrade to working
307
+ // but insecure code.
308
+ return object;
309
+ };
310
+ }
311
+
312
+ // ES5 15.2.3.11
313
+ // http://es5.github.com/#x15.2.3.11
314
+ if (!Object.isSealed) {
315
+ Object.isSealed = function isSealed(object) {
316
+ return false;
317
+ };
318
+ }
319
+
320
+ // ES5 15.2.3.12
321
+ // http://es5.github.com/#x15.2.3.12
322
+ if (!Object.isFrozen) {
323
+ Object.isFrozen = function isFrozen(object) {
324
+ return false;
325
+ };
326
+ }
327
+
328
+ // ES5 15.2.3.13
329
+ // http://es5.github.com/#x15.2.3.13
330
+ if (!Object.isExtensible) {
331
+ Object.isExtensible = function isExtensible(object) {
332
+ // 1. If Type(O) is not Object throw a TypeError exception.
333
+ if (Object(object) !== object) {
334
+ throw new TypeError(); // TODO message
335
+ }
336
+ // 2. Return the Boolean value of the [[Extensible]] internal property of O.
337
+ var name = '';
338
+ while (owns(object, name)) {
339
+ name += '?';
340
+ }
341
+ object[name] = true;
342
+ var returnValue = owns(object, name);
343
+ delete object[name];
344
+ return returnValue;
345
+ };
346
+ }
347
+
348
+ });
@@ -0,0 +1,6 @@
1
+ (function(e){"function"==typeof define?define(e):"function"==typeof YUI?YUI.add("es5-sham",e):e()})(function(){function e(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:f)});var d=Function.prototype.call,f=Object.prototype,g=d.bind(f.hasOwnProperty),h;if(h=g(f,"__defineGetter__"))defineGetter=d.bind(f.__defineGetter__),defineSetter=d.bind(f.__defineSetter__),
2
+ lookupGetter=d.bind(f.__lookupGetter__),lookupSetter=d.bind(f.__lookupSetter__);Object.getOwnPropertyDescriptor||(Object.getOwnPropertyDescriptor=function(a,b){if("object"!=typeof a&&"function"!=typeof a||null===a)throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object: "+a);if(g(a,b)){var c={enumerable:!0,configurable:!0};if(h){var j=a.__proto__;a.__proto__=f;var d=lookupGetter(a,b),e=lookupSetter(a,b);a.__proto__=j;if(d||e)return d&&(c.get=d),e&&(c.set=e),c}c.value=a[b];return c}});
3
+ Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(a){return Object.keys(a)});Object.create||(Object.create=function(a,b){function c(){}var d;if(null===a)d={__proto__:null};else{if("object"!==typeof a&&"function"!==typeof a)throw new TypeError("Object prototype may only be an Object or null");c.prototype=a;d=new c;d.__proto__=a}void 0!==b&&Object.defineProperties(d,b);return d});if(Object.defineProperty){var d=e({}),k="undefined"==typeof document||e(document.createElement("div"));if(!d||
4
+ !k)var i=Object.defineProperty}if(!Object.defineProperty||i)Object.defineProperty=function(a,b,c){if("object"!=typeof a&&"function"!=typeof a||null===a)throw new TypeError("Object.defineProperty called on non-object: "+a);if("object"!=typeof c&&"function"!=typeof c||null===c)throw new TypeError("Property description must be an object: "+c);if(i)try{return i.call(Object,a,b,c)}catch(d){}if(g(c,"value"))if(h&&(lookupGetter(a,b)||lookupSetter(a,b))){var e=a.__proto__;a.__proto__=f;delete a[b];a[b]=c.value;
5
+ a.__proto__=e}else a[b]=c.value;else{if(!h)throw new TypeError("getters & setters can not be defined on this javascript engine");g(c,"get")&&defineGetter(a,b,c.get);g(c,"set")&&defineSetter(a,b,c.set)}return a};Object.defineProperties||(Object.defineProperties=function(a,b){for(var c in b)g(b,c)&&"__proto__"!=c&&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(m){var l=
6
+ Object.freeze;Object.freeze=function(a){return"function"==typeof a?a:l(a)}}Object.preventExtensions||(Object.preventExtensions=function(a){return a});Object.isSealed||(Object.isSealed=function(){return!1});Object.isFrozen||(Object.isFrozen=function(){return!1});Object.isExtensible||(Object.isExtensible=function(a){if(Object(a)!==a)throw new TypeError;for(var b="";g(a,b);)b+="?";a[b]=!0;var c=g(a,b);delete a[b];return c})});
@@ -0,0 +1,963 @@
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
+ if (!Function.prototype.bind) {
36
+ Function.prototype.bind = function bind(that) { // .length is 1
37
+ // 1. Let Target be the this value.
38
+ var target = this;
39
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
40
+ if (typeof target != "function") {
41
+ throw new TypeError("Function.prototype.bind called on incompatible " + target);
42
+ }
43
+ // 3. Let A be a new (possibly empty) internal list of all of the
44
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
45
+ // XXX slicedArgs will stand in for "A" if used
46
+ var args = slice.call(arguments, 1); // for normal call
47
+ // 4. Let F be a new native ECMAScript object.
48
+ // 11. Set the [[Prototype]] internal property of F to the standard
49
+ // built-in Function prototype object as specified in 15.3.3.1.
50
+ // 12. Set the [[Call]] internal property of F as described in
51
+ // 15.3.4.5.1.
52
+ // 13. Set the [[Construct]] internal property of F as described in
53
+ // 15.3.4.5.2.
54
+ // 14. Set the [[HasInstance]] internal property of F as described in
55
+ // 15.3.4.5.3.
56
+ var bound = function () {
57
+
58
+ if (this instanceof bound) {
59
+ // 15.3.4.5.2 [[Construct]]
60
+ // When the [[Construct]] internal method of a function object,
61
+ // F that was created using the bind function is called with a
62
+ // list of arguments ExtraArgs, the following steps are taken:
63
+ // 1. Let target be the value of F's [[TargetFunction]]
64
+ // internal property.
65
+ // 2. If target has no [[Construct]] internal method, a
66
+ // TypeError exception is thrown.
67
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
68
+ // property.
69
+ // 4. Let args be a new list containing the same values as the
70
+ // list boundArgs in the same order followed by the same
71
+ // values as the list ExtraArgs in the same order.
72
+ // 5. Return the result of calling the [[Construct]] internal
73
+ // method of target providing args as the arguments.
74
+
75
+ var result = target.apply(
76
+ this,
77
+ args.concat(slice.call(arguments))
78
+ );
79
+ if (Object(result) === result) {
80
+ return result;
81
+ }
82
+ return this;
83
+
84
+ } else {
85
+ // 15.3.4.5.1 [[Call]]
86
+ // When the [[Call]] internal method of a function object, F,
87
+ // which was created using the bind function is called with a
88
+ // this value and a list of arguments ExtraArgs, the following
89
+ // steps are taken:
90
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
91
+ // property.
92
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
93
+ // property.
94
+ // 3. Let target be the value of F's [[TargetFunction]] internal
95
+ // property.
96
+ // 4. Let args be a new list containing the same values as the
97
+ // list boundArgs in the same order followed by the same
98
+ // values as the list ExtraArgs in the same order.
99
+ // 5. Return the result of calling the [[Call]] internal method
100
+ // of target providing boundThis as the this value and
101
+ // providing args as the arguments.
102
+
103
+ // equiv: target.call(this, ...boundArgs, ...args)
104
+ return target.apply(
105
+ that,
106
+ args.concat(slice.call(arguments))
107
+ );
108
+
109
+ }
110
+
111
+ };
112
+ if(target.prototype) {
113
+ bound.prototype = Object.create(target.prototype);
114
+ }
115
+ // XXX bound.length is never writable, so don't even try
116
+ //
117
+ // 15. If the [[Class]] internal property of Target is "Function", then
118
+ // a. Let L be the length property of Target minus the length of A.
119
+ // b. Set the length own property of F to either 0 or L, whichever is
120
+ // larger.
121
+ // 16. Else set the length own property of F to 0.
122
+ // 17. Set the attributes of the length own property of F to the values
123
+ // specified in 15.3.5.1.
124
+
125
+ // TODO
126
+ // 18. Set the [[Extensible]] internal property of F to true.
127
+
128
+ // TODO
129
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
130
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
131
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
132
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
133
+ // false.
134
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
135
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
136
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
137
+ // and false.
138
+
139
+ // TODO
140
+ // NOTE Function objects created using Function.prototype.bind do not
141
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
142
+ // [[Scope]] internal properties.
143
+ // XXX can't delete prototype in pure-js.
144
+
145
+ // 22. Return F.
146
+ return bound;
147
+ };
148
+ }
149
+
150
+ // Shortcut to an often accessed properties, in order to avoid multiple
151
+ // dereference that costs universally.
152
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
153
+ // us it in defining shortcuts.
154
+ var call = Function.prototype.call;
155
+ var prototypeOfArray = Array.prototype;
156
+ var prototypeOfObject = Object.prototype;
157
+ var slice = prototypeOfArray.slice;
158
+ // Having a toString local variable name breaks in Opera so use _toString.
159
+ var _toString = call.bind(prototypeOfObject.toString);
160
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
161
+
162
+ // If JS engine supports accessors creating shortcuts.
163
+ var defineGetter;
164
+ var defineSetter;
165
+ var lookupGetter;
166
+ var lookupSetter;
167
+ var supportsAccessors;
168
+ if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
169
+ defineGetter = call.bind(prototypeOfObject.__defineGetter__);
170
+ defineSetter = call.bind(prototypeOfObject.__defineSetter__);
171
+ lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
172
+ lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
173
+ }
174
+
175
+ //
176
+ // Array
177
+ // =====
178
+ //
179
+
180
+ // ES5 15.4.4.12
181
+ // http://es5.github.com/#x15.4.4.12
182
+ // Default value for second param
183
+ // [bugfix, ielt9, old browsers]
184
+ // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
185
+ if ([1,2].splice(0).length != 2) {
186
+ var array_splice = Array.prototype.splice;
187
+ Array.prototype.splice = function(start, deleteCount) {
188
+ if (!arguments.length) {
189
+ return [];
190
+ } else {
191
+ return array_splice.apply(this, [
192
+ start === void 0 ? 0 : start,
193
+ deleteCount === void 0 ? (this.length - start) : deleteCount
194
+ ].concat(slice.call(arguments, 2)))
195
+ }
196
+ };
197
+ }
198
+
199
+ // ES5 15.4.3.2
200
+ // http://es5.github.com/#x15.4.3.2
201
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
202
+ if (!Array.isArray) {
203
+ Array.isArray = function isArray(obj) {
204
+ return _toString(obj) == "[object Array]";
205
+ };
206
+ }
207
+
208
+ // The IsCallable() check in the Array functions
209
+ // has been replaced with a strict check on the
210
+ // internal class of the object to trap cases where
211
+ // the provided function was actually a regular
212
+ // expression literal, which in V8 and
213
+ // JavaScriptCore is a typeof "function". Only in
214
+ // V8 are regular expression literals permitted as
215
+ // reduce parameters, so it is desirable in the
216
+ // general case for the shim to match the more
217
+ // strict and common behavior of rejecting regular
218
+ // expressions.
219
+
220
+ // ES5 15.4.4.18
221
+ // http://es5.github.com/#x15.4.4.18
222
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
223
+
224
+ // Check failure of by-index access of string characters (IE < 9)
225
+ // and failure of `0 in boxedString` (Rhino)
226
+ var boxedString = Object("a"),
227
+ splitString = boxedString[0] != "a" || !(0 in boxedString);
228
+
229
+ if (!Array.prototype.forEach) {
230
+ Array.prototype.forEach = function forEach(fun /*, thisp*/) {
231
+ var object = toObject(this),
232
+ self = splitString && _toString(this) == "[object String]" ?
233
+ this.split("") :
234
+ object,
235
+ thisp = arguments[1],
236
+ i = -1,
237
+ length = self.length >>> 0;
238
+
239
+ // If no callback function or if callback is not a callable function
240
+ if (_toString(fun) != "[object Function]") {
241
+ throw new TypeError(); // TODO message
242
+ }
243
+
244
+ while (++i < length) {
245
+ if (i in self) {
246
+ // Invoke the callback function with call, passing arguments:
247
+ // context, property value, property key, thisArg object
248
+ // context
249
+ fun.call(thisp, self[i], i, object);
250
+ }
251
+ }
252
+ };
253
+ }
254
+
255
+ // ES5 15.4.4.19
256
+ // http://es5.github.com/#x15.4.4.19
257
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
258
+ if (!Array.prototype.map) {
259
+ Array.prototype.map = function map(fun /*, thisp*/) {
260
+ var object = toObject(this),
261
+ self = splitString && _toString(this) == "[object String]" ?
262
+ this.split("") :
263
+ object,
264
+ length = self.length >>> 0,
265
+ result = Array(length),
266
+ thisp = arguments[1];
267
+
268
+ // If no callback function or if callback is not a callable function
269
+ if (_toString(fun) != "[object Function]") {
270
+ throw new TypeError(fun + " is not a function");
271
+ }
272
+
273
+ for (var i = 0; i < length; i++) {
274
+ if (i in self)
275
+ result[i] = fun.call(thisp, self[i], i, object);
276
+ }
277
+ return result;
278
+ };
279
+ }
280
+
281
+ // ES5 15.4.4.20
282
+ // http://es5.github.com/#x15.4.4.20
283
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
284
+ if (!Array.prototype.filter) {
285
+ Array.prototype.filter = function filter(fun /*, thisp */) {
286
+ var object = toObject(this),
287
+ self = splitString && _toString(this) == "[object String]" ?
288
+ this.split("") :
289
+ object,
290
+ length = self.length >>> 0,
291
+ result = [],
292
+ value,
293
+ thisp = arguments[1];
294
+
295
+ // If no callback function or if callback is not a callable function
296
+ if (_toString(fun) != "[object Function]") {
297
+ throw new TypeError(fun + " is not a function");
298
+ }
299
+
300
+ for (var i = 0; i < length; i++) {
301
+ if (i in self) {
302
+ value = self[i];
303
+ if (fun.call(thisp, value, i, object)) {
304
+ result.push(value);
305
+ }
306
+ }
307
+ }
308
+ return result;
309
+ };
310
+ }
311
+
312
+ // ES5 15.4.4.16
313
+ // http://es5.github.com/#x15.4.4.16
314
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
315
+ if (!Array.prototype.every) {
316
+ Array.prototype.every = function every(fun /*, thisp */) {
317
+ var object = toObject(this),
318
+ self = splitString && _toString(this) == "[object String]" ?
319
+ this.split("") :
320
+ object,
321
+ length = self.length >>> 0,
322
+ thisp = arguments[1];
323
+
324
+ // If no callback function or if callback is not a callable function
325
+ if (_toString(fun) != "[object Function]") {
326
+ throw new TypeError(fun + " is not a function");
327
+ }
328
+
329
+ for (var i = 0; i < length; i++) {
330
+ if (i in self && !fun.call(thisp, self[i], i, object)) {
331
+ return false;
332
+ }
333
+ }
334
+ return true;
335
+ };
336
+ }
337
+
338
+ // ES5 15.4.4.17
339
+ // http://es5.github.com/#x15.4.4.17
340
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
341
+ if (!Array.prototype.some) {
342
+ Array.prototype.some = function some(fun /*, thisp */) {
343
+ var object = toObject(this),
344
+ self = splitString && _toString(this) == "[object String]" ?
345
+ this.split("") :
346
+ object,
347
+ length = self.length >>> 0,
348
+ thisp = arguments[1];
349
+
350
+ // If no callback function or if callback is not a callable function
351
+ if (_toString(fun) != "[object Function]") {
352
+ throw new TypeError(fun + " is not a function");
353
+ }
354
+
355
+ for (var i = 0; i < length; i++) {
356
+ if (i in self && fun.call(thisp, self[i], i, object)) {
357
+ return true;
358
+ }
359
+ }
360
+ return false;
361
+ };
362
+ }
363
+
364
+ // ES5 15.4.4.21
365
+ // http://es5.github.com/#x15.4.4.21
366
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
367
+ if (!Array.prototype.reduce) {
368
+ Array.prototype.reduce = function reduce(fun /*, initial*/) {
369
+ var object = toObject(this),
370
+ self = splitString && _toString(this) == "[object String]" ?
371
+ this.split("") :
372
+ object,
373
+ length = self.length >>> 0;
374
+
375
+ // If no callback function or if callback is not a callable function
376
+ if (_toString(fun) != "[object Function]") {
377
+ throw new TypeError(fun + " is not a function");
378
+ }
379
+
380
+ // no value to return if no initial value and an empty array
381
+ if (!length && arguments.length == 1) {
382
+ throw new TypeError("reduce of empty array with no initial value");
383
+ }
384
+
385
+ var i = 0;
386
+ var result;
387
+ if (arguments.length >= 2) {
388
+ result = arguments[1];
389
+ } else {
390
+ do {
391
+ if (i in self) {
392
+ result = self[i++];
393
+ break;
394
+ }
395
+
396
+ // if array contains no values, no initial value to return
397
+ if (++i >= length) {
398
+ throw new TypeError("reduce of empty array with no initial value");
399
+ }
400
+ } while (true);
401
+ }
402
+
403
+ for (; i < length; i++) {
404
+ if (i in self) {
405
+ result = fun.call(void 0, result, self[i], i, object);
406
+ }
407
+ }
408
+
409
+ return result;
410
+ };
411
+ }
412
+
413
+ // ES5 15.4.4.22
414
+ // http://es5.github.com/#x15.4.4.22
415
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
416
+ if (!Array.prototype.reduceRight) {
417
+ Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
418
+ var object = toObject(this),
419
+ self = splitString && _toString(this) == "[object String]" ?
420
+ this.split("") :
421
+ object,
422
+ length = self.length >>> 0;
423
+
424
+ // If no callback function or if callback is not a callable function
425
+ if (_toString(fun) != "[object Function]") {
426
+ throw new TypeError(fun + " is not a function");
427
+ }
428
+
429
+ // no value to return if no initial value, empty array
430
+ if (!length && arguments.length == 1) {
431
+ throw new TypeError("reduceRight of empty array with no initial value");
432
+ }
433
+
434
+ var result, i = length - 1;
435
+ if (arguments.length >= 2) {
436
+ result = arguments[1];
437
+ } else {
438
+ do {
439
+ if (i in self) {
440
+ result = self[i--];
441
+ break;
442
+ }
443
+
444
+ // if array contains no values, no initial value to return
445
+ if (--i < 0) {
446
+ throw new TypeError("reduceRight of empty array with no initial value");
447
+ }
448
+ } while (true);
449
+ }
450
+
451
+ do {
452
+ if (i in this) {
453
+ result = fun.call(void 0, result, self[i], i, object);
454
+ }
455
+ } while (i--);
456
+
457
+ return result;
458
+ };
459
+ }
460
+
461
+ // ES5 15.4.4.14
462
+ // http://es5.github.com/#x15.4.4.14
463
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
464
+ if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
465
+ Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
466
+ var self = splitString && _toString(this) == "[object String]" ?
467
+ this.split("") :
468
+ toObject(this),
469
+ length = self.length >>> 0;
470
+
471
+ if (!length) {
472
+ return -1;
473
+ }
474
+
475
+ var i = 0;
476
+ if (arguments.length > 1) {
477
+ i = toInteger(arguments[1]);
478
+ }
479
+
480
+ // handle negative indices
481
+ i = i >= 0 ? i : Math.max(0, length + i);
482
+ for (; i < length; i++) {
483
+ if (i in self && self[i] === sought) {
484
+ return i;
485
+ }
486
+ }
487
+ return -1;
488
+ };
489
+ }
490
+
491
+ // ES5 15.4.4.15
492
+ // http://es5.github.com/#x15.4.4.15
493
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
494
+ if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
495
+ Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
496
+ var self = splitString && _toString(this) == "[object String]" ?
497
+ this.split("") :
498
+ toObject(this),
499
+ length = self.length >>> 0;
500
+
501
+ if (!length) {
502
+ return -1;
503
+ }
504
+ var i = length - 1;
505
+ if (arguments.length > 1) {
506
+ i = Math.min(i, toInteger(arguments[1]));
507
+ }
508
+ // handle negative indices
509
+ i = i >= 0 ? i : length - Math.abs(i);
510
+ for (; i >= 0; i--) {
511
+ if (i in self && sought === self[i]) {
512
+ return i;
513
+ }
514
+ }
515
+ return -1;
516
+ };
517
+ }
518
+
519
+ //
520
+ // Object
521
+ // ======
522
+ //
523
+
524
+ // ES5 15.2.3.14
525
+ // http://es5.github.com/#x15.2.3.14
526
+ if (!Object.keys) {
527
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
528
+ var hasDontEnumBug = true,
529
+ dontEnums = [
530
+ "toString",
531
+ "toLocaleString",
532
+ "valueOf",
533
+ "hasOwnProperty",
534
+ "isPrototypeOf",
535
+ "propertyIsEnumerable",
536
+ "constructor"
537
+ ],
538
+ dontEnumsLength = dontEnums.length;
539
+
540
+ for (var key in {"toString": null}) {
541
+ hasDontEnumBug = false;
542
+ }
543
+
544
+ Object.keys = function keys(object) {
545
+
546
+ if (
547
+ (typeof object != "object" && typeof object != "function") ||
548
+ object === null
549
+ ) {
550
+ throw new TypeError("Object.keys called on a non-object");
551
+ }
552
+
553
+ var keys = [];
554
+ for (var name in object) {
555
+ if (owns(object, name)) {
556
+ keys.push(name);
557
+ }
558
+ }
559
+
560
+ if (hasDontEnumBug) {
561
+ for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
562
+ var dontEnum = dontEnums[i];
563
+ if (owns(object, dontEnum)) {
564
+ keys.push(dontEnum);
565
+ }
566
+ }
567
+ }
568
+ return keys;
569
+ };
570
+
571
+ }
572
+
573
+ //
574
+ // Date
575
+ // ====
576
+ //
577
+
578
+ // ES5 15.9.5.43
579
+ // http://es5.github.com/#x15.9.5.43
580
+ // This function returns a String value represent the instance in time
581
+ // represented by this Date object. The format of the String is the Date Time
582
+ // string format defined in 15.9.1.15. All fields are present in the String.
583
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
584
+ // this object is not a finite Number a RangeError exception is thrown.
585
+ var negativeDate = -62198755200000,
586
+ negativeYearString = "-000001";
587
+ if (
588
+ !Date.prototype.toISOString ||
589
+ (new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
590
+ ) {
591
+ Date.prototype.toISOString = function toISOString() {
592
+ var result, length, value, year, month;
593
+ if (!isFinite(this)) {
594
+ throw new RangeError("Date.prototype.toISOString called on non-finite value.");
595
+ }
596
+
597
+ year = this.getUTCFullYear();
598
+
599
+ month = this.getUTCMonth();
600
+ // see https://github.com/kriskowal/es5-shim/issues/111
601
+ year += Math.floor(month / 12);
602
+ month = (month % 12 + 12) % 12;
603
+
604
+ // the date time string format is specified in 15.9.1.15.
605
+ result = [month + 1, this.getUTCDate(),
606
+ this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
607
+ year = (
608
+ (year < 0 ? "-" : (year > 9999 ? "+" : "")) +
609
+ ("00000" + Math.abs(year))
610
+ .slice(0 <= year && year <= 9999 ? -4 : -6)
611
+ );
612
+
613
+ length = result.length;
614
+ while (length--) {
615
+ value = result[length];
616
+ // pad months, days, hours, minutes, and seconds to have two
617
+ // digits.
618
+ if (value < 10) {
619
+ result[length] = "0" + value;
620
+ }
621
+ }
622
+ // pad milliseconds to have three digits.
623
+ return (
624
+ year + "-" + result.slice(0, 2).join("-") +
625
+ "T" + result.slice(2).join(":") + "." +
626
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
627
+ );
628
+ };
629
+ }
630
+
631
+
632
+ // ES5 15.9.5.44
633
+ // http://es5.github.com/#x15.9.5.44
634
+ // This function provides a String representation of a Date object for use by
635
+ // JSON.stringify (15.12.3).
636
+ var dateToJSONIsSupported = false;
637
+ try {
638
+ dateToJSONIsSupported = (
639
+ Date.prototype.toJSON &&
640
+ new Date(NaN).toJSON() === null &&
641
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
642
+ Date.prototype.toJSON.call({ // generic
643
+ toISOString: function () {
644
+ return true;
645
+ }
646
+ })
647
+ );
648
+ } catch (e) {
649
+ }
650
+ if (!dateToJSONIsSupported) {
651
+ Date.prototype.toJSON = function toJSON(key) {
652
+ // When the toJSON method is called with argument key, the following
653
+ // steps are taken:
654
+
655
+ // 1. Let O be the result of calling ToObject, giving it the this
656
+ // value as its argument.
657
+ // 2. Let tv be toPrimitive(O, hint Number).
658
+ var o = Object(this),
659
+ tv = toPrimitive(o),
660
+ toISO;
661
+ // 3. If tv is a Number and is not finite, return null.
662
+ if (typeof tv === "number" && !isFinite(tv)) {
663
+ return null;
664
+ }
665
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
666
+ // O with argument "toISOString".
667
+ toISO = o.toISOString;
668
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
669
+ if (typeof toISO != "function") {
670
+ throw new TypeError("toISOString property is not callable");
671
+ }
672
+ // 6. Return the result of calling the [[Call]] internal method of
673
+ // toISO with O as the this value and an empty argument list.
674
+ return toISO.call(o);
675
+
676
+ // NOTE 1 The argument is ignored.
677
+
678
+ // NOTE 2 The toJSON function is intentionally generic; it does not
679
+ // require that its this value be a Date object. Therefore, it can be
680
+ // transferred to other kinds of objects for use as a method. However,
681
+ // it does require that any such object have a toISOString method. An
682
+ // object is free to use the argument key to filter its
683
+ // stringification.
684
+ };
685
+ }
686
+
687
+ // ES5 15.9.4.2
688
+ // http://es5.github.com/#x15.9.4.2
689
+ // based on work shared by Daniel Friesen (dantman)
690
+ // http://gist.github.com/303249
691
+ if (!Date.parse || "Date.parse is buggy") {
692
+ // XXX global assignment won't work in embeddings that use
693
+ // an alternate object for the context.
694
+ Date = (function(NativeDate) {
695
+
696
+ // Date.length === 7
697
+ var newDate = function Date(Y, M, D, h, m, s, ms) {
698
+ var length = arguments.length;
699
+ if (this instanceof NativeDate) {
700
+ var date = length == 1 && String(Y) === Y ? // isString(Y)
701
+ // We explicitly pass it through parse:
702
+ new NativeDate(newDate.parse(Y)) :
703
+ // We have to manually make calls depending on argument
704
+ // length here
705
+ length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
706
+ length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
707
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
708
+ length >= 4 ? new NativeDate(Y, M, D, h) :
709
+ length >= 3 ? new NativeDate(Y, M, D) :
710
+ length >= 2 ? new NativeDate(Y, M) :
711
+ length >= 1 ? new NativeDate(Y) :
712
+ new NativeDate();
713
+ // Prevent mixups with unfixed Date object
714
+ date.constructor = newDate;
715
+ return date;
716
+ }
717
+ return NativeDate.apply(this, arguments);
718
+ };
719
+
720
+ // 15.9.1.15 Date Time String Format.
721
+ var isoDateExpression = new RegExp("^" +
722
+ "(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
723
+ // 6-digit extended year
724
+ "(?:-(\\d{2})" + // optional month capture
725
+ "(?:-(\\d{2})" + // optional day capture
726
+ "(?:" + // capture hours:minutes:seconds.milliseconds
727
+ "T(\\d{2})" + // hours capture
728
+ ":(\\d{2})" + // minutes capture
729
+ "(?:" + // optional :seconds.milliseconds
730
+ ":(\\d{2})" + // seconds capture
731
+ "(?:\\.(\\d{3}))?" + // milliseconds capture
732
+ ")?" +
733
+ "(" + // capture UTC offset component
734
+ "Z|" + // UTC capture
735
+ "(?:" + // offset specifier +/-hours:minutes
736
+ "([-+])" + // sign capture
737
+ "(\\d{2})" + // hours offset capture
738
+ ":(\\d{2})" + // minutes offset capture
739
+ ")" +
740
+ ")?)?)?)?" +
741
+ "$");
742
+
743
+ var months = [
744
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
745
+ ];
746
+
747
+ function dayFromMonth(year, month) {
748
+ var t = month > 1 ? 1 : 0;
749
+ return (
750
+ months[month] +
751
+ Math.floor((year - 1969 + t) / 4) -
752
+ Math.floor((year - 1901 + t) / 100) +
753
+ Math.floor((year - 1601 + t) / 400) +
754
+ 365 * (year - 1970)
755
+ );
756
+ }
757
+
758
+ // Copy any custom methods a 3rd party library may have added
759
+ for (var key in NativeDate) {
760
+ newDate[key] = NativeDate[key];
761
+ }
762
+
763
+ // Copy "native" methods explicitly; they may be non-enumerable
764
+ newDate.now = NativeDate.now;
765
+ newDate.UTC = NativeDate.UTC;
766
+ newDate.prototype = NativeDate.prototype;
767
+ newDate.prototype.constructor = Date;
768
+
769
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
770
+ newDate.parse = function parse(string) {
771
+ var match = isoDateExpression.exec(string);
772
+ if (match) {
773
+ // parse months, days, hours, minutes, seconds, and milliseconds
774
+ // provide default values if necessary
775
+ // parse the UTC offset component
776
+ var year = Number(match[1]),
777
+ month = Number(match[2] || 1) - 1,
778
+ day = Number(match[3] || 1) - 1,
779
+ hour = Number(match[4] || 0),
780
+ minute = Number(match[5] || 0),
781
+ second = Number(match[6] || 0),
782
+ millisecond = Number(match[7] || 0),
783
+ // When time zone is missed, local offset should be used
784
+ // (ES 5.1 bug)
785
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
786
+ offset = !match[4] || match[8] ?
787
+ 0 : Number(new Date(1970, 0)),
788
+ signOffset = match[9] === "-" ? 1 : -1,
789
+ hourOffset = Number(match[10] || 0),
790
+ minuteOffset = Number(match[11] || 0),
791
+ result;
792
+ if (
793
+ hour < (
794
+ minute > 0 || second > 0 || millisecond > 0 ?
795
+ 24 : 25
796
+ ) &&
797
+ minute < 60 && second < 60 && millisecond < 1000 &&
798
+ month > -1 && month < 12 && hourOffset < 24 &&
799
+ minuteOffset < 60 && // detect invalid offsets
800
+ day > -1 &&
801
+ day < (
802
+ dayFromMonth(year, month + 1) -
803
+ dayFromMonth(year, month)
804
+ )
805
+ ) {
806
+ result = (
807
+ (dayFromMonth(year, month) + day) * 24 +
808
+ hour +
809
+ hourOffset * signOffset
810
+ ) * 60;
811
+ result = (
812
+ (result + minute + minuteOffset * signOffset) * 60 +
813
+ second
814
+ ) * 1000 + millisecond + offset;
815
+ if (-8.64e15 <= result && result <= 8.64e15) {
816
+ return result;
817
+ }
818
+ }
819
+ return NaN;
820
+ }
821
+ return NativeDate.parse.apply(this, arguments);
822
+ };
823
+
824
+ return newDate;
825
+ })(Date);
826
+ }
827
+
828
+ // ES5 15.9.4.4
829
+ // http://es5.github.com/#x15.9.4.4
830
+ if (!Date.now) {
831
+ Date.now = function now() {
832
+ return new Date().getTime();
833
+ };
834
+ }
835
+
836
+
837
+ //
838
+ // String
839
+ // ======
840
+ //
841
+
842
+
843
+ // ES5 15.5.4.14
844
+ // http://es5.github.com/#x15.5.4.14
845
+ // [bugfix, chrome]
846
+ // If separator is undefined, then the result array contains just one String,
847
+ // which is the this value (converted to a String). If limit is not undefined,
848
+ // then the output array is truncated so that it contains no more than limit
849
+ // elements.
850
+ // "0".split(undefined, 0) -> []
851
+ if("0".split(void 0, 0).length) {
852
+ var string_split = String.prototype.split;
853
+ String.prototype.split = function(separator, limit) {
854
+ if(separator === void 0 && limit === 0)return [];
855
+ return string_split.apply(this, arguments);
856
+ }
857
+ }
858
+
859
+ // ECMA-262, 3rd B.2.3
860
+ // Note an ECMAScript standart, although ECMAScript 3rd Edition has a
861
+ // non-normative section suggesting uniform semantics and it should be
862
+ // normalized across all browsers
863
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
864
+ if("".substr && "0b".substr(-1) !== "b") {
865
+ var string_substr = String.prototype.substr;
866
+ /**
867
+ * Get the substring of a string
868
+ * @param {integer} start where to start the substring
869
+ * @param {integer} length how many characters to return
870
+ * @return {string}
871
+ */
872
+ String.prototype.substr = function(start, length) {
873
+ return string_substr.call(
874
+ this,
875
+ start < 0 ? (start = this.length + start) < 0 ? 0 : start : start,
876
+ length
877
+ );
878
+ }
879
+ }
880
+
881
+ // ES5 15.5.4.20
882
+ // http://es5.github.com/#x15.5.4.20
883
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
884
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
885
+ "\u2029\uFEFF";
886
+ if (!String.prototype.trim || ws.trim()) {
887
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
888
+ // http://perfectionkills.com/whitespace-deviations/
889
+ ws = "[" + ws + "]";
890
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
891
+ trimEndRegexp = new RegExp(ws + ws + "*$");
892
+ String.prototype.trim = function trim() {
893
+ if (this === undefined || this === null) {
894
+ throw new TypeError("can't convert "+this+" to object");
895
+ }
896
+ return String(this)
897
+ .replace(trimBeginRegexp, "")
898
+ .replace(trimEndRegexp, "");
899
+ };
900
+ }
901
+
902
+ //
903
+ // Util
904
+ // ======
905
+ //
906
+
907
+ // ES5 9.4
908
+ // http://es5.github.com/#x9.4
909
+ // http://jsperf.com/to-integer
910
+
911
+ function toInteger(n) {
912
+ n = +n;
913
+ if (n !== n) { // isNaN
914
+ n = 0;
915
+ } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
916
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
917
+ }
918
+ return n;
919
+ }
920
+
921
+ function isPrimitive(input) {
922
+ var type = typeof input;
923
+ return (
924
+ input === null ||
925
+ type === "undefined" ||
926
+ type === "boolean" ||
927
+ type === "number" ||
928
+ type === "string"
929
+ );
930
+ }
931
+
932
+ function toPrimitive(input) {
933
+ var val, valueOf, toString;
934
+ if (isPrimitive(input)) {
935
+ return input;
936
+ }
937
+ valueOf = input.valueOf;
938
+ if (typeof valueOf === "function") {
939
+ val = valueOf.call(input);
940
+ if (isPrimitive(val)) {
941
+ return val;
942
+ }
943
+ }
944
+ toString = input.toString;
945
+ if (typeof toString === "function") {
946
+ val = toString.call(input);
947
+ if (isPrimitive(val)) {
948
+ return val;
949
+ }
950
+ }
951
+ throw new TypeError();
952
+ }
953
+
954
+ // ES5 9.9
955
+ // http://es5.github.com/#x9.9
956
+ var toObject = function (o) {
957
+ if (o == null) { // this matches both null and undefined
958
+ throw new TypeError("can't convert "+o+" to object");
959
+ }
960
+ return Object(o);
961
+ };
962
+
963
+ });