UNPKG

139 kBJavaScriptView Raw
1/*!
2 * https://github.com/paulmillr/es6-shim
3 * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
4 * and contributors, MIT License
5 * es6-shim: v0.35.4
6 * see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE
7 * Details and documentation:
8 * https://github.com/paulmillr/es6-shim/
9 */
10
11// UMD (Universal Module Definition)
12// see https://github.com/umdjs/umd/blob/master/returnExports.js
13(function (root, factory) {
14 /*global define */
15 if (typeof define === 'function' && define.amd) {
16 // AMD. Register as an anonymous module.
17 define(factory);
18 } else if (typeof exports === 'object') {
19 // Node. Does not work with strict CommonJS, but
20 // only CommonJS-like environments that support module.exports,
21 // like Node.
22 module.exports = factory();
23 } else {
24 // Browser globals (root is window)
25 root.returnExports = factory();
26 }
27}(this, function () {
28 'use strict';
29
30 var _apply = Function.call.bind(Function.apply);
31 var _call = Function.call.bind(Function.call);
32 var isArray = Array.isArray;
33 var keys = Object.keys;
34
35 var not = function notThunker(func) {
36 return function notThunk() {
37 return !_apply(func, this, arguments);
38 };
39 };
40 var throwsError = function (func) {
41 try {
42 func();
43 return false;
44 } catch (e) {
45 return true;
46 }
47 };
48 var valueOrFalseIfThrows = function valueOrFalseIfThrows(func) {
49 try {
50 return func();
51 } catch (e) {
52 return false;
53 }
54 };
55
56 var isCallableWithoutNew = not(throwsError);
57 var arePropertyDescriptorsSupported = function () {
58 // if Object.defineProperty exists but throws, it's IE 8
59 return !throwsError(function () {
60 return Object.defineProperty({}, 'x', { get: function () { } }); // eslint-disable-line getter-return
61 });
62 };
63 var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
64 var functionsHaveNames = (function foo() {}).name === 'foo';
65
66 var _forEach = Function.call.bind(Array.prototype.forEach);
67 var _reduce = Function.call.bind(Array.prototype.reduce);
68 var _filter = Function.call.bind(Array.prototype.filter);
69 var _some = Function.call.bind(Array.prototype.some);
70
71 var defineProperty = function (object, name, value, force) {
72 if (!force && name in object) { return; }
73 if (supportsDescriptors) {
74 Object.defineProperty(object, name, {
75 configurable: true,
76 enumerable: false,
77 writable: true,
78 value: value
79 });
80 } else {
81 object[name] = value;
82 }
83 };
84
85 // Define configurable, writable and non-enumerable props
86 // if they don’t exist.
87 var defineProperties = function (object, map, forceOverride) {
88 _forEach(keys(map), function (name) {
89 var method = map[name];
90 defineProperty(object, name, method, !!forceOverride);
91 });
92 };
93
94 var _toString = Function.call.bind(Object.prototype.toString);
95 var isCallable = typeof /abc/ === 'function' ? function IsCallableSlow(x) {
96 // Some old browsers (IE, FF) say that typeof /abc/ === 'function'
97 return typeof x === 'function' && _toString(x) === '[object Function]';
98 } : function IsCallableFast(x) { return typeof x === 'function'; };
99
100 var Value = {
101 getter: function (object, name, getter) {
102 if (!supportsDescriptors) {
103 throw new TypeError('getters require true ES5 support');
104 }
105 Object.defineProperty(object, name, {
106 configurable: true,
107 enumerable: false,
108 get: getter
109 });
110 },
111 proxy: function (originalObject, key, targetObject) {
112 if (!supportsDescriptors) {
113 throw new TypeError('getters require true ES5 support');
114 }
115 var originalDescriptor = Object.getOwnPropertyDescriptor(originalObject, key);
116 Object.defineProperty(targetObject, key, {
117 configurable: originalDescriptor.configurable,
118 enumerable: originalDescriptor.enumerable,
119 get: function getKey() { return originalObject[key]; },
120 set: function setKey(value) { originalObject[key] = value; }
121 });
122 },
123 redefine: function (object, property, newValue) {
124 if (supportsDescriptors) {
125 var descriptor = Object.getOwnPropertyDescriptor(object, property);
126 descriptor.value = newValue;
127 Object.defineProperty(object, property, descriptor);
128 } else {
129 object[property] = newValue;
130 }
131 },
132 defineByDescriptor: function (object, property, descriptor) {
133 if (supportsDescriptors) {
134 Object.defineProperty(object, property, descriptor);
135 } else if ('value' in descriptor) {
136 object[property] = descriptor.value;
137 }
138 },
139 preserveToString: function (target, source) {
140 if (source && isCallable(source.toString)) {
141 defineProperty(target, 'toString', source.toString.bind(source), true);
142 }
143 }
144 };
145
146 // Simple shim for Object.create on ES3 browsers
147 // (unlike real shim, no attempt to support `prototype === null`)
148 var create = Object.create || function (prototype, properties) {
149 var Prototype = function Prototype() {};
150 Prototype.prototype = prototype;
151 var object = new Prototype();
152 if (typeof properties !== 'undefined') {
153 keys(properties).forEach(function (key) {
154 Value.defineByDescriptor(object, key, properties[key]);
155 });
156 }
157 return object;
158 };
159
160 var supportsSubclassing = function (C, f) {
161 if (!Object.setPrototypeOf) { return false; /* skip test on IE < 11 */ }
162 return valueOrFalseIfThrows(function () {
163 var Sub = function Subclass(arg) {
164 var o = new C(arg);
165 Object.setPrototypeOf(o, Subclass.prototype);
166 return o;
167 };
168 Object.setPrototypeOf(Sub, C);
169 Sub.prototype = create(C.prototype, {
170 constructor: { value: Sub }
171 });
172 return f(Sub);
173 });
174 };
175
176 var getGlobal = function () {
177 /* global self, window */
178 // the only reliable means to get the global object is
179 // `Function('return this')()`
180 // However, this causes CSP violations in Chrome apps.
181 if (typeof self !== 'undefined') { return self; }
182 if (typeof window !== 'undefined') { return window; }
183 if (typeof global !== 'undefined') { return global; }
184 throw new Error('unable to locate global object');
185 };
186
187 var globals = getGlobal();
188 var globalIsFinite = globals.isFinite;
189 var _indexOf = Function.call.bind(String.prototype.indexOf);
190 var _arrayIndexOfApply = Function.apply.bind(Array.prototype.indexOf);
191 var _concat = Function.call.bind(Array.prototype.concat);
192 // var _sort = Function.call.bind(Array.prototype.sort);
193 var _strSlice = Function.call.bind(String.prototype.slice);
194 var _push = Function.call.bind(Array.prototype.push);
195 var _pushApply = Function.apply.bind(Array.prototype.push);
196 var _join = Function.call.bind(Array.prototype.join);
197 var _shift = Function.call.bind(Array.prototype.shift);
198 var _max = Math.max;
199 var _min = Math.min;
200 var _floor = Math.floor;
201 var _abs = Math.abs;
202 var _exp = Math.exp;
203 var _log = Math.log;
204 var _sqrt = Math.sqrt;
205 var _hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
206 var ArrayIterator; // make our implementation private
207 var noop = function () {};
208
209 var OrigMap = globals.Map;
210 var origMapDelete = OrigMap && OrigMap.prototype['delete'];
211 var origMapGet = OrigMap && OrigMap.prototype.get;
212 var origMapHas = OrigMap && OrigMap.prototype.has;
213 var origMapSet = OrigMap && OrigMap.prototype.set;
214
215 var Symbol = globals.Symbol || {};
216 var symbolSpecies = Symbol.species || '@@species';
217
218 var numberIsNaN = Number.isNaN || function isNaN(value) {
219 // NaN !== NaN, but they are identical.
220 // NaNs are the only non-reflexive value, i.e., if x !== x,
221 // then x is NaN.
222 // isNaN is broken: it converts its argument to number, so
223 // isNaN('foo') => true
224 return value !== value;
225 };
226 var numberIsFinite = Number.isFinite || function isFinite(value) {
227 return typeof value === 'number' && globalIsFinite(value);
228 };
229 var _sign = isCallable(Math.sign) ? Math.sign : function sign(value) {
230 var number = Number(value);
231 if (number === 0) { return number; }
232 if (numberIsNaN(number)) { return number; }
233 return number < 0 ? -1 : 1;
234 };
235 var _log1p = function log1p(value) {
236 var x = Number(value);
237 if (x < -1 || numberIsNaN(x)) { return NaN; }
238 if (x === 0 || x === Infinity) { return x; }
239 if (x === -1) { return -Infinity; }
240
241 return (1 + x) - 1 === 0 ? x : x * (_log(1 + x) / ((1 + x) - 1));
242 };
243
244 // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
245 // can be replaced with require('is-arguments') if we ever use a build process instead
246 var isStandardArguments = function isArguments(value) {
247 return _toString(value) === '[object Arguments]';
248 };
249 var isLegacyArguments = function isArguments(value) {
250 return value !== null
251 && typeof value === 'object'
252 && typeof value.length === 'number'
253 && value.length >= 0
254 && _toString(value) !== '[object Array]'
255 && _toString(value.callee) === '[object Function]';
256 };
257 var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
258
259 var Type = {
260 primitive: function (x) { return x === null || (typeof x !== 'function' && typeof x !== 'object'); },
261 string: function (x) { return _toString(x) === '[object String]'; },
262 regex: function (x) { return _toString(x) === '[object RegExp]'; },
263 symbol: function (x) {
264 return typeof globals.Symbol === 'function' && typeof x === 'symbol';
265 }
266 };
267
268 var overrideNative = function overrideNative(object, property, replacement) {
269 var original = object[property];
270 defineProperty(object, property, replacement, true);
271 Value.preserveToString(object[property], original);
272 };
273
274 // eslint-disable-next-line no-restricted-properties
275 var hasSymbols = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' && Type.symbol(Symbol());
276
277 // This is a private name in the es6 spec, equal to '[Symbol.iterator]'
278 // we're going to use an arbitrary _-prefixed name to make our shims
279 // work properly with each other, even though we don't have full Iterator
280 // support. That is, `Array.from(map.keys())` will work, but we don't
281 // pretend to export a "real" Iterator interface.
282 var $iterator$ = Type.symbol(Symbol.iterator) ? Symbol.iterator : '_es6-shim iterator_';
283 // Firefox ships a partial implementation using the name @@iterator.
284 // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
285 // So use that name if we detect it.
286 if (globals.Set && typeof new globals.Set()['@@iterator'] === 'function') {
287 $iterator$ = '@@iterator';
288 }
289
290 // Reflect
291 if (!globals.Reflect) {
292 defineProperty(globals, 'Reflect', {}, true);
293 }
294 var Reflect = globals.Reflect;
295
296 var $String = String;
297
298 /* global document */
299 var domAll = (typeof document === 'undefined' || !document) ? null : document.all;
300 var isNullOrUndefined = domAll == null ? function isNullOrUndefined(x) {
301 return x == null;
302 } : function isNullOrUndefinedAndNotDocumentAll(x) {
303 return x == null && x !== domAll;
304 };
305
306 var ES = {
307 // http://www.ecma-international.org/ecma-262/6.0/#sec-call
308 Call: function Call(F, V) {
309 var args = arguments.length > 2 ? arguments[2] : [];
310 if (!ES.IsCallable(F)) {
311 throw new TypeError(F + ' is not a function');
312 }
313 return _apply(F, V, args);
314 },
315
316 RequireObjectCoercible: function (x, optMessage) {
317 if (isNullOrUndefined(x)) {
318 throw new TypeError(optMessage || 'Cannot call method on ' + x);
319 }
320 return x;
321 },
322
323 // This might miss the "(non-standard exotic and does not implement
324 // [[Call]])" case from
325 // http://www.ecma-international.org/ecma-262/6.0/#sec-typeof-operator-runtime-semantics-evaluation
326 // but we can't find any evidence these objects exist in practice.
327 // If we find some in the future, you could test `Object(x) === x`,
328 // which is reliable according to
329 // http://www.ecma-international.org/ecma-262/6.0/#sec-toobject
330 // but is not well optimized by runtimes and creates an object
331 // whenever it returns false, and thus is very slow.
332 TypeIsObject: function (x) {
333 if (x === void 0 || x === null || x === true || x === false) {
334 return false;
335 }
336 return typeof x === 'function' || typeof x === 'object' || x === domAll;
337 },
338
339 ToObject: function (o, optMessage) {
340 return Object(ES.RequireObjectCoercible(o, optMessage));
341 },
342
343 IsCallable: isCallable,
344
345 IsConstructor: function (x) {
346 // We can't tell callables from constructors in ES5
347 return ES.IsCallable(x);
348 },
349
350 ToInt32: function (x) {
351 return ES.ToNumber(x) >> 0;
352 },
353
354 ToUint32: function (x) {
355 return ES.ToNumber(x) >>> 0;
356 },
357
358 ToNumber: function (value) {
359 if (hasSymbols && _toString(value) === '[object Symbol]') {
360 throw new TypeError('Cannot convert a Symbol value to a number');
361 }
362 return +value;
363 },
364
365 ToInteger: function (value) {
366 var number = ES.ToNumber(value);
367 if (numberIsNaN(number)) { return 0; }
368 if (number === 0 || !numberIsFinite(number)) { return number; }
369 return (number > 0 ? 1 : -1) * _floor(_abs(number));
370 },
371
372 ToLength: function (value) {
373 var len = ES.ToInteger(value);
374 if (len <= 0) { return 0; } // includes converting -0 to +0
375 if (len > Number.MAX_SAFE_INTEGER) { return Number.MAX_SAFE_INTEGER; }
376 return len;
377 },
378
379 SameValue: function (a, b) {
380 if (a === b) {
381 // 0 === -0, but they are not identical.
382 if (a === 0) { return 1 / a === 1 / b; }
383 return true;
384 }
385 return numberIsNaN(a) && numberIsNaN(b);
386 },
387
388 SameValueZero: function (a, b) {
389 // same as SameValue except for SameValueZero(+0, -0) == true
390 return (a === b) || (numberIsNaN(a) && numberIsNaN(b));
391 },
392
393 GetIterator: function (o) {
394 if (isArguments(o)) {
395 // special case support for `arguments`
396 return new ArrayIterator(o, 'value');
397 }
398 var itFn = ES.GetMethod(o, $iterator$);
399 if (!ES.IsCallable(itFn)) {
400 // Better diagnostics if itFn is null or undefined
401 throw new TypeError('value is not an iterable');
402 }
403 var it = ES.Call(itFn, o);
404 if (!ES.TypeIsObject(it)) {
405 throw new TypeError('bad iterator');
406 }
407 return it;
408 },
409
410 GetMethod: function (o, p) {
411 var func = ES.ToObject(o)[p];
412 if (isNullOrUndefined(func)) {
413 return void 0;
414 }
415 if (!ES.IsCallable(func)) {
416 throw new TypeError('Method not callable: ' + p);
417 }
418 return func;
419 },
420
421 IteratorComplete: function (iterResult) {
422 return !!iterResult.done;
423 },
424
425 IteratorClose: function (iterator, completionIsThrow) {
426 var returnMethod = ES.GetMethod(iterator, 'return');
427 if (returnMethod === void 0) {
428 return;
429 }
430 var innerResult, innerException;
431 try {
432 innerResult = ES.Call(returnMethod, iterator);
433 } catch (e) {
434 innerException = e;
435 }
436 if (completionIsThrow) {
437 return;
438 }
439 if (innerException) {
440 throw innerException;
441 }
442 if (!ES.TypeIsObject(innerResult)) {
443 throw new TypeError("Iterator's return method returned a non-object.");
444 }
445 },
446
447 IteratorNext: function (it) {
448 var result = arguments.length > 1 ? it.next(arguments[1]) : it.next();
449 if (!ES.TypeIsObject(result)) {
450 throw new TypeError('bad iterator');
451 }
452 return result;
453 },
454
455 IteratorStep: function (it) {
456 var result = ES.IteratorNext(it);
457 var done = ES.IteratorComplete(result);
458 return done ? false : result;
459 },
460
461 Construct: function (C, args, newTarget, isES6internal) {
462 var target = typeof newTarget === 'undefined' ? C : newTarget;
463
464 if (!isES6internal && Reflect.construct) {
465 // Try to use Reflect.construct if available
466 return Reflect.construct(C, args, target);
467 }
468 // OK, we have to fake it. This will only work if the
469 // C.[[ConstructorKind]] == "base" -- but that's the only
470 // kind we can make in ES5 code anyway.
471
472 // OrdinaryCreateFromConstructor(target, "%ObjectPrototype%")
473 var proto = target.prototype;
474 if (!ES.TypeIsObject(proto)) {
475 proto = Object.prototype;
476 }
477 var obj = create(proto);
478 // Call the constructor.
479 var result = ES.Call(C, obj, args);
480 return ES.TypeIsObject(result) ? result : obj;
481 },
482
483 SpeciesConstructor: function (O, defaultConstructor) {
484 var C = O.constructor;
485 if (C === void 0) {
486 return defaultConstructor;
487 }
488 if (!ES.TypeIsObject(C)) {
489 throw new TypeError('Bad constructor');
490 }
491 var S = C[symbolSpecies];
492 if (isNullOrUndefined(S)) {
493 return defaultConstructor;
494 }
495 if (!ES.IsConstructor(S)) {
496 throw new TypeError('Bad @@species');
497 }
498 return S;
499 },
500
501 CreateHTML: function (string, tag, attribute, value) {
502 var S = ES.ToString(string);
503 var p1 = '<' + tag;
504 if (attribute !== '') {
505 var V = ES.ToString(value);
506 var escapedV = V.replace(/"/g, '&quot;');
507 p1 += ' ' + attribute + '="' + escapedV + '"';
508 }
509 var p2 = p1 + '>';
510 var p3 = p2 + S;
511 return p3 + '</' + tag + '>';
512 },
513
514 IsRegExp: function IsRegExp(argument) {
515 if (!ES.TypeIsObject(argument)) {
516 return false;
517 }
518 var isRegExp = argument[Symbol.match];
519 if (typeof isRegExp !== 'undefined') {
520 return !!isRegExp;
521 }
522 return Type.regex(argument);
523 },
524
525 ToString: function ToString(string) {
526 if (hasSymbols && _toString(string) === '[object Symbol]') {
527 throw new TypeError('Cannot convert a Symbol value to a number');
528 }
529 return $String(string);
530 }
531 };
532
533 // Well-known Symbol shims
534 if (supportsDescriptors && hasSymbols) {
535 var defineWellKnownSymbol = function defineWellKnownSymbol(name) {
536 if (Type.symbol(Symbol[name])) {
537 return Symbol[name];
538 }
539 // eslint-disable-next-line no-restricted-properties
540 var sym = Symbol['for']('Symbol.' + name);
541 Object.defineProperty(Symbol, name, {
542 configurable: false,
543 enumerable: false,
544 writable: false,
545 value: sym
546 });
547 return sym;
548 };
549 if (!Type.symbol(Symbol.search)) {
550 var symbolSearch = defineWellKnownSymbol('search');
551 var originalSearch = String.prototype.search;
552 defineProperty(RegExp.prototype, symbolSearch, function search(string) {
553 return ES.Call(originalSearch, string, [this]);
554 });
555 var searchShim = function search(regexp) {
556 var O = ES.RequireObjectCoercible(this);
557 if (!isNullOrUndefined(regexp)) {
558 var searcher = ES.GetMethod(regexp, symbolSearch);
559 if (typeof searcher !== 'undefined') {
560 return ES.Call(searcher, regexp, [O]);
561 }
562 }
563 return ES.Call(originalSearch, O, [ES.ToString(regexp)]);
564 };
565 overrideNative(String.prototype, 'search', searchShim);
566 }
567 if (!Type.symbol(Symbol.replace)) {
568 var symbolReplace = defineWellKnownSymbol('replace');
569 var originalReplace = String.prototype.replace;
570 defineProperty(RegExp.prototype, symbolReplace, function replace(string, replaceValue) {
571 return ES.Call(originalReplace, string, [this, replaceValue]);
572 });
573 var replaceShim = function replace(searchValue, replaceValue) {
574 var O = ES.RequireObjectCoercible(this);
575 if (!isNullOrUndefined(searchValue)) {
576 var replacer = ES.GetMethod(searchValue, symbolReplace);
577 if (typeof replacer !== 'undefined') {
578 return ES.Call(replacer, searchValue, [O, replaceValue]);
579 }
580 }
581 return ES.Call(originalReplace, O, [ES.ToString(searchValue), replaceValue]);
582 };
583 overrideNative(String.prototype, 'replace', replaceShim);
584 }
585 if (!Type.symbol(Symbol.split)) {
586 var symbolSplit = defineWellKnownSymbol('split');
587 var originalSplit = String.prototype.split;
588 defineProperty(RegExp.prototype, symbolSplit, function split(string, limit) {
589 return ES.Call(originalSplit, string, [this, limit]);
590 });
591 var splitShim = function split(separator, limit) {
592 var O = ES.RequireObjectCoercible(this);
593 if (!isNullOrUndefined(separator)) {
594 var splitter = ES.GetMethod(separator, symbolSplit);
595 if (typeof splitter !== 'undefined') {
596 return ES.Call(splitter, separator, [O, limit]);
597 }
598 }
599 return ES.Call(originalSplit, O, [ES.ToString(separator), limit]);
600 };
601 overrideNative(String.prototype, 'split', splitShim);
602 }
603 var symbolMatchExists = Type.symbol(Symbol.match);
604 var stringMatchIgnoresSymbolMatch = symbolMatchExists && (function () {
605 // Firefox 41, through Nightly 45 has Symbol.match, but String#match ignores it.
606 // Firefox 40 and below have Symbol.match but String#match works fine.
607 var o = {};
608 o[Symbol.match] = function () { return 42; };
609 return 'a'.match(o) !== 42;
610 }());
611 if (!symbolMatchExists || stringMatchIgnoresSymbolMatch) {
612 var symbolMatch = defineWellKnownSymbol('match');
613
614 var originalMatch = String.prototype.match;
615 defineProperty(RegExp.prototype, symbolMatch, function match(string) {
616 return ES.Call(originalMatch, string, [this]);
617 });
618
619 var matchShim = function match(regexp) {
620 var O = ES.RequireObjectCoercible(this);
621 if (!isNullOrUndefined(regexp)) {
622 var matcher = ES.GetMethod(regexp, symbolMatch);
623 if (typeof matcher !== 'undefined') {
624 return ES.Call(matcher, regexp, [O]);
625 }
626 }
627 return ES.Call(originalMatch, O, [ES.ToString(regexp)]);
628 };
629 overrideNative(String.prototype, 'match', matchShim);
630 }
631 }
632
633 var wrapConstructor = function wrapConstructor(original, replacement, keysToSkip) {
634 Value.preserveToString(replacement, original);
635 if (Object.setPrototypeOf) {
636 // sets up proper prototype chain where possible
637 Object.setPrototypeOf(original, replacement);
638 }
639 if (supportsDescriptors) {
640 _forEach(Object.getOwnPropertyNames(original), function (key) {
641 if (key in noop || keysToSkip[key]) { return; }
642 Value.proxy(original, key, replacement);
643 });
644 } else {
645 _forEach(Object.keys(original), function (key) {
646 if (key in noop || keysToSkip[key]) { return; }
647 replacement[key] = original[key];
648 });
649 }
650 replacement.prototype = original.prototype;
651 Value.redefine(original.prototype, 'constructor', replacement);
652 };
653
654 var defaultSpeciesGetter = function () { return this; };
655 var addDefaultSpecies = function (C) {
656 if (supportsDescriptors && !_hasOwnProperty(C, symbolSpecies)) {
657 Value.getter(C, symbolSpecies, defaultSpeciesGetter);
658 }
659 };
660
661 var addIterator = function (prototype, impl) {
662 var implementation = impl || function iterator() { return this; };
663 defineProperty(prototype, $iterator$, implementation);
664 if (!prototype[$iterator$] && Type.symbol($iterator$)) {
665 // implementations are buggy when $iterator$ is a Symbol
666 prototype[$iterator$] = implementation;
667 }
668 };
669
670 var createDataProperty = function createDataProperty(object, name, value) {
671 if (supportsDescriptors) {
672 Object.defineProperty(object, name, {
673 configurable: true,
674 enumerable: true,
675 writable: true,
676 value: value
677 });
678 } else {
679 object[name] = value;
680 }
681 };
682 var createDataPropertyOrThrow = function createDataPropertyOrThrow(object, name, value) {
683 createDataProperty(object, name, value);
684 if (!ES.SameValue(object[name], value)) {
685 throw new TypeError('property is nonconfigurable');
686 }
687 };
688
689 var emulateES6construct = function (o, defaultNewTarget, defaultProto, slots) {
690 // This is an es5 approximation to es6 construct semantics. in es6,
691 // 'new Foo' invokes Foo.[[Construct]] which (for almost all objects)
692 // just sets the internal variable NewTarget (in es6 syntax `new.target`)
693 // to Foo and then returns Foo().
694
695 // Many ES6 object then have constructors of the form:
696 // 1. If NewTarget is undefined, throw a TypeError exception
697 // 2. Let xxx by OrdinaryCreateFromConstructor(NewTarget, yyy, zzz)
698
699 // So we're going to emulate those first two steps.
700 if (!ES.TypeIsObject(o)) {
701 throw new TypeError('Constructor requires `new`: ' + defaultNewTarget.name);
702 }
703 var proto = defaultNewTarget.prototype;
704 if (!ES.TypeIsObject(proto)) {
705 proto = defaultProto;
706 }
707 var obj = create(proto);
708 for (var name in slots) {
709 if (_hasOwnProperty(slots, name)) {
710 var value = slots[name];
711 defineProperty(obj, name, value, true);
712 }
713 }
714 return obj;
715 };
716
717 // Firefox 31 reports this function's length as 0
718 // https://bugzilla.mozilla.org/show_bug.cgi?id=1062484
719 if (String.fromCodePoint && String.fromCodePoint.length !== 1) {
720 var originalFromCodePoint = String.fromCodePoint;
721 overrideNative(String, 'fromCodePoint', function fromCodePoint(codePoints) {
722 return ES.Call(originalFromCodePoint, this, arguments);
723 });
724 }
725
726 var StringShims = {
727 fromCodePoint: function fromCodePoint(codePoints) {
728 var result = [];
729 var next;
730 for (var i = 0, length = arguments.length; i < length; i++) {
731 next = Number(arguments[i]);
732 if (!ES.SameValue(next, ES.ToInteger(next)) || next < 0 || next > 0x10FFFF) {
733 throw new RangeError('Invalid code point ' + next);
734 }
735
736 if (next < 0x10000) {
737 _push(result, String.fromCharCode(next));
738 } else {
739 next -= 0x10000;
740 _push(result, String.fromCharCode((next >> 10) + 0xD800));
741 _push(result, String.fromCharCode((next % 0x400) + 0xDC00));
742 }
743 }
744 return _join(result, '');
745 },
746
747 raw: function raw(template) {
748 var numberOfSubstitutions = arguments.length - 1;
749 var cooked = ES.ToObject(template, 'bad template');
750 var raw = ES.ToObject(cooked.raw, 'bad raw value');
751 var len = raw.length;
752 var literalSegments = ES.ToLength(len);
753 if (literalSegments <= 0) {
754 return '';
755 }
756
757 var stringElements = [];
758 var nextIndex = 0;
759 var nextKey, next, nextSeg, nextSub;
760 while (nextIndex < literalSegments) {
761 nextKey = ES.ToString(nextIndex);
762 nextSeg = ES.ToString(raw[nextKey]);
763 _push(stringElements, nextSeg);
764 if (nextIndex + 1 >= literalSegments) {
765 break;
766 }
767 next = nextIndex + 1 < arguments.length ? arguments[nextIndex + 1] : '';
768 nextSub = ES.ToString(next);
769 _push(stringElements, nextSub);
770 nextIndex += 1;
771 }
772 return _join(stringElements, '');
773 }
774 };
775 if (String.raw && String.raw({ raw: { 0: 'x', 1: 'y', length: 2 } }) !== 'xy') {
776 // IE 11 TP has a broken String.raw implementation
777 overrideNative(String, 'raw', StringShims.raw);
778 }
779 defineProperties(String, StringShims);
780
781 // Fast repeat, uses the `Exponentiation by squaring` algorithm.
782 // Perf: http://jsperf.com/string-repeat2/2
783 var stringRepeat = function repeat(s, times) {
784 if (times < 1) { return ''; }
785 if (times % 2) { return repeat(s, times - 1) + s; }
786 var half = repeat(s, times / 2);
787 return half + half;
788 };
789 var stringMaxLength = Infinity;
790
791 var StringPrototypeShims = {
792 repeat: function repeat(times) {
793 var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
794 var numTimes = ES.ToInteger(times);
795 if (numTimes < 0 || numTimes >= stringMaxLength) {
796 throw new RangeError('repeat count must be less than infinity and not overflow maximum string size');
797 }
798 return stringRepeat(thisStr, numTimes);
799 },
800
801 startsWith: function startsWith(searchString) {
802 var S = ES.ToString(ES.RequireObjectCoercible(this));
803 if (ES.IsRegExp(searchString)) {
804 throw new TypeError('Cannot call method "startsWith" with a regex');
805 }
806 var searchStr = ES.ToString(searchString);
807 var position;
808 if (arguments.length > 1) {
809 position = arguments[1];
810 }
811 var start = _max(ES.ToInteger(position), 0);
812 return _strSlice(S, start, start + searchStr.length) === searchStr;
813 },
814
815 endsWith: function endsWith(searchString) {
816 var S = ES.ToString(ES.RequireObjectCoercible(this));
817 if (ES.IsRegExp(searchString)) {
818 throw new TypeError('Cannot call method "endsWith" with a regex');
819 }
820 var searchStr = ES.ToString(searchString);
821 var len = S.length;
822 var endPosition;
823 if (arguments.length > 1) {
824 endPosition = arguments[1];
825 }
826 var pos = typeof endPosition === 'undefined' ? len : ES.ToInteger(endPosition);
827 var end = _min(_max(pos, 0), len);
828 return _strSlice(S, end - searchStr.length, end) === searchStr;
829 },
830
831 includes: function includes(searchString) {
832 if (ES.IsRegExp(searchString)) {
833 throw new TypeError('"includes" does not accept a RegExp');
834 }
835 var searchStr = ES.ToString(searchString);
836 var position;
837 if (arguments.length > 1) {
838 position = arguments[1];
839 }
840 // Somehow this trick makes method 100% compat with the spec.
841 return _indexOf(this, searchStr, position) !== -1;
842 },
843
844 codePointAt: function codePointAt(pos) {
845 var thisStr = ES.ToString(ES.RequireObjectCoercible(this));
846 var position = ES.ToInteger(pos);
847 var length = thisStr.length;
848 if (position >= 0 && position < length) {
849 var first = thisStr.charCodeAt(position);
850 var isEnd = position + 1 === length;
851 if (first < 0xD800 || first > 0xDBFF || isEnd) { return first; }
852 var second = thisStr.charCodeAt(position + 1);
853 if (second < 0xDC00 || second > 0xDFFF) { return first; }
854 return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000;
855 }
856 }
857 };
858 if (String.prototype.includes && 'a'.includes('a', Infinity) !== false) {
859 overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
860 }
861
862 if (String.prototype.startsWith && String.prototype.endsWith) {
863 var startsWithRejectsRegex = throwsError(function () {
864 /* throws if spec-compliant */
865 return '/a/'.startsWith(/a/);
866 });
867 var startsWithHandlesInfinity = valueOrFalseIfThrows(function () {
868 return 'abc'.startsWith('a', Infinity) === false;
869 });
870 if (!startsWithRejectsRegex || !startsWithHandlesInfinity) {
871 // Firefox (< 37?) and IE 11 TP have a noncompliant startsWith implementation
872 overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
873 overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
874 }
875 }
876 if (hasSymbols) {
877 var startsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
878 var re = /a/;
879 re[Symbol.match] = false;
880 return '/a/'.startsWith(re);
881 });
882 if (!startsWithSupportsSymbolMatch) {
883 overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
884 }
885 var endsWithSupportsSymbolMatch = valueOrFalseIfThrows(function () {
886 var re = /a/;
887 re[Symbol.match] = false;
888 return '/a/'.endsWith(re);
889 });
890 if (!endsWithSupportsSymbolMatch) {
891 overrideNative(String.prototype, 'endsWith', StringPrototypeShims.endsWith);
892 }
893 var includesSupportsSymbolMatch = valueOrFalseIfThrows(function () {
894 var re = /a/;
895 re[Symbol.match] = false;
896 return '/a/'.includes(re);
897 });
898 if (!includesSupportsSymbolMatch) {
899 overrideNative(String.prototype, 'includes', StringPrototypeShims.includes);
900 }
901 }
902
903 defineProperties(String.prototype, StringPrototypeShims);
904
905 // whitespace from: http://es5.github.io/#x15.5.4.20
906 // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324
907 var ws = [
908 '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
909 '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
910 '\u2029\uFEFF'
911 ].join('');
912 var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
913 var trimShim = function trim() {
914 return ES.ToString(ES.RequireObjectCoercible(this)).replace(trimRegexp, '');
915 };
916 var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
917 var nonWSregex = new RegExp('[' + nonWS + ']', 'g');
918 var isBadHexRegex = /^[-+]0x[0-9a-f]+$/i;
919 var hasStringTrimBug = nonWS.trim().length !== nonWS.length;
920 defineProperty(String.prototype, 'trim', trimShim, hasStringTrimBug);
921
922 // Given an argument x, it will return an IteratorResult object,
923 // with value set to x and done to false.
924 // Given no arguments, it will return an iterator completion object.
925 var iteratorResult = function (x) {
926 return { value: x, done: arguments.length === 0 };
927 };
928
929 // see http://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype-@@iterator
930 var StringIterator = function (s) {
931 ES.RequireObjectCoercible(s);
932 defineProperty(this, '_s', ES.ToString(s));
933 defineProperty(this, '_i', 0);
934 };
935 StringIterator.prototype.next = function () {
936 var s = this._s;
937 var i = this._i;
938 if (typeof s === 'undefined' || i >= s.length) {
939 this._s = void 0;
940 return iteratorResult();
941 }
942 var first = s.charCodeAt(i);
943 var second, len;
944 if (first < 0xD800 || first > 0xDBFF || (i + 1) === s.length) {
945 len = 1;
946 } else {
947 second = s.charCodeAt(i + 1);
948 len = (second < 0xDC00 || second > 0xDFFF) ? 1 : 2;
949 }
950 this._i = i + len;
951 return iteratorResult(s.substr(i, len));
952 };
953 addIterator(StringIterator.prototype);
954 addIterator(String.prototype, function () {
955 return new StringIterator(this);
956 });
957
958 var ArrayShims = {
959 from: function from(items) {
960 var C = this;
961 var mapFn;
962 if (arguments.length > 1) {
963 mapFn = arguments[1];
964 }
965 var mapping, T;
966 if (typeof mapFn === 'undefined') {
967 mapping = false;
968 } else {
969 if (!ES.IsCallable(mapFn)) {
970 throw new TypeError('Array.from: when provided, the second argument must be a function');
971 }
972 if (arguments.length > 2) {
973 T = arguments[2];
974 }
975 mapping = true;
976 }
977
978 // Note that that Arrays will use ArrayIterator:
979 // https://bugs.ecmascript.org/show_bug.cgi?id=2416
980 var usingIterator = typeof (isArguments(items) || ES.GetMethod(items, $iterator$)) !== 'undefined';
981
982 var length, result, i;
983 if (usingIterator) {
984 result = ES.IsConstructor(C) ? Object(new C()) : [];
985 var iterator = ES.GetIterator(items);
986 var next, nextValue;
987
988 i = 0;
989 while (true) {
990 next = ES.IteratorStep(iterator);
991 if (next === false) {
992 break;
993 }
994 nextValue = next.value;
995 try {
996 if (mapping) {
997 nextValue = typeof T === 'undefined' ? mapFn(nextValue, i) : _call(mapFn, T, nextValue, i);
998 }
999 result[i] = nextValue;
1000 } catch (e) {
1001 ES.IteratorClose(iterator, true);
1002 throw e;
1003 }
1004 i += 1;
1005 }
1006 length = i;
1007 } else {
1008 var arrayLike = ES.ToObject(items);
1009 length = ES.ToLength(arrayLike.length);
1010 result = ES.IsConstructor(C) ? Object(new C(length)) : new Array(length);
1011 var value;
1012 for (i = 0; i < length; ++i) {
1013 value = arrayLike[i];
1014 if (mapping) {
1015 value = typeof T === 'undefined' ? mapFn(value, i) : _call(mapFn, T, value, i);
1016 }
1017 createDataPropertyOrThrow(result, i, value);
1018 }
1019 }
1020
1021 result.length = length;
1022 return result;
1023 },
1024
1025 of: function of() {
1026 var len = arguments.length;
1027 var C = this;
1028 var A = isArray(C) || !ES.IsCallable(C) ? new Array(len) : ES.Construct(C, [len]);
1029 for (var k = 0; k < len; ++k) {
1030 createDataPropertyOrThrow(A, k, arguments[k]);
1031 }
1032 A.length = len;
1033 return A;
1034 }
1035 };
1036 defineProperties(Array, ArrayShims);
1037 addDefaultSpecies(Array);
1038
1039 // Our ArrayIterator is private; see
1040 // https://github.com/paulmillr/es6-shim/issues/252
1041 ArrayIterator = function (array, kind) {
1042 defineProperty(this, 'i', 0);
1043 defineProperty(this, 'array', array);
1044 defineProperty(this, 'kind', kind);
1045 };
1046
1047 defineProperties(ArrayIterator.prototype, {
1048 next: function () {
1049 var i = this.i;
1050 var array = this.array;
1051 if (!(this instanceof ArrayIterator)) {
1052 throw new TypeError('Not an ArrayIterator');
1053 }
1054 if (typeof array !== 'undefined') {
1055 var len = ES.ToLength(array.length);
1056 if (i < len) {
1057 //for (; i < len; i++) {
1058 var kind = this.kind;
1059 var retval;
1060 if (kind === 'key') {
1061 retval = i;
1062 } else if (kind === 'value') {
1063 retval = array[i];
1064 } else if (kind === 'entry') {
1065 retval = [i, array[i]];
1066 }
1067 this.i = i + 1;
1068 return iteratorResult(retval);
1069 }
1070 }
1071 this.array = void 0;
1072 return iteratorResult();
1073 }
1074 });
1075 addIterator(ArrayIterator.prototype);
1076
1077 /*
1078 var orderKeys = function orderKeys(a, b) {
1079 var aNumeric = String(ES.ToInteger(a)) === a;
1080 var bNumeric = String(ES.ToInteger(b)) === b;
1081 if (aNumeric && bNumeric) {
1082 return b - a;
1083 } else if (aNumeric && !bNumeric) {
1084 return -1;
1085 } else if (!aNumeric && bNumeric) {
1086 return 1;
1087 } else {
1088 return a.localeCompare(b);
1089 }
1090 };
1091
1092 var getAllKeys = function getAllKeys(object) {
1093 var ownKeys = [];
1094 var keys = [];
1095
1096 for (var key in object) {
1097 _push(_hasOwnProperty(object, key) ? ownKeys : keys, key);
1098 }
1099 _sort(ownKeys, orderKeys);
1100 _sort(keys, orderKeys);
1101
1102 return _concat(ownKeys, keys);
1103 };
1104 */
1105
1106 // note: this is positioned here because it depends on ArrayIterator
1107 var arrayOfSupportsSubclassing = Array.of === ArrayShims.of || (function () {
1108 // Detects a bug in Webkit nightly r181886
1109 var Foo = function Foo(len) { this.length = len; };
1110 Foo.prototype = [];
1111 var fooArr = Array.of.apply(Foo, [1, 2]);
1112 return fooArr instanceof Foo && fooArr.length === 2;
1113 }());
1114 if (!arrayOfSupportsSubclassing) {
1115 overrideNative(Array, 'of', ArrayShims.of);
1116 }
1117
1118 var ArrayPrototypeShims = {
1119 copyWithin: function copyWithin(target, start) {
1120 var o = ES.ToObject(this);
1121 var len = ES.ToLength(o.length);
1122 var relativeTarget = ES.ToInteger(target);
1123 var relativeStart = ES.ToInteger(start);
1124 var to = relativeTarget < 0 ? _max(len + relativeTarget, 0) : _min(relativeTarget, len);
1125 var from = relativeStart < 0 ? _max(len + relativeStart, 0) : _min(relativeStart, len);
1126 var end;
1127 if (arguments.length > 2) {
1128 end = arguments[2];
1129 }
1130 var relativeEnd = typeof end === 'undefined' ? len : ES.ToInteger(end);
1131 var finalItem = relativeEnd < 0 ? _max(len + relativeEnd, 0) : _min(relativeEnd, len);
1132 var count = _min(finalItem - from, len - to);
1133 var direction = 1;
1134 if (from < to && to < (from + count)) {
1135 direction = -1;
1136 from += count - 1;
1137 to += count - 1;
1138 }
1139 while (count > 0) {
1140 if (from in o) {
1141 o[to] = o[from];
1142 } else {
1143 delete o[to];
1144 }
1145 from += direction;
1146 to += direction;
1147 count -= 1;
1148 }
1149 return o;
1150 },
1151
1152 fill: function fill(value) {
1153 var start;
1154 if (arguments.length > 1) {
1155 start = arguments[1];
1156 }
1157 var end;
1158 if (arguments.length > 2) {
1159 end = arguments[2];
1160 }
1161 var O = ES.ToObject(this);
1162 var len = ES.ToLength(O.length);
1163 start = ES.ToInteger(typeof start === 'undefined' ? 0 : start);
1164 end = ES.ToInteger(typeof end === 'undefined' ? len : end);
1165
1166 var relativeStart = start < 0 ? _max(len + start, 0) : _min(start, len);
1167 var relativeEnd = end < 0 ? len + end : end;
1168
1169 for (var i = relativeStart; i < len && i < relativeEnd; ++i) {
1170 O[i] = value;
1171 }
1172 return O;
1173 },
1174
1175 find: function find(predicate) {
1176 var list = ES.ToObject(this);
1177 var length = ES.ToLength(list.length);
1178 if (!ES.IsCallable(predicate)) {
1179 throw new TypeError('Array#find: predicate must be a function');
1180 }
1181 var thisArg = arguments.length > 1 ? arguments[1] : null;
1182 for (var i = 0, value; i < length; i++) {
1183 value = list[i];
1184 if (thisArg) {
1185 if (_call(predicate, thisArg, value, i, list)) {
1186 return value;
1187 }
1188 } else if (predicate(value, i, list)) {
1189 return value;
1190 }
1191 }
1192 },
1193
1194 findIndex: function findIndex(predicate) {
1195 var list = ES.ToObject(this);
1196 var length = ES.ToLength(list.length);
1197 if (!ES.IsCallable(predicate)) {
1198 throw new TypeError('Array#findIndex: predicate must be a function');
1199 }
1200 var thisArg = arguments.length > 1 ? arguments[1] : null;
1201 for (var i = 0; i < length; i++) {
1202 if (thisArg) {
1203 if (_call(predicate, thisArg, list[i], i, list)) {
1204 return i;
1205 }
1206 } else if (predicate(list[i], i, list)) {
1207 return i;
1208 }
1209 }
1210 return -1;
1211 },
1212
1213 keys: function keys() {
1214 return new ArrayIterator(this, 'key');
1215 },
1216
1217 values: function values() {
1218 return new ArrayIterator(this, 'value');
1219 },
1220
1221 entries: function entries() {
1222 return new ArrayIterator(this, 'entry');
1223 }
1224 };
1225 // Safari 7.1 defines Array#keys and Array#entries natively,
1226 // but the resulting ArrayIterator objects don't have a "next" method.
1227 if (Array.prototype.keys && !ES.IsCallable([1].keys().next)) {
1228 delete Array.prototype.keys;
1229 }
1230 if (Array.prototype.entries && !ES.IsCallable([1].entries().next)) {
1231 delete Array.prototype.entries;
1232 }
1233
1234 // Chrome 38 defines Array#keys and Array#entries, and Array#@@iterator, but not Array#values
1235 if (Array.prototype.keys && Array.prototype.entries && !Array.prototype.values && Array.prototype[$iterator$]) {
1236 defineProperties(Array.prototype, {
1237 values: Array.prototype[$iterator$]
1238 });
1239 if (Type.symbol(Symbol.unscopables)) {
1240 Array.prototype[Symbol.unscopables].values = true;
1241 }
1242 }
1243 // Chrome 40 defines Array#values with the incorrect name, although Array#{keys,entries} have the correct name
1244 if (functionsHaveNames && Array.prototype.values && Array.prototype.values.name !== 'values') {
1245 var originalArrayPrototypeValues = Array.prototype.values;
1246 overrideNative(Array.prototype, 'values', function values() { return ES.Call(originalArrayPrototypeValues, this, arguments); });
1247 defineProperty(Array.prototype, $iterator$, Array.prototype.values, true);
1248 }
1249 defineProperties(Array.prototype, ArrayPrototypeShims);
1250
1251 if (1 / [true].indexOf(true, -0) < 0) {
1252 // indexOf when given a position arg of -0 should return +0.
1253 // https://github.com/tc39/ecma262/pull/316
1254 defineProperty(Array.prototype, 'indexOf', function indexOf(searchElement) {
1255 var value = _arrayIndexOfApply(this, arguments);
1256 if (value === 0 && (1 / value) < 0) {
1257 return 0;
1258 }
1259 return value;
1260 }, true);
1261 }
1262
1263 addIterator(Array.prototype, function () { return this.values(); });
1264 // Chrome defines keys/values/entries on Array, but doesn't give us
1265 // any way to identify its iterator. So add our own shimmed field.
1266 if (Object.getPrototypeOf) {
1267 var ChromeArrayIterator = Object.getPrototypeOf([].values());
1268 if (ChromeArrayIterator) { // in WSH, this is `undefined`
1269 addIterator(ChromeArrayIterator);
1270 }
1271 }
1272
1273 // note: this is positioned here because it relies on Array#entries
1274 var arrayFromSwallowsNegativeLengths = (function () {
1275 // Detects a Firefox bug in v32
1276 // https://bugzilla.mozilla.org/show_bug.cgi?id=1063993
1277 return valueOrFalseIfThrows(function () {
1278 return Array.from({ length: -1 }).length === 0;
1279 });
1280 }());
1281 var arrayFromHandlesIterables = (function () {
1282 // Detects a bug in Webkit nightly r181886
1283 var arr = Array.from([0].entries());
1284 return arr.length === 1 && isArray(arr[0]) && arr[0][0] === 0 && arr[0][1] === 0;
1285 }());
1286 if (!arrayFromSwallowsNegativeLengths || !arrayFromHandlesIterables) {
1287 overrideNative(Array, 'from', ArrayShims.from);
1288 }
1289 var arrayFromHandlesUndefinedMapFunction = (function () {
1290 // Microsoft Edge v0.11 throws if the mapFn argument is *provided* but undefined,
1291 // but the spec doesn't care if it's provided or not - undefined doesn't throw.
1292 return valueOrFalseIfThrows(function () {
1293 return Array.from([0], void 0);
1294 });
1295 }());
1296 if (!arrayFromHandlesUndefinedMapFunction) {
1297 var origArrayFrom = Array.from;
1298 overrideNative(Array, 'from', function from(items) {
1299 if (arguments.length > 1 && typeof arguments[1] !== 'undefined') {
1300 return ES.Call(origArrayFrom, this, arguments);
1301 }
1302 return _call(origArrayFrom, this, items);
1303
1304 });
1305 }
1306
1307 var int32sAsOne = -(Math.pow(2, 32) - 1);
1308 var toLengthsCorrectly = function (method, reversed) {
1309 var obj = { length: int32sAsOne };
1310 obj[reversed ? (obj.length >>> 0) - 1 : 0] = true;
1311 return valueOrFalseIfThrows(function () {
1312 _call(method, obj, function () {
1313 // note: in nonconforming browsers, this will be called
1314 // -1 >>> 0 times, which is 4294967295, so the throw matters.
1315 throw new RangeError('should not reach here');
1316 }, []);
1317 return true;
1318 });
1319 };
1320 if (!toLengthsCorrectly(Array.prototype.forEach)) {
1321 var originalForEach = Array.prototype.forEach;
1322 overrideNative(Array.prototype, 'forEach', function forEach(callbackFn) {
1323 return ES.Call(originalForEach, this.length >= 0 ? this : [], arguments);
1324 });
1325 }
1326 if (!toLengthsCorrectly(Array.prototype.map)) {
1327 var originalMap = Array.prototype.map;
1328 overrideNative(Array.prototype, 'map', function map(callbackFn) {
1329 return ES.Call(originalMap, this.length >= 0 ? this : [], arguments);
1330 });
1331 }
1332 if (!toLengthsCorrectly(Array.prototype.filter)) {
1333 var originalFilter = Array.prototype.filter;
1334 overrideNative(Array.prototype, 'filter', function filter(callbackFn) {
1335 return ES.Call(originalFilter, this.length >= 0 ? this : [], arguments);
1336 });
1337 }
1338 if (!toLengthsCorrectly(Array.prototype.some)) {
1339 var originalSome = Array.prototype.some;
1340 overrideNative(Array.prototype, 'some', function some(callbackFn) {
1341 return ES.Call(originalSome, this.length >= 0 ? this : [], arguments);
1342 });
1343 }
1344 if (!toLengthsCorrectly(Array.prototype.every)) {
1345 var originalEvery = Array.prototype.every;
1346 overrideNative(Array.prototype, 'every', function every(callbackFn) {
1347 return ES.Call(originalEvery, this.length >= 0 ? this : [], arguments);
1348 });
1349 }
1350 if (!toLengthsCorrectly(Array.prototype.reduce)) {
1351 var originalReduce = Array.prototype.reduce;
1352 overrideNative(Array.prototype, 'reduce', function reduce(callbackFn) {
1353 return ES.Call(originalReduce, this.length >= 0 ? this : [], arguments);
1354 });
1355 }
1356 if (!toLengthsCorrectly(Array.prototype.reduceRight, true)) {
1357 var originalReduceRight = Array.prototype.reduceRight;
1358 overrideNative(Array.prototype, 'reduceRight', function reduceRight(callbackFn) {
1359 return ES.Call(originalReduceRight, this.length >= 0 ? this : [], arguments);
1360 });
1361 }
1362
1363 var lacksOctalSupport = Number('0o10') !== 8;
1364 var lacksBinarySupport = Number('0b10') !== 2;
1365 var trimsNonWhitespace = _some(nonWS, function (c) {
1366 return Number(c + 0 + c) === 0;
1367 });
1368 if (lacksOctalSupport || lacksBinarySupport || trimsNonWhitespace) {
1369 var OrigNumber = Number;
1370 var binaryRegex = /^0b[01]+$/i;
1371 var octalRegex = /^0o[0-7]+$/i;
1372 // Note that in IE 8, RegExp.prototype.test doesn't seem to exist: ie, "test" is an own property of regexes. wtf.
1373 var isBinary = binaryRegex.test.bind(binaryRegex);
1374 var isOctal = octalRegex.test.bind(octalRegex);
1375 var toPrimitive = function (O, hint) { // need to replace this with `es-to-primitive/es6`
1376 var result;
1377 if (typeof O.valueOf === 'function') {
1378 result = O.valueOf();
1379 if (Type.primitive(result)) {
1380 return result;
1381 }
1382 }
1383 if (typeof O.toString === 'function') {
1384 result = O.toString();
1385 if (Type.primitive(result)) {
1386 return result;
1387 }
1388 }
1389 throw new TypeError('No default value');
1390 };
1391 var hasNonWS = nonWSregex.test.bind(nonWSregex);
1392 var isBadHex = isBadHexRegex.test.bind(isBadHexRegex);
1393 var NumberShim = (function () {
1394 // this is wrapped in an IIFE because of IE 6-8's wacky scoping issues with named function expressions.
1395 var NumberShim = function Number(value) {
1396 var primValue;
1397 if (arguments.length > 0) {
1398 primValue = Type.primitive(value) ? value : toPrimitive(value, 'number');
1399 } else {
1400 primValue = 0;
1401 }
1402 if (typeof primValue === 'string') {
1403 primValue = ES.Call(trimShim, primValue);
1404 if (isBinary(primValue)) {
1405 primValue = parseInt(_strSlice(primValue, 2), 2);
1406 } else if (isOctal(primValue)) {
1407 primValue = parseInt(_strSlice(primValue, 2), 8);
1408 } else if (hasNonWS(primValue) || isBadHex(primValue)) {
1409 primValue = NaN;
1410 }
1411 }
1412 var receiver = this;
1413 var valueOfSucceeds = valueOrFalseIfThrows(function () {
1414 OrigNumber.prototype.valueOf.call(receiver);
1415 return true;
1416 });
1417 if (receiver instanceof NumberShim && !valueOfSucceeds) {
1418 return new OrigNumber(primValue);
1419 }
1420 return OrigNumber(primValue);
1421 };
1422 return NumberShim;
1423 }());
1424 wrapConstructor(OrigNumber, NumberShim, {});
1425 // this is necessary for ES3 browsers, where these properties are non-enumerable.
1426 defineProperties(NumberShim, {
1427 NaN: OrigNumber.NaN,
1428 MAX_VALUE: OrigNumber.MAX_VALUE,
1429 MIN_VALUE: OrigNumber.MIN_VALUE,
1430 NEGATIVE_INFINITY: OrigNumber.NEGATIVE_INFINITY,
1431 POSITIVE_INFINITY: OrigNumber.POSITIVE_INFINITY
1432 });
1433 Number = NumberShim; // eslint-disable-line no-global-assign
1434 Value.redefine(globals, 'Number', NumberShim);
1435 }
1436
1437 var maxSafeInteger = Math.pow(2, 53) - 1;
1438 defineProperties(Number, {
1439 MAX_SAFE_INTEGER: maxSafeInteger,
1440 MIN_SAFE_INTEGER: -maxSafeInteger,
1441 EPSILON: 2.220446049250313e-16,
1442
1443 parseInt: globals.parseInt,
1444 parseFloat: globals.parseFloat,
1445
1446 isFinite: numberIsFinite,
1447
1448 isInteger: function isInteger(value) {
1449 return numberIsFinite(value) && ES.ToInteger(value) === value;
1450 },
1451
1452 isSafeInteger: function isSafeInteger(value) {
1453 return Number.isInteger(value) && _abs(value) <= Number.MAX_SAFE_INTEGER;
1454 },
1455
1456 isNaN: numberIsNaN
1457 });
1458 // Firefox 37 has a conforming Number.parseInt, but it's not === to the global parseInt (fixed in v40)
1459 defineProperty(Number, 'parseInt', globals.parseInt, Number.parseInt !== globals.parseInt);
1460
1461 // Work around bugs in Array#find and Array#findIndex -- early
1462 // implementations skipped holes in sparse arrays. (Note that the
1463 // implementations of find/findIndex indirectly use shimmed
1464 // methods of Number, so this test has to happen down here.)
1465 /* eslint-disable no-sparse-arrays */
1466 if ([, 1].find(function () { return true; }) === 1) {
1467 overrideNative(Array.prototype, 'find', ArrayPrototypeShims.find);
1468 }
1469 if ([, 1].findIndex(function () { return true; }) !== 0) {
1470 overrideNative(Array.prototype, 'findIndex', ArrayPrototypeShims.findIndex);
1471 }
1472 /* eslint-enable no-sparse-arrays */
1473
1474 var isEnumerableOn = Function.bind.call(Function.bind, Object.prototype.propertyIsEnumerable);
1475 var ensureEnumerable = function ensureEnumerable(obj, prop) {
1476 if (supportsDescriptors && isEnumerableOn(obj, prop)) {
1477 Object.defineProperty(obj, prop, { enumerable: false });
1478 }
1479 };
1480 var sliceArgs = function sliceArgs() {
1481 // per https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments
1482 // and https://gist.github.com/WebReflection/4327762cb87a8c634a29
1483 var initial = Number(this);
1484 var len = arguments.length;
1485 var desiredArgCount = len - initial;
1486 var args = new Array(desiredArgCount < 0 ? 0 : desiredArgCount);
1487 for (var i = initial; i < len; ++i) {
1488 args[i - initial] = arguments[i];
1489 }
1490 return args;
1491 };
1492 var assignTo = function assignTo(source) {
1493 return function assignToSource(target, key) {
1494 target[key] = source[key];
1495 return target;
1496 };
1497 };
1498 var assignReducer = function (target, source) {
1499 var sourceKeys = keys(Object(source));
1500 var symbols;
1501 if (ES.IsCallable(Object.getOwnPropertySymbols)) {
1502 symbols = _filter(Object.getOwnPropertySymbols(Object(source)), isEnumerableOn(source));
1503 }
1504 return _reduce(_concat(sourceKeys, symbols || []), assignTo(source), target);
1505 };
1506
1507 var ObjectShims = {
1508 // 19.1.3.1
1509 assign: function (target, source) {
1510 var to = ES.ToObject(target, 'Cannot convert undefined or null to object');
1511 return _reduce(ES.Call(sliceArgs, 1, arguments), assignReducer, to);
1512 },
1513
1514 // Added in WebKit in https://bugs.webkit.org/show_bug.cgi?id=143865
1515 is: function is(a, b) {
1516 return ES.SameValue(a, b);
1517 }
1518 };
1519 var assignHasPendingExceptions = Object.assign && Object.preventExtensions && (function () {
1520 // Firefox 37 still has "pending exception" logic in its Object.assign implementation,
1521 // which is 72% slower than our shim, and Firefox 40's native implementation.
1522 var thrower = Object.preventExtensions({ 1: 2 });
1523 try {
1524 Object.assign(thrower, 'xy');
1525 } catch (e) {
1526 return thrower[1] === 'y';
1527 }
1528 }());
1529 if (assignHasPendingExceptions) {
1530 overrideNative(Object, 'assign', ObjectShims.assign);
1531 }
1532 defineProperties(Object, ObjectShims);
1533
1534 if (supportsDescriptors) {
1535 var ES5ObjectShims = {
1536 // 19.1.3.9
1537 // shim from https://gist.github.com/WebReflection/5593554
1538 setPrototypeOf: (function (Object) {
1539 var set;
1540
1541 var checkArgs = function (O, proto) {
1542 if (!ES.TypeIsObject(O)) {
1543 throw new TypeError('cannot set prototype on a non-object');
1544 }
1545 if (!(proto === null || ES.TypeIsObject(proto))) {
1546 throw new TypeError('can only set prototype to an object or null' + proto);
1547 }
1548 };
1549
1550 var setPrototypeOf = function (O, proto) {
1551 checkArgs(O, proto);
1552 _call(set, O, proto);
1553 return O;
1554 };
1555
1556 try {
1557 // this works already in Firefox and Safari
1558 set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
1559 _call(set, {}, null);
1560 } catch (e) {
1561 if (Object.prototype !== ({}).__proto__) { // eslint-disable-line no-proto
1562 // IE < 11 cannot be shimmed
1563 return;
1564 }
1565 // probably Chrome or some old Mobile stock browser
1566 set = function (proto) {
1567 this.__proto__ = proto; // eslint-disable-line no-proto
1568 };
1569 // please note that this will **not** work
1570 // in those browsers that do not inherit
1571 // __proto__ by mistake from Object.prototype
1572 // in these cases we should probably throw an error
1573 // or at least be informed about the issue
1574 setPrototypeOf.polyfill = setPrototypeOf(
1575 setPrototypeOf({}, null),
1576 Object.prototype
1577 ) instanceof Object;
1578 // setPrototypeOf.polyfill === true means it works as meant
1579 // setPrototypeOf.polyfill === false means it's not 100% reliable
1580 // setPrototypeOf.polyfill === undefined
1581 // or
1582 // setPrototypeOf.polyfill == null means it's not a polyfill
1583 // which means it works as expected
1584 // we can even delete Object.prototype.__proto__;
1585 }
1586 return setPrototypeOf;
1587 }(Object))
1588 };
1589
1590 defineProperties(Object, ES5ObjectShims);
1591 }
1592
1593 // Workaround bug in Opera 12 where setPrototypeOf(x, null) doesn't work,
1594 // but Object.create(null) does.
1595 if (
1596 Object.setPrototypeOf
1597 && Object.getPrototypeOf
1598 && Object.getPrototypeOf(Object.setPrototypeOf({}, null)) !== null
1599 && Object.getPrototypeOf(Object.create(null)) === null
1600 ) {
1601 (function () {
1602 var FAKENULL = Object.create(null);
1603 var gpo = Object.getPrototypeOf;
1604 var spo = Object.setPrototypeOf;
1605 Object.getPrototypeOf = function (o) {
1606 var result = gpo(o);
1607 return result === FAKENULL ? null : result;
1608 };
1609 Object.setPrototypeOf = function (o, p) {
1610 var proto = p === null ? FAKENULL : p;
1611 return spo(o, proto);
1612 };
1613 Object.setPrototypeOf.polyfill = false;
1614 }());
1615 }
1616
1617 var objectKeysAcceptsPrimitives = !throwsError(function () { return Object.keys('foo'); });
1618 if (!objectKeysAcceptsPrimitives) {
1619 var originalObjectKeys = Object.keys;
1620 overrideNative(Object, 'keys', function keys(value) {
1621 return originalObjectKeys(ES.ToObject(value));
1622 });
1623 keys = Object.keys;
1624 }
1625 var objectKeysRejectsRegex = throwsError(function () { return Object.keys(/a/g); });
1626 if (objectKeysRejectsRegex) {
1627 var regexRejectingObjectKeys = Object.keys;
1628 overrideNative(Object, 'keys', function keys(value) {
1629 if (Type.regex(value)) {
1630 var regexKeys = [];
1631 for (var k in value) {
1632 if (_hasOwnProperty(value, k)) {
1633 _push(regexKeys, k);
1634 }
1635 }
1636 return regexKeys;
1637 }
1638 return regexRejectingObjectKeys(value);
1639 });
1640 keys = Object.keys;
1641 }
1642
1643 if (Object.getOwnPropertyNames) {
1644 var objectGOPNAcceptsPrimitives = !throwsError(function () { return Object.getOwnPropertyNames('foo'); });
1645 if (!objectGOPNAcceptsPrimitives) {
1646 var cachedWindowNames = typeof window === 'object' ? Object.getOwnPropertyNames(window) : [];
1647 var originalObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
1648 overrideNative(Object, 'getOwnPropertyNames', function getOwnPropertyNames(value) {
1649 var val = ES.ToObject(value);
1650 if (_toString(val) === '[object Window]') {
1651 try {
1652 return originalObjectGetOwnPropertyNames(val);
1653 } catch (e) {
1654 // IE bug where layout engine calls userland gOPN for cross-domain `window` objects
1655 return _concat([], cachedWindowNames);
1656 }
1657 }
1658 return originalObjectGetOwnPropertyNames(val);
1659 });
1660 }
1661 }
1662 if (Object.getOwnPropertyDescriptor) {
1663 var objectGOPDAcceptsPrimitives = !throwsError(function () { return Object.getOwnPropertyDescriptor('foo', 'bar'); });
1664 if (!objectGOPDAcceptsPrimitives) {
1665 var originalObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1666 overrideNative(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(value, property) {
1667 return originalObjectGetOwnPropertyDescriptor(ES.ToObject(value), property);
1668 });
1669 }
1670 }
1671 if (Object.seal) {
1672 var objectSealAcceptsPrimitives = !throwsError(function () { return Object.seal('foo'); });
1673 if (!objectSealAcceptsPrimitives) {
1674 var originalObjectSeal = Object.seal;
1675 overrideNative(Object, 'seal', function seal(value) {
1676 if (!ES.TypeIsObject(value)) { return value; }
1677 return originalObjectSeal(value);
1678 });
1679 }
1680 }
1681 if (Object.isSealed) {
1682 var objectIsSealedAcceptsPrimitives = !throwsError(function () { return Object.isSealed('foo'); });
1683 if (!objectIsSealedAcceptsPrimitives) {
1684 var originalObjectIsSealed = Object.isSealed;
1685 overrideNative(Object, 'isSealed', function isSealed(value) {
1686 if (!ES.TypeIsObject(value)) { return true; }
1687 return originalObjectIsSealed(value);
1688 });
1689 }
1690 }
1691 if (Object.freeze) {
1692 var objectFreezeAcceptsPrimitives = !throwsError(function () { return Object.freeze('foo'); });
1693 if (!objectFreezeAcceptsPrimitives) {
1694 var originalObjectFreeze = Object.freeze;
1695 overrideNative(Object, 'freeze', function freeze(value) {
1696 if (!ES.TypeIsObject(value)) { return value; }
1697 return originalObjectFreeze(value);
1698 });
1699 }
1700 }
1701 if (Object.isFrozen) {
1702 var objectIsFrozenAcceptsPrimitives = !throwsError(function () { return Object.isFrozen('foo'); });
1703 if (!objectIsFrozenAcceptsPrimitives) {
1704 var originalObjectIsFrozen = Object.isFrozen;
1705 overrideNative(Object, 'isFrozen', function isFrozen(value) {
1706 if (!ES.TypeIsObject(value)) { return true; }
1707 return originalObjectIsFrozen(value);
1708 });
1709 }
1710 }
1711 if (Object.preventExtensions) {
1712 var objectPreventExtensionsAcceptsPrimitives = !throwsError(function () { return Object.preventExtensions('foo'); });
1713 if (!objectPreventExtensionsAcceptsPrimitives) {
1714 var originalObjectPreventExtensions = Object.preventExtensions;
1715 overrideNative(Object, 'preventExtensions', function preventExtensions(value) {
1716 if (!ES.TypeIsObject(value)) { return value; }
1717 return originalObjectPreventExtensions(value);
1718 });
1719 }
1720 }
1721 if (Object.isExtensible) {
1722 var objectIsExtensibleAcceptsPrimitives = !throwsError(function () { return Object.isExtensible('foo'); });
1723 if (!objectIsExtensibleAcceptsPrimitives) {
1724 var originalObjectIsExtensible = Object.isExtensible;
1725 overrideNative(Object, 'isExtensible', function isExtensible(value) {
1726 if (!ES.TypeIsObject(value)) { return false; }
1727 return originalObjectIsExtensible(value);
1728 });
1729 }
1730 }
1731 if (Object.getPrototypeOf) {
1732 var objectGetProtoAcceptsPrimitives = !throwsError(function () { return Object.getPrototypeOf('foo'); });
1733 if (!objectGetProtoAcceptsPrimitives) {
1734 var originalGetProto = Object.getPrototypeOf;
1735 overrideNative(Object, 'getPrototypeOf', function getPrototypeOf(value) {
1736 return originalGetProto(ES.ToObject(value));
1737 });
1738 }
1739 }
1740
1741 var hasFlags = supportsDescriptors && (function () {
1742 var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
1743 return desc && ES.IsCallable(desc.get);
1744 }());
1745 if (supportsDescriptors && !hasFlags) {
1746 var regExpFlagsGetter = function flags() {
1747 if (!ES.TypeIsObject(this)) {
1748 throw new TypeError('Method called on incompatible type: must be an object.');
1749 }
1750 var result = '';
1751 if (this.global) {
1752 result += 'g';
1753 }
1754 if (this.ignoreCase) {
1755 result += 'i';
1756 }
1757 if (this.multiline) {
1758 result += 'm';
1759 }
1760 if (this.unicode) {
1761 result += 'u';
1762 }
1763 if (this.sticky) {
1764 result += 'y';
1765 }
1766 return result;
1767 };
1768
1769 Value.getter(RegExp.prototype, 'flags', regExpFlagsGetter);
1770 }
1771
1772 var regExpSupportsFlagsWithRegex = supportsDescriptors && valueOrFalseIfThrows(function () {
1773 return String(new RegExp(/a/g, 'i')) === '/a/i';
1774 });
1775 var regExpNeedsToSupportSymbolMatch = hasSymbols && supportsDescriptors && (function () {
1776 // Edge 0.12 supports flags fully, but does not support Symbol.match
1777 var regex = /./;
1778 regex[Symbol.match] = false;
1779 return RegExp(regex) === regex;
1780 }());
1781
1782 var regexToStringIsGeneric = valueOrFalseIfThrows(function () {
1783 return RegExp.prototype.toString.call({ source: 'abc' }) === '/abc/';
1784 });
1785 var regexToStringSupportsGenericFlags = regexToStringIsGeneric && valueOrFalseIfThrows(function () {
1786 return RegExp.prototype.toString.call({ source: 'a', flags: 'b' }) === '/a/b';
1787 });
1788 if (!regexToStringIsGeneric || !regexToStringSupportsGenericFlags) {
1789 var origRegExpToString = RegExp.prototype.toString;
1790 defineProperty(RegExp.prototype, 'toString', function toString() {
1791 var R = ES.RequireObjectCoercible(this);
1792 if (Type.regex(R)) {
1793 return _call(origRegExpToString, R);
1794 }
1795 var pattern = $String(R.source);
1796 var flags = $String(R.flags);
1797 return '/' + pattern + '/' + flags;
1798 }, true);
1799 Value.preserveToString(RegExp.prototype.toString, origRegExpToString);
1800 RegExp.prototype.toString.prototype = void 0;
1801 }
1802
1803 if (supportsDescriptors && (!regExpSupportsFlagsWithRegex || regExpNeedsToSupportSymbolMatch)) {
1804 var flagsGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
1805 var sourceDesc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source') || {};
1806 var legacySourceGetter = function () {
1807 // prior to it being a getter, it's own + nonconfigurable
1808 return this.source;
1809 };
1810 var sourceGetter = ES.IsCallable(sourceDesc.get) ? sourceDesc.get : legacySourceGetter;
1811
1812 var OrigRegExp = RegExp;
1813 var RegExpShim = (function () {
1814 return function RegExp(pattern, flags) {
1815 var patternIsRegExp = ES.IsRegExp(pattern);
1816 var calledWithNew = this instanceof RegExp;
1817 if (!calledWithNew && patternIsRegExp && typeof flags === 'undefined' && pattern.constructor === RegExp) {
1818 return pattern;
1819 }
1820
1821 var P = pattern;
1822 var F = flags;
1823 if (Type.regex(pattern)) {
1824 P = ES.Call(sourceGetter, pattern);
1825 F = typeof flags === 'undefined' ? ES.Call(flagsGetter, pattern) : flags;
1826 return new RegExp(P, F);
1827 } else if (patternIsRegExp) {
1828 P = pattern.source;
1829 F = typeof flags === 'undefined' ? pattern.flags : flags;
1830 }
1831 return new OrigRegExp(pattern, flags);
1832 };
1833 }());
1834 wrapConstructor(OrigRegExp, RegExpShim, {
1835 $input: true // Chrome < v39 & Opera < 26 have a nonstandard "$input" property
1836 });
1837 RegExp = RegExpShim; // eslint-disable-line no-global-assign
1838 Value.redefine(globals, 'RegExp', RegExpShim);
1839 }
1840
1841 if (supportsDescriptors) {
1842 var regexGlobals = {
1843 input: '$_',
1844 lastMatch: '$&',
1845 lastParen: '$+',
1846 leftContext: '$`',
1847 rightContext: '$\''
1848 };
1849 _forEach(keys(regexGlobals), function (prop) {
1850 if (prop in RegExp && !(regexGlobals[prop] in RegExp)) {
1851 Value.getter(RegExp, regexGlobals[prop], function get() {
1852 return RegExp[prop];
1853 });
1854 }
1855 });
1856 }
1857 addDefaultSpecies(RegExp);
1858
1859 var inverseEpsilon = 1 / Number.EPSILON;
1860 var roundTiesToEven = function roundTiesToEven(n) {
1861 // Even though this reduces down to `return n`, it takes advantage of built-in rounding.
1862 return (n + inverseEpsilon) - inverseEpsilon;
1863 };
1864 var BINARY_32_EPSILON = Math.pow(2, -23);
1865 var BINARY_32_MAX_VALUE = Math.pow(2, 127) * (2 - BINARY_32_EPSILON);
1866 var BINARY_32_MIN_VALUE = Math.pow(2, -126);
1867 var E = Math.E;
1868 var LOG2E = Math.LOG2E;
1869 var LOG10E = Math.LOG10E;
1870 var numberCLZ = Number.prototype.clz;
1871 delete Number.prototype.clz; // Safari 8 has Number#clz
1872
1873 var MathShims = {
1874 acosh: function acosh(value) {
1875 var x = Number(value);
1876 if (numberIsNaN(x) || value < 1) { return NaN; }
1877 if (x === 1) { return 0; }
1878 if (x === Infinity) { return x; }
1879
1880 var xInvSquared = 1 / (x * x);
1881 if (x < 2) {
1882 return _log1p(x - 1 + (_sqrt(1 - xInvSquared) * x));
1883 }
1884 var halfX = x / 2;
1885 return _log1p(halfX + (_sqrt(1 - xInvSquared) * halfX) - 1) + (1 / LOG2E);
1886 },
1887
1888 asinh: function asinh(value) {
1889 var x = Number(value);
1890 if (x === 0 || !globalIsFinite(x)) {
1891 return x;
1892 }
1893
1894 var a = _abs(x);
1895 var aSquared = a * a;
1896 var s = _sign(x);
1897 if (a < 1) {
1898 return s * _log1p(a + (aSquared / (_sqrt(aSquared + 1) + 1)));
1899 }
1900 return s * (_log1p((a / 2) + (_sqrt(1 + (1 / aSquared)) * a / 2) - 1) + (1 / LOG2E));
1901 },
1902
1903 atanh: function atanh(value) {
1904 var x = Number(value);
1905
1906 if (x === 0) { return x; }
1907 if (x === -1) { return -Infinity; }
1908 if (x === 1) { return Infinity; }
1909 if (numberIsNaN(x) || x < -1 || x > 1) {
1910 return NaN;
1911 }
1912
1913 var a = _abs(x);
1914 return _sign(x) * _log1p(2 * a / (1 - a)) / 2;
1915 },
1916
1917 cbrt: function cbrt(value) {
1918 var x = Number(value);
1919 if (x === 0) { return x; }
1920 var negate = x < 0;
1921 var result;
1922 if (negate) { x = -x; }
1923 if (x === Infinity) {
1924 result = Infinity;
1925 } else {
1926 result = _exp(_log(x) / 3);
1927 // from http://en.wikipedia.org/wiki/Cube_root#Numerical_methods
1928 result = ((x / (result * result)) + (2 * result)) / 3;
1929 }
1930 return negate ? -result : result;
1931 },
1932
1933 clz32: function clz32(value) {
1934 // See https://bugs.ecmascript.org/show_bug.cgi?id=2465
1935 var x = Number(value);
1936 var number = ES.ToUint32(x);
1937 if (number === 0) {
1938 return 32;
1939 }
1940 return numberCLZ ? ES.Call(numberCLZ, number) : 31 - _floor(_log(number + 0.5) * LOG2E);
1941 },
1942
1943 cosh: function cosh(value) {
1944 var x = Number(value);
1945 if (x === 0) { return 1; } // +0 or -0
1946 if (numberIsNaN(x)) { return NaN; }
1947 if (!globalIsFinite(x)) { return Infinity; }
1948
1949 var t = _exp(_abs(x) - 1);
1950 return (t + (1 / (t * E * E))) * (E / 2);
1951 },
1952
1953 expm1: function expm1(value) {
1954 var x = Number(value);
1955 if (x === -Infinity) { return -1; }
1956 if (!globalIsFinite(x) || x === 0) { return x; }
1957 if (_abs(x) > 0.5) {
1958 return _exp(x) - 1;
1959 }
1960 // A more precise approximation using Taylor series expansion
1961 // from https://github.com/paulmillr/es6-shim/issues/314#issuecomment-70293986
1962 var t = x;
1963 var sum = 0;
1964 var n = 1;
1965 while (sum + t !== sum) {
1966 sum += t;
1967 n += 1;
1968 t *= x / n;
1969 }
1970 return sum;
1971 },
1972
1973 hypot: function hypot(x, y) {
1974 var result = 0;
1975 var largest = 0;
1976 for (var i = 0; i < arguments.length; ++i) {
1977 var value = _abs(Number(arguments[i]));
1978 if (largest < value) {
1979 result *= (largest / value) * (largest / value);
1980 result += 1;
1981 largest = value;
1982 } else {
1983 result += value > 0 ? (value / largest) * (value / largest) : value;
1984 }
1985 }
1986 return largest === Infinity ? Infinity : largest * _sqrt(result);
1987 },
1988
1989 log2: function log2(value) {
1990 return _log(value) * LOG2E;
1991 },
1992
1993 log10: function log10(value) {
1994 return _log(value) * LOG10E;
1995 },
1996
1997 log1p: _log1p,
1998
1999 sign: _sign,
2000
2001 sinh: function sinh(value) {
2002 var x = Number(value);
2003 if (!globalIsFinite(x) || x === 0) { return x; }
2004
2005 var a = _abs(x);
2006 if (a < 1) {
2007 var u = Math.expm1(a);
2008 return _sign(x) * u * (1 + (1 / (u + 1))) / 2;
2009 }
2010 var t = _exp(a - 1);
2011 return _sign(x) * (t - (1 / (t * E * E))) * (E / 2);
2012 },
2013
2014 tanh: function tanh(value) {
2015 var x = Number(value);
2016 if (numberIsNaN(x) || x === 0) { return x; }
2017 // can exit early at +-20 as JS loses precision for true value at this integer
2018 if (x >= 20) { return 1; }
2019 if (x <= -20) { return -1; }
2020
2021 return (Math.expm1(x) - Math.expm1(-x)) / (_exp(x) + _exp(-x));
2022 },
2023
2024 trunc: function trunc(value) {
2025 var x = Number(value);
2026 return x < 0 ? -_floor(-x) : _floor(x);
2027 },
2028
2029 imul: function imul(x, y) {
2030 // taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
2031 var a = ES.ToUint32(x);
2032 var b = ES.ToUint32(y);
2033 var ah = (a >>> 16) & 0xffff;
2034 var al = a & 0xffff;
2035 var bh = (b >>> 16) & 0xffff;
2036 var bl = b & 0xffff;
2037 // the shift by 0 fixes the sign on the high part
2038 // the final |0 converts the unsigned value into a signed value
2039 return (al * bl) + ((((ah * bl) + (al * bh)) << 16) >>> 0) | 0;
2040 },
2041
2042 fround: function fround(x) {
2043 var v = Number(x);
2044 if (v === 0 || v === Infinity || v === -Infinity || numberIsNaN(v)) {
2045 return v;
2046 }
2047 var sign = _sign(v);
2048 var abs = _abs(v);
2049 if (abs < BINARY_32_MIN_VALUE) {
2050 return sign * roundTiesToEven(abs / BINARY_32_MIN_VALUE / BINARY_32_EPSILON) * BINARY_32_MIN_VALUE * BINARY_32_EPSILON;
2051 }
2052 // Veltkamp's splitting (?)
2053 var a = (1 + (BINARY_32_EPSILON / Number.EPSILON)) * abs;
2054 var result = a - (a - abs);
2055 if (result > BINARY_32_MAX_VALUE || numberIsNaN(result)) {
2056 return sign * Infinity;
2057 }
2058 return sign * result;
2059 }
2060 };
2061
2062 var withinULPDistance = function withinULPDistance(result, expected, distance) {
2063 return _abs(1 - (result / expected)) / Number.EPSILON < (distance || 8);
2064 };
2065
2066 defineProperties(Math, MathShims);
2067 // Chrome < 40 sinh returns ∞ for large numbers
2068 defineProperty(Math, 'sinh', MathShims.sinh, Math.sinh(710) === Infinity);
2069 // Chrome < 40 cosh returns ∞ for large numbers
2070 defineProperty(Math, 'cosh', MathShims.cosh, Math.cosh(710) === Infinity);
2071 // IE 11 TP has an imprecise log1p: reports Math.log1p(-1e-17) as 0
2072 defineProperty(Math, 'log1p', MathShims.log1p, Math.log1p(-1e-17) !== -1e-17);
2073 // IE 11 TP has an imprecise asinh: reports Math.asinh(-1e7) as not exactly equal to -Math.asinh(1e7)
2074 defineProperty(Math, 'asinh', MathShims.asinh, Math.asinh(-1e7) !== -Math.asinh(1e7));
2075 // Chrome < 54 asinh returns ∞ for large numbers and should not
2076 defineProperty(Math, 'asinh', MathShims.asinh, Math.asinh(1e+300) === Infinity);
2077 // Chrome < 54 atanh incorrectly returns 0 for large numbers
2078 defineProperty(Math, 'atanh', MathShims.atanh, Math.atanh(1e-300) === 0);
2079 // Chrome 40 has an imprecise Math.tanh with very small numbers
2080 defineProperty(Math, 'tanh', MathShims.tanh, Math.tanh(-2e-17) !== -2e-17);
2081 // Chrome 40 loses Math.acosh precision with high numbers
2082 defineProperty(Math, 'acosh', MathShims.acosh, Math.acosh(Number.MAX_VALUE) === Infinity);
2083 // Chrome < 54 has an inaccurate acosh for EPSILON deltas
2084 defineProperty(Math, 'acosh', MathShims.acosh, !withinULPDistance(Math.acosh(1 + Number.EPSILON), Math.sqrt(2 * Number.EPSILON)));
2085 // Firefox 38 on Windows
2086 defineProperty(Math, 'cbrt', MathShims.cbrt, !withinULPDistance(Math.cbrt(1e-300), 1e-100));
2087 // node 0.11 has an imprecise Math.sinh with very small numbers
2088 defineProperty(Math, 'sinh', MathShims.sinh, Math.sinh(-2e-17) !== -2e-17);
2089 // FF 35 on Linux reports 22025.465794806725 for Math.expm1(10)
2090 var expm1OfTen = Math.expm1(10);
2091 defineProperty(Math, 'expm1', MathShims.expm1, expm1OfTen > 22025.465794806719 || expm1OfTen < 22025.4657948067165168);
2092 // node v12.11 - v12.15 report NaN
2093 defineProperty(Math, 'hypot', MathShims.hypot, Math.hypot(Infinity, NaN) !== Infinity);
2094
2095 var origMathRound = Math.round;
2096 // breaks in e.g. Safari 8, Internet Explorer 11, Opera 12
2097 var roundHandlesBoundaryConditions = Math.round(0.5 - (Number.EPSILON / 4)) === 0
2098 && Math.round(-0.5 + (Number.EPSILON / 3.99)) === 1;
2099
2100 // When engines use Math.floor(x + 0.5) internally, Math.round can be buggy for large integers.
2101 // This behavior should be governed by "round to nearest, ties to even mode"
2102 // see http://www.ecma-international.org/ecma-262/6.0/#sec-terms-and-definitions-number-type
2103 // These are the boundary cases where it breaks.
2104 var smallestPositiveNumberWhereRoundBreaks = inverseEpsilon + 1;
2105 var largestPositiveNumberWhereRoundBreaks = (2 * inverseEpsilon) - 1;
2106 var roundDoesNotIncreaseIntegers = [
2107 smallestPositiveNumberWhereRoundBreaks,
2108 largestPositiveNumberWhereRoundBreaks
2109 ].every(function (num) {
2110 return Math.round(num) === num;
2111 });
2112 defineProperty(Math, 'round', function round(x) {
2113 var floor = _floor(x);
2114 var ceil = floor === -1 ? -0 : floor + 1;
2115 return x - floor < 0.5 ? floor : ceil;
2116 }, !roundHandlesBoundaryConditions || !roundDoesNotIncreaseIntegers);
2117 Value.preserveToString(Math.round, origMathRound);
2118
2119 var origImul = Math.imul;
2120 if (Math.imul(0xffffffff, 5) !== -5) {
2121 // Safari 6.1, at least, reports "0" for this value
2122 Math.imul = MathShims.imul;
2123 Value.preserveToString(Math.imul, origImul);
2124 }
2125 if (Math.imul.length !== 2) {
2126 // Safari 8.0.4 has a length of 1
2127 // fixed in https://bugs.webkit.org/show_bug.cgi?id=143658
2128 overrideNative(Math, 'imul', function imul(x, y) {
2129 return ES.Call(origImul, Math, arguments);
2130 });
2131 }
2132
2133 // Promises
2134 // Simplest possible implementation; use a 3rd-party library if you
2135 // want the best possible speed and/or long stack traces.
2136 var PromiseShim = (function () {
2137 var setTimeout = globals.setTimeout;
2138 // some environments don't have setTimeout - no way to shim here.
2139 if (typeof setTimeout !== 'function' && typeof setTimeout !== 'object') { return; }
2140
2141 ES.IsPromise = function (promise) {
2142 if (!ES.TypeIsObject(promise)) {
2143 return false;
2144 }
2145 if (typeof promise._promise === 'undefined') {
2146 return false; // uninitialized, or missing our hidden field.
2147 }
2148 return true;
2149 };
2150
2151 // "PromiseCapability" in the spec is what most promise implementations
2152 // call a "deferred".
2153 var PromiseCapability = function (C) {
2154 if (!ES.IsConstructor(C)) {
2155 throw new TypeError('Bad promise constructor');
2156 }
2157 var capability = this;
2158 var resolver = function (resolve, reject) {
2159 if (capability.resolve !== void 0 || capability.reject !== void 0) {
2160 throw new TypeError('Bad Promise implementation!');
2161 }
2162 capability.resolve = resolve;
2163 capability.reject = reject;
2164 };
2165 // Initialize fields to inform optimizers about the object shape.
2166 capability.resolve = void 0;
2167 capability.reject = void 0;
2168 capability.promise = new C(resolver);
2169 if (!(ES.IsCallable(capability.resolve) && ES.IsCallable(capability.reject))) {
2170 throw new TypeError('Bad promise constructor');
2171 }
2172 };
2173
2174 // find an appropriate setImmediate-alike
2175 var makeZeroTimeout;
2176 if (typeof window !== 'undefined' && ES.IsCallable(window.postMessage)) {
2177 makeZeroTimeout = function () {
2178 // from http://dbaron.org/log/20100309-faster-timeouts
2179 var timeouts = [];
2180 var messageName = 'zero-timeout-message';
2181 var setZeroTimeout = function (fn) {
2182 _push(timeouts, fn);
2183 window.postMessage(messageName, '*');
2184 };
2185 var handleMessage = function (event) {
2186 if (event.source === window && event.data === messageName) {
2187 event.stopPropagation();
2188 if (timeouts.length === 0) { return; }
2189 var fn = _shift(timeouts);
2190 fn();
2191 }
2192 };
2193 window.addEventListener('message', handleMessage, true);
2194 return setZeroTimeout;
2195 };
2196 }
2197 var makePromiseAsap = function () {
2198 // An efficient task-scheduler based on a pre-existing Promise
2199 // implementation, which we can use even if we override the
2200 // global Promise below (in order to workaround bugs)
2201 // https://github.com/Raynos/observ-hash/issues/2#issuecomment-35857671
2202 var P = globals.Promise;
2203 var pr = P && P.resolve && P.resolve();
2204 return pr && function (task) {
2205 return pr.then(task);
2206 };
2207 };
2208 var enqueue = ES.IsCallable(globals.setImmediate)
2209 ? globals.setImmediate
2210 : (
2211 typeof process === 'object' && process.nextTick
2212 ? process.nextTick
2213 : makePromiseAsap() || (ES.IsCallable(makeZeroTimeout) ? makeZeroTimeout() : function (task) { setTimeout(task, 0); })
2214 ); // fallback
2215
2216 // Constants for Promise implementation
2217 var PROMISE_IDENTITY = function (x) { return x; };
2218 var PROMISE_THROWER = function (e) { throw e; };
2219 var PROMISE_PENDING = 0;
2220 var PROMISE_FULFILLED = 1;
2221 var PROMISE_REJECTED = 2;
2222 // We store fulfill/reject handlers and capabilities in a single array.
2223 var PROMISE_FULFILL_OFFSET = 0;
2224 var PROMISE_REJECT_OFFSET = 1;
2225 var PROMISE_CAPABILITY_OFFSET = 2;
2226 // This is used in an optimization for chaining promises via then.
2227 var PROMISE_FAKE_CAPABILITY = {};
2228
2229 var enqueuePromiseReactionJob = function (handler, capability, argument) {
2230 enqueue(function () {
2231 promiseReactionJob(handler, capability, argument);
2232 });
2233 };
2234
2235 var promiseReactionJob = function (handler, promiseCapability, argument) {
2236 var handlerResult, f;
2237 if (promiseCapability === PROMISE_FAKE_CAPABILITY) {
2238 // Fast case, when we don't actually need to chain through to a
2239 // (real) promiseCapability.
2240 return handler(argument);
2241 }
2242 try {
2243 handlerResult = handler(argument);
2244 f = promiseCapability.resolve;
2245 } catch (e) {
2246 handlerResult = e;
2247 f = promiseCapability.reject;
2248 }
2249 f(handlerResult);
2250 };
2251
2252 var fulfillPromise = function (promise, value) {
2253 var _promise = promise._promise;
2254 var length = _promise.reactionLength;
2255 if (length > 0) {
2256 enqueuePromiseReactionJob(
2257 _promise.fulfillReactionHandler0,
2258 _promise.reactionCapability0,
2259 value
2260 );
2261 _promise.fulfillReactionHandler0 = void 0;
2262 _promise.rejectReactions0 = void 0;
2263 _promise.reactionCapability0 = void 0;
2264 if (length > 1) {
2265 for (var i = 1, idx = 0; i < length; i++, idx += 3) {
2266 enqueuePromiseReactionJob(
2267 _promise[idx + PROMISE_FULFILL_OFFSET],
2268 _promise[idx + PROMISE_CAPABILITY_OFFSET],
2269 value
2270 );
2271 promise[idx + PROMISE_FULFILL_OFFSET] = void 0;
2272 promise[idx + PROMISE_REJECT_OFFSET] = void 0;
2273 promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0;
2274 }
2275 }
2276 }
2277 _promise.result = value;
2278 _promise.state = PROMISE_FULFILLED;
2279 _promise.reactionLength = 0;
2280 };
2281
2282 var rejectPromise = function (promise, reason) {
2283 var _promise = promise._promise;
2284 var length = _promise.reactionLength;
2285 if (length > 0) {
2286 enqueuePromiseReactionJob(
2287 _promise.rejectReactionHandler0,
2288 _promise.reactionCapability0,
2289 reason
2290 );
2291 _promise.fulfillReactionHandler0 = void 0;
2292 _promise.rejectReactions0 = void 0;
2293 _promise.reactionCapability0 = void 0;
2294 if (length > 1) {
2295 for (var i = 1, idx = 0; i < length; i++, idx += 3) {
2296 enqueuePromiseReactionJob(
2297 _promise[idx + PROMISE_REJECT_OFFSET],
2298 _promise[idx + PROMISE_CAPABILITY_OFFSET],
2299 reason
2300 );
2301 promise[idx + PROMISE_FULFILL_OFFSET] = void 0;
2302 promise[idx + PROMISE_REJECT_OFFSET] = void 0;
2303 promise[idx + PROMISE_CAPABILITY_OFFSET] = void 0;
2304 }
2305 }
2306 }
2307 _promise.result = reason;
2308 _promise.state = PROMISE_REJECTED;
2309 _promise.reactionLength = 0;
2310 };
2311
2312 var createResolvingFunctions = function (promise) {
2313 var alreadyResolved = false;
2314 var resolve = function (resolution) {
2315 var then;
2316 if (alreadyResolved) { return; }
2317 alreadyResolved = true;
2318 if (resolution === promise) {
2319 return rejectPromise(promise, new TypeError('Self resolution'));
2320 }
2321 if (!ES.TypeIsObject(resolution)) {
2322 return fulfillPromise(promise, resolution);
2323 }
2324 try {
2325 then = resolution.then;
2326 } catch (e) {
2327 return rejectPromise(promise, e);
2328 }
2329 if (!ES.IsCallable(then)) {
2330 return fulfillPromise(promise, resolution);
2331 }
2332 enqueue(function () {
2333 promiseResolveThenableJob(promise, resolution, then);
2334 });
2335 };
2336 var reject = function (reason) {
2337 if (alreadyResolved) { return; }
2338 alreadyResolved = true;
2339 return rejectPromise(promise, reason);
2340 };
2341 return { resolve: resolve, reject: reject };
2342 };
2343
2344 var optimizedThen = function (then, thenable, resolve, reject) {
2345 // Optimization: since we discard the result, we can pass our
2346 // own then implementation a special hint to let it know it
2347 // doesn't have to create it. (The PROMISE_FAKE_CAPABILITY
2348 // object is local to this implementation and unforgeable outside.)
2349 if (then === Promise$prototype$then) {
2350 _call(then, thenable, resolve, reject, PROMISE_FAKE_CAPABILITY);
2351 } else {
2352 _call(then, thenable, resolve, reject);
2353 }
2354 };
2355 var promiseResolveThenableJob = function (promise, thenable, then) {
2356 var resolvingFunctions = createResolvingFunctions(promise);
2357 var resolve = resolvingFunctions.resolve;
2358 var reject = resolvingFunctions.reject;
2359 try {
2360 optimizedThen(then, thenable, resolve, reject);
2361 } catch (e) {
2362 reject(e);
2363 }
2364 };
2365
2366 var Promise$prototype, Promise$prototype$then;
2367 var Promise = (function () {
2368 var PromiseShim = function Promise(resolver) {
2369 if (!(this instanceof PromiseShim)) {
2370 throw new TypeError('Constructor Promise requires "new"');
2371 }
2372 if (this && this._promise) {
2373 throw new TypeError('Bad construction');
2374 }
2375 // see https://bugs.ecmascript.org/show_bug.cgi?id=2482
2376 if (!ES.IsCallable(resolver)) {
2377 throw new TypeError('not a valid resolver');
2378 }
2379 var promise = emulateES6construct(this, PromiseShim, Promise$prototype, {
2380 _promise: {
2381 result: void 0,
2382 state: PROMISE_PENDING,
2383 // The first member of the "reactions" array is inlined here,
2384 // since most promises only have one reaction.
2385 // We've also exploded the 'reaction' object to inline the
2386 // "handler" and "capability" fields, since both fulfill and
2387 // reject reactions share the same capability.
2388 reactionLength: 0,
2389 fulfillReactionHandler0: void 0,
2390 rejectReactionHandler0: void 0,
2391 reactionCapability0: void 0
2392 }
2393 });
2394 var resolvingFunctions = createResolvingFunctions(promise);
2395 var reject = resolvingFunctions.reject;
2396 try {
2397 resolver(resolvingFunctions.resolve, reject);
2398 } catch (e) {
2399 reject(e);
2400 }
2401 return promise;
2402 };
2403 return PromiseShim;
2404 }());
2405 Promise$prototype = Promise.prototype;
2406
2407 var _promiseAllResolver = function (index, values, capability, remaining) {
2408 var alreadyCalled = false;
2409 return function (x) {
2410 if (alreadyCalled) { return; }
2411 alreadyCalled = true;
2412 values[index] = x;
2413 if ((--remaining.count) === 0) {
2414 var resolve = capability.resolve;
2415 resolve(values); // call w/ this===undefined
2416 }
2417 };
2418 };
2419
2420 var performPromiseAll = function (iteratorRecord, C, resultCapability) {
2421 var it = iteratorRecord.iterator;
2422 var values = [];
2423 var remaining = { count: 1 };
2424 var next, nextValue;
2425 var index = 0;
2426 while (true) {
2427 try {
2428 next = ES.IteratorStep(it);
2429 if (next === false) {
2430 iteratorRecord.done = true;
2431 break;
2432 }
2433 nextValue = next.value;
2434 } catch (e) {
2435 iteratorRecord.done = true;
2436 throw e;
2437 }
2438 values[index] = void 0;
2439 var nextPromise = C.resolve(nextValue);
2440 var resolveElement = _promiseAllResolver(
2441 index,
2442 values,
2443 resultCapability,
2444 remaining
2445 );
2446 remaining.count += 1;
2447 optimizedThen(nextPromise.then, nextPromise, resolveElement, resultCapability.reject);
2448 index += 1;
2449 }
2450 if ((--remaining.count) === 0) {
2451 var resolve = resultCapability.resolve;
2452 resolve(values); // call w/ this===undefined
2453 }
2454 return resultCapability.promise;
2455 };
2456
2457 var performPromiseRace = function (iteratorRecord, C, resultCapability) {
2458 var it = iteratorRecord.iterator;
2459 var next, nextValue, nextPromise;
2460 while (true) {
2461 try {
2462 next = ES.IteratorStep(it);
2463 if (next === false) {
2464 // NOTE: If iterable has no items, resulting promise will never
2465 // resolve; see:
2466 // https://github.com/domenic/promises-unwrapping/issues/75
2467 // https://bugs.ecmascript.org/show_bug.cgi?id=2515
2468 iteratorRecord.done = true;
2469 break;
2470 }
2471 nextValue = next.value;
2472 } catch (e) {
2473 iteratorRecord.done = true;
2474 throw e;
2475 }
2476 nextPromise = C.resolve(nextValue);
2477 optimizedThen(nextPromise.then, nextPromise, resultCapability.resolve, resultCapability.reject);
2478 }
2479 return resultCapability.promise;
2480 };
2481
2482 defineProperties(Promise, {
2483 all: function all(iterable) {
2484 var C = this;
2485 if (!ES.TypeIsObject(C)) {
2486 throw new TypeError('Promise is not object');
2487 }
2488 var capability = new PromiseCapability(C);
2489 var iterator, iteratorRecord;
2490 try {
2491 iterator = ES.GetIterator(iterable);
2492 iteratorRecord = { iterator: iterator, done: false };
2493 return performPromiseAll(iteratorRecord, C, capability);
2494 } catch (e) {
2495 var exception = e;
2496 if (iteratorRecord && !iteratorRecord.done) {
2497 try {
2498 ES.IteratorClose(iterator, true);
2499 } catch (ee) {
2500 exception = ee;
2501 }
2502 }
2503 var reject = capability.reject;
2504 reject(exception);
2505 return capability.promise;
2506 }
2507 },
2508
2509 race: function race(iterable) {
2510 var C = this;
2511 if (!ES.TypeIsObject(C)) {
2512 throw new TypeError('Promise is not object');
2513 }
2514 var capability = new PromiseCapability(C);
2515 var iterator, iteratorRecord;
2516 try {
2517 iterator = ES.GetIterator(iterable);
2518 iteratorRecord = { iterator: iterator, done: false };
2519 return performPromiseRace(iteratorRecord, C, capability);
2520 } catch (e) {
2521 var exception = e;
2522 if (iteratorRecord && !iteratorRecord.done) {
2523 try {
2524 ES.IteratorClose(iterator, true);
2525 } catch (ee) {
2526 exception = ee;
2527 }
2528 }
2529 var reject = capability.reject;
2530 reject(exception);
2531 return capability.promise;
2532 }
2533 },
2534
2535 reject: function reject(reason) {
2536 var C = this;
2537 if (!ES.TypeIsObject(C)) {
2538 throw new TypeError('Bad promise constructor');
2539 }
2540 var capability = new PromiseCapability(C);
2541 var rejectFunc = capability.reject;
2542 rejectFunc(reason); // call with this===undefined
2543 return capability.promise;
2544 },
2545
2546 resolve: function resolve(v) {
2547 // See https://esdiscuss.org/topic/fixing-promise-resolve for spec
2548 var C = this;
2549 if (!ES.TypeIsObject(C)) {
2550 throw new TypeError('Bad promise constructor');
2551 }
2552 if (ES.IsPromise(v)) {
2553 var constructor = v.constructor;
2554 if (constructor === C) {
2555 return v;
2556 }
2557 }
2558 var capability = new PromiseCapability(C);
2559 var resolveFunc = capability.resolve;
2560 resolveFunc(v); // call with this===undefined
2561 return capability.promise;
2562 }
2563 });
2564
2565 defineProperties(Promise$prototype, {
2566 'catch': function (onRejected) {
2567 return this.then(null, onRejected);
2568 },
2569
2570 then: function then(onFulfilled, onRejected) {
2571 var promise = this;
2572 if (!ES.IsPromise(promise)) { throw new TypeError('not a promise'); }
2573 var C = ES.SpeciesConstructor(promise, Promise);
2574 var resultCapability;
2575 var returnValueIsIgnored = arguments.length > 2 && arguments[2] === PROMISE_FAKE_CAPABILITY;
2576 if (returnValueIsIgnored && C === Promise) {
2577 resultCapability = PROMISE_FAKE_CAPABILITY;
2578 } else {
2579 resultCapability = new PromiseCapability(C);
2580 }
2581 // PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability)
2582 // Note that we've split the 'reaction' object into its two
2583 // components, "capabilities" and "handler"
2584 // "capabilities" is always equal to `resultCapability`
2585 var fulfillReactionHandler = ES.IsCallable(onFulfilled) ? onFulfilled : PROMISE_IDENTITY;
2586 var rejectReactionHandler = ES.IsCallable(onRejected) ? onRejected : PROMISE_THROWER;
2587 var _promise = promise._promise;
2588 var value;
2589 if (_promise.state === PROMISE_PENDING) {
2590 if (_promise.reactionLength === 0) {
2591 _promise.fulfillReactionHandler0 = fulfillReactionHandler;
2592 _promise.rejectReactionHandler0 = rejectReactionHandler;
2593 _promise.reactionCapability0 = resultCapability;
2594 } else {
2595 var idx = 3 * (_promise.reactionLength - 1);
2596 _promise[idx + PROMISE_FULFILL_OFFSET] = fulfillReactionHandler;
2597 _promise[idx + PROMISE_REJECT_OFFSET] = rejectReactionHandler;
2598 _promise[idx + PROMISE_CAPABILITY_OFFSET] = resultCapability;
2599 }
2600 _promise.reactionLength += 1;
2601 } else if (_promise.state === PROMISE_FULFILLED) {
2602 value = _promise.result;
2603 enqueuePromiseReactionJob(
2604 fulfillReactionHandler,
2605 resultCapability,
2606 value
2607 );
2608 } else if (_promise.state === PROMISE_REJECTED) {
2609 value = _promise.result;
2610 enqueuePromiseReactionJob(
2611 rejectReactionHandler,
2612 resultCapability,
2613 value
2614 );
2615 } else {
2616 throw new TypeError('unexpected Promise state');
2617 }
2618 return resultCapability.promise;
2619 }
2620 });
2621 // This helps the optimizer by ensuring that methods which take
2622 // capabilities aren't polymorphic.
2623 PROMISE_FAKE_CAPABILITY = new PromiseCapability(Promise);
2624 Promise$prototype$then = Promise$prototype.then;
2625
2626 return Promise;
2627 }());
2628
2629 // Chrome's native Promise has extra methods that it shouldn't have. Let's remove them.
2630 if (globals.Promise) {
2631 delete globals.Promise.accept;
2632 delete globals.Promise.defer;
2633 delete globals.Promise.prototype.chain;
2634 }
2635
2636 if (typeof PromiseShim === 'function') {
2637 // export the Promise constructor.
2638 defineProperties(globals, { Promise: PromiseShim });
2639 // In Chrome 33 (and thereabouts) Promise is defined, but the
2640 // implementation is buggy in a number of ways. Let's check subclassing
2641 // support to see if we have a buggy implementation.
2642 var promiseSupportsSubclassing = supportsSubclassing(globals.Promise, function (S) {
2643 return S.resolve(42).then(function () {}) instanceof S;
2644 });
2645 var promiseIgnoresNonFunctionThenCallbacks = !throwsError(function () {
2646 return globals.Promise.reject(42).then(null, 5).then(null, noop);
2647 });
2648 var promiseRequiresObjectContext = throwsError(function () { return globals.Promise.call(3, noop); });
2649 // Promise.resolve() was errata'ed late in the ES6 process.
2650 // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1170742
2651 // https://code.google.com/p/v8/issues/detail?id=4161
2652 // It serves as a proxy for a number of other bugs in early Promise
2653 // implementations.
2654 var promiseResolveBroken = (function (Promise) {
2655 var p = Promise.resolve(5);
2656 p.constructor = {};
2657 var p2 = Promise.resolve(p);
2658 try {
2659 p2.then(null, noop).then(null, noop); // avoid "uncaught rejection" warnings in console
2660 } catch (e) {
2661 return true; // v8 native Promises break here https://code.google.com/p/chromium/issues/detail?id=575314
2662 }
2663 return p === p2; // This *should* be false!
2664 }(globals.Promise));
2665
2666 // Chrome 46 (probably older too) does not retrieve a thenable's .then synchronously
2667 var getsThenSynchronously = supportsDescriptors && (function () {
2668 var count = 0;
2669 // eslint-disable-next-line getter-return
2670 var thenable = Object.defineProperty({}, 'then', { get: function () { count += 1; } });
2671 Promise.resolve(thenable);
2672 return count === 1;
2673 }());
2674
2675 var BadResolverPromise = function BadResolverPromise(executor) {
2676 var p = new Promise(executor);
2677 executor(3, function () {});
2678 this.then = p.then;
2679 this.constructor = BadResolverPromise;
2680 };
2681 BadResolverPromise.prototype = Promise.prototype;
2682 BadResolverPromise.all = Promise.all;
2683 // Chrome Canary 49 (probably older too) has some implementation bugs
2684 var hasBadResolverPromise = valueOrFalseIfThrows(function () {
2685 return !!BadResolverPromise.all([1, 2]);
2686 });
2687
2688 if (
2689 !promiseSupportsSubclassing
2690 || !promiseIgnoresNonFunctionThenCallbacks
2691 || !promiseRequiresObjectContext
2692 || promiseResolveBroken
2693 || !getsThenSynchronously
2694 || hasBadResolverPromise
2695 ) {
2696 Promise = PromiseShim; // eslint-disable-line no-global-assign
2697 overrideNative(globals, 'Promise', PromiseShim);
2698 }
2699 if (Promise.all.length !== 1) {
2700 var origAll = Promise.all;
2701 overrideNative(Promise, 'all', function all(iterable) {
2702 return ES.Call(origAll, this, arguments);
2703 });
2704 }
2705 if (Promise.race.length !== 1) {
2706 var origRace = Promise.race;
2707 overrideNative(Promise, 'race', function race(iterable) {
2708 return ES.Call(origRace, this, arguments);
2709 });
2710 }
2711 if (Promise.resolve.length !== 1) {
2712 var origResolve = Promise.resolve;
2713 overrideNative(Promise, 'resolve', function resolve(x) {
2714 return ES.Call(origResolve, this, arguments);
2715 });
2716 }
2717 if (Promise.reject.length !== 1) {
2718 var origReject = Promise.reject;
2719 overrideNative(Promise, 'reject', function reject(r) {
2720 return ES.Call(origReject, this, arguments);
2721 });
2722 }
2723 ensureEnumerable(Promise, 'all');
2724 ensureEnumerable(Promise, 'race');
2725 ensureEnumerable(Promise, 'resolve');
2726 ensureEnumerable(Promise, 'reject');
2727 addDefaultSpecies(Promise);
2728 }
2729
2730 // Map and Set require a true ES5 environment
2731 // Their fast path also requires that the environment preserve
2732 // property insertion order, which is not guaranteed by the spec.
2733 var testOrder = function (a) {
2734 var b = keys(_reduce(a, function (o, k) {
2735 o[k] = true;
2736 return o;
2737 }, {}));
2738 return a.join(':') === b.join(':');
2739 };
2740 var preservesInsertionOrder = testOrder(['z', 'a', 'bb']);
2741 // some engines (eg, Chrome) only preserve insertion order for string keys
2742 var preservesNumericInsertionOrder = testOrder(['z', 1, 'a', '3', 2]);
2743
2744 if (supportsDescriptors) {
2745
2746 var fastkey = function fastkey(key, skipInsertionOrderCheck) {
2747 if (!skipInsertionOrderCheck && !preservesInsertionOrder) {
2748 return null;
2749 }
2750 if (isNullOrUndefined(key)) {
2751 return '^' + ES.ToString(key);
2752 } else if (typeof key === 'string') {
2753 return '$' + key;
2754 } else if (typeof key === 'number') {
2755 // note that -0 will get coerced to "0" when used as a property key
2756 if (!preservesNumericInsertionOrder) {
2757 return 'n' + key;
2758 }
2759 return key;
2760 } else if (typeof key === 'boolean') {
2761 return 'b' + key;
2762 }
2763 return null;
2764 };
2765
2766 var emptyObject = function emptyObject() {
2767 // accomodate some older not-quite-ES5 browsers
2768 return Object.create ? Object.create(null) : {};
2769 };
2770
2771 var addIterableToMap = function addIterableToMap(MapConstructor, map, iterable) {
2772 if (isArray(iterable) || Type.string(iterable)) {
2773 _forEach(iterable, function (entry) {
2774 if (!ES.TypeIsObject(entry)) {
2775 throw new TypeError('Iterator value ' + entry + ' is not an entry object');
2776 }
2777 map.set(entry[0], entry[1]);
2778 });
2779 } else if (iterable instanceof MapConstructor) {
2780 _call(MapConstructor.prototype.forEach, iterable, function (value, key) {
2781 map.set(key, value);
2782 });
2783 } else {
2784 var iter, adder;
2785 if (!isNullOrUndefined(iterable)) {
2786 adder = map.set;
2787 if (!ES.IsCallable(adder)) { throw new TypeError('bad map'); }
2788 iter = ES.GetIterator(iterable);
2789 }
2790 if (typeof iter !== 'undefined') {
2791 while (true) {
2792 var next = ES.IteratorStep(iter);
2793 if (next === false) { break; }
2794 var nextItem = next.value;
2795 try {
2796 if (!ES.TypeIsObject(nextItem)) {
2797 throw new TypeError('Iterator value ' + nextItem + ' is not an entry object');
2798 }
2799 _call(adder, map, nextItem[0], nextItem[1]);
2800 } catch (e) {
2801 ES.IteratorClose(iter, true);
2802 throw e;
2803 }
2804 }
2805 }
2806 }
2807 };
2808 var addIterableToSet = function addIterableToSet(SetConstructor, set, iterable) {
2809 if (isArray(iterable) || Type.string(iterable)) {
2810 _forEach(iterable, function (value) {
2811 set.add(value);
2812 });
2813 } else if (iterable instanceof SetConstructor) {
2814 _call(SetConstructor.prototype.forEach, iterable, function (value) {
2815 set.add(value);
2816 });
2817 } else {
2818 var iter, adder;
2819 if (!isNullOrUndefined(iterable)) {
2820 adder = set.add;
2821 if (!ES.IsCallable(adder)) { throw new TypeError('bad set'); }
2822 iter = ES.GetIterator(iterable);
2823 }
2824 if (typeof iter !== 'undefined') {
2825 while (true) {
2826 var next = ES.IteratorStep(iter);
2827 if (next === false) { break; }
2828 var nextValue = next.value;
2829 try {
2830 _call(adder, set, nextValue);
2831 } catch (e) {
2832 ES.IteratorClose(iter, true);
2833 throw e;
2834 }
2835 }
2836 }
2837 }
2838 };
2839
2840 var collectionShims = {
2841 Map: (function () {
2842
2843 var empty = {};
2844
2845 var MapEntry = function MapEntry(key, value) {
2846 this.key = key;
2847 this.value = value;
2848 this.next = null;
2849 this.prev = null;
2850 };
2851
2852 MapEntry.prototype.isRemoved = function isRemoved() {
2853 return this.key === empty;
2854 };
2855
2856 var isMap = function isMap(map) {
2857 return !!map._es6map;
2858 };
2859
2860 var requireMapSlot = function requireMapSlot(map, method) {
2861 if (!ES.TypeIsObject(map) || !isMap(map)) {
2862 throw new TypeError('Method Map.prototype.' + method + ' called on incompatible receiver ' + ES.ToString(map));
2863 }
2864 };
2865
2866 var MapIterator = function MapIterator(map, kind) {
2867 requireMapSlot(map, '[[MapIterator]]');
2868 defineProperty(this, 'head', map._head);
2869 defineProperty(this, 'i', this.head);
2870 defineProperty(this, 'kind', kind);
2871 };
2872
2873 MapIterator.prototype = {
2874 isMapIterator: true,
2875 next: function next() {
2876 if (!this.isMapIterator) {
2877 throw new TypeError('Not a MapIterator');
2878 }
2879 var i = this.i;
2880 var kind = this.kind;
2881 var head = this.head;
2882 if (typeof this.i === 'undefined') {
2883 return iteratorResult();
2884 }
2885 while (i.isRemoved() && i !== head) {
2886 // back up off of removed entries
2887 i = i.prev;
2888 }
2889 // advance to next unreturned element.
2890 var result;
2891 while (i.next !== head) {
2892 i = i.next;
2893 if (!i.isRemoved()) {
2894 if (kind === 'key') {
2895 result = i.key;
2896 } else if (kind === 'value') {
2897 result = i.value;
2898 } else {
2899 result = [i.key, i.value];
2900 }
2901 this.i = i;
2902 return iteratorResult(result);
2903 }
2904 }
2905 // once the iterator is done, it is done forever.
2906 this.i = void 0;
2907 return iteratorResult();
2908 }
2909 };
2910 addIterator(MapIterator.prototype);
2911
2912 var Map$prototype;
2913 var MapShim = function Map() {
2914 if (!(this instanceof Map)) {
2915 throw new TypeError('Constructor Map requires "new"');
2916 }
2917 if (this && this._es6map) {
2918 throw new TypeError('Bad construction');
2919 }
2920 var map = emulateES6construct(this, Map, Map$prototype, {
2921 _es6map: true,
2922 _head: null,
2923 _map: OrigMap ? new OrigMap() : null,
2924 _size: 0,
2925 _storage: emptyObject()
2926 });
2927
2928 var head = new MapEntry(null, null);
2929 // circular doubly-linked list.
2930 /* eslint no-multi-assign: 1 */
2931 head.next = head.prev = head;
2932 map._head = head;
2933
2934 // Optionally initialize map from iterable
2935 if (arguments.length > 0) {
2936 addIterableToMap(Map, map, arguments[0]);
2937 }
2938 return map;
2939 };
2940 Map$prototype = MapShim.prototype;
2941
2942 Value.getter(Map$prototype, 'size', function () {
2943 if (typeof this._size === 'undefined') {
2944 throw new TypeError('size method called on incompatible Map');
2945 }
2946 return this._size;
2947 });
2948
2949 defineProperties(Map$prototype, {
2950 get: function get(key) {
2951 requireMapSlot(this, 'get');
2952 var entry;
2953 var fkey = fastkey(key, true);
2954 if (fkey !== null) {
2955 // fast O(1) path
2956 entry = this._storage[fkey];
2957 if (entry) {
2958 return entry.value;
2959 }
2960 return;
2961
2962 }
2963 if (this._map) {
2964 // fast object key path
2965 entry = origMapGet.call(this._map, key);
2966 if (entry) {
2967 return entry.value;
2968 }
2969 return;
2970
2971 }
2972 var head = this._head;
2973 var i = head;
2974 while ((i = i.next) !== head) {
2975 if (ES.SameValueZero(i.key, key)) {
2976 return i.value;
2977 }
2978 }
2979 },
2980
2981 has: function has(key) {
2982 requireMapSlot(this, 'has');
2983 var fkey = fastkey(key, true);
2984 if (fkey !== null) {
2985 // fast O(1) path
2986 return typeof this._storage[fkey] !== 'undefined';
2987 }
2988 if (this._map) {
2989 // fast object key path
2990 return origMapHas.call(this._map, key);
2991 }
2992 var head = this._head;
2993 var i = head;
2994 while ((i = i.next) !== head) {
2995 if (ES.SameValueZero(i.key, key)) {
2996 return true;
2997 }
2998 }
2999 return false;
3000 },
3001
3002 set: function set(key, value) {
3003 requireMapSlot(this, 'set');
3004 var head = this._head;
3005 var i = head;
3006 var entry;
3007 var fkey = fastkey(key, true);
3008 if (fkey !== null) {
3009 // fast O(1) path
3010 if (typeof this._storage[fkey] !== 'undefined') {
3011 this._storage[fkey].value = value;
3012 return this;
3013 }
3014 entry = this._storage[fkey] = new MapEntry(key, value); /* eslint no-multi-assign: 1 */
3015 i = head.prev;
3016 // fall through
3017
3018 } else if (this._map) {
3019 // fast object key path
3020 if (origMapHas.call(this._map, key)) {
3021 origMapGet.call(this._map, key).value = value;
3022 } else {
3023 entry = new MapEntry(key, value);
3024 origMapSet.call(this._map, key, entry);
3025 i = head.prev;
3026 // fall through
3027 }
3028 }
3029 while ((i = i.next) !== head) {
3030 if (ES.SameValueZero(i.key, key)) {
3031 i.value = value;
3032 return this;
3033 }
3034 }
3035 entry = entry || new MapEntry(key, value);
3036 if (ES.SameValue(-0, key)) {
3037 entry.key = +0; // coerce -0 to +0 in entry
3038 }
3039 entry.next = this._head;
3040 entry.prev = this._head.prev;
3041 entry.prev.next = entry;
3042 entry.next.prev = entry;
3043 this._size += 1;
3044 return this;
3045 },
3046
3047 'delete': function (key) {
3048 requireMapSlot(this, 'delete');
3049 var head = this._head;
3050 var i = head;
3051 var fkey = fastkey(key, true);
3052 if (fkey !== null) {
3053 // fast O(1) path
3054 if (typeof this._storage[fkey] === 'undefined') {
3055 return false;
3056 }
3057 i = this._storage[fkey].prev;
3058 delete this._storage[fkey];
3059 // fall through
3060 } else if (this._map) {
3061 // fast object key path
3062 if (!origMapHas.call(this._map, key)) {
3063 return false;
3064 }
3065 i = origMapGet.call(this._map, key).prev;
3066 origMapDelete.call(this._map, key);
3067 // fall through
3068 }
3069 while ((i = i.next) !== head) {
3070 if (ES.SameValueZero(i.key, key)) {
3071 i.key = empty;
3072 i.value = empty;
3073 i.prev.next = i.next;
3074 i.next.prev = i.prev;
3075 this._size -= 1;
3076 return true;
3077 }
3078 }
3079 return false;
3080 },
3081
3082 clear: function clear() {
3083 /* eslint no-multi-assign: 1 */
3084 requireMapSlot(this, 'clear');
3085 this._map = OrigMap ? new OrigMap() : null;
3086 this._size = 0;
3087 this._storage = emptyObject();
3088 var head = this._head;
3089 var i = head;
3090 var p = i.next;
3091 while ((i = p) !== head) {
3092 i.key = empty;
3093 i.value = empty;
3094 p = i.next;
3095 i.next = i.prev = head;
3096 }
3097 head.next = head.prev = head;
3098 },
3099
3100 keys: function keys() {
3101 requireMapSlot(this, 'keys');
3102 return new MapIterator(this, 'key');
3103 },
3104
3105 values: function values() {
3106 requireMapSlot(this, 'values');
3107 return new MapIterator(this, 'value');
3108 },
3109
3110 entries: function entries() {
3111 requireMapSlot(this, 'entries');
3112 return new MapIterator(this, 'key+value');
3113 },
3114
3115 forEach: function forEach(callback) {
3116 requireMapSlot(this, 'forEach');
3117 var context = arguments.length > 1 ? arguments[1] : null;
3118 var it = this.entries();
3119 for (var entry = it.next(); !entry.done; entry = it.next()) {
3120 if (context) {
3121 _call(callback, context, entry.value[1], entry.value[0], this);
3122 } else {
3123 callback(entry.value[1], entry.value[0], this);
3124 }
3125 }
3126 }
3127 });
3128 addIterator(Map$prototype, Map$prototype.entries);
3129
3130 return MapShim;
3131 }()),
3132
3133 Set: (function () {
3134 var isSet = function isSet(set) {
3135 return set._es6set && typeof set._storage !== 'undefined';
3136 };
3137 var requireSetSlot = function requireSetSlot(set, method) {
3138 if (!ES.TypeIsObject(set) || !isSet(set)) {
3139 // https://github.com/paulmillr/es6-shim/issues/176
3140 throw new TypeError('Set.prototype.' + method + ' called on incompatible receiver ' + ES.ToString(set));
3141 }
3142 };
3143
3144 // Creating a Map is expensive. To speed up the common case of
3145 // Sets containing only string or numeric keys, we use an object
3146 // as backing storage and lazily create a full Map only when
3147 // required.
3148 var Set$prototype;
3149 var SetShim = function Set() {
3150 if (!(this instanceof Set)) {
3151 throw new TypeError('Constructor Set requires "new"');
3152 }
3153 if (this && this._es6set) {
3154 throw new TypeError('Bad construction');
3155 }
3156 var set = emulateES6construct(this, Set, Set$prototype, {
3157 _es6set: true,
3158 '[[SetData]]': null,
3159 _storage: emptyObject()
3160 });
3161 if (!set._es6set) {
3162 throw new TypeError('bad set');
3163 }
3164
3165 // Optionally initialize Set from iterable
3166 if (arguments.length > 0) {
3167 addIterableToSet(Set, set, arguments[0]);
3168 }
3169 return set;
3170 };
3171 Set$prototype = SetShim.prototype;
3172
3173 var decodeKey = function (key) {
3174 var k = key;
3175 if (k === '^null') {
3176 return null;
3177 } else if (k === '^undefined') {
3178 return void 0;
3179 }
3180 var first = k.charAt(0);
3181 if (first === '$') {
3182 return _strSlice(k, 1);
3183 } else if (first === 'n') {
3184 return +_strSlice(k, 1);
3185 } else if (first === 'b') {
3186 return k === 'btrue';
3187 }
3188
3189 return +k;
3190 };
3191 // Switch from the object backing storage to a full Map.
3192 var ensureMap = function ensureMap(set) {
3193 if (!set['[[SetData]]']) {
3194 var m = new collectionShims.Map();
3195 set['[[SetData]]'] = m;
3196 _forEach(keys(set._storage), function (key) {
3197 var k = decodeKey(key);
3198 m.set(k, k);
3199 });
3200 set['[[SetData]]'] = m;
3201 }
3202 set._storage = null; // free old backing storage
3203 };
3204
3205 Value.getter(SetShim.prototype, 'size', function () {
3206 requireSetSlot(this, 'size');
3207 if (this._storage) {
3208 return keys(this._storage).length;
3209 }
3210 ensureMap(this);
3211 return this['[[SetData]]'].size;
3212 });
3213
3214 defineProperties(SetShim.prototype, {
3215 has: function has(key) {
3216 requireSetSlot(this, 'has');
3217 var fkey;
3218 if (this._storage && (fkey = fastkey(key)) !== null) {
3219 return !!this._storage[fkey];
3220 }
3221 ensureMap(this);
3222 return this['[[SetData]]'].has(key);
3223 },
3224
3225 add: function add(key) {
3226 requireSetSlot(this, 'add');
3227 var fkey;
3228 if (this._storage && (fkey = fastkey(key)) !== null) {
3229 this._storage[fkey] = true;
3230 return this;
3231 }
3232 ensureMap(this);
3233 this['[[SetData]]'].set(key, key);
3234 return this;
3235 },
3236
3237 'delete': function (key) {
3238 requireSetSlot(this, 'delete');
3239 var fkey;
3240 if (this._storage && (fkey = fastkey(key)) !== null) {
3241 var hasFKey = _hasOwnProperty(this._storage, fkey);
3242 return (delete this._storage[fkey]) && hasFKey;
3243 }
3244 ensureMap(this);
3245 return this['[[SetData]]']['delete'](key);
3246 },
3247
3248 clear: function clear() {
3249 requireSetSlot(this, 'clear');
3250 if (this._storage) {
3251 this._storage = emptyObject();
3252 }
3253 if (this['[[SetData]]']) {
3254 this['[[SetData]]'].clear();
3255 }
3256 },
3257
3258 values: function values() {
3259 requireSetSlot(this, 'values');
3260 ensureMap(this);
3261 return new SetIterator(this['[[SetData]]'].values());
3262 },
3263
3264 entries: function entries() {
3265 requireSetSlot(this, 'entries');
3266 ensureMap(this);
3267 return new SetIterator(this['[[SetData]]'].entries());
3268 },
3269
3270 forEach: function forEach(callback) {
3271 requireSetSlot(this, 'forEach');
3272 var context = arguments.length > 1 ? arguments[1] : null;
3273 var entireSet = this;
3274 ensureMap(entireSet);
3275 this['[[SetData]]'].forEach(function (value, key) {
3276 if (context) {
3277 _call(callback, context, key, key, entireSet);
3278 } else {
3279 callback(key, key, entireSet);
3280 }
3281 });
3282 }
3283 });
3284 defineProperty(SetShim.prototype, 'keys', SetShim.prototype.values, true);
3285 addIterator(SetShim.prototype, SetShim.prototype.values);
3286
3287 var SetIterator = function SetIterator(it) {
3288 defineProperty(this, 'it', it);
3289 };
3290 SetIterator.prototype = {
3291 isSetIterator: true,
3292 next: function next() {
3293 if (!this.isSetIterator) {
3294 throw new TypeError('Not a SetIterator');
3295 }
3296 return this.it.next();
3297 }
3298 };
3299 addIterator(SetIterator.prototype);
3300
3301 return SetShim;
3302 }())
3303 };
3304
3305 var isGoogleTranslate = globals.Set && !Set.prototype['delete'] && Set.prototype.remove && Set.prototype.items && Set.prototype.map && Array.isArray(new Set().keys);
3306 if (isGoogleTranslate) {
3307 // special-case force removal of wildly invalid Set implementation in Google Translate iframes
3308 // see https://github.com/paulmillr/es6-shim/issues/438 / https://twitter.com/ljharb/status/849335573114363904
3309 globals.Set = collectionShims.Set;
3310 }
3311 if (globals.Map || globals.Set) {
3312 // Safari 8, for example, doesn't accept an iterable.
3313 var mapAcceptsArguments = valueOrFalseIfThrows(function () { return new Map([[1, 2]]).get(1) === 2; });
3314 if (!mapAcceptsArguments) {
3315 globals.Map = function Map() {
3316 if (!(this instanceof Map)) {
3317 throw new TypeError('Constructor Map requires "new"');
3318 }
3319 var m = new OrigMap();
3320 if (arguments.length > 0) {
3321 addIterableToMap(Map, m, arguments[0]);
3322 }
3323 delete m.constructor;
3324 Object.setPrototypeOf(m, globals.Map.prototype);
3325 return m;
3326 };
3327 globals.Map.prototype = create(OrigMap.prototype);
3328 defineProperty(globals.Map.prototype, 'constructor', globals.Map, true);
3329 Value.preserveToString(globals.Map, OrigMap);
3330 }
3331 var testMap = new Map();
3332 var mapUsesSameValueZero = (function () {
3333 // Chrome 38-42, node 0.11/0.12, iojs 1/2 also have a bug when the Map has a size > 4
3334 var m = new Map([[1, 0], [2, 0], [3, 0], [4, 0]]);
3335 m.set(-0, m);
3336 return m.get(0) === m && m.get(-0) === m && m.has(0) && m.has(-0);
3337 }());
3338 var mapSupportsChaining = testMap.set(1, 2) === testMap;
3339 if (!mapUsesSameValueZero || !mapSupportsChaining) {
3340 overrideNative(Map.prototype, 'set', function set(k, v) {
3341 _call(origMapSet, this, k === 0 ? 0 : k, v);
3342 return this;
3343 });
3344 }
3345 if (!mapUsesSameValueZero) {
3346 defineProperties(Map.prototype, {
3347 get: function get(k) {
3348 return _call(origMapGet, this, k === 0 ? 0 : k);
3349 },
3350 has: function has(k) {
3351 return _call(origMapHas, this, k === 0 ? 0 : k);
3352 }
3353 }, true);
3354 Value.preserveToString(Map.prototype.get, origMapGet);
3355 Value.preserveToString(Map.prototype.has, origMapHas);
3356 }
3357 var testSet = new Set();
3358 var setUsesSameValueZero = Set.prototype['delete'] && Set.prototype.add && Set.prototype.has && (function (s) {
3359 s['delete'](0);
3360 s.add(-0);
3361 return !s.has(0);
3362 }(testSet));
3363 var setSupportsChaining = testSet.add(1) === testSet;
3364 if (!setUsesSameValueZero || !setSupportsChaining) {
3365 var origSetAdd = Set.prototype.add;
3366 Set.prototype.add = function add(v) {
3367 _call(origSetAdd, this, v === 0 ? 0 : v);
3368 return this;
3369 };
3370 Value.preserveToString(Set.prototype.add, origSetAdd);
3371 }
3372 if (!setUsesSameValueZero) {
3373 var origSetHas = Set.prototype.has;
3374 Set.prototype.has = function has(v) {
3375 return _call(origSetHas, this, v === 0 ? 0 : v);
3376 };
3377 Value.preserveToString(Set.prototype.has, origSetHas);
3378 var origSetDel = Set.prototype['delete'];
3379 Set.prototype['delete'] = function SetDelete(v) {
3380 return _call(origSetDel, this, v === 0 ? 0 : v);
3381 };
3382 Value.preserveToString(Set.prototype['delete'], origSetDel);
3383 }
3384 var mapSupportsSubclassing = supportsSubclassing(globals.Map, function (M) {
3385 var m = new M([]);
3386 // Firefox 32 is ok with the instantiating the subclass but will
3387 // throw when the map is used.
3388 m.set(42, 42);
3389 return m instanceof M;
3390 });
3391 // without Object.setPrototypeOf, subclassing is not possible
3392 var mapFailsToSupportSubclassing = Object.setPrototypeOf && !mapSupportsSubclassing;
3393 var mapRequiresNew = (function () {
3394 try {
3395 return !(globals.Map() instanceof globals.Map);
3396 } catch (e) {
3397 return e instanceof TypeError;
3398 }
3399 }());
3400 if (globals.Map.length !== 0 || mapFailsToSupportSubclassing || !mapRequiresNew) {
3401 globals.Map = function Map() {
3402 if (!(this instanceof Map)) {
3403 throw new TypeError('Constructor Map requires "new"');
3404 }
3405 var m = new OrigMap();
3406 if (arguments.length > 0) {
3407 addIterableToMap(Map, m, arguments[0]);
3408 }
3409 delete m.constructor;
3410 Object.setPrototypeOf(m, Map.prototype);
3411 return m;
3412 };
3413 globals.Map.prototype = OrigMap.prototype;
3414 defineProperty(globals.Map.prototype, 'constructor', globals.Map, true);
3415 Value.preserveToString(globals.Map, OrigMap);
3416 }
3417 var setSupportsSubclassing = supportsSubclassing(globals.Set, function (S) {
3418 var s = new S([]);
3419 s.add(42, 42);
3420 return s instanceof S;
3421 });
3422 // without Object.setPrototypeOf, subclassing is not possible
3423 var setFailsToSupportSubclassing = Object.setPrototypeOf && !setSupportsSubclassing;
3424 var setRequiresNew = (function () {
3425 try {
3426 return !(globals.Set() instanceof globals.Set);
3427 } catch (e) {
3428 return e instanceof TypeError;
3429 }
3430 }());
3431 if (globals.Set.length !== 0 || setFailsToSupportSubclassing || !setRequiresNew) {
3432 var OrigSet = globals.Set;
3433 globals.Set = function Set() {
3434 if (!(this instanceof Set)) {
3435 throw new TypeError('Constructor Set requires "new"');
3436 }
3437 var s = new OrigSet();
3438 if (arguments.length > 0) {
3439 addIterableToSet(Set, s, arguments[0]);
3440 }
3441 delete s.constructor;
3442 Object.setPrototypeOf(s, Set.prototype);
3443 return s;
3444 };
3445 globals.Set.prototype = OrigSet.prototype;
3446 defineProperty(globals.Set.prototype, 'constructor', globals.Set, true);
3447 Value.preserveToString(globals.Set, OrigSet);
3448 }
3449 var newMap = new globals.Map();
3450 var mapIterationThrowsStopIterator = !valueOrFalseIfThrows(function () {
3451 return newMap.keys().next().done;
3452 });
3453 /*
3454 - In Firefox < 23, Map#size is a function.
3455 - In all current Firefox, Set#entries/keys/values & Map#clear do not exist
3456 - https://bugzilla.mozilla.org/show_bug.cgi?id=869996
3457 - In Firefox 24, Map and Set do not implement forEach
3458 - In Firefox 25 at least, Map and Set are callable without "new"
3459 */
3460 if (
3461 typeof globals.Map.prototype.clear !== 'function'
3462 || new globals.Set().size !== 0
3463 || newMap.size !== 0
3464 || typeof globals.Map.prototype.keys !== 'function'
3465 || typeof globals.Set.prototype.keys !== 'function'
3466 || typeof globals.Map.prototype.forEach !== 'function'
3467 || typeof globals.Set.prototype.forEach !== 'function'
3468 || isCallableWithoutNew(globals.Map)
3469 || isCallableWithoutNew(globals.Set)
3470 || typeof newMap.keys().next !== 'function' // Safari 8
3471 || mapIterationThrowsStopIterator // Firefox 25
3472 || !mapSupportsSubclassing
3473 ) {
3474 defineProperties(globals, {
3475 Map: collectionShims.Map,
3476 Set: collectionShims.Set
3477 }, true);
3478 }
3479
3480 if (globals.Set.prototype.keys !== globals.Set.prototype.values) {
3481 // Fixed in WebKit with https://bugs.webkit.org/show_bug.cgi?id=144190
3482 defineProperty(globals.Set.prototype, 'keys', globals.Set.prototype.values, true);
3483 }
3484
3485 // Shim incomplete iterator implementations.
3486 addIterator(Object.getPrototypeOf((new globals.Map()).keys()));
3487 addIterator(Object.getPrototypeOf((new globals.Set()).keys()));
3488
3489 if (functionsHaveNames && globals.Set.prototype.has.name !== 'has') {
3490 // Microsoft Edge v0.11.10074.0 is missing a name on Set#has
3491 var anonymousSetHas = globals.Set.prototype.has;
3492 overrideNative(globals.Set.prototype, 'has', function has(key) {
3493 return _call(anonymousSetHas, this, key);
3494 });
3495 }
3496 }
3497 defineProperties(globals, collectionShims);
3498 addDefaultSpecies(globals.Map);
3499 addDefaultSpecies(globals.Set);
3500 }
3501
3502 var throwUnlessTargetIsObject = function throwUnlessTargetIsObject(target) {
3503 if (!ES.TypeIsObject(target)) {
3504 throw new TypeError('target must be an object');
3505 }
3506 };
3507
3508 // Some Reflect methods are basically the same as
3509 // those on the Object global, except that a TypeError is thrown if
3510 // target isn't an object. As well as returning a boolean indicating
3511 // the success of the operation.
3512 var ReflectShims = {
3513 // Apply method in a functional form.
3514 apply: function apply() {
3515 return ES.Call(ES.Call, null, arguments);
3516 },
3517
3518 // New operator in a functional form.
3519 construct: function construct(constructor, args) {
3520 if (!ES.IsConstructor(constructor)) {
3521 throw new TypeError('First argument must be a constructor.');
3522 }
3523 var newTarget = arguments.length > 2 ? arguments[2] : constructor;
3524 if (!ES.IsConstructor(newTarget)) {
3525 throw new TypeError('new.target must be a constructor.');
3526 }
3527 return ES.Construct(constructor, args, newTarget, 'internal');
3528 },
3529
3530 // When deleting a non-existent or configurable property,
3531 // true is returned.
3532 // When attempting to delete a non-configurable property,
3533 // it will return false.
3534 deleteProperty: function deleteProperty(target, key) {
3535 throwUnlessTargetIsObject(target);
3536 if (supportsDescriptors) {
3537 var desc = Object.getOwnPropertyDescriptor(target, key);
3538
3539 if (desc && !desc.configurable) {
3540 return false;
3541 }
3542 }
3543
3544 // Will return true.
3545 return delete target[key];
3546 },
3547
3548 has: function has(target, key) {
3549 throwUnlessTargetIsObject(target);
3550 return key in target;
3551 }
3552 };
3553
3554 if (Object.getOwnPropertyNames) {
3555 Object.assign(ReflectShims, {
3556 // Basically the result of calling the internal [[OwnPropertyKeys]].
3557 // Concatenating propertyNames and propertySymbols should do the trick.
3558 // This should continue to work together with a Symbol shim
3559 // which overrides Object.getOwnPropertyNames and implements
3560 // Object.getOwnPropertySymbols.
3561 ownKeys: function ownKeys(target) {
3562 throwUnlessTargetIsObject(target);
3563 var keys = Object.getOwnPropertyNames(target);
3564
3565 if (ES.IsCallable(Object.getOwnPropertySymbols)) {
3566 _pushApply(keys, Object.getOwnPropertySymbols(target));
3567 }
3568
3569 return keys;
3570 }
3571 });
3572 }
3573
3574 var callAndCatchException = function ConvertExceptionToBoolean(func) {
3575 return !throwsError(func);
3576 };
3577
3578 if (Object.preventExtensions) {
3579 Object.assign(ReflectShims, {
3580 isExtensible: function isExtensible(target) {
3581 throwUnlessTargetIsObject(target);
3582 return Object.isExtensible(target);
3583 },
3584 preventExtensions: function preventExtensions(target) {
3585 throwUnlessTargetIsObject(target);
3586 return callAndCatchException(function () {
3587 return Object.preventExtensions(target);
3588 });
3589 }
3590 });
3591 }
3592
3593 if (supportsDescriptors) {
3594 var internalGet = function get(target, key, receiver) {
3595 var desc = Object.getOwnPropertyDescriptor(target, key);
3596
3597 if (!desc) {
3598 var parent = Object.getPrototypeOf(target);
3599
3600 if (parent === null) {
3601 return void 0;
3602 }
3603
3604 return internalGet(parent, key, receiver);
3605 }
3606
3607 if ('value' in desc) {
3608 return desc.value;
3609 }
3610
3611 if (desc.get) {
3612 return ES.Call(desc.get, receiver);
3613 }
3614
3615 return void 0;
3616 };
3617
3618 var internalSet = function set(target, key, value, receiver) {
3619 var desc = Object.getOwnPropertyDescriptor(target, key);
3620
3621 if (!desc) {
3622 var parent = Object.getPrototypeOf(target);
3623
3624 if (parent !== null) {
3625 return internalSet(parent, key, value, receiver);
3626 }
3627
3628 desc = {
3629 value: void 0,
3630 writable: true,
3631 enumerable: true,
3632 configurable: true
3633 };
3634 }
3635
3636 if ('value' in desc) {
3637 if (!desc.writable) {
3638 return false;
3639 }
3640
3641 if (!ES.TypeIsObject(receiver)) {
3642 return false;
3643 }
3644
3645 var existingDesc = Object.getOwnPropertyDescriptor(receiver, key);
3646
3647 if (existingDesc) {
3648 return Reflect.defineProperty(receiver, key, {
3649 value: value
3650 });
3651 }
3652 return Reflect.defineProperty(receiver, key, {
3653 value: value,
3654 writable: true,
3655 enumerable: true,
3656 configurable: true
3657 });
3658
3659 }
3660
3661 if (desc.set) {
3662 _call(desc.set, receiver, value);
3663 return true;
3664 }
3665
3666 return false;
3667 };
3668
3669 Object.assign(ReflectShims, {
3670 defineProperty: function defineProperty(target, propertyKey, attributes) {
3671 throwUnlessTargetIsObject(target);
3672 return callAndCatchException(function () {
3673 return Object.defineProperty(target, propertyKey, attributes);
3674 });
3675 },
3676
3677 getOwnPropertyDescriptor: function getOwnPropertyDescriptor(target, propertyKey) {
3678 throwUnlessTargetIsObject(target);
3679 return Object.getOwnPropertyDescriptor(target, propertyKey);
3680 },
3681
3682 // Syntax in a functional form.
3683 get: function get(target, key) {
3684 throwUnlessTargetIsObject(target);
3685 var receiver = arguments.length > 2 ? arguments[2] : target;
3686
3687 return internalGet(target, key, receiver);
3688 },
3689
3690 set: function set(target, key, value) {
3691 throwUnlessTargetIsObject(target);
3692 var receiver = arguments.length > 3 ? arguments[3] : target;
3693
3694 return internalSet(target, key, value, receiver);
3695 }
3696 });
3697 }
3698
3699 if (Object.getPrototypeOf) {
3700 var objectDotGetPrototypeOf = Object.getPrototypeOf;
3701 ReflectShims.getPrototypeOf = function getPrototypeOf(target) {
3702 throwUnlessTargetIsObject(target);
3703 return objectDotGetPrototypeOf(target);
3704 };
3705 }
3706
3707 if (Object.setPrototypeOf && ReflectShims.getPrototypeOf) {
3708 var willCreateCircularPrototype = function (object, lastProto) {
3709 var proto = lastProto;
3710 while (proto) {
3711 if (object === proto) {
3712 return true;
3713 }
3714 proto = ReflectShims.getPrototypeOf(proto);
3715 }
3716 return false;
3717 };
3718
3719 Object.assign(ReflectShims, {
3720 // Sets the prototype of the given object.
3721 // Returns true on success, otherwise false.
3722 setPrototypeOf: function setPrototypeOf(object, proto) {
3723 throwUnlessTargetIsObject(object);
3724 if (proto !== null && !ES.TypeIsObject(proto)) {
3725 throw new TypeError('proto must be an object or null');
3726 }
3727
3728 // If they already are the same, we're done.
3729 if (proto === Reflect.getPrototypeOf(object)) {
3730 return true;
3731 }
3732
3733 // Cannot alter prototype if object not extensible.
3734 if (Reflect.isExtensible && !Reflect.isExtensible(object)) {
3735 return false;
3736 }
3737
3738 // Ensure that we do not create a circular prototype chain.
3739 if (willCreateCircularPrototype(object, proto)) {
3740 return false;
3741 }
3742
3743 Object.setPrototypeOf(object, proto);
3744
3745 return true;
3746 }
3747 });
3748 }
3749 var defineOrOverrideReflectProperty = function (key, shim) {
3750 if (!ES.IsCallable(globals.Reflect[key])) {
3751 defineProperty(globals.Reflect, key, shim);
3752 } else {
3753 var acceptsPrimitives = valueOrFalseIfThrows(function () {
3754 globals.Reflect[key](1);
3755 globals.Reflect[key](NaN);
3756 globals.Reflect[key](true);
3757 return true;
3758 });
3759 if (acceptsPrimitives) {
3760 overrideNative(globals.Reflect, key, shim);
3761 }
3762 }
3763 };
3764 Object.keys(ReflectShims).forEach(function (key) {
3765 defineOrOverrideReflectProperty(key, ReflectShims[key]);
3766 });
3767 var originalReflectGetProto = globals.Reflect.getPrototypeOf;
3768 if (functionsHaveNames && originalReflectGetProto && originalReflectGetProto.name !== 'getPrototypeOf') {
3769 overrideNative(globals.Reflect, 'getPrototypeOf', function getPrototypeOf(target) {
3770 return _call(originalReflectGetProto, globals.Reflect, target);
3771 });
3772 }
3773 if (globals.Reflect.setPrototypeOf) {
3774 if (valueOrFalseIfThrows(function () {
3775 globals.Reflect.setPrototypeOf(1, {});
3776 return true;
3777 })) {
3778 overrideNative(globals.Reflect, 'setPrototypeOf', ReflectShims.setPrototypeOf);
3779 }
3780 }
3781 if (globals.Reflect.defineProperty) {
3782 if (!valueOrFalseIfThrows(function () {
3783 var basic = !globals.Reflect.defineProperty(1, 'test', { value: 1 });
3784 // "extensible" fails on Edge 0.12
3785 var extensible = typeof Object.preventExtensions !== 'function' || !globals.Reflect.defineProperty(Object.preventExtensions({}), 'test', {});
3786 return basic && extensible;
3787 })) {
3788 overrideNative(globals.Reflect, 'defineProperty', ReflectShims.defineProperty);
3789 }
3790 }
3791 if (globals.Reflect.construct) {
3792 if (!valueOrFalseIfThrows(function () {
3793 var F = function F() {};
3794 return globals.Reflect.construct(function () {}, [], F) instanceof F;
3795 })) {
3796 overrideNative(globals.Reflect, 'construct', ReflectShims.construct);
3797 }
3798 }
3799
3800 if (String(new Date(NaN)) !== 'Invalid Date') {
3801 var dateToString = Date.prototype.toString;
3802 var shimmedDateToString = function toString() {
3803 var valueOf = +this;
3804 if (valueOf !== valueOf) {
3805 return 'Invalid Date';
3806 }
3807 return ES.Call(dateToString, this);
3808 };
3809 overrideNative(Date.prototype, 'toString', shimmedDateToString);
3810 }
3811
3812 // Annex B HTML methods
3813 // http://www.ecma-international.org/ecma-262/6.0/#sec-additional-properties-of-the-string.prototype-object
3814 var stringHTMLshims = {
3815 anchor: function anchor(name) { return ES.CreateHTML(this, 'a', 'name', name); },
3816 big: function big() { return ES.CreateHTML(this, 'big', '', ''); },
3817 blink: function blink() { return ES.CreateHTML(this, 'blink', '', ''); },
3818 bold: function bold() { return ES.CreateHTML(this, 'b', '', ''); },
3819 fixed: function fixed() { return ES.CreateHTML(this, 'tt', '', ''); },
3820 fontcolor: function fontcolor(color) { return ES.CreateHTML(this, 'font', 'color', color); },
3821 fontsize: function fontsize(size) { return ES.CreateHTML(this, 'font', 'size', size); },
3822 italics: function italics() { return ES.CreateHTML(this, 'i', '', ''); },
3823 link: function link(url) { return ES.CreateHTML(this, 'a', 'href', url); },
3824 small: function small() { return ES.CreateHTML(this, 'small', '', ''); },
3825 strike: function strike() { return ES.CreateHTML(this, 'strike', '', ''); },
3826 sub: function sub() { return ES.CreateHTML(this, 'sub', '', ''); },
3827 sup: function sub() { return ES.CreateHTML(this, 'sup', '', ''); }
3828 };
3829 _forEach(Object.keys(stringHTMLshims), function (key) {
3830 var method = String.prototype[key];
3831 var shouldOverwrite = false;
3832 if (ES.IsCallable(method)) {
3833 var output = _call(method, '', ' " ');
3834 var quotesCount = _concat([], output.match(/"/g)).length;
3835 shouldOverwrite = output !== output.toLowerCase() || quotesCount > 2;
3836 } else {
3837 shouldOverwrite = true;
3838 }
3839 if (shouldOverwrite) {
3840 overrideNative(String.prototype, key, stringHTMLshims[key]);
3841 }
3842 });
3843
3844 var JSONstringifiesSymbols = (function () {
3845 // Microsoft Edge v0.12 stringifies Symbols incorrectly
3846 if (!hasSymbols) { return false; } // Symbols are not supported
3847 var stringify = typeof JSON === 'object' && typeof JSON.stringify === 'function' ? JSON.stringify : null;
3848 if (!stringify) { return false; } // JSON.stringify is not supported
3849 if (typeof stringify(Symbol()) !== 'undefined') { return true; } // Symbols should become `undefined`
3850 if (stringify([Symbol()]) !== '[null]') { return true; } // Symbols in arrays should become `null`
3851 var obj = { a: Symbol() };
3852 obj[Symbol()] = true;
3853 if (stringify(obj) !== '{}') { return true; } // Symbol-valued keys *and* Symbol-valued properties should be omitted
3854 return false;
3855 }());
3856 var JSONstringifyAcceptsObjectSymbol = valueOrFalseIfThrows(function () {
3857 // Chrome 45 throws on stringifying object symbols
3858 if (!hasSymbols) { return true; } // Symbols are not supported
3859 return JSON.stringify(Object(Symbol())) === '{}' && JSON.stringify([Object(Symbol())]) === '[{}]';
3860 });
3861 if (JSONstringifiesSymbols || !JSONstringifyAcceptsObjectSymbol) {
3862 var origStringify = JSON.stringify;
3863 overrideNative(JSON, 'stringify', function stringify(value) {
3864 if (typeof value === 'symbol') { return; }
3865 var replacer;
3866 if (arguments.length > 1) {
3867 replacer = arguments[1];
3868 }
3869 var args = [value];
3870 if (!isArray(replacer)) {
3871 var replaceFn = ES.IsCallable(replacer) ? replacer : null;
3872 var wrappedReplacer = function (key, val) {
3873 var parsedValue = replaceFn ? _call(replaceFn, this, key, val) : val;
3874 if (typeof parsedValue !== 'symbol') {
3875 if (Type.symbol(parsedValue)) {
3876 return assignTo({})(parsedValue);
3877 }
3878 return parsedValue;
3879
3880 }
3881 };
3882 args.push(wrappedReplacer);
3883 } else {
3884 // create wrapped replacer that handles an array replacer?
3885 args.push(replacer);
3886 }
3887 if (arguments.length > 2) {
3888 args.push(arguments[2]);
3889 }
3890 return origStringify.apply(this, args);
3891 });
3892 }
3893
3894 return globals;
3895}));