2 * HTML5 Element Shim for IE8
4 * **THIS CODE MUST BE LOADED IN THE <HEAD> OF THE DOCUMENT**
6 * Video.js uses the video tag as an embed code, even in IE8 which
7 * doesn't have support for HTML5 video. The following code is needed
8 * to make it possible to use the video tag. Otherwise IE8 ignores everything
9 * inside the video tag.
11 if (typeof window.HTMLVideoElement === 'undefined') {
12 document.createElement('video');
13 document.createElement('audio');
14 document.createElement('track');
18 * https://github.com/es-shims/es5-shim
19 * @license es5-shim Copyright 2009-2015 by contributors, MIT License
20 * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
23 // vim: ts=4 sts=4 sw=4 expandtab
25 // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
28 // UMD (Universal Module Definition)
29 // see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
30 (function (root, factory) {
33 /* global define, exports, module */
34 if (typeof define === 'function' && define.amd) {
35 // AMD. Register as an anonymous module.
37 } else if (typeof exports === 'object') {
38 // Node. Does not work with strict CommonJS, but
39 // only CommonJS-like enviroments that support module.exports,
41 module.exports = factory();
43 // Browser globals (root is window)
44 root.returnExports = factory();
49 * Brings an environment as close to ECMAScript 5 compliance
50 * as is possible with the facilities of erstwhile engines.
52 * Annotated ES5: http://es5.github.com/ (specific links below)
53 * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
54 * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
57 // Shortcut to an often accessed properties, in order to avoid multiple
58 // dereference that costs universally. This also holds a reference to known-good
61 var ArrayPrototype = $Array.prototype;
63 var ObjectPrototype = $Object.prototype;
64 var FunctionPrototype = Function.prototype;
66 var StringPrototype = $String.prototype;
68 var NumberPrototype = $Number.prototype;
69 var array_slice = ArrayPrototype.slice;
70 var array_splice = ArrayPrototype.splice;
71 var array_push = ArrayPrototype.push;
72 var array_unshift = ArrayPrototype.unshift;
73 var array_concat = ArrayPrototype.concat;
74 var call = FunctionPrototype.call;
75 var apply = FunctionPrototype.apply;
79 // Having a toString local variable name breaks in Opera so use to_string.
80 var to_string = ObjectPrototype.toString;
82 var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
83 var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
84 var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
85 var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };
87 /* inlined from http://npmjs.com/define-properties */
88 var supportsDescriptors = $Object.defineProperty && (function () {
91 $Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
92 for (var _ in obj) { return false; }
94 } catch (e) { /* this is ES3 */
98 var defineProperties = (function (has) {
99 // Define configurable, writable, and non-enumerable props
100 // if they don't exist.
102 if (supportsDescriptors) {
103 defineProperty = function (object, name, method, forceAssign) {
104 if (!forceAssign && (name in object)) { return; }
105 $Object.defineProperty(object, name, {
113 defineProperty = function (object, name, method, forceAssign) {
114 if (!forceAssign && (name in object)) { return; }
115 object[name] = method;
118 return function defineProperties(object, map, forceAssign) {
119 for (var name in map) {
120 if (has.call(map, name)) {
121 defineProperty(object, name, map[name], forceAssign);
125 }(ObjectPrototype.hasOwnProperty));
132 /* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
133 var isPrimitive = function isPrimitive(input) {
134 var type = typeof input;
135 return input === null || (type !== 'object' && type !== 'function');
138 var isActualNaN = $Number.isNaN || function (x) { return x !== x; };
142 // http://es5.github.com/#x9.4
143 // http://jsperf.com/to-integer
144 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
145 ToInteger: function ToInteger(num) {
147 if (isActualNaN(n)) {
149 } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
150 n = (n > 0 || -1) * Math.floor(Math.abs(n));
155 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
156 ToPrimitive: function ToPrimitive(input) {
157 var val, valueOf, toStr;
158 if (isPrimitive(input)) {
161 valueOf = input.valueOf;
162 if (isCallable(valueOf)) {
163 val = valueOf.call(input);
164 if (isPrimitive(val)) {
168 toStr = input.toString;
169 if (isCallable(toStr)) {
170 val = toStr.call(input);
171 if (isPrimitive(val)) {
175 throw new TypeError();
179 // http://es5.github.com/#x9.9
180 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
181 ToObject: function (o) {
182 if (o == null) { // this matches both null and undefined
183 throw new TypeError("can't convert " + o + ' to object');
188 /* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
189 ToUint32: function ToUint32(x) {
200 // http://es5.github.com/#x15.3.4.5
202 var Empty = function Empty() {};
204 defineProperties(FunctionPrototype, {
205 bind: function bind(that) { // .length is 1
206 // 1. Let Target be the this value.
208 // 2. If IsCallable(Target) is false, throw a TypeError exception.
209 if (!isCallable(target)) {
210 throw new TypeError('Function.prototype.bind called on incompatible ' + target);
212 // 3. Let A be a new (possibly empty) internal list of all of the
213 // argument values provided after thisArg (arg1, arg2 etc), in order.
214 // XXX slicedArgs will stand in for "A" if used
215 var args = array_slice.call(arguments, 1); // for normal call
216 // 4. Let F be a new native ECMAScript object.
217 // 11. Set the [[Prototype]] internal property of F to the standard
218 // built-in Function prototype object as specified in 15.3.3.1.
219 // 12. Set the [[Call]] internal property of F as described in
221 // 13. Set the [[Construct]] internal property of F as described in
223 // 14. Set the [[HasInstance]] internal property of F as described in
226 var binder = function () {
228 if (this instanceof bound) {
229 // 15.3.4.5.2 [[Construct]]
230 // When the [[Construct]] internal method of a function object,
231 // F that was created using the bind function is called with a
232 // list of arguments ExtraArgs, the following steps are taken:
233 // 1. Let target be the value of F's [[TargetFunction]]
234 // internal property.
235 // 2. If target has no [[Construct]] internal method, a
236 // TypeError exception is thrown.
237 // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
239 // 4. Let args be a new list containing the same values as the
240 // list boundArgs in the same order followed by the same
241 // values as the list ExtraArgs in the same order.
242 // 5. Return the result of calling the [[Construct]] internal
243 // method of target providing args as the arguments.
245 var result = target.apply(
247 array_concat.call(args, array_slice.call(arguments))
249 if ($Object(result) === result) {
255 // 15.3.4.5.1 [[Call]]
256 // When the [[Call]] internal method of a function object, F,
257 // which was created using the bind function is called with a
258 // this value and a list of arguments ExtraArgs, the following
260 // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
262 // 2. Let boundThis be the value of F's [[BoundThis]] internal
264 // 3. Let target be the value of F's [[TargetFunction]] internal
266 // 4. Let args be a new list containing the same values as the
267 // list boundArgs in the same order followed by the same
268 // values as the list ExtraArgs in the same order.
269 // 5. Return the result of calling the [[Call]] internal method
270 // of target providing boundThis as the this value and
271 // providing args as the arguments.
273 // equiv: target.call(this, ...boundArgs, ...args)
276 array_concat.call(args, array_slice.call(arguments))
283 // 15. If the [[Class]] internal property of Target is "Function", then
284 // a. Let L be the length property of Target minus the length of A.
285 // b. Set the length own property of F to either 0 or L, whichever is
287 // 16. Else set the length own property of F to 0.
289 var boundLength = max(0, target.length - args.length);
291 // 17. Set the attributes of the length own property of F to the values
292 // specified in 15.3.5.1.
294 for (var i = 0; i < boundLength; i++) {
295 array_push.call(boundArgs, '$' + i);
298 // XXX Build a dynamic function with desired amount of arguments is the only
299 // way to set the length property of a function.
300 // In environments where Content Security Policies enabled (Chrome extensions,
301 // for ex.) all use of eval or Function costructor throws an exception.
302 // However in all of these environments Function.prototype.bind exists
303 // and so this code will never be executed.
304 bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
306 if (target.prototype) {
307 Empty.prototype = target.prototype;
308 bound.prototype = new Empty();
309 // Clean up dangling references.
310 Empty.prototype = null;
314 // 18. Set the [[Extensible]] internal property of F to true.
317 // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
318 // 20. Call the [[DefineOwnProperty]] internal method of F with
319 // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
320 // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
322 // 21. Call the [[DefineOwnProperty]] internal method of F with
323 // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
324 // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
328 // NOTE Function objects created using Function.prototype.bind do not
329 // have a prototype property or the [[Code]], [[FormalParameters]], and
330 // [[Scope]] internal properties.
331 // XXX can't delete prototype in pure-js.
338 // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
339 // use it in defining shortcuts.
340 var owns = call.bind(ObjectPrototype.hasOwnProperty);
341 var toStr = call.bind(ObjectPrototype.toString);
342 var arraySlice = call.bind(array_slice);
343 var arraySliceApply = apply.bind(array_slice);
344 var strSlice = call.bind(StringPrototype.slice);
345 var strSplit = call.bind(StringPrototype.split);
346 var strIndexOf = call.bind(StringPrototype.indexOf);
347 var pushCall = call.bind(array_push);
348 var isEnum = call.bind(ObjectPrototype.propertyIsEnumerable);
349 var arraySort = call.bind(ArrayPrototype.sort);
356 var isArray = $Array.isArray || function isArray(obj) {
357 return toStr(obj) === '[object Array]';
361 // http://es5.github.com/#x15.4.4.13
362 // Return len+argCount.
364 // IE < 8 bug: [].unshift(0) === undefined but should be "1"
365 var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
366 defineProperties(ArrayPrototype, {
367 unshift: function () {
368 array_unshift.apply(this, arguments);
371 }, hasUnshiftReturnValueBug);
374 // http://es5.github.com/#x15.4.3.2
375 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
376 defineProperties($Array, { isArray: isArray });
378 // The IsCallable() check in the Array functions
379 // has been replaced with a strict check on the
380 // internal class of the object to trap cases where
381 // the provided function was actually a regular
382 // expression literal, which in V8 and
383 // JavaScriptCore is a typeof "function". Only in
384 // V8 are regular expression literals permitted as
385 // reduce parameters, so it is desirable in the
386 // general case for the shim to match the more
387 // strict and common behavior of rejecting regular
391 // http://es5.github.com/#x15.4.4.18
392 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
394 // Check failure of by-index access of string characters (IE < 9)
395 // and failure of `0 in boxedString` (Rhino)
396 var boxedString = $Object('a');
397 var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
399 var properlyBoxesContext = function properlyBoxed(method) {
400 // Check node 0.6.21 bug where third parameter is not boxed
401 var properlyBoxesNonStrict = true;
402 var properlyBoxesStrict = true;
403 var threwException = false;
406 method.call('foo', function (_, __, context) {
407 if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
410 method.call([1], function () {
413 properlyBoxesStrict = typeof this === 'string';
416 threwException = true;
419 return !!method && !threwException && properlyBoxesNonStrict && properlyBoxesStrict;
422 defineProperties(ArrayPrototype, {
423 forEach: function forEach(callbackfn/*, thisArg*/) {
424 var object = ES.ToObject(this);
425 var self = splitString && isString(this) ? strSplit(this, '') : object;
427 var length = ES.ToUint32(self.length);
429 if (arguments.length > 1) {
433 // If no callback function or if callback is not a callable function
434 if (!isCallable(callbackfn)) {
435 throw new TypeError('Array.prototype.forEach callback must be a function');
438 while (++i < length) {
440 // Invoke the callback function with call, passing arguments:
441 // context, property value, property key, thisArg object
442 if (typeof T === 'undefined') {
443 callbackfn(self[i], i, object);
445 callbackfn.call(T, self[i], i, object);
450 }, !properlyBoxesContext(ArrayPrototype.forEach));
453 // http://es5.github.com/#x15.4.4.19
454 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
455 defineProperties(ArrayPrototype, {
456 map: function map(callbackfn/*, thisArg*/) {
457 var object = ES.ToObject(this);
458 var self = splitString && isString(this) ? strSplit(this, '') : object;
459 var length = ES.ToUint32(self.length);
460 var result = $Array(length);
462 if (arguments.length > 1) {
466 // If no callback function or if callback is not a callable function
467 if (!isCallable(callbackfn)) {
468 throw new TypeError('Array.prototype.map callback must be a function');
471 for (var i = 0; i < length; i++) {
473 if (typeof T === 'undefined') {
474 result[i] = callbackfn(self[i], i, object);
476 result[i] = callbackfn.call(T, self[i], i, object);
482 }, !properlyBoxesContext(ArrayPrototype.map));
485 // http://es5.github.com/#x15.4.4.20
486 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
487 defineProperties(ArrayPrototype, {
488 filter: function filter(callbackfn/*, thisArg*/) {
489 var object = ES.ToObject(this);
490 var self = splitString && isString(this) ? strSplit(this, '') : object;
491 var length = ES.ToUint32(self.length);
495 if (arguments.length > 1) {
499 // If no callback function or if callback is not a callable function
500 if (!isCallable(callbackfn)) {
501 throw new TypeError('Array.prototype.filter callback must be a function');
504 for (var i = 0; i < length; i++) {
507 if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
508 pushCall(result, value);
514 }, !properlyBoxesContext(ArrayPrototype.filter));
517 // http://es5.github.com/#x15.4.4.16
518 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
519 defineProperties(ArrayPrototype, {
520 every: function every(callbackfn/*, thisArg*/) {
521 var object = ES.ToObject(this);
522 var self = splitString && isString(this) ? strSplit(this, '') : object;
523 var length = ES.ToUint32(self.length);
525 if (arguments.length > 1) {
529 // If no callback function or if callback is not a callable function
530 if (!isCallable(callbackfn)) {
531 throw new TypeError('Array.prototype.every callback must be a function');
534 for (var i = 0; i < length; i++) {
535 if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
541 }, !properlyBoxesContext(ArrayPrototype.every));
544 // http://es5.github.com/#x15.4.4.17
545 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
546 defineProperties(ArrayPrototype, {
547 some: function some(callbackfn/*, thisArg */) {
548 var object = ES.ToObject(this);
549 var self = splitString && isString(this) ? strSplit(this, '') : object;
550 var length = ES.ToUint32(self.length);
552 if (arguments.length > 1) {
556 // If no callback function or if callback is not a callable function
557 if (!isCallable(callbackfn)) {
558 throw new TypeError('Array.prototype.some callback must be a function');
561 for (var i = 0; i < length; i++) {
562 if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
568 }, !properlyBoxesContext(ArrayPrototype.some));
571 // http://es5.github.com/#x15.4.4.21
572 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
573 var reduceCoercesToObject = false;
574 if (ArrayPrototype.reduce) {
575 reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object';
577 defineProperties(ArrayPrototype, {
578 reduce: function reduce(callbackfn/*, initialValue*/) {
579 var object = ES.ToObject(this);
580 var self = splitString && isString(this) ? strSplit(this, '') : object;
581 var length = ES.ToUint32(self.length);
583 // If no callback function or if callback is not a callable function
584 if (!isCallable(callbackfn)) {
585 throw new TypeError('Array.prototype.reduce callback must be a function');
588 // no value to return if no initial value and an empty array
589 if (length === 0 && arguments.length === 1) {
590 throw new TypeError('reduce of empty array with no initial value');
595 if (arguments.length >= 2) {
596 result = arguments[1];
604 // if array contains no values, no initial value to return
606 throw new TypeError('reduce of empty array with no initial value');
611 for (; i < length; i++) {
613 result = callbackfn(result, self[i], i, object);
619 }, !reduceCoercesToObject);
622 // http://es5.github.com/#x15.4.4.22
623 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
624 var reduceRightCoercesToObject = false;
625 if (ArrayPrototype.reduceRight) {
626 reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object';
628 defineProperties(ArrayPrototype, {
629 reduceRight: function reduceRight(callbackfn/*, initial*/) {
630 var object = ES.ToObject(this);
631 var self = splitString && isString(this) ? strSplit(this, '') : object;
632 var length = ES.ToUint32(self.length);
634 // If no callback function or if callback is not a callable function
635 if (!isCallable(callbackfn)) {
636 throw new TypeError('Array.prototype.reduceRight callback must be a function');
639 // no value to return if no initial value, empty array
640 if (length === 0 && arguments.length === 1) {
641 throw new TypeError('reduceRight of empty array with no initial value');
646 if (arguments.length >= 2) {
647 result = arguments[1];
655 // if array contains no values, no initial value to return
657 throw new TypeError('reduceRight of empty array with no initial value');
668 result = callbackfn(result, self[i], i, object);
674 }, !reduceRightCoercesToObject);
677 // http://es5.github.com/#x15.4.4.14
678 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
679 var hasFirefox2IndexOfBug = ArrayPrototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
680 defineProperties(ArrayPrototype, {
681 indexOf: function indexOf(searchElement/*, fromIndex */) {
682 var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
683 var length = ES.ToUint32(self.length);
690 if (arguments.length > 1) {
691 i = ES.ToInteger(arguments[1]);
694 // handle negative indices
695 i = i >= 0 ? i : max(0, length + i);
696 for (; i < length; i++) {
697 if (i in self && self[i] === searchElement) {
703 }, hasFirefox2IndexOfBug);
706 // http://es5.github.com/#x15.4.4.15
707 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
708 var hasFirefox2LastIndexOfBug = ArrayPrototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
709 defineProperties(ArrayPrototype, {
710 lastIndexOf: function lastIndexOf(searchElement/*, fromIndex */) {
711 var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
712 var length = ES.ToUint32(self.length);
718 if (arguments.length > 1) {
719 i = min(i, ES.ToInteger(arguments[1]));
721 // handle negative indices
722 i = i >= 0 ? i : length - Math.abs(i);
723 for (; i >= 0; i--) {
724 if (i in self && searchElement === self[i]) {
730 }, hasFirefox2LastIndexOfBug);
733 // http://es5.github.com/#x15.4.4.12
734 var spliceNoopReturnsEmptyArray = (function () {
736 var result = a.splice();
737 return a.length === 2 && isArray(result) && result.length === 0;
739 defineProperties(ArrayPrototype, {
740 // Safari 5.0 bug where .splice() returns undefined
741 splice: function splice(start, deleteCount) {
742 if (arguments.length === 0) {
745 return array_splice.apply(this, arguments);
748 }, !spliceNoopReturnsEmptyArray);
750 var spliceWorksWithEmptyObject = (function () {
752 ArrayPrototype.splice.call(obj, 0, 0, 1);
753 return obj.length === 1;
755 defineProperties(ArrayPrototype, {
756 splice: function splice(start, deleteCount) {
757 if (arguments.length === 0) { return []; }
758 var args = arguments;
759 this.length = max(ES.ToInteger(this.length), 0);
760 if (arguments.length > 0 && typeof deleteCount !== 'number') {
761 args = arraySlice(arguments);
762 if (args.length < 2) {
763 pushCall(args, this.length - start);
765 args[1] = ES.ToInteger(deleteCount);
768 return array_splice.apply(this, args);
770 }, !spliceWorksWithEmptyObject);
771 var spliceWorksWithLargeSparseArrays = (function () {
772 // Per https://github.com/es-shims/es5-shim/issues/295
773 // Safari 7/8 breaks with sparse arrays of size 1e5 or greater
774 var arr = new $Array(1e5);
775 // note: the index MUST be 8 or larger or the test will false pass
778 // note: this test must be defined *after* the indexOf shim
779 // per https://github.com/es-shims/es5-shim/issues/313
780 return arr.indexOf('x') === 7;
782 var spliceWorksWithSmallSparseArrays = (function () {
783 // Per https://github.com/es-shims/es5-shim/issues/295
784 // Opera 12.15 breaks on this, no idea why.
788 arr.splice(n + 1, 0, 'b');
789 return arr[n] === 'a';
791 defineProperties(ArrayPrototype, {
792 splice: function splice(start, deleteCount) {
793 var O = ES.ToObject(this);
795 var len = ES.ToUint32(O.length);
796 var relativeStart = ES.ToInteger(start);
797 var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
798 var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
802 while (k < actualDeleteCount) {
803 from = $String(actualStart + k);
810 var items = arraySlice(arguments, 2);
811 var itemCount = items.length;
813 if (itemCount < actualDeleteCount) {
815 while (k < (len - actualDeleteCount)) {
816 from = $String(k + actualDeleteCount);
817 to = $String(k + itemCount);
826 while (k > (len - actualDeleteCount + itemCount)) {
830 } else if (itemCount > actualDeleteCount) {
831 k = len - actualDeleteCount;
832 while (k > actualStart) {
833 from = $String(k + actualDeleteCount - 1);
834 to = $String(k + itemCount - 1);
844 for (var i = 0; i < items.length; ++i) {
848 O.length = len - actualDeleteCount + itemCount;
852 }, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);
854 var originalJoin = ArrayPrototype.join;
855 var hasStringJoinBug;
857 hasStringJoinBug = Array.prototype.join.call('123', ',') !== '1,2,3';
859 hasStringJoinBug = true;
861 if (hasStringJoinBug) {
862 defineProperties(ArrayPrototype, {
863 join: function join(separator) {
864 var sep = typeof separator === 'undefined' ? ',' : separator;
865 return originalJoin.call(isString(this) ? strSplit(this, '') : this, sep);
867 }, hasStringJoinBug);
870 var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
871 if (hasJoinUndefinedBug) {
872 defineProperties(ArrayPrototype, {
873 join: function join(separator) {
874 var sep = typeof separator === 'undefined' ? ',' : separator;
875 return originalJoin.call(this, sep);
877 }, hasJoinUndefinedBug);
880 var pushShim = function push(item) {
881 var O = ES.ToObject(this);
882 var n = ES.ToUint32(O.length);
884 while (i < arguments.length) {
885 O[n + i] = arguments[i];
892 var pushIsNotGeneric = (function () {
894 var result = Array.prototype.push.call(obj, undefined);
895 return result !== 1 || obj.length !== 1 || typeof obj[0] !== 'undefined' || !owns(obj, 0);
897 defineProperties(ArrayPrototype, {
898 push: function push(item) {
900 return array_push.apply(this, arguments);
902 return pushShim.apply(this, arguments);
904 }, pushIsNotGeneric);
906 // This fixes a very weird bug in Opera 10.6 when pushing `undefined
907 var pushUndefinedIsWeird = (function () {
909 var result = arr.push(undefined);
910 return result !== 1 || arr.length !== 1 || typeof arr[0] !== 'undefined' || !owns(arr, 0);
912 defineProperties(ArrayPrototype, { push: pushShim }, pushUndefinedIsWeird);
915 // http://es5.github.io/#x15.4.4.10
916 // Fix boxed string bug
917 defineProperties(ArrayPrototype, {
918 slice: function (start, end) {
919 var arr = isString(this) ? strSplit(this, '') : this;
920 return arraySliceApply(arr, arguments);
924 var sortIgnoresNonFunctions = (function () {
932 var sortThrowsOnRegex = (function () {
933 // this is a problem in Firefox 4, in which `typeof /a/ === 'function'`
940 var sortIgnoresUndefined = (function () {
941 // applies in IE 8, for one.
943 [1, 2].sort(undefined);
948 defineProperties(ArrayPrototype, {
949 sort: function sort(compareFn) {
950 if (typeof compareFn === 'undefined') {
951 return arraySort(this);
953 if (!isCallable(compareFn)) {
954 throw new TypeError('Array.prototype.sort callback must be a function');
956 return arraySort(this, compareFn);
958 }, sortIgnoresNonFunctions || !sortIgnoresUndefined || !sortThrowsOnRegex);
966 // http://es5.github.com/#x15.2.3.14
968 // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
969 var hasDontEnumBug = !({ 'toString': null }).propertyIsEnumerable('toString');
970 var hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype');
971 var hasStringEnumBug = !owns('x', '0');
972 var equalsConstructorPrototype = function (o) {
973 var ctor = o.constructor;
974 return ctor && ctor.prototype === o;
976 var blacklistedKeys = {
984 $webkitIndexedDB: true,
985 $webkitStorageInfo: true,
988 var hasAutomationEqualityBug = (function () {
990 if (typeof window === 'undefined') { return false; }
991 for (var k in window) {
993 if (!blacklistedKeys['$' + k] && owns(window, k) && window[k] !== null && typeof window[k] === 'object') {
994 equalsConstructorPrototype(window[k]);
1002 var equalsConstructorPrototypeIfNotBuggy = function (object) {
1003 if (typeof window === 'undefined' || !hasAutomationEqualityBug) { return equalsConstructorPrototype(object); }
1005 return equalsConstructorPrototype(object);
1016 'propertyIsEnumerable',
1019 var dontEnumsLength = dontEnums.length;
1021 // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
1022 // can be replaced with require('is-arguments') if we ever use a build process instead
1023 var isStandardArguments = function isArguments(value) {
1024 return toStr(value) === '[object Arguments]';
1026 var isLegacyArguments = function isArguments(value) {
1027 return value !== null &&
1028 typeof value === 'object' &&
1029 typeof value.length === 'number' &&
1030 value.length >= 0 &&
1032 isCallable(value.callee);
1034 var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
1036 defineProperties($Object, {
1037 keys: function keys(object) {
1038 var isFn = isCallable(object);
1039 var isArgs = isArguments(object);
1040 var isObject = object !== null && typeof object === 'object';
1041 var isStr = isObject && isString(object);
1043 if (!isObject && !isFn && !isArgs) {
1044 throw new TypeError('Object.keys called on a non-object');
1048 var skipProto = hasProtoEnumBug && isFn;
1049 if ((isStr && hasStringEnumBug) || isArgs) {
1050 for (var i = 0; i < object.length; ++i) {
1051 pushCall(theKeys, $String(i));
1056 for (var name in object) {
1057 if (!(skipProto && name === 'prototype') && owns(object, name)) {
1058 pushCall(theKeys, $String(name));
1063 if (hasDontEnumBug) {
1064 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1065 for (var j = 0; j < dontEnumsLength; j++) {
1066 var dontEnum = dontEnums[j];
1067 if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
1068 pushCall(theKeys, dontEnum);
1076 var keysWorksWithArguments = $Object.keys && (function () {
1078 return $Object.keys(arguments).length === 2;
1080 var keysHasArgumentsLengthBug = $Object.keys && (function () {
1081 var argKeys = $Object.keys(arguments);
1082 return arguments.length !== 1 || argKeys.length !== 1 || argKeys[0] !== 1;
1084 var originalKeys = $Object.keys;
1085 defineProperties($Object, {
1086 keys: function keys(object) {
1087 if (isArguments(object)) {
1088 return originalKeys(arraySlice(object));
1090 return originalKeys(object);
1093 }, !keysWorksWithArguments || keysHasArgumentsLengthBug);
1100 var hasNegativeMonthYearBug = new Date(-3509827329600292).getUTCMonth() !== 0;
1101 var aNegativeTestDate = new Date(-1509842289600292);
1102 var aPositiveTestDate = new Date(1449662400000);
1103 var hasToUTCStringFormatBug = aNegativeTestDate.toUTCString() !== 'Mon, 01 Jan -45875 11:59:59 GMT';
1104 var hasToDateStringFormatBug;
1105 var hasToStringFormatBug;
1106 var timeZoneOffset = aNegativeTestDate.getTimezoneOffset();
1107 if (timeZoneOffset < -720) {
1108 hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Tue Jan 02 -45875';
1109 hasToStringFormatBug = !(/^Thu Dec 10 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
1111 hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Mon Jan 01 -45875';
1112 hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
1115 var originalGetFullYear = call.bind(Date.prototype.getFullYear);
1116 var originalGetMonth = call.bind(Date.prototype.getMonth);
1117 var originalGetDate = call.bind(Date.prototype.getDate);
1118 var originalGetUTCFullYear = call.bind(Date.prototype.getUTCFullYear);
1119 var originalGetUTCMonth = call.bind(Date.prototype.getUTCMonth);
1120 var originalGetUTCDate = call.bind(Date.prototype.getUTCDate);
1121 var originalGetUTCDay = call.bind(Date.prototype.getUTCDay);
1122 var originalGetUTCHours = call.bind(Date.prototype.getUTCHours);
1123 var originalGetUTCMinutes = call.bind(Date.prototype.getUTCMinutes);
1124 var originalGetUTCSeconds = call.bind(Date.prototype.getUTCSeconds);
1125 var originalGetUTCMilliseconds = call.bind(Date.prototype.getUTCMilliseconds);
1126 var dayName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
1127 var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
1128 var daysInMonth = function daysInMonth(month, year) {
1129 return originalGetDate(new Date(year, month, 0));
1132 defineProperties(Date.prototype, {
1133 getFullYear: function getFullYear() {
1134 if (!this || !(this instanceof Date)) {
1135 throw new TypeError('this is not a Date object.');
1137 var year = originalGetFullYear(this);
1138 if (year < 0 && originalGetMonth(this) > 11) {
1143 getMonth: function getMonth() {
1144 if (!this || !(this instanceof Date)) {
1145 throw new TypeError('this is not a Date object.');
1147 var year = originalGetFullYear(this);
1148 var month = originalGetMonth(this);
1149 if (year < 0 && month > 11) {
1154 getDate: function getDate() {
1155 if (!this || !(this instanceof Date)) {
1156 throw new TypeError('this is not a Date object.');
1158 var year = originalGetFullYear(this);
1159 var month = originalGetMonth(this);
1160 var date = originalGetDate(this);
1161 if (year < 0 && month > 11) {
1165 var days = daysInMonth(0, year + 1);
1166 return (days - date) + 1;
1170 getUTCFullYear: function getUTCFullYear() {
1171 if (!this || !(this instanceof Date)) {
1172 throw new TypeError('this is not a Date object.');
1174 var year = originalGetUTCFullYear(this);
1175 if (year < 0 && originalGetUTCMonth(this) > 11) {
1180 getUTCMonth: function getUTCMonth() {
1181 if (!this || !(this instanceof Date)) {
1182 throw new TypeError('this is not a Date object.');
1184 var year = originalGetUTCFullYear(this);
1185 var month = originalGetUTCMonth(this);
1186 if (year < 0 && month > 11) {
1191 getUTCDate: function getUTCDate() {
1192 if (!this || !(this instanceof Date)) {
1193 throw new TypeError('this is not a Date object.');
1195 var year = originalGetUTCFullYear(this);
1196 var month = originalGetUTCMonth(this);
1197 var date = originalGetUTCDate(this);
1198 if (year < 0 && month > 11) {
1202 var days = daysInMonth(0, year + 1);
1203 return (days - date) + 1;
1207 }, hasNegativeMonthYearBug);
1209 defineProperties(Date.prototype, {
1210 toUTCString: function toUTCString() {
1211 if (!this || !(this instanceof Date)) {
1212 throw new TypeError('this is not a Date object.');
1214 var day = originalGetUTCDay(this);
1215 var date = originalGetUTCDate(this);
1216 var month = originalGetUTCMonth(this);
1217 var year = originalGetUTCFullYear(this);
1218 var hour = originalGetUTCHours(this);
1219 var minute = originalGetUTCMinutes(this);
1220 var second = originalGetUTCSeconds(this);
1221 return dayName[day] + ', ' +
1222 (date < 10 ? '0' + date : date) + ' ' +
1223 monthName[month] + ' ' +
1225 (hour < 10 ? '0' + hour : hour) + ':' +
1226 (minute < 10 ? '0' + minute : minute) + ':' +
1227 (second < 10 ? '0' + second : second) + ' GMT';
1229 }, hasNegativeMonthYearBug || hasToUTCStringFormatBug);
1232 defineProperties(Date.prototype, {
1233 toDateString: function toDateString() {
1234 if (!this || !(this instanceof Date)) {
1235 throw new TypeError('this is not a Date object.');
1237 var day = this.getDay();
1238 var date = this.getDate();
1239 var month = this.getMonth();
1240 var year = this.getFullYear();
1241 return dayName[day] + ' ' +
1242 monthName[month] + ' ' +
1243 (date < 10 ? '0' + date : date) + ' ' +
1246 }, hasNegativeMonthYearBug || hasToDateStringFormatBug);
1248 // can't use defineProperties here because of toString enumeration issue in IE <= 8
1249 if (hasNegativeMonthYearBug || hasToStringFormatBug) {
1250 Date.prototype.toString = function toString() {
1251 if (!this || !(this instanceof Date)) {
1252 throw new TypeError('this is not a Date object.');
1254 var day = this.getDay();
1255 var date = this.getDate();
1256 var month = this.getMonth();
1257 var year = this.getFullYear();
1258 var hour = this.getHours();
1259 var minute = this.getMinutes();
1260 var second = this.getSeconds();
1261 var timezoneOffset = this.getTimezoneOffset();
1262 var hoursOffset = Math.floor(Math.abs(timezoneOffset) / 60);
1263 var minutesOffset = Math.floor(Math.abs(timezoneOffset) % 60);
1264 return dayName[day] + ' ' +
1265 monthName[month] + ' ' +
1266 (date < 10 ? '0' + date : date) + ' ' +
1268 (hour < 10 ? '0' + hour : hour) + ':' +
1269 (minute < 10 ? '0' + minute : minute) + ':' +
1270 (second < 10 ? '0' + second : second) + ' GMT' +
1271 (timezoneOffset > 0 ? '-' : '+') +
1272 (hoursOffset < 10 ? '0' + hoursOffset : hoursOffset) +
1273 (minutesOffset < 10 ? '0' + minutesOffset : minutesOffset);
1275 if (supportsDescriptors) {
1276 $Object.defineProperty(Date.prototype, 'toString', {
1285 // http://es5.github.com/#x15.9.5.43
1286 // This function returns a String value represent the instance in time
1287 // represented by this Date object. The format of the String is the Date Time
1288 // string format defined in 15.9.1.15. All fields are present in the String.
1289 // The time zone is always UTC, denoted by the suffix Z. If the time value of
1290 // this object is not a finite Number a RangeError exception is thrown.
1291 var negativeDate = -62198755200000;
1292 var negativeYearString = '-000001';
1293 var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
1294 var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
1296 defineProperties(Date.prototype, {
1297 toISOString: function toISOString() {
1298 if (!isFinite(this)) {
1299 throw new RangeError('Date.prototype.toISOString called on non-finite value.');
1302 var year = originalGetUTCFullYear(this);
1304 var month = originalGetUTCMonth(this);
1305 // see https://github.com/es-shims/es5-shim/issues/111
1306 year += Math.floor(month / 12);
1307 month = (month % 12 + 12) % 12;
1309 // the date time string format is specified in 15.9.1.15.
1310 var result = [month + 1, originalGetUTCDate(this), originalGetUTCHours(this), originalGetUTCMinutes(this), originalGetUTCSeconds(this)];
1312 (year < 0 ? '-' : (year > 9999 ? '+' : '')) +
1313 strSlice('00000' + Math.abs(year), (0 <= year && year <= 9999) ? -4 : -6)
1316 for (var i = 0; i < result.length; ++i) {
1317 // pad months, days, hours, minutes, and seconds to have two digits.
1318 result[i] = strSlice('00' + result[i], -2);
1320 // pad milliseconds to have three digits.
1322 year + '-' + arraySlice(result, 0, 2).join('-') +
1323 'T' + arraySlice(result, 2).join(':') + '.' +
1324 strSlice('000' + originalGetUTCMilliseconds(this), -3) + 'Z'
1327 }, hasNegativeDateBug || hasSafari51DateBug);
1330 // http://es5.github.com/#x15.9.5.44
1331 // This function provides a String representation of a Date object for use by
1332 // JSON.stringify (15.12.3).
1333 var dateToJSONIsSupported = (function () {
1335 return Date.prototype.toJSON &&
1336 new Date(NaN).toJSON() === null &&
1337 new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
1338 Date.prototype.toJSON.call({ // generic
1339 toISOString: function () { return true; }
1345 if (!dateToJSONIsSupported) {
1346 Date.prototype.toJSON = function toJSON(key) {
1347 // When the toJSON method is called with argument key, the following
1350 // 1. Let O be the result of calling ToObject, giving it the this
1351 // value as its argument.
1352 // 2. Let tv be ES.ToPrimitive(O, hint Number).
1353 var O = $Object(this);
1354 var tv = ES.ToPrimitive(O);
1355 // 3. If tv is a Number and is not finite, return null.
1356 if (typeof tv === 'number' && !isFinite(tv)) {
1359 // 4. Let toISO be the result of calling the [[Get]] internal method of
1360 // O with argument "toISOString".
1361 var toISO = O.toISOString;
1362 // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1363 if (!isCallable(toISO)) {
1364 throw new TypeError('toISOString property is not callable');
1366 // 6. Return the result of calling the [[Call]] internal method of
1367 // toISO with O as the this value and an empty argument list.
1368 return toISO.call(O);
1370 // NOTE 1 The argument is ignored.
1372 // NOTE 2 The toJSON function is intentionally generic; it does not
1373 // require that its this value be a Date object. Therefore, it can be
1374 // transferred to other kinds of objects for use as a method. However,
1375 // it does require that any such object have a toISOString method. An
1376 // object is free to use the argument key to filter its
1382 // http://es5.github.com/#x15.9.4.2
1383 // based on work shared by Daniel Friesen (dantman)
1384 // http://gist.github.com/303249
1385 var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
1386 var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
1387 var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
1388 if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
1389 // XXX global assignment won't work in embeddings that use
1390 // an alternate object for the context.
1391 /* global Date: true */
1392 /* eslint-disable no-undef */
1393 var maxSafeUnsigned32Bit = Math.pow(2, 31) - 1;
1394 var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
1395 Date = (function (NativeDate) {
1396 /* eslint-enable no-undef */
1397 // Date.length === 7
1398 var DateShim = function Date(Y, M, D, h, m, s, ms) {
1399 var length = arguments.length;
1401 if (this instanceof NativeDate) {
1404 if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
1405 // work around a Safari 8/9 bug where it treats the seconds as signed
1406 var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1407 var sToShift = Math.floor(msToShift / 1e3);
1408 seconds += sToShift;
1409 millis -= sToShift * 1e3;
1411 date = length === 1 && $String(Y) === Y ? // isString(Y)
1412 // We explicitly pass it through parse:
1413 new NativeDate(DateShim.parse(Y)) :
1414 // We have to manually make calls depending on argument
1416 length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis) :
1417 length >= 6 ? new NativeDate(Y, M, D, h, m, seconds) :
1418 length >= 5 ? new NativeDate(Y, M, D, h, m) :
1419 length >= 4 ? new NativeDate(Y, M, D, h) :
1420 length >= 3 ? new NativeDate(Y, M, D) :
1421 length >= 2 ? new NativeDate(Y, M) :
1422 length >= 1 ? new NativeDate(Y) :
1425 date = NativeDate.apply(this, arguments);
1427 if (!isPrimitive(date)) {
1428 // Prevent mixups with unfixed Date object
1429 defineProperties(date, { constructor: DateShim }, true);
1434 // 15.9.1.15 Date Time String Format.
1435 var isoDateExpression = new RegExp('^' +
1436 '(\\d{4}|[+-]\\d{6})' + // four-digit year capture or sign +
1437 // 6-digit extended year
1438 '(?:-(\\d{2})' + // optional month capture
1439 '(?:-(\\d{2})' + // optional day capture
1440 '(?:' + // capture hours:minutes:seconds.milliseconds
1441 'T(\\d{2})' + // hours capture
1442 ':(\\d{2})' + // minutes capture
1443 '(?:' + // optional :seconds.milliseconds
1444 ':(\\d{2})' + // seconds capture
1445 '(?:(\\.\\d{1,}))?' + // milliseconds capture
1447 '(' + // capture UTC offset component
1448 'Z|' + // UTC capture
1449 '(?:' + // offset specifier +/-hours:minutes
1450 '([-+])' + // sign capture
1451 '(\\d{2})' + // hours offset capture
1452 ':(\\d{2})' + // minutes offset capture
1457 var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
1459 var dayFromMonth = function dayFromMonth(year, month) {
1460 var t = month > 1 ? 1 : 0;
1463 Math.floor((year - 1969 + t) / 4) -
1464 Math.floor((year - 1901 + t) / 100) +
1465 Math.floor((year - 1601 + t) / 400) +
1470 var toUTC = function toUTC(t) {
1473 if (hasSafariSignedIntBug && ms > maxSafeUnsigned32Bit) {
1474 // work around a Safari 8/9 bug where it treats the seconds as signed
1475 var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1476 var sToShift = Math.floor(msToShift / 1e3);
1478 ms -= sToShift * 1e3;
1480 return $Number(new NativeDate(1970, 0, 1, 0, 0, s, ms));
1483 // Copy any custom methods a 3rd party library may have added
1484 for (var key in NativeDate) {
1485 if (owns(NativeDate, key)) {
1486 DateShim[key] = NativeDate[key];
1490 // Copy "native" methods explicitly; they may be non-enumerable
1491 defineProperties(DateShim, {
1492 now: NativeDate.now,
1495 DateShim.prototype = NativeDate.prototype;
1496 defineProperties(DateShim.prototype, {
1497 constructor: DateShim
1500 // Upgrade Date.parse to handle simplified ISO 8601 strings
1501 var parseShim = function parse(string) {
1502 var match = isoDateExpression.exec(string);
1504 // parse months, days, hours, minutes, seconds, and milliseconds
1505 // provide default values if necessary
1506 // parse the UTC offset component
1507 var year = $Number(match[1]),
1508 month = $Number(match[2] || 1) - 1,
1509 day = $Number(match[3] || 1) - 1,
1510 hour = $Number(match[4] || 0),
1511 minute = $Number(match[5] || 0),
1512 second = $Number(match[6] || 0),
1513 millisecond = Math.floor($Number(match[7] || 0) * 1000),
1514 // When time zone is missed, local offset should be used
1516 // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1517 isLocalTime = Boolean(match[4] && !match[8]),
1518 signOffset = match[9] === '-' ? 1 : -1,
1519 hourOffset = $Number(match[10] || 0),
1520 minuteOffset = $Number(match[11] || 0),
1522 var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
1524 hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25) &&
1525 minute < 60 && second < 60 && millisecond < 1000 &&
1526 month > -1 && month < 12 && hourOffset < 24 &&
1527 minuteOffset < 60 && // detect invalid offsets
1529 day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
1532 (dayFromMonth(year, month) + day) * 24 +
1534 hourOffset * signOffset
1537 (result + minute + minuteOffset * signOffset) * 60 +
1539 ) * 1000 + millisecond;
1541 result = toUTC(result);
1543 if (-8.64e15 <= result && result <= 8.64e15) {
1549 return NativeDate.parse.apply(this, arguments);
1551 defineProperties(DateShim, { parse: parseShim });
1555 /* global Date: false */
1559 // http://es5.github.com/#x15.9.4.4
1561 Date.now = function now() {
1562 return new Date().getTime();
1572 // http://es5.github.com/#x15.7.4.5
1573 var hasToFixedBugs = NumberPrototype.toFixed && (
1574 (0.00008).toFixed(3) !== '0.000' ||
1575 (0.9).toFixed(0) !== '1' ||
1576 (1.255).toFixed(2) !== '1.25' ||
1577 (1000000000000000128).toFixed(0) !== '1000000000000000128'
1580 var toFixedHelpers = {
1583 data: [0, 0, 0, 0, 0, 0],
1584 multiply: function multiply(n, c) {
1587 while (++i < toFixedHelpers.size) {
1588 c2 += n * toFixedHelpers.data[i];
1589 toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
1590 c2 = Math.floor(c2 / toFixedHelpers.base);
1593 divide: function divide(n) {
1594 var i = toFixedHelpers.size, c = 0;
1596 c += toFixedHelpers.data[i];
1597 toFixedHelpers.data[i] = Math.floor(c / n);
1598 c = (c % n) * toFixedHelpers.base;
1601 numToString: function numToString() {
1602 var i = toFixedHelpers.size;
1605 if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
1606 var t = $String(toFixedHelpers.data[i]);
1610 s += strSlice('0000000', 0, 7 - t.length) + t;
1616 pow: function pow(x, n, acc) {
1617 return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1619 log: function log(x) {
1622 while (x2 >= 4096) {
1634 var toFixedShim = function toFixed(fractionDigits) {
1635 var f, x, s, m, e, z, j, k;
1637 // Test for NaN and round fractionDigits down
1638 f = $Number(fractionDigits);
1639 f = isActualNaN(f) ? 0 : Math.floor(f);
1641 if (f < 0 || f > 20) {
1642 throw new RangeError('Number.toFixed called with invalid number of decimals');
1647 if (isActualNaN(x)) {
1651 // If it is too big or small, return the string value of the number
1652 if (x <= -1e21 || x >= 1e21) {
1667 // -70 < log2(x) < 70
1668 e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
1669 z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
1670 z *= 0x10000000000000; // Math.pow(2, 52);
1676 toFixedHelpers.multiply(0, z);
1680 toFixedHelpers.multiply(1e7, 0);
1684 toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
1688 toFixedHelpers.divide(1 << 23);
1692 toFixedHelpers.divide(1 << j);
1693 toFixedHelpers.multiply(1, 1);
1694 toFixedHelpers.divide(2);
1695 m = toFixedHelpers.numToString();
1697 toFixedHelpers.multiply(0, z);
1698 toFixedHelpers.multiply(1 << (-e), 0);
1699 m = toFixedHelpers.numToString() + strSlice('0.00000000000000000000', 2, 2 + f);
1707 m = s + strSlice('0.0000000000000000000', 0, f - k + 2) + m;
1709 m = s + strSlice(m, 0, k - f) + '.' + strSlice(m, k - f);
1717 defineProperties(NumberPrototype, { toFixed: toFixedShim }, hasToFixedBugs);
1719 var hasToPrecisionUndefinedBug = (function () {
1721 return 1.0.toPrecision(undefined) === '1';
1726 var originalToPrecision = NumberPrototype.toPrecision;
1727 defineProperties(NumberPrototype, {
1728 toPrecision: function toPrecision(precision) {
1729 return typeof precision === 'undefined' ? originalToPrecision.call(this) : originalToPrecision.call(this, precision);
1731 }, hasToPrecisionUndefinedBug);
1739 // http://es5.github.com/#x15.5.4.14
1741 // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1742 // Many browsers do not split properly with regular expressions or they
1743 // do not perform the split correctly under obscure conditions.
1744 // See http://blog.stevenlevithan.com/archives/cross-browser-split
1745 // I've tested in many browsers and this seems to cover the deviant ones:
1746 // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1747 // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1748 // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1749 // [undefined, "t", undefined, "e", ...]
1750 // ''.split(/.?/) should be [], not [""]
1751 // '.'.split(/()()/) should be ["."], not ["", "", "."]
1754 'ab'.split(/(?:ab)*/).length !== 2 ||
1755 '.'.split(/(.?)(.?)/).length !== 4 ||
1756 'tesst'.split(/(s)*/)[1] === 't' ||
1757 'test'.split(/(?:)/, -1).length !== 4 ||
1758 ''.split(/.?/).length ||
1759 '.'.split(/()()/).length > 1
1762 var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
1763 var maxSafe32BitInt = Math.pow(2, 32) - 1;
1765 StringPrototype.split = function (separator, limit) {
1766 var string = String(this);
1767 if (typeof separator === 'undefined' && limit === 0) {
1771 // If `separator` is not a regex, use native split
1772 if (!isRegex(separator)) {
1773 return strSplit(this, separator, limit);
1777 var flags = (separator.ignoreCase ? 'i' : '') +
1778 (separator.multiline ? 'm' : '') +
1779 (separator.unicode ? 'u' : '') + // in ES6
1780 (separator.sticky ? 'y' : ''), // Firefox 3+ and ES6
1782 // Make `global` and avoid `lastIndex` issues by working with a copy
1783 separator2, match, lastIndex, lastLength;
1784 var separatorCopy = new RegExp(separator.source, flags + 'g');
1785 if (!compliantExecNpcg) {
1786 // Doesn't need flags gy, but they don't hurt
1787 separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
1789 /* Values for `limit`, per the spec:
1790 * If undefined: 4294967295 // maxSafe32BitInt
1791 * If 0, Infinity, or NaN: 0
1792 * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1793 * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1794 * If other: Type-convert, then use the above rules
1796 var splitLimit = typeof limit === 'undefined' ? maxSafe32BitInt : ES.ToUint32(limit);
1797 match = separatorCopy.exec(string);
1799 // `separatorCopy.lastIndex` is not reliable cross-browser
1800 lastIndex = match.index + match[0].length;
1801 if (lastIndex > lastLastIndex) {
1802 pushCall(output, strSlice(string, lastLastIndex, match.index));
1803 // Fix browsers whose `exec` methods don't consistently return `undefined` for
1804 // nonparticipating capturing groups
1805 if (!compliantExecNpcg && match.length > 1) {
1806 /* eslint-disable no-loop-func */
1807 match[0].replace(separator2, function () {
1808 for (var i = 1; i < arguments.length - 2; i++) {
1809 if (typeof arguments[i] === 'undefined') {
1814 /* eslint-enable no-loop-func */
1816 if (match.length > 1 && match.index < string.length) {
1817 array_push.apply(output, arraySlice(match, 1));
1819 lastLength = match[0].length;
1820 lastLastIndex = lastIndex;
1821 if (output.length >= splitLimit) {
1825 if (separatorCopy.lastIndex === match.index) {
1826 separatorCopy.lastIndex++; // Avoid an infinite loop
1828 match = separatorCopy.exec(string);
1830 if (lastLastIndex === string.length) {
1831 if (lastLength || !separatorCopy.test('')) {
1832 pushCall(output, '');
1835 pushCall(output, strSlice(string, lastLastIndex));
1837 return output.length > splitLimit ? strSlice(output, 0, splitLimit) : output;
1842 // If separator is undefined, then the result array contains just one String,
1843 // which is the this value (converted to a String). If limit is not undefined,
1844 // then the output array is truncated so that it contains no more than limit
1846 // "0".split(undefined, 0) -> []
1847 } else if ('0'.split(void 0, 0).length) {
1848 StringPrototype.split = function split(separator, limit) {
1849 if (typeof separator === 'undefined' && limit === 0) { return []; }
1850 return strSplit(this, separator, limit);
1854 var str_replace = StringPrototype.replace;
1855 var replaceReportsGroupsCorrectly = (function () {
1857 'x'.replace(/x(.)?/g, function (match, group) {
1858 pushCall(groups, group);
1860 return groups.length === 1 && typeof groups[0] === 'undefined';
1863 if (!replaceReportsGroupsCorrectly) {
1864 StringPrototype.replace = function replace(searchValue, replaceValue) {
1865 var isFn = isCallable(replaceValue);
1866 var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
1867 if (!isFn || !hasCapturingGroups) {
1868 return str_replace.call(this, searchValue, replaceValue);
1870 var wrappedReplaceValue = function (match) {
1871 var length = arguments.length;
1872 var originalLastIndex = searchValue.lastIndex;
1873 searchValue.lastIndex = 0;
1874 var args = searchValue.exec(match) || [];
1875 searchValue.lastIndex = originalLastIndex;
1876 pushCall(args, arguments[length - 2], arguments[length - 1]);
1877 return replaceValue.apply(this, args);
1879 return str_replace.call(this, searchValue, wrappedReplaceValue);
1884 // ECMA-262, 3rd B.2.3
1885 // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
1886 // non-normative section suggesting uniform semantics and it should be
1887 // normalized across all browsers
1888 // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1889 var string_substr = StringPrototype.substr;
1890 var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
1891 defineProperties(StringPrototype, {
1892 substr: function substr(start, length) {
1893 var normalizedStart = start;
1895 normalizedStart = max(this.length + start, 0);
1897 return string_substr.call(this, normalizedStart, length);
1899 }, hasNegativeSubstrBug);
1902 // whitespace from: http://es5.github.io/#x15.5.4.20
1903 var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
1904 '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
1906 var zeroWidth = '\u200b';
1907 var wsRegexChars = '[' + ws + ']';
1908 var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
1909 var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
1910 var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
1911 defineProperties(StringPrototype, {
1912 // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1913 // http://perfectionkills.com/whitespace-deviations/
1914 trim: function trim() {
1915 if (typeof this === 'undefined' || this === null) {
1916 throw new TypeError("can't convert " + this + ' to object');
1918 return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
1920 }, hasTrimWhitespaceBug);
1921 var trim = call.bind(String.prototype.trim);
1923 var hasLastIndexBug = StringPrototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
1924 defineProperties(StringPrototype, {
1925 lastIndexOf: function lastIndexOf(searchString) {
1926 if (typeof this === 'undefined' || this === null) {
1927 throw new TypeError("can't convert " + this + ' to object');
1929 var S = $String(this);
1930 var searchStr = $String(searchString);
1931 var numPos = arguments.length > 1 ? $Number(arguments[1]) : NaN;
1932 var pos = isActualNaN(numPos) ? Infinity : ES.ToInteger(numPos);
1933 var start = min(max(pos, 0), S.length);
1934 var searchLen = searchStr.length;
1935 var k = start + searchLen;
1937 k = max(0, k - searchLen);
1938 var index = strIndexOf(strSlice(S, k, start + searchLen), searchStr);
1945 }, hasLastIndexBug);
1947 var originalLastIndexOf = StringPrototype.lastIndexOf;
1948 defineProperties(StringPrototype, {
1949 lastIndexOf: function lastIndexOf(searchString) {
1950 return originalLastIndexOf.apply(this, arguments);
1952 }, StringPrototype.lastIndexOf.length !== 1);
1955 /* eslint-disable radix */
1956 if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
1957 /* eslint-enable radix */
1958 /* global parseInt: true */
1959 parseInt = (function (origParseInt) {
1960 var hexRegex = /^[\-+]?0[xX]/;
1961 return function parseInt(str, radix) {
1962 var string = trim(str);
1963 var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
1964 return origParseInt(string, defaultedRadix);
1969 // https://es5.github.io/#x15.1.2.3
1970 if (1 / parseFloat('-0') !== -Infinity) {
1971 /* global parseFloat: true */
1972 parseFloat = (function (origParseFloat) {
1973 return function parseFloat(string) {
1974 var inputString = trim(string);
1975 var result = origParseFloat(inputString);
1976 return result === 0 && strSlice(inputString, 0, 1) === '-' ? -0 : result;
1981 if (String(new RangeError('test')) !== 'RangeError: test') {
1982 var errorToStringShim = function toString() {
1983 if (typeof this === 'undefined' || this === null) {
1984 throw new TypeError("can't convert " + this + ' to object');
1986 var name = this.name;
1987 if (typeof name === 'undefined') {
1989 } else if (typeof name !== 'string') {
1990 name = $String(name);
1992 var msg = this.message;
1993 if (typeof msg === 'undefined') {
1995 } else if (typeof msg !== 'string') {
2004 return name + ': ' + msg;
2006 // can't use defineProperties here because of toString enumeration issue in IE <= 8
2007 Error.prototype.toString = errorToStringShim;
2010 if (supportsDescriptors) {
2011 var ensureNonEnumerable = function (obj, prop) {
2012 if (isEnum(obj, prop)) {
2013 var desc = Object.getOwnPropertyDescriptor(obj, prop);
2014 desc.enumerable = false;
2015 Object.defineProperty(obj, prop, desc);
2018 ensureNonEnumerable(Error.prototype, 'message');
2019 if (Error.prototype.message !== '') {
2020 Error.prototype.message = '';
2022 ensureNonEnumerable(Error.prototype, 'name');
2025 if (String(/a/mig) !== '/a/gim') {
2026 var regexToString = function toString() {
2027 var str = '/' + this.source + '/';
2031 if (this.ignoreCase) {
2034 if (this.multiline) {
2039 // can't use defineProperties here because of toString enumeration issue in IE <= 8
2040 RegExp.prototype.toString = regexToString;
2046 * https://github.com/es-shims/es5-shim
2047 * @license es5-shim Copyright 2009-2015 by contributors, MIT License
2048 * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
2051 // vim: ts=4 sts=4 sw=4 expandtab
2053 // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
2056 // UMD (Universal Module Definition)
2057 // see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
2058 (function (root, factory) {
2061 /* global define, exports, module */
2062 if (typeof define === 'function' && define.amd) {
2063 // AMD. Register as an anonymous module.
2065 } else if (typeof exports === 'object') {
2066 // Node. Does not work with strict CommonJS, but
2067 // only CommonJS-like enviroments that support module.exports,
2069 module.exports = factory();
2071 // Browser globals (root is window)
2072 root.returnExports = factory();
2074 }(this, function () {
2076 var call = Function.call;
2077 var prototypeOfObject = Object.prototype;
2078 var owns = call.bind(prototypeOfObject.hasOwnProperty);
2079 var isEnumerable = call.bind(prototypeOfObject.propertyIsEnumerable);
2080 var toStr = call.bind(prototypeOfObject.toString);
2082 // If JS engine supports accessors creating shortcuts.
2087 var supportsAccessors = owns(prototypeOfObject, '__defineGetter__');
2088 if (supportsAccessors) {
2089 /* eslint-disable no-underscore-dangle */
2090 defineGetter = call.bind(prototypeOfObject.__defineGetter__);
2091 defineSetter = call.bind(prototypeOfObject.__defineSetter__);
2092 lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
2093 lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
2094 /* eslint-enable no-underscore-dangle */
2098 // http://es5.github.com/#x15.2.3.2
2099 if (!Object.getPrototypeOf) {
2100 // https://github.com/es-shims/es5-shim/issues#issue/2
2101 // http://ejohn.org/blog/objectgetprototypeof/
2102 // recommended by fschaefer on github
2104 // sure, and webreflection says ^_^
2105 // ... this will nerever possibly return null
2106 // ... Opera Mini breaks here with infinite loops
2107 Object.getPrototypeOf = function getPrototypeOf(object) {
2108 /* eslint-disable no-proto */
2109 var proto = object.__proto__;
2110 /* eslint-enable no-proto */
2111 if (proto || proto === null) {
2113 } else if (toStr(object.constructor) === '[object Function]') {
2114 return object.constructor.prototype;
2115 } else if (object instanceof Object) {
2116 return prototypeOfObject;
2118 // Correctly return null for Objects created with `Object.create(null)`
2119 // (shammed or native) or `{ __proto__: null}`. Also returns null for
2120 // cross-realm objects on browsers that lack `__proto__` support (like
2121 // IE <11), but that's the best we can do.
2128 // http://es5.github.com/#x15.2.3.3
2130 var doesGetOwnPropertyDescriptorWork = function doesGetOwnPropertyDescriptorWork(object) {
2132 object.sentinel = 0;
2133 return Object.getOwnPropertyDescriptor(object, 'sentinel').value === 0;
2134 } catch (exception) {
2139 // check whether getOwnPropertyDescriptor works if it's given. Otherwise, shim partially.
2140 if (Object.defineProperty) {
2141 var getOwnPropertyDescriptorWorksOnObject = doesGetOwnPropertyDescriptorWork({});
2142 var getOwnPropertyDescriptorWorksOnDom = typeof document === 'undefined' ||
2143 doesGetOwnPropertyDescriptorWork(document.createElement('div'));
2144 if (!getOwnPropertyDescriptorWorksOnDom || !getOwnPropertyDescriptorWorksOnObject) {
2145 var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
2149 if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
2150 var ERR_NON_OBJECT = 'Object.getOwnPropertyDescriptor called on a non-object: ';
2152 /* eslint-disable no-proto */
2153 Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
2154 if ((typeof object !== 'object' && typeof object !== 'function') || object === null) {
2155 throw new TypeError(ERR_NON_OBJECT + object);
2158 // make a valiant attempt to use the real getOwnPropertyDescriptor
2159 // for I8's DOM elements.
2160 if (getOwnPropertyDescriptorFallback) {
2162 return getOwnPropertyDescriptorFallback.call(Object, object, property);
2163 } catch (exception) {
2164 // try the shim if the real one doesn't work
2170 // If object does not owns property return undefined immediately.
2171 if (!owns(object, property)) {
2175 // If object has a property then it's for sure `configurable`, and
2176 // probably `enumerable`. Detect enumerability though.
2178 enumerable: isEnumerable(object, property),
2182 // If JS engine supports accessor properties then property may be a
2183 // getter or setter.
2184 if (supportsAccessors) {
2185 // Unfortunately `__lookupGetter__` will return a getter even
2186 // if object has own non getter property along with a same named
2187 // inherited getter. To avoid misbehavior we temporary remove
2188 // `__proto__` so that `__lookupGetter__` will return getter only
2189 // if it's owned by an object.
2190 var prototype = object.__proto__;
2191 var notPrototypeOfObject = object !== prototypeOfObject;
2192 // avoid recursion problem, breaking in Opera Mini when
2193 // Object.getOwnPropertyDescriptor(Object.prototype, 'toString')
2194 // or any other Object.prototype accessor
2195 if (notPrototypeOfObject) {
2196 object.__proto__ = prototypeOfObject;
2199 var getter = lookupGetter(object, property);
2200 var setter = lookupSetter(object, property);
2202 if (notPrototypeOfObject) {
2203 // Once we have getter and setter we can put values back.
2204 object.__proto__ = prototype;
2207 if (getter || setter) {
2209 descriptor.get = getter;
2212 descriptor.set = setter;
2214 // If it was accessor property we're done and return here
2215 // in order to avoid adding `value` to the descriptor.
2220 // If we got this far we know that object has an own property that is
2221 // not an accessor so we set it as a value and return descriptor.
2222 descriptor.value = object[property];
2223 descriptor.writable = true;
2226 /* eslint-enable no-proto */
2230 // http://es5.github.com/#x15.2.3.4
2231 if (!Object.getOwnPropertyNames) {
2232 Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
2233 return Object.keys(object);
2238 // http://es5.github.com/#x15.2.3.5
2239 if (!Object.create) {
2241 // Contributed by Brandon Benvie, October, 2012
2243 var supportsProto = !({ __proto__: null } instanceof Object);
2244 // the following produces false positives
2245 // in Opera Mini => not a reliable check
2246 // Object.prototype.__proto__ === null
2248 // Check for document.domain and active x support
2249 // No need to use active x approach when document.domain is not set
2250 // see https://github.com/es-shims/es5-shim/issues/150
2251 // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
2252 /* global ActiveXObject */
2253 var shouldUseActiveX = function shouldUseActiveX() {
2254 // return early if document.domain not set
2255 if (!document.domain) {
2260 return !!new ActiveXObject('htmlfile');
2261 } catch (exception) {
2266 // This supports IE8 when document.domain is used
2267 // see https://github.com/es-shims/es5-shim/issues/150
2268 // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
2269 var getEmptyViaActiveX = function getEmptyViaActiveX() {
2273 xDoc = new ActiveXObject('htmlfile');
2275 xDoc.write('<script><\/script>');
2278 empty = xDoc.parentWindow.Object.prototype;
2284 // The original implementation using an iframe
2285 // before the activex approach was added
2286 // see https://github.com/es-shims/es5-shim/issues/150
2287 var getEmptyViaIFrame = function getEmptyViaIFrame() {
2288 var iframe = document.createElement('iframe');
2289 var parent = document.body || document.documentElement;
2292 iframe.style.display = 'none';
2293 parent.appendChild(iframe);
2294 /* eslint-disable no-script-url */
2295 iframe.src = 'javascript:';
2296 /* eslint-enable no-script-url */
2298 empty = iframe.contentWindow.Object.prototype;
2299 parent.removeChild(iframe);
2305 /* global document */
2306 if (supportsProto || typeof document === 'undefined') {
2307 createEmpty = function () {
2308 return { __proto__: null };
2311 // In old IE __proto__ can't be used to manually set `null`, nor does
2312 // any other method exist to make an object that inherits from nothing,
2313 // aside from Object.prototype itself. Instead, create a new global
2314 // object and *steal* its Object.prototype and strip it bare. This is
2315 // used as the prototype to create nullary objects.
2316 createEmpty = function () {
2317 // Determine which approach to use
2318 // see https://github.com/es-shims/es5-shim/issues/150
2319 var empty = shouldUseActiveX() ? getEmptyViaActiveX() : getEmptyViaIFrame();
2321 delete empty.constructor;
2322 delete empty.hasOwnProperty;
2323 delete empty.propertyIsEnumerable;
2324 delete empty.isPrototypeOf;
2325 delete empty.toLocaleString;
2326 delete empty.toString;
2327 delete empty.valueOf;
2329 var Empty = function Empty() {};
2330 Empty.prototype = empty;
2331 // short-circuit future calls
2332 createEmpty = function () {
2339 Object.create = function create(prototype, properties) {
2342 var Type = function Type() {}; // An empty constructor.
2344 if (prototype === null) {
2345 object = createEmpty();
2347 if (typeof prototype !== 'object' && typeof prototype !== 'function') {
2348 // In the native implementation `parent` can be `null`
2349 // OR *any* `instanceof Object` (Object|Function|Array|RegExp|etc)
2350 // Use `typeof` tho, b/c in old IE, DOM elements are not `instanceof Object`
2351 // like they are in modern browsers. Using `Object.create` on DOM elements
2352 // is...err...probably inappropriate, but the native version allows for it.
2353 throw new TypeError('Object prototype may only be an Object or null'); // same msg as Chrome
2355 Type.prototype = prototype;
2356 object = new Type();
2357 // IE has no built-in implementation of `Object.getPrototypeOf`
2358 // neither `__proto__`, but this manually setting `__proto__` will
2359 // guarantee that `Object.getPrototypeOf` will work as expected with
2360 // objects created using `Object.create`
2361 /* eslint-disable no-proto */
2362 object.__proto__ = prototype;
2363 /* eslint-enable no-proto */
2366 if (properties !== void 0) {
2367 Object.defineProperties(object, properties);
2375 // http://es5.github.com/#x15.2.3.6
2377 // Patch for WebKit and IE8 standard mode
2378 // Designed by hax <hax.github.com>
2379 // related issue: https://github.com/es-shims/es5-shim/issues#issue/5
2381 // http://msdn.microsoft.com/en-us/library/dd282900.aspx
2382 // http://msdn.microsoft.com/en-us/library/dd229916.aspx
2384 // https://bugs.webkit.org/show_bug.cgi?id=36423
2386 var doesDefinePropertyWork = function doesDefinePropertyWork(object) {
2388 Object.defineProperty(object, 'sentinel', {});
2389 return 'sentinel' in object;
2390 } catch (exception) {
2395 // check whether defineProperty works if it's given. Otherwise,
2397 if (Object.defineProperty) {
2398 var definePropertyWorksOnObject = doesDefinePropertyWork({});
2399 var definePropertyWorksOnDom = typeof document === 'undefined' ||
2400 doesDefinePropertyWork(document.createElement('div'));
2401 if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
2402 var definePropertyFallback = Object.defineProperty,
2403 definePropertiesFallback = Object.defineProperties;
2407 if (!Object.defineProperty || definePropertyFallback) {
2408 var ERR_NON_OBJECT_DESCRIPTOR = 'Property description must be an object: ';
2409 var ERR_NON_OBJECT_TARGET = 'Object.defineProperty called on non-object: ';
2410 var ERR_ACCESSORS_NOT_SUPPORTED = 'getters & setters can not be defined on this javascript engine';
2412 Object.defineProperty = function defineProperty(object, property, descriptor) {
2413 if ((typeof object !== 'object' && typeof object !== 'function') || object === null) {
2414 throw new TypeError(ERR_NON_OBJECT_TARGET + object);
2416 if ((typeof descriptor !== 'object' && typeof descriptor !== 'function') || descriptor === null) {
2417 throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
2419 // make a valiant attempt to use the real defineProperty
2420 // for I8's DOM elements.
2421 if (definePropertyFallback) {
2423 return definePropertyFallback.call(Object, object, property, descriptor);
2424 } catch (exception) {
2425 // try the shim if the real one doesn't work
2429 // If it's a data property.
2430 if ('value' in descriptor) {
2431 // fail silently if 'writable', 'enumerable', or 'configurable'
2432 // are requested but not supported
2434 // alternate approach:
2435 if ( // can't implement these features; allow false but not true
2436 ('writable' in descriptor && !descriptor.writable) ||
2437 ('enumerable' in descriptor && !descriptor.enumerable) ||
2438 ('configurable' in descriptor && !descriptor.configurable)
2440 throw new RangeError(
2441 'This implementation of Object.defineProperty does not support configurable, enumerable, or writable.'
2445 if (supportsAccessors && (lookupGetter(object, property) || lookupSetter(object, property))) {
2446 // As accessors are supported only on engines implementing
2447 // `__proto__` we can safely override `__proto__` while defining
2448 // a property to make sure that we don't hit an inherited
2450 /* eslint-disable no-proto */
2451 var prototype = object.__proto__;
2452 object.__proto__ = prototypeOfObject;
2453 // Deleting a property anyway since getter / setter may be
2454 // defined on object itself.
2455 delete object[property];
2456 object[property] = descriptor.value;
2457 // Setting original `__proto__` back now.
2458 object.__proto__ = prototype;
2459 /* eslint-enable no-proto */
2461 object[property] = descriptor.value;
2464 if (!supportsAccessors && (('get' in descriptor) || ('set' in descriptor))) {
2465 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
2467 // If we got that far then getters and setters can be defined !!
2468 if ('get' in descriptor) {
2469 defineGetter(object, property, descriptor.get);
2471 if ('set' in descriptor) {
2472 defineSetter(object, property, descriptor.set);
2480 // http://es5.github.com/#x15.2.3.7
2481 if (!Object.defineProperties || definePropertiesFallback) {
2482 Object.defineProperties = function defineProperties(object, properties) {
2483 // make a valiant attempt to use the real defineProperties
2484 if (definePropertiesFallback) {
2486 return definePropertiesFallback.call(Object, object, properties);
2487 } catch (exception) {
2488 // try the shim if the real one doesn't work
2492 Object.keys(properties).forEach(function (property) {
2493 if (property !== '__proto__') {
2494 Object.defineProperty(object, property, properties[property]);
2502 // http://es5.github.com/#x15.2.3.8
2504 Object.seal = function seal(object) {
2505 if (Object(object) !== object) {
2506 throw new TypeError('Object.seal can only be called on Objects.');
2508 // this is misleading and breaks feature-detection, but
2509 // allows "securable" code to "gracefully" degrade to working
2510 // but insecure code.
2516 // http://es5.github.com/#x15.2.3.9
2517 if (!Object.freeze) {
2518 Object.freeze = function freeze(object) {
2519 if (Object(object) !== object) {
2520 throw new TypeError('Object.freeze can only be called on Objects.');
2522 // this is misleading and breaks feature-detection, but
2523 // allows "securable" code to "gracefully" degrade to working
2524 // but insecure code.
2529 // detect a Rhino bug and patch it
2531 Object.freeze(function () {});
2532 } catch (exception) {
2533 Object.freeze = (function (freezeObject) {
2534 return function freeze(object) {
2535 if (typeof object === 'function') {
2538 return freezeObject(object);
2545 // http://es5.github.com/#x15.2.3.10
2546 if (!Object.preventExtensions) {
2547 Object.preventExtensions = function preventExtensions(object) {
2548 if (Object(object) !== object) {
2549 throw new TypeError('Object.preventExtensions can only be called on Objects.');
2551 // this is misleading and breaks feature-detection, but
2552 // allows "securable" code to "gracefully" degrade to working
2553 // but insecure code.
2559 // http://es5.github.com/#x15.2.3.11
2560 if (!Object.isSealed) {
2561 Object.isSealed = function isSealed(object) {
2562 if (Object(object) !== object) {
2563 throw new TypeError('Object.isSealed can only be called on Objects.');
2570 // http://es5.github.com/#x15.2.3.12
2571 if (!Object.isFrozen) {
2572 Object.isFrozen = function isFrozen(object) {
2573 if (Object(object) !== object) {
2574 throw new TypeError('Object.isFrozen can only be called on Objects.');
2581 // http://es5.github.com/#x15.2.3.13
2582 if (!Object.isExtensible) {
2583 Object.isExtensible = function isExtensible(object) {
2584 // 1. If Type(O) is not Object throw a TypeError exception.
2585 if (Object(object) !== object) {
2586 throw new TypeError('Object.isExtensible can only be called on Objects.');
2588 // 2. Return the Boolean value of the [[Extensible]] internal property of O.
2590 while (owns(object, name)) {
2593 object[name] = true;
2594 var returnValue = owns(object, name);
2595 delete object[name];