· 5 years ago · Feb 24, 2020, 09:04 PM
1/* Polyfill service v3.44.0
2 * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
3 *
4 * Features requested: Array.prototype.findIndex,Array.prototype.flat,Array.prototype.includes,Number.parseFloat,Object.entries,String.prototype.repeat,default,fetch
5 *
6 * - _DOMTokenList, License: ISC (required by "DOMTokenList", "default")
7 * - _ESAbstract.ArrayCreate, License: CC0 (required by "Array.from", "default", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
8 * - _ESAbstract.Call, License: CC0 (required by "Array.prototype.findIndex", "Array.from", "default", "_ESAbstract.FlattenIntoArray", "Array.prototype.flat", "Array.prototype.forEach", "fetch", "URL", "_ESAbstract.GetIterator", "Map", "Set", "_ESAbstract.IteratorClose", "_ESAbstract.IteratorNext", "_ESAbstract.IteratorStep", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.includes", "String.prototype.repeat", "Array.of", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor", "Object.assign", "Array.prototype.filter", "Symbol", "Symbol.iterator", "Array.prototype.map", "_ESAbstract.OrdinaryToPrimitive")
9 * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.from", "default", "Array.of", "_ESAbstract.FlattenIntoArray", "Array.prototype.flat", "_ESAbstract.CreateIterResultObject", "Map", "Set")
10 * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.from", "default", "Array.of", "_ESAbstract.FlattenIntoArray", "Array.prototype.flat", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.iterator", "fetch", "Array.prototype.map")
11 * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.prototype.findIndex", "Array.prototype.flat", "Array.prototype.includes", "Number.parseFloat", "Object.entries", "String.prototype.repeat", "Array.from", "default", "Array.of", "Array.prototype.fill", "Map", "Number.isNaN", "Object.assign", "Object.getOwnPropertyDescriptor", "Object.keys", "Set", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "String.prototype.trim", "Array.prototype.forEach", "fetch", "URL", "Object.getOwnPropertyNames", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "Array.isArray", "Object.create", "_ESAbstract.GetIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Symbol", "Symbol.iterator", "Object.isExtensible", "Function.prototype.bind", "Object.defineProperties", "Object.getPrototypeOf", "Array.prototype.filter", "Array.prototype.map", "Object.freeze")
12 * - _ESAbstract.Get, License: CC0 (required by "Array.prototype.findIndex", "Array.prototype.flat", "Array.prototype.includes", "Array.from", "default", "Array.prototype.fill", "Object.assign", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.FlattenIntoArray", "_ESAbstract.EnumerableOwnProperties", "Object.entries", "Array.prototype.forEach", "fetch", "URL", "_ESAbstract.IteratorValue", "Map", "Set", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Object.defineProperties", "Object.create", "_ESAbstract.GetIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "Symbol", "Symbol.iterator", "_ESAbstract.GetPrototypeFromConstructor", "Array.prototype.filter", "Array.prototype.map", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.repeat", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor")
13 * - _ESAbstract.HasOwnProperty, License: CC0 (required by "Object.getOwnPropertyDescriptor", "default", "Object.assign")
14 * - _ESAbstract.HasProperty, License: CC0 (required by "_ESAbstract.FlattenIntoArray", "Array.prototype.flat", "Array.prototype.forEach", "fetch", "URL", "default", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "Array.prototype.filter", "Symbol", "Map", "Array.from", "Set", "Symbol.iterator", "Array.prototype.map")
15 * - _ESAbstract.IsArray, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat", "_ESAbstract.FlattenIntoArray", "Array.isArray", "Map", "default", "Array.from", "Set", "URL")
16 * - _ESAbstract.IsCallable, License: CC0 (required by "Array.prototype.findIndex", "Array.from", "default", "Map", "Set", "Array.prototype.forEach", "fetch", "URL", "_ESAbstract.GetMethod", "Function.prototype.bind", "Object.getOwnPropertyDescriptor", "Object.assign", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat", "Array.prototype.filter", "Symbol", "Symbol.iterator", "Array.prototype.map", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.includes", "String.prototype.repeat", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToPropertyKey")
17 * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.repeat", "String.prototype.endsWith", "default", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.TrimString", "String.prototype.trim", "Number.parseFloat")
18 * - _ESAbstract.SameValueNonNumber, License: CC0 (required by "_ESAbstract.SameValueZero", "Array.prototype.includes", "Map", "default", "Array.from", "Set")
19 * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.findIndex", "_ESAbstract.IteratorComplete", "Map", "default", "Array.from", "Set", "_ESAbstract.IteratorStep", "_ESAbstract.IsRegExp", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "Array.prototype.filter", "Symbol", "Symbol.iterator", "fetch")
20 * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.flat", "Array.prototype.includes", "String.prototype.repeat", "Array.prototype.fill", "default", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToLength", "Array.prototype.findIndex", "Array.from", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent")
21 * - _ESAbstract.ToLength, License: CC0 (required by "Array.prototype.findIndex", "Array.prototype.flat", "Array.prototype.includes", "Array.from", "default", "Array.prototype.fill", "_ESAbstract.FlattenIntoArray", "Array.prototype.forEach", "fetch", "URL", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.iterator", "Array.prototype.map")
22 * - _ESAbstract.ToObject, License: CC0 (required by "Array.prototype.findIndex", "Array.prototype.flat", "Array.prototype.includes", "Object.entries", "Array.from", "default", "Array.prototype.fill", "Object.assign", "Object.getOwnPropertyDescriptor", "Array.prototype.forEach", "fetch", "URL", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "Object.defineProperties", "Object.create", "Map", "Set", "_ESAbstract.GetIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Symbol", "Symbol.iterator", "_ESAbstract.GetV", "_ESAbstract.GetMethod", "Array.prototype.filter", "Array.prototype.map")
23 * - _ESAbstract.GetV, License: CC0 (required by "_ESAbstract.GetMethod", "Array.from", "default", "Map", "Set", "_ESAbstract.GetIterator")
24 * - _ESAbstract.GetMethod, License: CC0 (required by "Array.from", "default", "Map", "Set", "_ESAbstract.IsConstructor", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat", "_ESAbstract.GetIterator", "_ESAbstract.IteratorClose", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.findIndex", "Array.prototype.includes", "String.prototype.repeat", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor", "Object.assign")
25 * - _ESAbstract.Type, License: CC0 (required by "Object.entries", "Map", "default", "Array.from", "Number.isNaN", "Object.getOwnPropertyDescriptor", "Object.assign", "_ESAbstract.ToString", "Array.prototype.findIndex", "Array.prototype.includes", "String.prototype.repeat", "Array.of", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat", "_ESAbstract.SameValueZero", "Set", "_ESAbstract.EnumerableOwnProperties", "_ESAbstract.IsConstructor", "_ESAbstract.GetIterator", "_ESAbstract.IteratorClose", "_ESAbstract.IteratorValue", "_ESAbstract.CreateIterResultObject", "_ESAbstract.IteratorComplete", "_ESAbstract.IteratorStep", "_ESAbstract.IteratorNext", "Object.create", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Symbol", "Symbol.iterator", "fetch", "Object.isExtensible", "_ESAbstract.ToPropertyKey", "_ESAbstract.IsRegExp", "Object.defineProperties", "URL", "_ESAbstract.ToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryToPrimitive")
26 * - _ESAbstract.CreateIterResultObject, License: CC0 (required by "Map", "default", "Array.from", "Set")
27 * - _ESAbstract.GetPrototypeFromConstructor, License: CC0 (required by "_ESAbstract.OrdinaryCreateFromConstructor", "Map", "default", "Array.from", "Set", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
28 * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "Map", "default", "Array.from", "Set", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
29 * - _ESAbstract.IsConstructor, License: CC0 (required by "Array.from", "default", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat", "_ESAbstract.Construct")
30 * - _ESAbstract.Construct, License: CC0 (required by "Array.from", "default", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
31 * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.flat", "Array.prototype.filter", "Symbol", "Map", "default", "Array.from", "Set", "Symbol.iterator", "fetch", "Array.prototype.map")
32 * - _ESAbstract.IsRegExp, License: CC0 (required by "String.prototype.endsWith", "default", "String.prototype.includes", "String.prototype.startsWith")
33 * - _ESAbstract.IteratorClose, License: CC0 (required by "Array.from", "default", "Map", "Set")
34 * - _ESAbstract.IteratorComplete, License: CC0 (required by "Map", "default", "Array.from", "Set", "_ESAbstract.IteratorStep")
35 * - _ESAbstract.IteratorNext, License: CC0 (required by "Map", "default", "Array.from", "Set", "_ESAbstract.IteratorStep")
36 * - _ESAbstract.IteratorStep, License: CC0 (required by "Array.from", "default", "Map", "Set")
37 * - _ESAbstract.IteratorValue, License: CC0 (required by "Array.from", "default", "Map", "Set")
38 * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.findIndex", "Array.prototype.includes", "String.prototype.repeat", "Array.from", "default", "Array.of", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor", "Object.assign")
39 * - _ESAbstract.SameValueZero, License: CC0 (required by "Array.prototype.includes", "Map", "default", "Array.from", "Set")
40 * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.prototype.findIndex", "Array.prototype.includes", "String.prototype.repeat", "Array.from", "default", "Array.of", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor", "Object.assign")
41 * - _ESAbstract.ToString, License: CC0 (required by "Array.prototype.findIndex", "Array.prototype.includes", "String.prototype.repeat", "Array.from", "default", "Array.of", "Array.prototype.fill", "String.prototype.endsWith", "String.prototype.includes", "String.prototype.startsWith", "_ESAbstract.FlattenIntoArray", "Array.prototype.flat", "Array.prototype.forEach", "fetch", "URL", "Array.prototype.indexOf", "Element.prototype.after", "Element.prototype.before", "Event", "CustomEvent", "_ESAbstract.ToPropertyKey", "Object.getOwnPropertyDescriptor", "Object.assign", "_ESAbstract.TrimString", "String.prototype.trim", "Number.parseFloat", "Array.prototype.filter", "Symbol", "Map", "Set", "Symbol.iterator", "Array.prototype.map")
42 * - _ESAbstract.FlattenIntoArray, License: CC0 (required by "Array.prototype.flat")
43 * - _ESAbstract.ToPropertyKey, License: CC0 (required by "Object.getOwnPropertyDescriptor", "default", "Object.assign")
44 * - _ESAbstract.TrimString, License: CC0 (required by "String.prototype.trim", "default", "Number.parseFloat")
45 * - _mutation, License: CC0 (required by "DocumentFragment.prototype.append", "default", "DocumentFragment.prototype.prepend", "Element.prototype.after", "Element.prototype.append", "Element.prototype.before", "Element.prototype.prepend", "Element.prototype.remove", "Element.prototype.replaceWith")
46 * - Array.of, License: CC0 (required by "default")
47 * - Array.prototype.fill, License: CC0 (required by "default")
48 * - Array.prototype.findIndex, License: CC0
49 * - Array.prototype.flat, License: CC0
50 * - Array.prototype.includes, License: MIT (required by "Event", "default", "CustomEvent")
51 * - DocumentFragment.prototype.append, License: CC0 (required by "default")
52 * - DocumentFragment.prototype.prepend, License: CC0 (required by "default")
53 * - DOMTokenList, License: CC0 (required by "default", "Element.prototype.classList")
54 * - Element.prototype.after, License: CC0 (required by "default")
55 * - Element.prototype.append, License: CC0 (required by "default")
56 * - Element.prototype.before, License: CC0 (required by "default")
57 * - Element.prototype.classList, License: ISC (required by "default")
58 * - Element.prototype.matches, License: CC0 (required by "default", "Element.prototype.closest")
59 * - Element.prototype.closest, License: CC0 (required by "default")
60 * - Element.prototype.prepend, License: CC0 (required by "default")
61 * - Element.prototype.remove, License: CC0 (required by "default")
62 * - Element.prototype.replaceWith, License: CC0 (required by "default")
63 * - Event, License: CC0 (required by "default", "CustomEvent", "XMLHttpRequest", "fetch")
64 * - CustomEvent, License: CC0 (required by "default")
65 * - Node.prototype.contains, License: CC0 (required by "default")
66 * - Number.isNaN, License: MIT (required by "default")
67 * - Object.getOwnPropertyDescriptor, License: CC0 (required by "default", "Object.assign", "_ESAbstract.EnumerableOwnProperties", "Object.entries", "Symbol", "Map", "Array.from", "Set", "Symbol.iterator", "fetch", "Object.defineProperties", "URL", "Object.create", "_ESAbstract.GetIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
68 * - Object.isExtensible, License: CC0 (required by "Map", "default", "Array.from")
69 * - Object.keys, License: MIT (required by "default", "Object.assign", "_ESAbstract.EnumerableOwnProperties", "Object.entries", "Symbol", "Map", "Array.from", "Set", "Symbol.iterator", "fetch", "Object.defineProperties", "URL", "Object.create", "_ESAbstract.GetIterator", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "Array.of", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.flat")
70 * - _ESAbstract.EnumerableOwnProperties, License: CC0 (required by "Object.entries")
71 * - Object.entries, License: CC0
72 * - Object.assign, License: CC0 (required by "default")
73 * - String.prototype.endsWith, License: CC0 (required by "default")
74 * - String.prototype.includes, License: CC0 (required by "default")
75 * - String.prototype.repeat, License: CC0
76 * - String.prototype.startsWith, License: CC0 (required by "default")
77 * - String.prototype.trim, License: CC0 (required by "default", "Number.parseFloat")
78 * - Number.parseFloat, License: MIT
79 * - Symbol, License: MIT (required by "Map", "default", "Array.from", "Set", "Symbol.iterator", "fetch", "Symbol.species", "Symbol.toStringTag", "Promise")
80 * - Symbol.iterator, License: MIT (required by "fetch", "Array.from", "default", "Map", "Set", "_ESAbstract.GetIterator")
81 * - _ESAbstract.GetIterator, License: CC0 (required by "Array.from", "default", "Map", "Set")
82 * - Symbol.species, License: MIT (required by "Map", "default", "Array.from", "Set")
83 * - Map, License: CC0 (required by "default", "Array.from")
84 * - Set, License: CC0 (required by "default", "Array.from")
85 * - Array.from, License: CC0 (required by "default")
86 * - Symbol.toStringTag, License: MIT (required by "Promise", "default", "fetch")
87 * - Promise, License: MIT (required by "default", "fetch")
88 * - fetch, License: MIT
89 * - URL, License: CC0-1.0 (required by "default") */
90
91(function(self, undefined) {
92
93// _DOMTokenList
94/*
95Copyright (c) 2016, John Gardner
96
97Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
98
99THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
100*/
101var _DOMTokenList = (function() { // eslint-disable-line no-unused-vars
102 var dpSupport = true;
103 var defineGetter = function (object, name, fn, configurable) {
104 if (Object.defineProperty)
105 Object.defineProperty(object, name, {
106 configurable: false === dpSupport ? true : !!configurable,
107 get: fn
108 });
109
110 else object.__defineGetter__(name, fn);
111 };
112
113 /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
114 try {
115 defineGetter({}, "support");
116 }
117 catch (e) {
118 dpSupport = false;
119 }
120
121
122 var _DOMTokenList = function (el, prop) {
123 var that = this;
124 var tokens = [];
125 var tokenMap = {};
126 var length = 0;
127 var maxLength = 0;
128 var addIndexGetter = function (i) {
129 defineGetter(that, i, function () {
130 preop();
131 return tokens[i];
132 }, false);
133
134 };
135 var reindex = function () {
136
137 /** Define getter functions for array-like access to the tokenList's contents. */
138 if (length >= maxLength)
139 for (; maxLength < length; ++maxLength) {
140 addIndexGetter(maxLength);
141 }
142 };
143
144 /** Helper function called at the start of each class method. Internal use only. */
145 var preop = function () {
146 var error;
147 var i;
148 var args = arguments;
149 var rSpace = /\s+/;
150
151 /** Validate the token/s passed to an instance method, if any. */
152 if (args.length)
153 for (i = 0; i < args.length; ++i)
154 if (rSpace.test(args[i])) {
155 error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
156 error.code = 5;
157 error.name = "InvalidCharacterError";
158 throw error;
159 }
160
161
162 /** Split the new value apart by whitespace*/
163 if (typeof el[prop] === "object") {
164 tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
165 } else {
166 tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
167 }
168
169 /** Avoid treating blank strings as single-item token lists */
170 if ("" === tokens[0]) tokens = [];
171
172 /** Repopulate the internal token lists */
173 tokenMap = {};
174 for (i = 0; i < tokens.length; ++i)
175 tokenMap[tokens[i]] = true;
176 length = tokens.length;
177 reindex();
178 };
179
180 /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
181 preop();
182
183 /** Return the number of tokens in the underlying string. Read-only. */
184 defineGetter(that, "length", function () {
185 preop();
186 return length;
187 });
188
189 /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
190 that.toLocaleString =
191 that.toString = function () {
192 preop();
193 return tokens.join(" ");
194 };
195
196 that.item = function (idx) {
197 preop();
198 return tokens[idx];
199 };
200
201 that.contains = function (token) {
202 preop();
203 return !!tokenMap[token];
204 };
205
206 that.add = function () {
207 preop.apply(that, args = arguments);
208
209 for (var args, token, i = 0, l = args.length; i < l; ++i) {
210 token = args[i];
211 if (!tokenMap[token]) {
212 tokens.push(token);
213 tokenMap[token] = true;
214 }
215 }
216
217 /** Update the targeted attribute of the attached element if the token list's changed. */
218 if (length !== tokens.length) {
219 length = tokens.length >>> 0;
220 if (typeof el[prop] === "object") {
221 el[prop].baseVal = tokens.join(" ");
222 } else {
223 el[prop] = tokens.join(" ");
224 }
225 reindex();
226 }
227 };
228
229 that.remove = function () {
230 preop.apply(that, args = arguments);
231
232 /** Build a hash of token names to compare against when recollecting our token list. */
233 for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
234 ignore[args[i]] = true;
235 delete tokenMap[args[i]];
236 }
237
238 /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
239 for (i = 0; i < tokens.length; ++i)
240 if (!ignore[tokens[i]]) t.push(tokens[i]);
241
242 tokens = t;
243 length = t.length >>> 0;
244
245 /** Update the targeted attribute of the attached element. */
246 if (typeof el[prop] === "object") {
247 el[prop].baseVal = tokens.join(" ");
248 } else {
249 el[prop] = tokens.join(" ");
250 }
251 reindex();
252 };
253
254 that.toggle = function (token, force) {
255 preop.apply(that, [token]);
256
257 /** Token state's being forced. */
258 if (undefined !== force) {
259 if (force) {
260 that.add(token);
261 return true;
262 } else {
263 that.remove(token);
264 return false;
265 }
266 }
267
268 /** Token already exists in tokenList. Remove it, and return FALSE. */
269 if (tokenMap[token]) {
270 that.remove(token);
271 return false;
272 }
273
274 /** Otherwise, add the token and return TRUE. */
275 that.add(token);
276 return true;
277 };
278
279 return that;
280 };
281
282 return _DOMTokenList;
283}());
284
285// _ESAbstract.ArrayCreate
286// 9.4.2.2. ArrayCreate ( length [ , proto ] )
287function ArrayCreate(length /* [, proto] */) { // eslint-disable-line no-unused-vars
288 // 1. Assert: length is an integer Number ≥ 0.
289 // 2. If length is -0, set length to +0.
290 if (1 / length === -Infinity) {
291 length = 0;
292 }
293 // 3. If length>2^32-1, throw a RangeError exception.
294 if (length > (Math.pow(2, 32) - 1)) {
295 throw new RangeError('Invalid array length');
296 }
297 // 4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%.
298 // 5. Let A be a newly created Array exotic object.
299 var A = [];
300 // 6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1.
301 // 7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1.
302 // 8. Set A.[[Prototype]] to proto.
303 // 9. Set A.[[Extensible]] to true.
304 // 10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
305 A.length = length;
306 // 11. Return A.
307 return A;
308}
309
310// _ESAbstract.Call
311/* global IsCallable */
312// 7.3.12. Call ( F, V [ , argumentsList ] )
313function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars
314 // 1. If argumentsList is not present, set argumentsList to a new empty List.
315 var argumentsList = arguments.length > 2 ? arguments[2] : [];
316 // 2. If IsCallable(F) is false, throw a TypeError exception.
317 if (IsCallable(F) === false) {
318 throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.');
319 }
320 // 3. Return ? F.[[Call]](V, argumentsList).
321 return F.apply(V, argumentsList);
322}
323
324// _ESAbstract.CreateDataProperty
325// 7.3.4. CreateDataProperty ( O, P, V )
326// NOTE
327// This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator.
328// Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.
329function CreateDataProperty(O, P, V) { // eslint-disable-line no-unused-vars
330 // 1. Assert: Type(O) is Object.
331 // 2. Assert: IsPropertyKey(P) is true.
332 // 3. Let newDesc be the PropertyDescriptor{ [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
333 var newDesc = {
334 value: V,
335 writable: true,
336 enumerable: true,
337 configurable: true
338 };
339 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
340 try {
341 Object.defineProperty(O, P, newDesc);
342 return true;
343 } catch (e) {
344 return false;
345 }
346}
347
348// _ESAbstract.CreateDataPropertyOrThrow
349/* global CreateDataProperty */
350// 7.3.6. CreateDataPropertyOrThrow ( O, P, V )
351function CreateDataPropertyOrThrow(O, P, V) { // eslint-disable-line no-unused-vars
352 // 1. Assert: Type(O) is Object.
353 // 2. Assert: IsPropertyKey(P) is true.
354 // 3. Let success be ? CreateDataProperty(O, P, V).
355 var success = CreateDataProperty(O, P, V);
356 // 4. If success is false, throw a TypeError exception.
357 if (!success) {
358 throw new TypeError('Cannot assign value `' + Object.prototype.toString.call(V) + '` to property `' + Object.prototype.toString.call(P) + '` on object `' + Object.prototype.toString.call(O) + '`');
359 }
360 // 5. Return success.
361 return success;
362}
363
364// _ESAbstract.CreateMethodProperty
365// 7.3.5. CreateMethodProperty ( O, P, V )
366function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars
367 // 1. Assert: Type(O) is Object.
368 // 2. Assert: IsPropertyKey(P) is true.
369 // 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
370 var newDesc = {
371 value: V,
372 writable: true,
373 enumerable: false,
374 configurable: true
375 };
376 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
377 Object.defineProperty(O, P, newDesc);
378}
379
380// _ESAbstract.Get
381// 7.3.1. Get ( O, P )
382function Get(O, P) { // eslint-disable-line no-unused-vars
383 // 1. Assert: Type(O) is Object.
384 // 2. Assert: IsPropertyKey(P) is true.
385 // 3. Return ? O.[[Get]](P, O).
386 return O[P];
387}
388
389// _ESAbstract.HasOwnProperty
390// 7.3.11 HasOwnProperty (O, P)
391function HasOwnProperty(o, p) { // eslint-disable-line no-unused-vars
392 // 1. Assert: Type(O) is Object.
393 // 2. Assert: IsPropertyKey(P) is true.
394 // 3. Let desc be ? O.[[GetOwnProperty]](P).
395 // 4. If desc is undefined, return false.
396 // 5. Return true.
397 // Polyfill.io - As we expect user agents to support ES3 fully we can skip the above steps and use Object.prototype.hasOwnProperty to do them for us.
398 return Object.prototype.hasOwnProperty.call(o, p);
399}
400
401// _ESAbstract.HasProperty
402// 7.3.10. HasProperty ( O, P )
403function HasProperty(O, P) { // eslint-disable-line no-unused-vars
404 // Assert: Type(O) is Object.
405 // Assert: IsPropertyKey(P) is true.
406 // Return ? O.[[HasProperty]](P).
407 return P in O;
408}
409
410// _ESAbstract.IsArray
411// 7.2.2. IsArray ( argument )
412function IsArray(argument) { // eslint-disable-line no-unused-vars
413 // 1. If Type(argument) is not Object, return false.
414 // 2. If argument is an Array exotic object, return true.
415 // 3. If argument is a Proxy exotic object, then
416 // a. If argument.[[ProxyHandler]] is null, throw a TypeError exception.
417 // b. Let target be argument.[[ProxyTarget]].
418 // c. Return ? IsArray(target).
419 // 4. Return false.
420
421 // Polyfill.io - We can skip all the above steps and check the string returned from Object.prototype.toString().
422 return Object.prototype.toString.call(argument) === '[object Array]';
423}
424
425// _ESAbstract.IsCallable
426// 7.2.3. IsCallable ( argument )
427function IsCallable(argument) { // eslint-disable-line no-unused-vars
428 // 1. If Type(argument) is not Object, return false.
429 // 2. If argument has a [[Call]] internal method, return true.
430 // 3. Return false.
431
432 // Polyfill.io - Only function objects have a [[Call]] internal method. This means we can simplify this function to check that the argument has a type of function.
433 return typeof argument === 'function';
434}
435
436// _ESAbstract.RequireObjectCoercible
437// 7.2.1. RequireObjectCoercible ( argument )
438// The abstract operation ToObject converts argument to a value of type Object according to Table 12:
439// Table 12: ToObject Conversions
440/*
441|----------------------------------------------------------------------------------------------------------------------------------------------------|
442| Argument Type | Result |
443|----------------------------------------------------------------------------------------------------------------------------------------------------|
444| Undefined | Throw a TypeError exception. |
445| Null | Throw a TypeError exception. |
446| Boolean | Return argument. |
447| Number | Return argument. |
448| String | Return argument. |
449| Symbol | Return argument. |
450| Object | Return argument. |
451|----------------------------------------------------------------------------------------------------------------------------------------------------|
452*/
453function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars
454 if (argument === null || argument === undefined) {
455 throw TypeError();
456 }
457 return argument;
458}
459
460// _ESAbstract.SameValueNonNumber
461// 7.2.12. SameValueNonNumber ( x, y )
462function SameValueNonNumber(x, y) { // eslint-disable-line no-unused-vars
463 // 1. Assert: Type(x) is not Number.
464 // 2. Assert: Type(x) is the same as Type(y).
465 // 3. If Type(x) is Undefined, return true.
466 // 4. If Type(x) is Null, return true.
467 // 5. If Type(x) is String, then
468 // a. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
469 // 6. If Type(x) is Boolean, then
470 // a. If x and y are both true or both false, return true; otherwise, return false.
471 // 7. If Type(x) is Symbol, then
472 // a. If x and y are both the same Symbol value, return true; otherwise, return false.
473 // 8. If x and y are the same Object value, return true. Otherwise, return false.
474
475 // Polyfill.io - We can skip all above steps because the === operator does it all for us.
476 return x === y;
477}
478
479// _ESAbstract.ToBoolean
480// 7.1.2. ToBoolean ( argument )
481// The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9:
482/*
483--------------------------------------------------------------------------------------------------------------
484| Argument Type | Result |
485--------------------------------------------------------------------------------------------------------------
486| Undefined | Return false. |
487| Null | Return false. |
488| Boolean | Return argument. |
489| Number | If argument is +0, -0, or NaN, return false; otherwise return true. |
490| String | If argument is the empty String (its length is zero), return false; otherwise return true. |
491| Symbol | Return true. |
492| Object | Return true. |
493--------------------------------------------------------------------------------------------------------------
494*/
495function ToBoolean(argument) { // eslint-disable-line no-unused-vars
496 return Boolean(argument);
497}
498
499// _ESAbstract.ToInteger
500// 7.1.4. ToInteger ( argument )
501function ToInteger(argument) { // eslint-disable-line no-unused-vars
502 // 1. Let number be ? ToNumber(argument).
503 var number = Number(argument);
504 // 2. If number is NaN, return +0.
505 if (isNaN(number)) {
506 return 0;
507 }
508 // 3. If number is +0, -0, +∞, or -∞, return number.
509 if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
510 return number;
511 }
512 // 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
513 return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number));
514}
515
516// _ESAbstract.ToLength
517/* global ToInteger */
518// 7.1.15. ToLength ( argument )
519function ToLength(argument) { // eslint-disable-line no-unused-vars
520 // 1. Let len be ? ToInteger(argument).
521 var len = ToInteger(argument);
522 // 2. If len ≤ +0, return +0.
523 if (len <= 0) {
524 return 0;
525 }
526 // 3. Return min(len, 253-1).
527 return Math.min(len, Math.pow(2, 53) -1);
528}
529
530// _ESAbstract.ToObject
531// 7.1.13 ToObject ( argument )
532// The abstract operation ToObject converts argument to a value of type Object according to Table 12:
533// Table 12: ToObject Conversions
534/*
535|----------------------------------------------------------------------------------------------------------------------------------------------------|
536| Argument Type | Result |
537|----------------------------------------------------------------------------------------------------------------------------------------------------|
538| Undefined | Throw a TypeError exception. |
539| Null | Throw a TypeError exception. |
540| Boolean | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. |
541| Number | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects. |
542| String | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects. |
543| Symbol | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects. |
544| Object | Return argument. |
545|----------------------------------------------------------------------------------------------------------------------------------------------------|
546*/
547function ToObject(argument) { // eslint-disable-line no-unused-vars
548 if (argument === null || argument === undefined) {
549 throw TypeError();
550 }
551 return Object(argument);
552}
553
554// _ESAbstract.GetV
555/* global ToObject */
556// 7.3.2 GetV (V, P)
557function GetV(v, p) { // eslint-disable-line no-unused-vars
558 // 1. Assert: IsPropertyKey(P) is true.
559 // 2. Let O be ? ToObject(V).
560 var o = ToObject(v);
561 // 3. Return ? O.[[Get]](P, V).
562 return o[p];
563}
564
565// _ESAbstract.GetMethod
566/* global GetV, IsCallable */
567// 7.3.9. GetMethod ( V, P )
568function GetMethod(V, P) { // eslint-disable-line no-unused-vars
569 // 1. Assert: IsPropertyKey(P) is true.
570 // 2. Let func be ? GetV(V, P).
571 var func = GetV(V, P);
572 // 3. If func is either undefined or null, return undefined.
573 if (func === null || func === undefined) {
574 return undefined;
575 }
576 // 4. If IsCallable(func) is false, throw a TypeError exception.
577 if (IsCallable(func) === false) {
578 throw new TypeError('Method not callable: ' + P);
579 }
580 // 5. Return func.
581 return func;
582}
583
584// _ESAbstract.Type
585// "Type(x)" is used as shorthand for "the type of x"...
586function Type(x) { // eslint-disable-line no-unused-vars
587 switch (typeof x) {
588 case 'undefined':
589 return 'undefined';
590 case 'boolean':
591 return 'boolean';
592 case 'number':
593 return 'number';
594 case 'string':
595 return 'string';
596 case 'symbol':
597 return 'symbol';
598 default:
599 // typeof null is 'object'
600 if (x === null) return 'null';
601 // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`.
602 if ('Symbol' in self && (x instanceof self.Symbol || x.constructor === self.Symbol)) return 'symbol';
603 return 'object';
604 }
605}
606
607// _ESAbstract.CreateIterResultObject
608/* global Type, CreateDataProperty */
609// 7.4.7. CreateIterResultObject ( value, done )
610function CreateIterResultObject(value, done) { // eslint-disable-line no-unused-vars
611 // 1. Assert: Type(done) is Boolean.
612 if (Type(done) !== 'boolean') {
613 throw new Error();
614 }
615 // 2. Let obj be ObjectCreate(%ObjectPrototype%).
616 var obj = {};
617 // 3. Perform CreateDataProperty(obj, "value", value).
618 CreateDataProperty(obj, "value", value);
619 // 4. Perform CreateDataProperty(obj, "done", done).
620 CreateDataProperty(obj, "done", done);
621 // 5. Return obj.
622 return obj;
623}
624
625// _ESAbstract.GetPrototypeFromConstructor
626/* global Get, Type */
627// 9.1.14. GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
628function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
629 // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
630 // 2. Assert: IsCallable(constructor) is true.
631 // 3. Let proto be ? Get(constructor, "prototype").
632 var proto = Get(constructor, "prototype");
633 // 4. If Type(proto) is not Object, then
634 if (Type(proto) !== 'object') {
635 // a. Let realm be ? GetFunctionRealm(constructor).
636 // b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
637 proto = intrinsicDefaultProto;
638 }
639 // 5. Return proto.
640 return proto;
641}
642
643// _ESAbstract.OrdinaryCreateFromConstructor
644/* global GetPrototypeFromConstructor */
645// 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
646function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
647 var internalSlotsList = arguments[2] || {};
648 // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object.
649 // The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object.
650
651 // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
652 var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
653
654 // 3. Return ObjectCreate(proto, internalSlotsList).
655 // Polyfill.io - We do not pass internalSlotsList to Object.create because Object.create does not use the default ordinary object definitions specified in 9.1.
656 var obj = Object.create(proto);
657 for (var name in internalSlotsList) {
658 if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) {
659 Object.defineProperty(obj, name, {
660 configurable: true,
661 enumerable: false,
662 writable: true,
663 value: internalSlotsList[name]
664 });
665 }
666 }
667 return obj;
668}
669
670// _ESAbstract.IsConstructor
671/* global Type */
672// 7.2.4. IsConstructor ( argument )
673function IsConstructor(argument) { // eslint-disable-line no-unused-vars
674 // 1. If Type(argument) is not Object, return false.
675 if (Type(argument) !== 'object') {
676 return false;
677 }
678 // 2. If argument has a [[Construct]] internal method, return true.
679 // 3. Return false.
680
681 // Polyfill.io - `new argument` is the only way to truly test if a function is a constructor.
682 // We choose to not use`new argument` because the argument could have side effects when called.
683 // Instead we check to see if the argument is a function and if it has a prototype.
684 // Arrow functions do not have a [[Construct]] internal method, nor do they have a prototype.
685 return typeof argument === 'function' && !!argument.prototype;
686}
687
688// _ESAbstract.Construct
689/* global IsConstructor, OrdinaryCreateFromConstructor, Call */
690// 7.3.13. Construct ( F [ , argumentsList [ , newTarget ]] )
691function Construct(F /* [ , argumentsList [ , newTarget ]] */) { // eslint-disable-line no-unused-vars
692 // 1. If newTarget is not present, set newTarget to F.
693 var newTarget = arguments.length > 2 ? arguments[2] : F;
694
695 // 2. If argumentsList is not present, set argumentsList to a new empty List.
696 var argumentsList = arguments.length > 1 ? arguments[1] : [];
697
698 // 3. Assert: IsConstructor(F) is true.
699 if (!IsConstructor(F)) {
700 throw new TypeError('F must be a constructor.');
701 }
702
703 // 4. Assert: IsConstructor(newTarget) is true.
704 if (!IsConstructor(newTarget)) {
705 throw new TypeError('newTarget must be a constructor.');
706 }
707
708 // 5. Return ? F.[[Construct]](argumentsList, newTarget).
709 // Polyfill.io - If newTarget is the same as F, it is equivalent to new F(...argumentsList).
710 if (newTarget === F) {
711 return new (Function.prototype.bind.apply(F, [null].concat(argumentsList)))();
712 } else {
713 // Polyfill.io - This is mimicking section 9.2.2 step 5.a.
714 var obj = OrdinaryCreateFromConstructor(newTarget, Object.prototype);
715 return Call(F, obj, argumentsList);
716 }
717}
718
719// _ESAbstract.ArraySpeciesCreate
720/* global IsArray, ArrayCreate, Get, Type, IsConstructor, Construct */
721// 9.4.2.3. ArraySpeciesCreate ( originalArray, length )
722function ArraySpeciesCreate(originalArray, length) { // eslint-disable-line no-unused-vars
723 // 1. Assert: length is an integer Number ≥ 0.
724 // 2. If length is -0, set length to +0.
725 if (length === 0 && 1/length === -Infinity) {
726 length = 0;
727 }
728
729 // 3. Let isArray be ? IsArray(originalArray).
730 var isArray = IsArray(originalArray);
731
732 // 4. If isArray is false, return ? ArrayCreate(length).
733 if (isArray === false) {
734 return ArrayCreate(length);
735 }
736
737 // 5. Let C be ? Get(originalArray, "constructor").
738 var C = Get(originalArray, 'constructor');
739
740 // Polyfill.io - We skip this section as not sure how to make a cross-realm normal Array, a same-realm Array.
741 // 6. If IsConstructor(C) is true, then
742 // if (IsConstructor(C)) {
743 // a. Let thisRealm be the current Realm Record.
744 // b. Let realmC be ? GetFunctionRealm(C).
745 // c. If thisRealm and realmC are not the same Realm Record, then
746 // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
747 // }
748 // 7. If Type(C) is Object, then
749 if (Type(C) === 'object') {
750 // a. Set C to ? Get(C, @@species).
751 C = 'Symbol' in self && 'species' in self.Symbol ? Get(C, self.Symbol.species) : undefined;
752 // b. If C is null, set C to undefined.
753 if (C === null) {
754 C = undefined;
755 }
756 }
757 // 8. If C is undefined, return ? ArrayCreate(length).
758 if (C === undefined) {
759 return ArrayCreate(length);
760 }
761 // 9. If IsConstructor(C) is false, throw a TypeError exception.
762 if (!IsConstructor(C)) {
763 throw new TypeError('C must be a constructor');
764 }
765 // 10. Return ? Construct(C, « length »).
766 return Construct(C, [length]);
767}
768
769// _ESAbstract.IsRegExp
770/* global Type, Get, ToBoolean */
771// 7.2.8. IsRegExp ( argument )
772function IsRegExp(argument) { // eslint-disable-line no-unused-vars
773 // 1. If Type(argument) is not Object, return false.
774 if (Type(argument) !== 'object') {
775 return false;
776 }
777 // 2. Let matcher be ? Get(argument, @@match).
778 var matcher = 'Symbol' in self && 'match' in self.Symbol ? Get(argument, self.Symbol.match) : undefined;
779 // 3. If matcher is not undefined, return ToBoolean(matcher).
780 if (matcher !== undefined) {
781 return ToBoolean(matcher);
782 }
783 // 4. If argument has a [[RegExpMatcher]] internal slot, return true.
784 try {
785 var lastIndex = argument.lastIndex;
786 argument.lastIndex = 0;
787 RegExp.prototype.exec.call(argument);
788 return true;
789 // eslint-disable-next-line no-empty
790 } catch (e) {} finally {
791 argument.lastIndex = lastIndex;
792 }
793 // 5. Return false.
794 return false;
795}
796
797// _ESAbstract.IteratorClose
798/* global GetMethod, Type, Call */
799// 7.4.6. IteratorClose ( iteratorRecord, completion )
800function IteratorClose(iteratorRecord, completion) { // eslint-disable-line no-unused-vars
801 // 1. Assert: Type(iteratorRecord.[[Iterator]]) is Object.
802 if (Type(iteratorRecord['[[Iterator]]']) !== 'object') {
803 throw new Error(Object.prototype.toString.call(iteratorRecord['[[Iterator]]']) + 'is not an Object.');
804 }
805 // 2. Assert: completion is a Completion Record.
806 // Polyfill.io - Ignoring this step as there is no way to check if something is a Completion Record in userland JavaScript.
807
808 // 3. Let iterator be iteratorRecord.[[Iterator]].
809 var iterator = iteratorRecord['[[Iterator]]'];
810 // 4. Let return be ? GetMethod(iterator, "return").
811 // Polyfill.io - We name it returnMethod because return is a keyword and can not be used as an identifier (E.G. variable name, function name etc).
812 var returnMethod = GetMethod(iterator, "return");
813 // 5. If return is undefined, return Completion(completion).
814 if (returnMethod === undefined) {
815 return completion;
816 }
817 // 6. Let innerResult be Call(return, iterator, « »).
818 try {
819 var innerResult = Call(returnMethod, iterator);
820 } catch (error) {
821 var innerException = error;
822 }
823 // 7. If completion.[[Type]] is throw, return Completion(completion).
824 if (completion) {
825 return completion;
826 }
827 // 8. If innerResult.[[Type]] is throw, return Completion(innerResult).
828 if (innerException) {
829 throw innerException;
830 }
831 // 9. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
832 if (Type(innerResult) !== 'object') {
833 throw new TypeError("Iterator's return method returned a non-object.");
834 }
835 // 10. Return Completion(completion).
836 return completion;
837}
838
839// _ESAbstract.IteratorComplete
840/* global Type, ToBoolean, Get */
841// 7.4.3 IteratorComplete ( iterResult )
842function IteratorComplete(iterResult) { // eslint-disable-line no-unused-vars
843 // 1. Assert: Type(iterResult) is Object.
844 if (Type(iterResult) !== 'object') {
845 throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.');
846 }
847 // 2. Return ToBoolean(? Get(iterResult, "done")).
848 return ToBoolean(Get(iterResult, "done"));
849}
850
851// _ESAbstract.IteratorNext
852/* global Call, Type */
853// 7.4.2. IteratorNext ( iteratorRecord [ , value ] )
854function IteratorNext(iteratorRecord /* [, value] */) { // eslint-disable-line no-unused-vars
855 // 1. If value is not present, then
856 if (arguments.length < 2) {
857 // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « »).
858 var result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]']);
859 // 2. Else,
860 } else {
861 // a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
862 result = Call(iteratorRecord['[[NextMethod]]'], iteratorRecord['[[Iterator]]'], [arguments[1]]);
863 }
864 // 3. If Type(result) is not Object, throw a TypeError exception.
865 if (Type(result) !== 'object') {
866 throw new TypeError('bad iterator');
867 }
868 // 4. Return result.
869 return result;
870}
871
872// _ESAbstract.IteratorStep
873/* global IteratorNext, IteratorComplete */
874// 7.4.5. IteratorStep ( iteratorRecord )
875function IteratorStep(iteratorRecord) { // eslint-disable-line no-unused-vars
876 // 1. Let result be ? IteratorNext(iteratorRecord).
877 var result = IteratorNext(iteratorRecord);
878 // 2. Let done be ? IteratorComplete(result).
879 var done = IteratorComplete(result);
880 // 3. If done is true, return false.
881 if (done === true) {
882 return false;
883 }
884 // 4. Return result.
885 return result;
886}
887
888// _ESAbstract.IteratorValue
889/* global Type, Get */
890// 7.4.4 IteratorValue ( iterResult )
891function IteratorValue(iterResult) { // eslint-disable-line no-unused-vars
892 // Assert: Type(iterResult) is Object.
893 if (Type(iterResult) !== 'object') {
894 throw new Error(Object.prototype.toString.call(iterResult) + 'is not an Object.');
895 }
896 // Return ? Get(iterResult, "value").
897 return Get(iterResult, "value");
898}
899
900// _ESAbstract.OrdinaryToPrimitive
901/* global Get, IsCallable, Call, Type */
902// 7.1.1.1. OrdinaryToPrimitive ( O, hint )
903function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars
904 // 1. Assert: Type(O) is Object.
905 // 2. Assert: Type(hint) is String and its value is either "string" or "number".
906 // 3. If hint is "string", then
907 if (hint === 'string') {
908 // a. Let methodNames be « "toString", "valueOf" ».
909 var methodNames = ['toString', 'valueOf'];
910 // 4. Else,
911 } else {
912 // a. Let methodNames be « "valueOf", "toString" ».
913 methodNames = ['valueOf', 'toString'];
914 }
915 // 5. For each name in methodNames in List order, do
916 for (var i = 0; i < methodNames.length; ++i) {
917 var name = methodNames[i];
918 // a. Let method be ? Get(O, name).
919 var method = Get(O, name);
920 // b. If IsCallable(method) is true, then
921 if (IsCallable(method)) {
922 // i. Let result be ? Call(method, O).
923 var result = Call(method, O);
924 // ii. If Type(result) is not Object, return result.
925 if (Type(result) !== 'object') {
926 return result;
927 }
928 }
929 }
930 // 6. Throw a TypeError exception.
931 throw new TypeError('Cannot convert to primitive.');
932}
933
934// _ESAbstract.SameValueZero
935/* global Type, SameValueNonNumber */
936// 7.2.11. SameValueZero ( x, y )
937function SameValueZero (x, y) { // eslint-disable-line no-unused-vars
938 // 1. If Type(x) is different from Type(y), return false.
939 if (Type(x) !== Type(y)) {
940 return false;
941 }
942 // 2. If Type(x) is Number, then
943 if (Type(x) === 'number') {
944 // a. If x is NaN and y is NaN, return true.
945 if (isNaN(x) && isNaN(y)) {
946 return true;
947 }
948 // b. If x is +0 and y is -0, return true.
949 if (1/x === Infinity && 1/y === -Infinity) {
950 return true;
951 }
952 // c. If x is -0 and y is +0, return true.
953 if (1/x === -Infinity && 1/y === Infinity) {
954 return true;
955 }
956 // d. If x is the same Number value as y, return true.
957 if (x === y) {
958 return true;
959 }
960 // e. Return false.
961 return false;
962 }
963 // 3. Return SameValueNonNumber(x, y).
964 return SameValueNonNumber(x, y);
965}
966
967// _ESAbstract.ToPrimitive
968/* global Type, GetMethod, Call, OrdinaryToPrimitive */
969// 7.1.1. ToPrimitive ( input [ , PreferredType ] )
970function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars
971 var PreferredType = arguments.length > 1 ? arguments[1] : undefined;
972 // 1. Assert: input is an ECMAScript language value.
973 // 2. If Type(input) is Object, then
974 if (Type(input) === 'object') {
975 // a. If PreferredType is not present, let hint be "default".
976 if (arguments.length < 2) {
977 var hint = 'default';
978 // b. Else if PreferredType is hint String, let hint be "string".
979 } else if (PreferredType === String) {
980 hint = 'string';
981 // c. Else PreferredType is hint Number, let hint be "number".
982 } else if (PreferredType === Number) {
983 hint = 'number';
984 }
985 // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
986 var exoticToPrim = typeof self.Symbol === 'function' && typeof self.Symbol.toPrimitive === 'symbol' ? GetMethod(input, self.Symbol.toPrimitive) : undefined;
987 // e. If exoticToPrim is not undefined, then
988 if (exoticToPrim !== undefined) {
989 // i. Let result be ? Call(exoticToPrim, input, « hint »).
990 var result = Call(exoticToPrim, input, [hint]);
991 // ii. If Type(result) is not Object, return result.
992 if (Type(result) !== 'object') {
993 return result;
994 }
995 // iii. Throw a TypeError exception.
996 throw new TypeError('Cannot convert exotic object to primitive.');
997 }
998 // f. If hint is "default", set hint to "number".
999 if (hint === 'default') {
1000 hint = 'number';
1001 }
1002 // g. Return ? OrdinaryToPrimitive(input, hint).
1003 return OrdinaryToPrimitive(input, hint);
1004 }
1005 // 3. Return input
1006 return input;
1007}
1008// _ESAbstract.ToString
1009/* global Type, ToPrimitive */
1010// 7.1.12. ToString ( argument )
1011// The abstract operation ToString converts argument to a value of type String according to Table 11:
1012// Table 11: ToString Conversions
1013/*
1014|---------------|--------------------------------------------------------|
1015| Argument Type | Result |
1016|---------------|--------------------------------------------------------|
1017| Undefined | Return "undefined". |
1018|---------------|--------------------------------------------------------|
1019| Null | Return "null". |
1020|---------------|--------------------------------------------------------|
1021| Boolean | If argument is true, return "true". |
1022| | If argument is false, return "false". |
1023|---------------|--------------------------------------------------------|
1024| Number | Return NumberToString(argument). |
1025|---------------|--------------------------------------------------------|
1026| String | Return argument. |
1027|---------------|--------------------------------------------------------|
1028| Symbol | Throw a TypeError exception. |
1029|---------------|--------------------------------------------------------|
1030| Object | Apply the following steps: |
1031| | Let primValue be ? ToPrimitive(argument, hint String). |
1032| | Return ? ToString(primValue). |
1033|---------------|--------------------------------------------------------|
1034*/
1035function ToString(argument) { // eslint-disable-line no-unused-vars
1036 switch(Type(argument)) {
1037 case 'symbol':
1038 throw new TypeError('Cannot convert a Symbol value to a string');
1039 case 'object':
1040 var primValue = ToPrimitive(argument, String);
1041 return ToString(primValue);
1042 default:
1043 return String(argument);
1044 }
1045}
1046
1047// _ESAbstract.FlattenIntoArray
1048/* globals ToString, HasProperty, Get, Call, IsArray, ToLength, CreateDataPropertyOrThrow */
1049// 22.1.3.10.1 FlattenIntoArray(target, source, sourceLen, start, depth [ , mapperFunction, thisArg ])
1050function FlattenIntoArray(target, source, sourceLen, start, depth /* , mapperFunction, thisArg */ ) { // eslint-disable-line no-unused-vars
1051 var mapperFunction = arguments[5];
1052 var thisArg = arguments[6];
1053 // 1. Let targetIndex be start.
1054 var targetIndex = start;
1055 // 2. Let sourceIndex be 0.
1056 var sourceIndex = 0;
1057 // 3. Repeat, while sourceIndex < sourceLen
1058 while (sourceIndex < sourceLen) {
1059 // a. Let P be ! ToString(sourceIndex).
1060 var P = ToString(sourceIndex);
1061 // b. Let exists be ? HasProperty(source, P).
1062 var exists = HasProperty(source, P);
1063 // c. If exists is true, then
1064 if (exists === true) {
1065 // i. Let element be ? Get(source, P).
1066 var element = Get(source, P);
1067 // ii. If mapperFunction is present, then
1068 if (5 in arguments) {
1069 // 1. Assert: thisArg is present.
1070 // 2. Set element to ? Call(mapperFunction, thisArg , « element, sourceIndex, source »).
1071 element = Call(mapperFunction, thisArg, [element, sourceIndex, source]);
1072 }
1073 // iii. Let shouldFlatten be false.
1074 var shouldFlatten = false;
1075 // iv. If depth > 0, then
1076 if (depth > 0) {
1077 // 1. Set shouldFlatten to ? IsArray(element).
1078 shouldFlatten = IsArray(element);
1079 }
1080 // v. If shouldFlatten is true, then
1081 if (shouldFlatten === true) {
1082 // 1. Let elementLen be ? ToLength(? Get(element, "length")).
1083 var elementLen = ToLength(Get(element, "length"));
1084 // 2. Set targetIndex to ? FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1).
1085 targetIndex = FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1);
1086 // vi. Else,
1087 } else {
1088 // 1. If targetIndex ≥ 253-1, throw a TypeError exception.
1089 if (targetIndex >= (Math.pow(2, 53) - 1)) {
1090 throw new TypeError("targetIndex is greater than or equal to 2^53-1");
1091 }
1092 // 2. Perform ? CreateDataPropertyOrThrow(target, ! ToString(targetIndex), element).
1093 CreateDataPropertyOrThrow(target, ToString(targetIndex), element);
1094 // 3. Increase targetIndex by 1.
1095 targetIndex += 1;
1096 }
1097 }
1098 // d. Increase sourceIndex by 1.
1099 sourceIndex += 1;
1100 }
1101 // 4. Return targetIndex.
1102 return targetIndex;
1103}
1104// _ESAbstract.ToPropertyKey
1105/* globals ToPrimitive, Type, ToString */
1106// 7.1.14. ToPropertyKey ( argument )
1107function ToPropertyKey(argument) { // eslint-disable-line no-unused-vars
1108 // 1. Let key be ? ToPrimitive(argument, hint String).
1109 var key = ToPrimitive(argument, String);
1110 // 2. If Type(key) is Symbol, then
1111 if (Type(key) === 'symbol') {
1112 // a. Return key.
1113 return key;
1114 }
1115 // 3. Return ! ToString(key).
1116 return ToString(key);
1117}
1118
1119// _ESAbstract.TrimString
1120/* eslint-disable no-control-regex */
1121/* global RequireObjectCoercible, ToString */
1122// TrimString ( string, where )
1123function TrimString(string, where) { // eslint-disable-line no-unused-vars
1124 // 1. Let str be ? RequireObjectCoercible(string).
1125 var str = RequireObjectCoercible(string);
1126 // 2. Let S be ? ToString(str).
1127 var S = ToString(str);
1128 // 3. If where is "start", let T be a String value that is a copy of S with leading white space removed.
1129 // The definition of white space is the union of WhiteSpace and LineTerminator. When determining whether a Unicode code point is in Unicode general category “Space_Separator” (“Zs”), code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in 6.1.4.
1130 var whitespace = /[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/.source;
1131 if (where === 'start') {
1132 var T = String.prototype.replace.call(S, new RegExp('^' + whitespace, 'g'), '');
1133 // 4. Else if where is "end", let T be a String value that is a copy of S with trailing white space removed.
1134 } else if (where === "end") {
1135 T = String.prototype.replace.call(S, new RegExp(whitespace + '$', 'g'), '');
1136 // 5. Else,
1137 } else {
1138 // a. Assert: where is "start+end".
1139 // b. Let T be a String value that is a copy of S with both leading and trailing white space removed.
1140 T = String.prototype.replace.call(S, new RegExp('^' + whitespace + '|' + whitespace + '$', 'g'), '');
1141 }
1142 // 6. Return T.
1143 return T;
1144}
1145// _mutation
1146var _mutation = (function () { // eslint-disable-line no-unused-vars
1147
1148 function isNode(object) {
1149 // DOM, Level2
1150 if (typeof Node === 'function') {
1151 return object instanceof Node;
1152 }
1153 // Older browsers, check if it looks like a Node instance)
1154 return object &&
1155 typeof object === "object" &&
1156 object.nodeName &&
1157 object.nodeType >= 1 &&
1158 object.nodeType <= 12;
1159 }
1160
1161 // http://dom.spec.whatwg.org/#mutation-method-macro
1162 return function mutation(nodes) {
1163 if (nodes.length === 1) {
1164 return isNode(nodes[0]) ? nodes[0] : document.createTextNode(nodes[0] + '');
1165 }
1166
1167 var fragment = document.createDocumentFragment();
1168 for (var i = 0; i < nodes.length; i++) {
1169 fragment.appendChild(isNode(nodes[i]) ? nodes[i] : document.createTextNode(nodes[i] + ''));
1170
1171 }
1172 return fragment;
1173 };
1174}());
1175if (!("of"in Array
1176)) {
1177
1178// Array.of
1179/* global ArrayCreate, Construct, CreateDataPropertyOrThrow, CreateMethodProperty, IsConstructor, ToString */
1180// 22.1.2.3. Array.of ( ...items )
1181CreateMethodProperty(Array, 'of', function of() {
1182 // 1. Let len be the actual number of arguments passed to this function.
1183 var len = arguments.length;
1184 // 2. Let items be the List of arguments passed to this function.
1185 var items = arguments;
1186 // 3. Let C be the this value.
1187 var C = this;
1188 // 4. If IsConstructor(C) is true, then
1189 if (IsConstructor(C)) {
1190 // a. Let A be ? Construct(C, « len »).
1191 var A = Construct(C, [len]);
1192 // 5. Else,
1193 } else {
1194 // a. Let A be ? ArrayCreate(len).
1195 A = ArrayCreate(len);
1196 }
1197 // 6. Let k be 0.
1198 var k = 0;
1199 // 7. Repeat, while k < len
1200 while (k < len) {
1201 // a. Let kValue be items[k].
1202 var kValue = items[k];
1203 // b. Let Pk be ! ToString(k).
1204 var Pk = ToString(k);
1205 // c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue).
1206 CreateDataPropertyOrThrow(A, Pk, kValue);
1207 // d. Increase k by 1.
1208 k = k + 1;
1209
1210 }
1211 // 8. Perform ? Set(A, "length", len, true)
1212 A.length = len;
1213 // 9. Return A.
1214 return A;
1215});
1216
1217}
1218
1219if (!("fill"in Array.prototype
1220)) {
1221
1222// Array.prototype.fill
1223/* global CreateMethodProperty, Get, ToInteger, ToLength, ToObject, ToString */
1224// 22.1.3.6. Array.prototype.fill ( value [ , start [ , end ] ] )
1225CreateMethodProperty(Array.prototype, 'fill', function fill(value /* [ , start [ , end ] ] */) {
1226 var start = arguments[1];
1227 var end = arguments[2];
1228 // 1. Let O be ? ToObject(this value).
1229 var O = ToObject(this);
1230 // 2. Let len be ? ToLength(? Get(O, "length")).
1231 var len = ToLength(Get(O, "length"));
1232 // 3. Let relativeStart be ? ToInteger(start).
1233 var relativeStart = ToInteger(start);
1234 // 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be min(relativeStart, len)
1235 var k = relativeStart < 0 ? Math.max((len + relativeStart), 0) : Math.min(relativeStart, len);
1236 // 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end).
1237 var relativeEnd = end === undefined ? len : ToInteger(end);
1238 // 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let final be min(relativeEnd, len).
1239 var final = relativeEnd < 0 ? Math.max((len + relativeEnd), 0) : Math.min(relativeEnd, len);
1240 // 7. Repeat, while k < final
1241 while (k < final) {
1242 // a. Let Pk be ! ToString(k).
1243 var Pk = ToString(k);
1244 // b. Perform ? Set(O, Pk, value, true).
1245 O[Pk] = value;
1246 // c. Increase k by 1.
1247 k = k + 1;
1248 }
1249 // 8. Return O.
1250 return O;
1251});
1252
1253}
1254
1255if (!("findIndex"in Array.prototype
1256)) {
1257
1258// Array.prototype.findIndex
1259/* global Call, CreateMethodProperty, Get, IsCallable, ToBoolean, ToLength, ToObject, ToString */
1260// 22.1.3.9. Array.prototype.findIndex ( predicate [ , thisArg ] )
1261CreateMethodProperty(Array.prototype, 'findIndex', function findIndex(predicate /* [ , thisArg ] */) {
1262 // 1. Let O be ? ToObject(this value).
1263 var O = ToObject(this);
1264 // 2. Let len be ? ToLength(? Get(O, "length")).
1265 var len = ToLength(Get(O, "length"));
1266 // 3. If IsCallable(predicate) is false, throw a TypeError exception.
1267 if (IsCallable(predicate) === false) {
1268 throw new TypeError(predicate + ' is not a function');
1269 }
1270 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1271 var T = arguments.length > 1 ? arguments[1] : undefined;
1272 // 5. Let k be 0.
1273 var k = 0;
1274 // 6. Repeat, while k < len
1275 while (k < len) {
1276 // a. Let Pk be ! ToString(k).
1277 var Pk = ToString(k);
1278 // b. Let kValue be ? Get(O, Pk).
1279 var kValue = Get(O, Pk);
1280 // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
1281 var testResult = ToBoolean(Call(predicate, T, [kValue, k, O]));
1282 // d. If testResult is true, return k.
1283 if (testResult) {
1284 return k;
1285 }
1286 // e. Increase k by 1.
1287 k = k + 1;
1288 }
1289 // 7. Return -1.
1290 return -1;
1291});
1292
1293}
1294
1295if (!("flat"in Array.prototype
1296)) {
1297
1298// Array.prototype.flat
1299/* global CreateMethodProperty, ToObject, ToLength, Get, ToInteger, ArraySpeciesCreate, FlattenIntoArray */
1300// 22.1.3.10 Array.prototype.flat( [ depth ] )
1301CreateMethodProperty(Array.prototype, 'flat', function flat() {
1302 "use strict";
1303 var depth = arguments[0];
1304 // 1. Let O be ? ToObject(this value).
1305 var O = ToObject(this);
1306 // 2. Let sourceLen be ? ToLength(? Get(O, "length")).
1307 var sourceLen = ToLength(Get(O, "length"));
1308 // 3. Let depthNum be 1.
1309 var depthNum = 1;
1310 // 4. If depth is not undefined, then
1311 if (depth !== void 0) {
1312 // a. Set depthNum to ? ToInteger(depth).
1313 depthNum = ToInteger(depth);
1314 }
1315 // 5. Let A be ? ArraySpeciesCreate(O, 0).
1316 var A = ArraySpeciesCreate(O,0);
1317 // 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, depthNum).
1318 FlattenIntoArray(A, O, sourceLen, 0, depthNum);
1319 // 7. Return A.
1320 return A;
1321});
1322}
1323
1324if (!("includes"in Array.prototype
1325)) {
1326
1327// Array.prototype.includes
1328/* global CreateMethodProperty, Get, SameValueZero, ToInteger, ToLength, ToObject, ToString */
1329// 22.1.3.11. Array.prototype.includes ( searchElement [ , fromIndex ] )
1330CreateMethodProperty(Array.prototype, 'includes', function includes(searchElement /* [ , fromIndex ] */) {
1331 'use strict';
1332 // 1. Let O be ? ToObject(this value).
1333 var O = ToObject(this);
1334 // 2. Let len be ? ToLength(? Get(O, "length")).
1335 var len = ToLength(Get(O, "length"));
1336 // 3. If len is 0, return false.
1337 if (len === 0) {
1338 return false;
1339 }
1340 // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.)
1341 var n = ToInteger(arguments[1]);
1342 // 5. If n ≥ 0, then
1343 if (n >= 0) {
1344 // a. Let k be n.
1345 var k = n;
1346 // 6. Else n < 0,
1347 } else {
1348 // a. Let k be len + n.
1349 k = len + n;
1350 // b. If k < 0, let k be 0.
1351 if (k < 0) {
1352 k = 0;
1353 }
1354 }
1355 // 7. Repeat, while k < len
1356 while (k < len) {
1357 // a. Let elementK be the result of ? Get(O, ! ToString(k)).
1358 var elementK = Get(O, ToString(k));
1359 // b. If SameValueZero(searchElement, elementK) is true, return true.
1360 if (SameValueZero(searchElement, elementK)) {
1361 return true;
1362 }
1363 // c. Increase k by 1.
1364 k = k + 1;
1365 }
1366 // 8. Return false.
1367 return false;
1368});
1369
1370}
1371
1372if (!("DocumentFragment"in self&&"append"in DocumentFragment.prototype
1373)) {
1374
1375// DocumentFragment.prototype.append
1376/* global _mutation */
1377DocumentFragment.prototype.append = function append() {
1378 this.appendChild(_mutation(arguments));
1379};
1380
1381}
1382
1383if (!("DocumentFragment"in self&&"prepend"in DocumentFragment.prototype
1384)) {
1385
1386// DocumentFragment.prototype.prepend
1387/* global _mutation */
1388DocumentFragment.prototype.prepend = function prepend() {
1389 this.insertBefore(_mutation(arguments), this.firstChild);
1390};
1391
1392}
1393
1394if (!("DOMTokenList"in self&&function(e){return!("classList"in e)||!e.classList.toggle("x",!1)&&!e.className}(document.createElement("x"))
1395)) {
1396
1397// DOMTokenList
1398/* global _DOMTokenList */
1399(function (global) {
1400 var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
1401
1402 if (
1403 !nativeImpl ||
1404 (
1405 !!document.createElementNS &&
1406 !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
1407 !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
1408 )
1409 ) {
1410 global.DOMTokenList = _DOMTokenList;
1411 }
1412
1413 // Add second argument to native DOMTokenList.toggle() if necessary
1414 (function () {
1415 var e = document.createElement('span');
1416 if (!('classList' in e)) return;
1417 e.classList.toggle('x', false);
1418 if (!e.classList.contains('x')) return;
1419 e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
1420 var force = arguments[1];
1421 if (force === undefined) {
1422 var add = !this.contains(token);
1423 this[add ? 'add' : 'remove'](token);
1424 return add;
1425 }
1426 force = !!force;
1427 this[force ? 'add' : 'remove'](token);
1428 return force;
1429 };
1430 }());
1431
1432 // Add multiple arguments to native DOMTokenList.add() if necessary
1433 (function () {
1434 var e = document.createElement('span');
1435 if (!('classList' in e)) return;
1436 e.classList.add('a', 'b');
1437 if (e.classList.contains('b')) return;
1438 var native = e.classList.constructor.prototype.add;
1439 e.classList.constructor.prototype.add = function () {
1440 var args = arguments;
1441 var l = arguments.length;
1442 for (var i = 0; i < l; i++) {
1443 native.call(this, args[i]);
1444 }
1445 };
1446 }());
1447
1448 // Add multiple arguments to native DOMTokenList.remove() if necessary
1449 (function () {
1450 var e = document.createElement('span');
1451 if (!('classList' in e)) return;
1452 e.classList.add('a');
1453 e.classList.add('b');
1454 e.classList.remove('a', 'b');
1455 if (!e.classList.contains('b')) return;
1456 var native = e.classList.constructor.prototype.remove;
1457 e.classList.constructor.prototype.remove = function () {
1458 var args = arguments;
1459 var l = arguments.length;
1460 for (var i = 0; i < l; i++) {
1461 native.call(this, args[i]);
1462 }
1463 };
1464 }());
1465
1466}(self));
1467
1468}
1469
1470if (!("Element"in self&&"after"in Element.prototype
1471)) {
1472
1473// Element.prototype.after
1474/* global _mutation */
1475Document.prototype.after = Element.prototype.after = function after() {
1476 if (this.parentNode) {
1477 var args = Array.prototype.slice.call(arguments),
1478 viableNextSibling = this.nextSibling,
1479 idx = viableNextSibling ? args.indexOf(viableNextSibling) : -1;
1480
1481 while (idx !== -1) {
1482 viableNextSibling = viableNextSibling.nextSibling;
1483 if (!viableNextSibling) {
1484 break;
1485 }
1486 idx = args.indexOf(viableNextSibling);
1487 }
1488
1489 this.parentNode.insertBefore(_mutation(arguments), viableNextSibling);
1490 }
1491};
1492
1493// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
1494// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
1495if ("Text" in self) {
1496 Text.prototype.after = Element.prototype.after;
1497}
1498
1499}
1500
1501if (!("Element"in self&&"append"in Element.prototype
1502)) {
1503
1504// Element.prototype.append
1505/* global _mutation */
1506Document.prototype.append = Element.prototype.append = function append() {
1507 this.appendChild(_mutation(arguments));
1508};
1509
1510}
1511
1512if (!("Element"in self&&"before"in Element.prototype
1513)) {
1514
1515// Element.prototype.before
1516/* global _mutation */
1517Document.prototype.before = Element.prototype.before = function before() {
1518 if (this.parentNode) {
1519 var args = Array.prototype.slice.call(arguments),
1520 viablePreviousSibling = this.previousSibling,
1521 idx = viablePreviousSibling ? args.indexOf(viablePreviousSibling) : -1;
1522
1523 while (idx !== -1) {
1524 viablePreviousSibling = viablePreviousSibling.previousSibling;
1525 if (!viablePreviousSibling) {
1526 break;
1527 }
1528 idx = args.indexOf(viablePreviousSibling);
1529 }
1530
1531 this.parentNode.insertBefore(
1532 _mutation(arguments),
1533 viablePreviousSibling ? viablePreviousSibling.nextSibling : this.parentNode.firstChild
1534 );
1535 }
1536};
1537
1538// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
1539// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
1540if ("Text" in self) {
1541 Text.prototype.before = Element.prototype.before;
1542}
1543
1544}
1545
1546if (!("document"in self&&"classList"in document.documentElement&&"Element"in self&&"classList"in Element.prototype&&function(){var e=document.createElement("span")
1547return e.classList.add("a","b"),e.classList.contains("b")}()
1548)) {
1549
1550// Element.prototype.classList
1551/* global _DOMTokenList */
1552/*
1553Copyright (c) 2016, John Gardner
1554
1555Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
1556
1557THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1558*/
1559(function (global) {
1560 var dpSupport = true;
1561 var defineGetter = function (object, name, fn, configurable) {
1562 if (Object.defineProperty)
1563 Object.defineProperty(object, name, {
1564 configurable: false === dpSupport ? true : !!configurable,
1565 get: fn
1566 });
1567
1568 else object.__defineGetter__(name, fn);
1569 };
1570 /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1571 try {
1572 defineGetter({}, "support");
1573 }
1574 catch (e) {
1575 dpSupport = false;
1576 }
1577 /** Polyfills a property with a DOMTokenList */
1578 var addProp = function (o, name, attr) {
1579
1580 defineGetter(o.prototype, name, function () {
1581 var tokenList;
1582
1583 var THIS = this,
1584
1585 /** Prevent this from firing twice for some reason. What the hell, IE. */
1586 gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
1587 if(THIS[gibberishProperty]) return tokenList;
1588 THIS[gibberishProperty] = true;
1589
1590 /**
1591 * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
1592 *
1593 * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
1594 * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
1595 * element instead, this would conflict with element types which use indexed properties (such as forms and
1596 * select lists).
1597 */
1598 if (false === dpSupport) {
1599
1600 var visage;
1601 var mirror = addProp.mirror || document.createElement("div");
1602 var reflections = mirror.childNodes;
1603 var l = reflections.length;
1604
1605 for (var i = 0; i < l; ++i)
1606 if (reflections[i]._R === THIS) {
1607 visage = reflections[i];
1608 break;
1609 }
1610
1611 /** Couldn't find an element's reflection inside the mirror. Materialise one. */
1612 visage || (visage = mirror.appendChild(document.createElement("div")));
1613
1614 tokenList = DOMTokenList.call(visage, THIS, attr);
1615 } else tokenList = new _DOMTokenList(THIS, attr);
1616
1617 defineGetter(THIS, name, function () {
1618 return tokenList;
1619 });
1620 delete THIS[gibberishProperty];
1621
1622 return tokenList;
1623 }, true);
1624 };
1625
1626 addProp(global.Element, "classList", "className");
1627 addProp(global.HTMLElement, "classList", "className");
1628 addProp(global.HTMLLinkElement, "relList", "rel");
1629 addProp(global.HTMLAnchorElement, "relList", "rel");
1630 addProp(global.HTMLAreaElement, "relList", "rel");
1631}(self));
1632
1633}
1634
1635if (!("document"in self&&"matches"in document.documentElement
1636)) {
1637
1638// Element.prototype.matches
1639Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
1640
1641 var element = this;
1642 var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
1643 var index = 0;
1644
1645 while (elements[index] && elements[index] !== element) {
1646 ++index;
1647 }
1648
1649 return !!elements[index];
1650};
1651
1652}
1653
1654if (!("document"in self&&"closest"in document.documentElement
1655)) {
1656
1657// Element.prototype.closest
1658Element.prototype.closest = function closest(selector) {
1659 var node = this;
1660
1661 while (node) {
1662 if (node.matches(selector)) return node;
1663 else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
1664 }
1665
1666 return null;
1667};
1668
1669}
1670
1671if (!("Element"in self&&"prepend"in Element.prototype
1672)) {
1673
1674// Element.prototype.prepend
1675/* global _mutation */
1676Document.prototype.prepend = Element.prototype.prepend = function prepend() {
1677 this.insertBefore(_mutation(arguments), this.firstChild);
1678};
1679
1680}
1681
1682if (!("Element"in self&&"remove"in Element.prototype
1683)) {
1684
1685// Element.prototype.remove
1686Document.prototype.remove = Element.prototype.remove = function remove() {
1687 if (this.parentNode) {
1688 this.parentNode.removeChild(this);
1689 }
1690};
1691
1692// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
1693// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
1694if ("Text" in self) {
1695 Text.prototype.remove = Element.prototype.remove;
1696}
1697
1698}
1699
1700if (!("Element"in self&&"replaceWith"in Element.prototype
1701)) {
1702
1703// Element.prototype.replaceWith
1704/* global _mutation */
1705Document.prototype.replaceWith = Element.prototype.replaceWith = function replaceWith() {
1706 if (this.parentNode) {
1707 this.parentNode.replaceChild(_mutation(arguments), this);
1708 }
1709};
1710
1711// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
1712// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
1713if ('Text' in self) {
1714 Text.prototype.replaceWith = Element.prototype.replaceWith;
1715}
1716
1717}
1718
1719if (!((function(n){if(!("Event"in n))return!1
1720try{return new Event("click"),!0}catch(t){return!1}})(self)
1721)) {
1722
1723// Event
1724(function () {
1725 var unlistenableWindowEvents = {
1726 click: 1,
1727 dblclick: 1,
1728 keyup: 1,
1729 keypress: 1,
1730 keydown: 1,
1731 mousedown: 1,
1732 mouseup: 1,
1733 mousemove: 1,
1734 mouseover: 1,
1735 mouseenter: 1,
1736 mouseleave: 1,
1737 mouseout: 1,
1738 storage: 1,
1739 storagecommit: 1,
1740 textinput: 1
1741 };
1742
1743 // This polyfill depends on availability of `document` so will not run in a worker
1744 // However, we asssume there are no browsers with worker support that lack proper
1745 // support for `Event` within the worker
1746 if (typeof document === 'undefined' || typeof window === 'undefined') return;
1747
1748 var existingProto = (window.Event && window.Event.prototype) || null;
1749 function Event(type, eventInitDict) {
1750 if (!type) {
1751 throw new Error('Not enough arguments');
1752 }
1753
1754 var event;
1755 // Shortcut if browser supports createEvent
1756 if ('createEvent' in document) {
1757 event = document.createEvent('Event');
1758 var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1759 var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1760
1761 event.initEvent(type, bubbles, cancelable);
1762
1763 return event;
1764 }
1765
1766 event = document.createEventObject();
1767
1768 event.type = type;
1769 event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1770 event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1771
1772 return event;
1773 }
1774 Event.NONE = 0;
1775 Event.CAPTURING_PHASE = 1;
1776 Event.AT_TARGET = 2;
1777 Event.BUBBLING_PHASE = 3;
1778 window.Event = Window.prototype.Event = Event;
1779 if (existingProto) {
1780 Object.defineProperty(window.Event, 'prototype', {
1781 configurable: false,
1782 enumerable: false,
1783 writable: true,
1784 value: existingProto
1785 });
1786 }
1787
1788 if (!('createEvent' in document)) {
1789 window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
1790 var
1791 element = this,
1792 type = arguments[0],
1793 listener = arguments[1];
1794
1795 if (element === window && type in unlistenableWindowEvents) {
1796 throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
1797 }
1798
1799 if (!element._events) {
1800 element._events = {};
1801 }
1802
1803 if (!element._events[type]) {
1804 element._events[type] = function (event) {
1805 var
1806 list = element._events[event.type].list,
1807 events = list.slice(),
1808 index = -1,
1809 length = events.length,
1810 eventElement;
1811
1812 event.preventDefault = function preventDefault() {
1813 if (event.cancelable !== false) {
1814 event.returnValue = false;
1815 }
1816 };
1817
1818 event.stopPropagation = function stopPropagation() {
1819 event.cancelBubble = true;
1820 };
1821
1822 event.stopImmediatePropagation = function stopImmediatePropagation() {
1823 event.cancelBubble = true;
1824 event.cancelImmediate = true;
1825 };
1826
1827 event.currentTarget = element;
1828 event.relatedTarget = event.fromElement || null;
1829 event.target = event.target || event.srcElement || element;
1830 event.timeStamp = new Date().getTime();
1831
1832 if (event.clientX) {
1833 event.pageX = event.clientX + document.documentElement.scrollLeft;
1834 event.pageY = event.clientY + document.documentElement.scrollTop;
1835 }
1836
1837 while (++index < length && !event.cancelImmediate) {
1838 if (index in events) {
1839 eventElement = events[index];
1840
1841 if (list.includes(eventElement) && typeof eventElement === 'function') {
1842 eventElement.call(element, event);
1843 }
1844 }
1845 }
1846 };
1847
1848 element._events[type].list = [];
1849
1850 if (element.attachEvent) {
1851 element.attachEvent('on' + type, element._events[type]);
1852 }
1853 }
1854
1855 element._events[type].list.push(listener);
1856 };
1857
1858 window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
1859 var
1860 element = this,
1861 type = arguments[0],
1862 listener = arguments[1],
1863 index;
1864
1865 if (element._events && element._events[type] && element._events[type].list) {
1866 index = element._events[type].list.indexOf(listener);
1867
1868 if (index !== -1) {
1869 element._events[type].list.splice(index, 1);
1870
1871 if (!element._events[type].list.length) {
1872 if (element.detachEvent) {
1873 element.detachEvent('on' + type, element._events[type]);
1874 }
1875 delete element._events[type];
1876 }
1877 }
1878 }
1879 };
1880
1881 window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
1882 if (!arguments.length) {
1883 throw new Error('Not enough arguments');
1884 }
1885
1886 if (!event || typeof event.type !== 'string') {
1887 throw new Error('DOM Events Exception 0');
1888 }
1889
1890 var element = this, type = event.type;
1891
1892 try {
1893 if (!event.bubbles) {
1894 event.cancelBubble = true;
1895
1896 var cancelBubbleEvent = function (event) {
1897 event.cancelBubble = true;
1898
1899 (element || window).detachEvent('on' + type, cancelBubbleEvent);
1900 };
1901
1902 this.attachEvent('on' + type, cancelBubbleEvent);
1903 }
1904
1905 this.fireEvent('on' + type, event);
1906 } catch (error) {
1907 event.target = element;
1908
1909 do {
1910 event.currentTarget = element;
1911
1912 if ('_events' in element && typeof element._events[type] === 'function') {
1913 element._events[type].call(element, event);
1914 }
1915
1916 if (typeof element['on' + type] === 'function') {
1917 element['on' + type].call(element, event);
1918 }
1919
1920 element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
1921 } while (element && !event.cancelBubble);
1922 }
1923
1924 return true;
1925 };
1926
1927 // Add the DOMContentLoaded Event
1928 document.attachEvent('onreadystatechange', function() {
1929 if (document.readyState === 'complete') {
1930 document.dispatchEvent(new Event('DOMContentLoaded', {
1931 bubbles: true
1932 }));
1933 }
1934 });
1935 }
1936}());
1937
1938}
1939
1940if (!("CustomEvent"in self&&("function"==typeof self.CustomEvent||self.CustomEvent.toString().indexOf("CustomEventConstructor")>-1)
1941)) {
1942
1943// CustomEvent
1944self.CustomEvent = function CustomEvent(type, eventInitDict) {
1945 if (!type) {
1946 throw Error('TypeError: Failed to construct "CustomEvent": An event name must be provided.');
1947 }
1948
1949 var event;
1950 eventInitDict = eventInitDict || {bubbles: false, cancelable: false, detail: null};
1951
1952 if ('createEvent' in document) {
1953 try {
1954 event = document.createEvent('CustomEvent');
1955 event.initCustomEvent(type, eventInitDict.bubbles, eventInitDict.cancelable, eventInitDict.detail);
1956 } catch (error) {
1957 // for browsers which don't support CustomEvent at all, we use a regular event instead
1958 event = document.createEvent('Event');
1959 event.initEvent(type, eventInitDict.bubbles, eventInitDict.cancelable);
1960 event.detail = eventInitDict.detail;
1961 }
1962 } else {
1963
1964 // IE8
1965 event = new Event(type, eventInitDict);
1966 event.detail = eventInitDict && eventInitDict.detail || null;
1967 }
1968 return event;
1969};
1970
1971CustomEvent.prototype = Event.prototype;
1972
1973}
1974
1975if (!(document.contains
1976)) {
1977
1978// Node.prototype.contains
1979(function() {
1980
1981 function contains(node) {
1982 if (!(0 in arguments)) {
1983 throw new TypeError('1 argument is required');
1984 }
1985
1986 do {
1987 if (this === node) {
1988 return true;
1989 }
1990 // eslint-disable-next-line no-cond-assign
1991 } while (node = node && node.parentNode);
1992
1993 return false;
1994 }
1995
1996 // IE
1997 if ('HTMLElement' in self && 'contains' in HTMLElement.prototype) {
1998 try {
1999 delete HTMLElement.prototype.contains;
2000 // eslint-disable-next-line no-empty
2001 } catch (e) {}
2002 }
2003
2004 if ('Node' in self) {
2005 Node.prototype.contains = contains;
2006 } else {
2007 document.contains = Element.prototype.contains = contains;
2008 }
2009
2010}());
2011
2012}
2013
2014if (!("isNaN"in Number
2015)) {
2016
2017// Number.isNaN
2018/* global CreateMethodProperty, Type */
2019(function () {
2020 var that = self;
2021 // 20.1.2.4. Number.isNaN ( number )
2022 CreateMethodProperty(Number, 'isNaN', function isNaN(number) {
2023 // 1. If Type(number) is not Number, return false.
2024 if (Type(number) !== 'number') {
2025 return false;
2026 }
2027 // 2. If number is NaN, return true.
2028 if (that.isNaN(number)) {
2029 return true;
2030 }
2031 // 3. Otherwise, return false.
2032 return false;
2033 });
2034}());
2035
2036}
2037
2038if (!("getOwnPropertyDescriptor"in Object&&"function"==typeof Object.getOwnPropertyDescriptor&&function(){try{return"3"===Object.getOwnPropertyDescriptor("13.7",1).value}catch(t){return!1}}()
2039)) {
2040
2041// Object.getOwnPropertyDescriptor
2042/* global CreateMethodProperty, ToObject, ToPropertyKey, HasOwnProperty, Type */
2043(function () {
2044 var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
2045
2046 var supportsDOMDescriptors = (function () {
2047 try {
2048 return Object.defineProperty(document.createElement('div'), 'one', {
2049 get: function () {
2050 return 1;
2051 }
2052 }).one === 1;
2053 } catch (e) {
2054 return false;
2055 }
2056 });
2057
2058 var toString = ({}).toString;
2059 var split = ''.split;
2060
2061 // 19.1.2.8 Object.getOwnPropertyDescriptor ( O, P )
2062 CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(O, P) {
2063 // 1. Let obj be ? ToObject(O).
2064 var obj = ToObject(O);
2065 // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8)
2066 obj = (Type(obj) === 'string' || obj instanceof String) && toString.call(O) == '[object String]' ? split.call(O, '') : Object(O);
2067
2068 // 2. Let key be ? ToPropertyKey(P).
2069 var key = ToPropertyKey(P);
2070
2071 // 3. Let desc be ? obj.[[GetOwnProperty]](key).
2072 // 4. Return FromPropertyDescriptor(desc).
2073 // Polyfill.io Internet Explorer 8 natively supports property descriptors only on DOM objects.
2074 // We will fallback to the polyfill implementation if the native implementation throws an error.
2075 if (supportsDOMDescriptors) {
2076 try {
2077 return nativeGetOwnPropertyDescriptor(obj, key);
2078 // eslint-disable-next-line no-empty
2079 } catch (error) {}
2080 }
2081 if (HasOwnProperty(obj, key)) {
2082 return {
2083 enumerable: true,
2084 configurable: true,
2085 writable: true,
2086 value: obj[key]
2087 };
2088 }
2089 });
2090}());
2091
2092}
2093
2094if (!("isExtensible"in Object
2095)) {
2096
2097// Object.isExtensible
2098/* global CreateMethodProperty, Type */
2099
2100(function (nativeIsExtensible) {
2101 // 19.1.2.13 Object.isExtensible ( O )
2102 CreateMethodProperty(Object, 'isExtensible', function isExtensible(O) {
2103 // 1. If Type(O) is not Object, return false.
2104 if (Type(O) !== "object") {
2105 return false;
2106 }
2107 // 2. Return ? IsExtensible(O).
2108 return nativeIsExtensible ? nativeIsExtensible(O) : true;
2109 });
2110}(Object.isExtensible));
2111
2112}
2113
2114if (!("keys"in Object&&function(){return 2===Object.keys(arguments).length}(1,2)&&function(){try{return Object.keys(""),!0}catch(t){return!1}}()
2115)) {
2116
2117// Object.keys
2118/* global CreateMethodProperty */
2119CreateMethodProperty(Object, "keys", (function() {
2120 'use strict';
2121
2122 // modified from https://github.com/es-shims/object-keys
2123
2124 var has = Object.prototype.hasOwnProperty;
2125 var toStr = Object.prototype.toString;
2126 var isEnumerable = Object.prototype.propertyIsEnumerable;
2127 var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
2128 var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
2129 var dontEnums = [
2130 'toString',
2131 'toLocaleString',
2132 'valueOf',
2133 'hasOwnProperty',
2134 'isPrototypeOf',
2135 'propertyIsEnumerable',
2136 'constructor'
2137 ];
2138 var equalsConstructorPrototype = function (o) {
2139 var ctor = o.constructor;
2140 return ctor && ctor.prototype === o;
2141 };
2142 var excludedKeys = {
2143 $console: true,
2144 $external: true,
2145 $frame: true,
2146 $frameElement: true,
2147 $frames: true,
2148 $innerHeight: true,
2149 $innerWidth: true,
2150 $outerHeight: true,
2151 $outerWidth: true,
2152 $pageXOffset: true,
2153 $pageYOffset: true,
2154 $parent: true,
2155 $scrollLeft: true,
2156 $scrollTop: true,
2157 $scrollX: true,
2158 $scrollY: true,
2159 $self: true,
2160 $webkitIndexedDB: true,
2161 $webkitStorageInfo: true,
2162 $window: true
2163 };
2164 var hasAutomationEqualityBug = (function () {
2165 if (typeof window === 'undefined') { return false; }
2166 for (var k in window) {
2167 try {
2168 if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
2169 try {
2170 equalsConstructorPrototype(window[k]);
2171 } catch (e) {
2172 return true;
2173 }
2174 }
2175 } catch (e) {
2176 return true;
2177 }
2178 }
2179 return false;
2180 }());
2181 var equalsConstructorPrototypeIfNotBuggy = function (o) {
2182 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
2183 return equalsConstructorPrototype(o);
2184 }
2185 try {
2186 return equalsConstructorPrototype(o);
2187 } catch (e) {
2188 return false;
2189 }
2190 };
2191
2192 function isArgumentsObject(value) {
2193 var str = toStr.call(value);
2194 var isArgs = str === '[object Arguments]';
2195 if (!isArgs) {
2196 isArgs = str !== '[object Array]' &&
2197 value !== null &&
2198 typeof value === 'object' &&
2199 typeof value.length === 'number' &&
2200 value.length >= 0 &&
2201 toStr.call(value.callee) === '[object Function]';
2202 }
2203 return isArgs;
2204 }
2205
2206 return function keys(object) {
2207 var isFunction = toStr.call(object) === '[object Function]';
2208 var isArguments = isArgumentsObject(object);
2209 var isString = toStr.call(object) === '[object String]';
2210 var theKeys = [];
2211
2212 if (object === undefined || object === null) {
2213 throw new TypeError('Cannot convert undefined or null to object');
2214 }
2215
2216 var skipProto = hasProtoEnumBug && isFunction;
2217 if (isString && object.length > 0 && !has.call(object, 0)) {
2218 for (var i = 0; i < object.length; ++i) {
2219 theKeys.push(String(i));
2220 }
2221 }
2222
2223 if (isArguments && object.length > 0) {
2224 for (var j = 0; j < object.length; ++j) {
2225 theKeys.push(String(j));
2226 }
2227 } else {
2228 for (var name in object) {
2229 if (!(skipProto && name === 'prototype') && has.call(object, name)) {
2230 theKeys.push(String(name));
2231 }
2232 }
2233 }
2234
2235 if (hasDontEnumBug) {
2236 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
2237
2238 for (var k = 0; k < dontEnums.length; ++k) {
2239 if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
2240 theKeys.push(dontEnums[k]);
2241 }
2242 }
2243 }
2244 return theKeys;
2245 };
2246}()));
2247
2248}
2249
2250
2251// _ESAbstract.EnumerableOwnProperties
2252/* globals Type, Get */
2253// 7.3.21. EnumerableOwnProperties ( O, kind )
2254function EnumerableOwnProperties(O, kind) { // eslint-disable-line no-unused-vars
2255 // 1. Assert: Type(O) is Object.
2256 // 2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
2257 var ownKeys = Object.keys(O);
2258 // 3. Let properties be a new empty List.
2259 var properties = [];
2260 // 4. For each element key of ownKeys in List order, do
2261 var length = ownKeys.length;
2262 for (var i = 0; i < length; i++) {
2263 var key = ownKeys[i];
2264 // a. If Type(key) is String, then
2265 if (Type(key) === 'string') {
2266 // i. Let desc be ? O.[[GetOwnProperty]](key).
2267 var desc = Object.getOwnPropertyDescriptor(O, key);
2268 // ii. If desc is not undefined and desc.[[Enumerable]] is true, then
2269 if (desc && desc.enumerable) {
2270 // 1. If kind is "key", append key to properties.
2271 if (kind === 'key') {
2272 properties.push(key);
2273 // 2. Else,
2274 } else {
2275 // a. Let value be ? Get(O, key).
2276 var value = Get(O, key);
2277 // b. If kind is "value", append value to properties.
2278 if (kind === 'value') {
2279 properties.push(value);
2280 // c. Else,
2281 } else {
2282 // i. Assert: kind is "key+value".
2283 // ii. Let entry be CreateArrayFromList(« key, value »).
2284 var entry = [key, value];
2285 // iii. Append entry to properties.
2286 properties.push(entry);
2287 }
2288 }
2289 }
2290 }
2291 }
2292 // 5. Order the elements of properties so they are in the same relative order as would be produced by the Iterator that would be returned if the EnumerateObjectProperties internal method were invoked with O.
2293 // 6. Return properties.
2294 return properties;
2295}
2296if (!("entries"in Object
2297)) {
2298
2299// Object.entries
2300/* global CreateMethodProperty, EnumerableOwnProperties, ToObject, Type */
2301
2302(function () {
2303 var toString = ({}).toString;
2304 var split = ''.split;
2305
2306 // 19.1.2.5. Object.entries ( O )
2307 CreateMethodProperty(Object, 'entries', function entries(O) {
2308 // 1. Let obj be ? ToObject(O).
2309 var obj = ToObject(O);
2310 // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8)
2311 obj = (Type(obj) === 'string' || obj instanceof String) && toString.call(O) == '[object String]' ? split.call(O, '') : Object(O);
2312 // 2. Let nameList be ? EnumerableOwnProperties(obj, "key+value").
2313 var nameList = EnumerableOwnProperties(obj, "key+value");
2314 // 3. Return CreateArrayFromList(nameList).
2315 // Polyfill.io - nameList is already an array.
2316 return nameList;
2317 });
2318}());
2319}
2320
2321if (!("assign"in Object
2322)) {
2323
2324// Object.assign
2325/* global CreateMethodProperty, Get, ToObject */
2326// 19.1.2.1 Object.assign ( target, ...sources )
2327CreateMethodProperty(Object, 'assign', function assign(target, source) { // eslint-disable-line no-unused-vars
2328 // 1. Let to be ? ToObject(target).
2329 var to = ToObject(target);
2330
2331 // 2. If only one argument was passed, return to.
2332 if (arguments.length === 1) {
2333 return to;
2334 }
2335
2336 // 3. Let sources be the List of argument values starting with the second argument
2337 var sources = Array.prototype.slice.call(arguments, 1);
2338
2339 // 4. For each element nextSource of sources, in ascending index order, do
2340 var index1;
2341 var index2;
2342 var keys;
2343 var from;
2344 for (index1 = 0; index1 < sources.length; index1++) {
2345 var nextSource = sources[index1];
2346 // a. If nextSource is undefined or null, let keys be a new empty List.
2347 if (nextSource === undefined || nextSource === null) {
2348 keys = [];
2349 // b. Else,
2350 } else {
2351 // Polyfill.io - In order to get strings in ES3 and old V8 working correctly we need to split them into an array ourselves.
2352 // i. Let from be ! ToObject(nextSource).
2353 from = Object.prototype.toString.call(nextSource) === '[object String]' ? String(nextSource).split('') : ToObject(nextSource);
2354 // ii. Let keys be ? from.[[OwnPropertyKeys]]().
2355 /*
2356 This step in our polyfill is not complying with the specification.
2357 [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols.
2358 TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]].
2359 */
2360 keys = Object.keys(from);
2361 }
2362
2363 // c. For each element nextKey of keys in List order, do
2364 for (index2 = 0; index2 < keys.length; index2++) {
2365 var nextKey = keys[index2];
2366 var enumerable;
2367 try {
2368 // i. Let desc be ? from.[[GetOwnProperty]](nextKey).
2369 var desc = Object.getOwnPropertyDescriptor(from, nextKey);
2370 // ii. If desc is not undefined and desc.[[Enumerable]] is true, then
2371 enumerable = desc !== undefined && desc.enumerable === true;
2372 } catch (e) {
2373 // Polyfill.io - We use Object.prototype.propertyIsEnumerable as a fallback
2374 // because `Object.getOwnPropertyDescriptor(window.location, 'hash')` causes Internet Explorer 11 to crash.
2375 enumerable = Object.prototype.propertyIsEnumerable.call(from, nextKey);
2376 }
2377 if (enumerable) {
2378 // 1. Let propValue be ? Get(from, nextKey).
2379 var propValue = Get(from, nextKey);
2380 // 2. Perform ? Set(to, nextKey, propValue, true).
2381 to[nextKey] = propValue;
2382 }
2383 }
2384 }
2385 // 5. Return to.
2386 return to;
2387});
2388
2389}
2390
2391if (!("endsWith"in String.prototype
2392)) {
2393
2394// String.prototype.endsWith
2395/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */
2396// 21.1.3.6. String.prototype.endsWith ( searchString [ , endPosition ] )
2397CreateMethodProperty(String.prototype, 'endsWith', function endsWith(searchString /* [ , endPosition ] */) {
2398 'use strict';
2399 var endPosition = arguments.length > 1 ? arguments[1] : undefined;
2400 // 1. Let O be ? RequireObjectCoercible(this value).
2401 var O = RequireObjectCoercible(this);
2402 // 2. Let S be ? ToString(O).
2403 var S = ToString(O);
2404 // 3. Let isRegExp be ? IsRegExp(searchString).
2405 var isRegExp = IsRegExp(searchString);
2406 // 4. If isRegExp is true, throw a TypeError exception.
2407 if (isRegExp) {
2408 throw new TypeError('First argument to String.prototype.endsWith must not be a regular expression');
2409 }
2410 // 5. Let searchStr be ? ToString(searchString).
2411 var searchStr = ToString(searchString);
2412 // 6. Let len be the length of S.
2413 var len = S.length;
2414 // 7. If endPosition is undefined, let pos be len, else let pos be ? ToInteger(endPosition).
2415 var pos = endPosition === undefined ? len : ToInteger(endPosition);
2416 // 8. Let end be min(max(pos, 0), len).
2417 var end = Math.min(Math.max(pos, 0), len);
2418 // 9. Let searchLength be the length of searchStr.
2419 var searchLength = searchStr.length;
2420 // 10. Let start be end - searchLength.
2421 var start = end - searchLength;
2422 // 11. If start is less than 0, return false.
2423 if (start < 0) {
2424 return false;
2425 }
2426 // 12. If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr, return true.
2427 if (S.substr(start, searchLength) === searchStr) {
2428 return true;
2429 }
2430 // 13. Otherwise, return false.
2431 return false;
2432});
2433
2434}
2435
2436if (!("includes"in String.prototype
2437)) {
2438
2439// String.prototype.includes
2440/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */
2441// 21.1.3.7. String.prototype.includes ( searchString [ , position ] )
2442CreateMethodProperty(String.prototype, 'includes', function includes(searchString /* [ , position ] */) {
2443 'use strict';
2444 var position = arguments.length > 1 ? arguments[1] : undefined;
2445 // 1. Let O be ? RequireObjectCoercible(this value).
2446 var O = RequireObjectCoercible(this);
2447 // 2. Let S be ? ToString(O).
2448 var S = ToString(O);
2449 // 3. Let isRegExp be ? IsRegExp(searchString).
2450 var isRegExp = IsRegExp(searchString);
2451 // 4. If isRegExp is true, throw a TypeError exception.
2452 if (isRegExp) {
2453 throw new TypeError('First argument to String.prototype.includes must not be a regular expression');
2454 }
2455 // 5. Let searchStr be ? ToString(searchString).
2456 var searchStr = ToString(searchString);
2457 // 6. Let pos be ? ToInteger(position). (If position is undefined, this step produces the value 0.)
2458 var pos = ToInteger(position);
2459 // 7. Let len be the length of S.
2460 var len = S.length;
2461 // 8. Let start be min(max(pos, 0), len).
2462 var start = Math.min(Math.max(pos, 0), len);
2463 // 9. Let searchLen be the length of searchStr.
2464 // var searchLength = searchStr.length;
2465 // 10. If there exists any integer k not smaller than start such that k + searchLen is not greater than len, and for all nonnegative integers j less than searchLen, the code unit at index k+j within S is the same as the code unit at index j within searchStr, return true; but if there is no such integer k, return false.
2466 return String.prototype.indexOf.call(S, searchStr, start) !== -1;
2467});
2468
2469}
2470
2471if (!("repeat"in String.prototype
2472)) {
2473
2474// String.prototype.repeat
2475/* global CreateMethodProperty, RequireObjectCoercible, ToInteger, ToString */
2476// 21.1.3.15String.prototype.repeat ( count )
2477CreateMethodProperty(String.prototype, 'repeat', function repeat(count) {
2478 'use strict';
2479 // 1. Let O be ? RequireObjectCoercible(this value).
2480 var O = RequireObjectCoercible(this);
2481 // 2. Let S be ? ToString(O).
2482 var S = ToString(O);
2483 // 3. Let n be ? ToInteger(count).
2484 var n = ToInteger(count);
2485 // 4. If n < 0, throw a RangeError exception.
2486 if (n < 0) {
2487 throw new RangeError('Invalid count value');
2488 }
2489 // 5. If n is +∞, throw a RangeError exception.
2490 if (n === Infinity) {
2491 throw new RangeError('Invalid count value');
2492 }
2493 // 6. Let T be the String value that is made from n copies of S appended together. If n is 0, T is the empty String.
2494 var T = n === 0 ? '' : new Array(n + 1).join(S);
2495 // 7. Return T.
2496 return T;
2497});
2498
2499}
2500
2501if (!("startsWith"in String.prototype
2502)) {
2503
2504// String.prototype.startsWith
2505/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */
2506// 21.1.3.20. String.prototype.startsWith ( searchString [ , position ] )
2507CreateMethodProperty(String.prototype, 'startsWith', function startsWith(searchString /* [ , position ] */) {
2508 'use strict';
2509 var position = arguments.length > 1 ? arguments[1] : undefined;
2510 // 1. Let O be ? RequireObjectCoercible(this value).
2511 var O = RequireObjectCoercible(this);
2512 // 2. Let S be ? ToString(O).
2513 var S = ToString(O);
2514 // 3. Let isRegExp be ? IsRegExp(searchString).
2515 var isRegExp = IsRegExp(searchString);
2516 // 4. If isRegExp is true, throw a TypeError exception.
2517 if (isRegExp) {
2518 throw new TypeError('First argument to String.prototype.startsWith must not be a regular expression');
2519 }
2520 // 5. Let searchStr be ? ToString(searchString).
2521 var searchStr = ToString(searchString);
2522 // 6. Let pos be ? ToInteger(position). (If position is undefined, this step produces the value 0.)
2523 var pos = ToInteger(position);
2524 // 7. Let len be the length of S.
2525 var len = S.length;
2526 // 8. Let start be min(max(pos, 0), len).
2527 var start = Math.min(Math.max(pos, 0), len);
2528 // 9. Let searchLength be the length of searchStr.
2529 var searchLength = searchStr.length;
2530 // 10. If searchLength+start is greater than len, return false.
2531 if (searchLength + start > len) {
2532 return false;
2533 }
2534 // 11. If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr, return true.
2535 if (S.substr(start).indexOf(searchString) === 0) {
2536 return true;
2537 }
2538 // 12. Otherwise, return false.
2539 return false;
2540});
2541
2542}
2543
2544if (!("trim"in String.prototype&&function(){var r="
"
2545return!"\t\n\x0B\f\r \u2028\u2029\ufeff".trim()&&r.trim()===r}()
2546)) {
2547
2548// String.prototype.trim
2549/* global CreateMethodProperty, TrimString */
2550// 21.1.3.27. String.prototype.trim ( )
2551CreateMethodProperty(String.prototype, 'trim', function trim() {
2552 'use strict';
2553 // Let S be this value.
2554 var S = this;
2555 // Return ? TrimString(S, "start+end").
2556 return TrimString(S, "start+end");
2557});
2558
2559}
2560
2561if (!("parseFloat"in Number&&1/parseFloat("\t\n\x0B\f\r \u2028\u2029\ufeff-0")==-Infinity
2562)) {
2563
2564// Number.parseFloat
2565/* global CreateMethodProperty */
2566(function (nativeparseFloat, global) {
2567 var parseFloat = function parseFloat(str) {
2568 var string = String(str).trim();
2569 var result = nativeparseFloat(string);
2570 return result === 0 && string.charAt(0) == '-' ? -0 : result;
2571 }
2572 try {
2573 CreateMethodProperty(global, 'parseFloat', parseFloat);
2574 } catch (e) {
2575 // IE8 throws an error here if we set enumerable to false.
2576 // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx
2577 global.parseFloat = parseFloat;
2578 }
2579 // 20.1.2.12. Number.parseFloat ( string )
2580 // The value of the Number.parseFloat data property is the same built-in function object that is the value of the parseFloat property of the global object defined in 18.2.4.
2581 CreateMethodProperty(Number, 'parseFloat', global.parseFloat);
2582}(parseFloat, this));
2583}
2584
2585if (!("Symbol"in self&&0===self.Symbol.length
2586)) {
2587
2588// Symbol
2589// A modification of https://github.com/WebReflection/get-own-property-symbols
2590// (C) Andrea Giammarchi - MIT Licensed
2591
2592(function (Object, GOPS, global) {
2593 'use strict'; //so that ({}).toString.call(null) returns the correct [object Null] rather than [object Window]
2594
2595 var setDescriptor;
2596 var id = 0;
2597 var random = '' + Math.random();
2598 var prefix = '__\x01symbol:';
2599 var prefixLength = prefix.length;
2600 var internalSymbol = '__\x01symbol@@' + random;
2601 var DP = 'defineProperty';
2602 var DPies = 'defineProperties';
2603 var GOPN = 'getOwnPropertyNames';
2604 var GOPD = 'getOwnPropertyDescriptor';
2605 var PIE = 'propertyIsEnumerable';
2606 var ObjectProto = Object.prototype;
2607 var hOP = ObjectProto.hasOwnProperty;
2608 var pIE = ObjectProto[PIE];
2609 var toString = ObjectProto.toString;
2610 var concat = Array.prototype.concat;
2611 var cachedWindowNames = Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : [];
2612 var nGOPN = Object[GOPN];
2613 var gOPN = function getOwnPropertyNames (obj) {
2614 if (toString.call(obj) === '[object Window]') {
2615 try {
2616 return nGOPN(obj);
2617 } catch (e) {
2618 // IE bug where layout engine calls userland gOPN for cross-domain `window` objects
2619 return concat.call([], cachedWindowNames);
2620 }
2621 }
2622 return nGOPN(obj);
2623 };
2624 var gOPD = Object[GOPD];
2625 var create = Object.create;
2626 var keys = Object.keys;
2627 var freeze = Object.freeze || Object;
2628 var defineProperty = Object[DP];
2629 var $defineProperties = Object[DPies];
2630 var descriptor = gOPD(Object, GOPN);
2631 var addInternalIfNeeded = function (o, uid, enumerable) {
2632 if (!hOP.call(o, internalSymbol)) {
2633 try {
2634 defineProperty(o, internalSymbol, {
2635 enumerable: false,
2636 configurable: false,
2637 writable: false,
2638 value: {}
2639 });
2640 } catch (e) {
2641 o[internalSymbol] = {};
2642 }
2643 }
2644 o[internalSymbol]['@@' + uid] = enumerable;
2645 };
2646 var createWithSymbols = function (proto, descriptors) {
2647 var self = create(proto);
2648 gOPN(descriptors).forEach(function (key) {
2649 if (propertyIsEnumerable.call(descriptors, key)) {
2650 $defineProperty(self, key, descriptors[key]);
2651 }
2652 });
2653 return self;
2654 };
2655 var copyAsNonEnumerable = function (descriptor) {
2656 var newDescriptor = create(descriptor);
2657 newDescriptor.enumerable = false;
2658 return newDescriptor;
2659 };
2660 var get = function get(){};
2661 var onlyNonSymbols = function (name) {
2662 return name != internalSymbol &&
2663 !hOP.call(source, name);
2664 };
2665 var onlySymbols = function (name) {
2666 return name != internalSymbol &&
2667 hOP.call(source, name);
2668 };
2669 var propertyIsEnumerable = function propertyIsEnumerable(key) {
2670 var uid = '' + key;
2671 return onlySymbols(uid) ? (
2672 hOP.call(this, uid) &&
2673 this[internalSymbol]['@@' + uid]
2674 ) : pIE.call(this, key);
2675 };
2676 var setAndGetSymbol = function (uid) {
2677 var descriptor = {
2678 enumerable: false,
2679 configurable: true,
2680 get: get,
2681 set: function (value) {
2682 setDescriptor(this, uid, {
2683 enumerable: false,
2684 configurable: true,
2685 writable: true,
2686 value: value
2687 });
2688 addInternalIfNeeded(this, uid, true);
2689 }
2690 };
2691 try {
2692 defineProperty(ObjectProto, uid, descriptor);
2693 } catch (e) {
2694 ObjectProto[uid] = descriptor.value;
2695 }
2696 return freeze(source[uid] = defineProperty(
2697 Object(uid),
2698 'constructor',
2699 sourceConstructor
2700 ));
2701 };
2702 var Symbol = function Symbol() {
2703 var description = arguments[0];
2704 if (this instanceof Symbol) {
2705 throw new TypeError('Symbol is not a constructor');
2706 }
2707 return setAndGetSymbol(
2708 prefix.concat(description || '', random, ++id)
2709 );
2710 };
2711 var source = create(null);
2712 var sourceConstructor = {value: Symbol};
2713 var sourceMap = function (uid) {
2714 return source[uid];
2715 };
2716 var $defineProperty = function defineProp(o, key, descriptor) {
2717 var uid = '' + key;
2718 if (onlySymbols(uid)) {
2719 setDescriptor(o, uid, descriptor.enumerable ?
2720 copyAsNonEnumerable(descriptor) : descriptor);
2721 addInternalIfNeeded(o, uid, !!descriptor.enumerable);
2722 } else {
2723 defineProperty(o, key, descriptor);
2724 }
2725 return o;
2726 };
2727
2728 var onlyInternalSymbols = function (obj) {
2729 return function (name) {
2730 return hOP.call(obj, internalSymbol) && hOP.call(obj[internalSymbol], '@@' + name);
2731 };
2732 };
2733 var $getOwnPropertySymbols = function getOwnPropertySymbols(o) {
2734 return gOPN(o).filter(o === ObjectProto ? onlyInternalSymbols(o) : onlySymbols).map(sourceMap);
2735 }
2736 ;
2737
2738 descriptor.value = $defineProperty;
2739 defineProperty(Object, DP, descriptor);
2740
2741 descriptor.value = $getOwnPropertySymbols;
2742 defineProperty(Object, GOPS, descriptor);
2743
2744 descriptor.value = function getOwnPropertyNames(o) {
2745 return gOPN(o).filter(onlyNonSymbols);
2746 };
2747 defineProperty(Object, GOPN, descriptor);
2748
2749 descriptor.value = function defineProperties(o, descriptors) {
2750 var symbols = $getOwnPropertySymbols(descriptors);
2751 if (symbols.length) {
2752 keys(descriptors).concat(symbols).forEach(function (uid) {
2753 if (propertyIsEnumerable.call(descriptors, uid)) {
2754 $defineProperty(o, uid, descriptors[uid]);
2755 }
2756 });
2757 } else {
2758 $defineProperties(o, descriptors);
2759 }
2760 return o;
2761 };
2762 defineProperty(Object, DPies, descriptor);
2763
2764 descriptor.value = propertyIsEnumerable;
2765 defineProperty(ObjectProto, PIE, descriptor);
2766
2767 descriptor.value = Symbol;
2768 defineProperty(global, 'Symbol', descriptor);
2769
2770 // defining `Symbol.for(key)`
2771 descriptor.value = function (key) {
2772 var uid = prefix.concat(prefix, key, random);
2773 return uid in ObjectProto ? source[uid] : setAndGetSymbol(uid);
2774 };
2775 defineProperty(Symbol, 'for', descriptor);
2776
2777 // defining `Symbol.keyFor(symbol)`
2778 descriptor.value = function (symbol) {
2779 if (onlyNonSymbols(symbol))
2780 throw new TypeError(symbol + ' is not a symbol');
2781 return hOP.call(source, symbol) ?
2782 symbol.slice(prefixLength * 2, -random.length) :
2783 void 0
2784 ;
2785 };
2786 defineProperty(Symbol, 'keyFor', descriptor);
2787
2788 descriptor.value = function getOwnPropertyDescriptor(o, key) {
2789 var descriptor = gOPD(o, key);
2790 if (descriptor && onlySymbols(key)) {
2791 descriptor.enumerable = propertyIsEnumerable.call(o, key);
2792 }
2793 return descriptor;
2794 };
2795 defineProperty(Object, GOPD, descriptor);
2796
2797 descriptor.value = function (proto, descriptors) {
2798 return arguments.length === 1 || typeof descriptors === "undefined" ?
2799 create(proto) :
2800 createWithSymbols(proto, descriptors);
2801 };
2802 defineProperty(Object, 'create', descriptor);
2803
2804 var strictModeSupported = (function(){ 'use strict'; return this; }).call(null) === null;
2805 if (strictModeSupported) {
2806 descriptor.value = function () {
2807 var str = toString.call(this);
2808 return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str;
2809 };
2810 } else {
2811 descriptor.value = function () {
2812 // https://github.com/Financial-Times/polyfill-library/issues/164#issuecomment-486965300
2813 // Polyfill.io this code is here for the situation where a browser does not
2814 // support strict mode and is executing `Object.prototype.toString.call(null)`.
2815 // This code ensures that we return the correct result in that situation however,
2816 // this code also introduces a bug where it will return the incorrect result for
2817 // `Object.prototype.toString.call(window)`. We can't have the correct result for
2818 // both `window` and `null`, so we have opted for `null` as we believe this is the more
2819 // common situation.
2820 if (this === window) {
2821 return '[object Null]';
2822 }
2823
2824 var str = toString.call(this);
2825 return (str === '[object String]' && onlySymbols(this)) ? '[object Symbol]' : str;
2826 };
2827 }
2828 defineProperty(ObjectProto, 'toString', descriptor);
2829
2830 setDescriptor = function (o, key, descriptor) {
2831 var protoDescriptor = gOPD(ObjectProto, key);
2832 delete ObjectProto[key];
2833 defineProperty(o, key, descriptor);
2834 if (o !== ObjectProto) {
2835 defineProperty(ObjectProto, key, protoDescriptor);
2836 }
2837 };
2838
2839}(Object, 'getOwnPropertySymbols', this));
2840
2841}
2842
2843if (!("Symbol"in self&&"iterator"in self.Symbol
2844)) {
2845
2846// Symbol.iterator
2847Object.defineProperty(self.Symbol, 'iterator', { value: self.Symbol('iterator') });
2848
2849}
2850
2851
2852// _ESAbstract.GetIterator
2853/* global GetMethod, Symbol, Call, Type, GetV */
2854// 7.4.1. GetIterator ( obj [ , method ] )
2855// The abstract operation GetIterator with argument obj and optional argument method performs the following steps:
2856function GetIterator(obj /*, method */) { // eslint-disable-line no-unused-vars
2857 // 1. If method is not present, then
2858 // a. Set method to ? GetMethod(obj, @@iterator).
2859 var method = arguments.length > 1 ? arguments[1] : GetMethod(obj, Symbol.iterator);
2860 // 2. Let iterator be ? Call(method, obj).
2861 var iterator = Call(method, obj);
2862 // 3. If Type(iterator) is not Object, throw a TypeError exception.
2863 if (Type(iterator) !== 'object') {
2864 throw new TypeError('bad iterator');
2865 }
2866 // 4. Let nextMethod be ? GetV(iterator, "next").
2867 var nextMethod = GetV(iterator, "next");
2868 // 5. Let iteratorRecord be Record {[[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false}.
2869 var iteratorRecord = Object.create(null);
2870 iteratorRecord['[[Iterator]]'] = iterator;
2871 iteratorRecord['[[NextMethod]]'] = nextMethod;
2872 iteratorRecord['[[Done]]'] = false;
2873 // 6. Return iteratorRecord.
2874 return iteratorRecord;
2875}
2876if (!("Symbol"in self&&"species"in self.Symbol
2877)) {
2878
2879// Symbol.species
2880/* global Symbol */
2881Object.defineProperty(Symbol, 'species', { value: Symbol('species') });
2882
2883}
2884
2885if (!("Map"in self&&function(t){try{var n=new t.Map([[1,1],[2,2]])
2886return 0===t.Map.length&&2===n.size&&"Symbol"in t&&"iterator"in t.Symbol&&"function"==typeof n[t.Symbol.iterator]}catch(e){return!1}}(self)
2887)) {
2888
2889// Map
2890/* global CreateIterResultObject, CreateMethodProperty, GetIterator, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Type, Symbol */
2891(function (global) {
2892 var supportsGetters = (function () {
2893 try {
2894 var a = {};
2895 Object.defineProperty(a, 't', {
2896 configurable: true,
2897 enumerable: false,
2898 get: function () {
2899 return true;
2900 },
2901 set: undefined
2902 });
2903 return !!a.t;
2904 } catch (e) {
2905 return false;
2906 }
2907 }());
2908
2909 // Need an internal counter to assign unique IDs to a key map
2910 var _uniqueHashId = 0;
2911 // Create a unique key name for storing meta data on functions and objects to enable lookups in hash table
2912 var _metaKey = Symbol('meta_' + (Math.random() * 100000000) + ''.replace('.', ''));
2913
2914 /**
2915 * hashKey()
2916 * Function that given a key of `any` type, returns a string key value to enable hash map optimization for accessing Map data structure
2917 * @param {string|integer|function|object} recordKey - Record key to normalize to string accessor for hash map
2918 * @returns {string|false} - Returns a hashed string value or false if non extensible object key
2919 */
2920 var hashKey = function(recordKey) {
2921 // Check to see if we are dealing with object or function type.
2922 if (typeof recordKey === 'object' ? recordKey !== null : typeof recordKey === 'function') {
2923 // Check to see if we are dealing with a non extensible object
2924 if (!Object.isExtensible(recordKey)) {
2925 // Return `false`
2926 return false;
2927 }
2928 if (!recordKey[_metaKey]) {
2929 var uniqueHashKey = typeof(recordKey)+'-'+(++_uniqueHashId);
2930 Object.defineProperty(recordKey, _metaKey, {
2931 configurable: false,
2932 enumerable: false,
2933 writable: false,
2934 value: uniqueHashKey
2935 });
2936 }
2937 // Return previously defined hashed key
2938 return recordKey[_metaKey];
2939 }
2940 // If this is just a primitive, we can cast it to a string and return it
2941 return ''+recordKey;
2942 };
2943
2944 /**
2945 * getRecordIndex()
2946 * Function that given a Map and a key of `any` type, returns an index number that coorelates with a record found in `this._keys[index]` and `this._values[index]`
2947 * @param {Map} map - Map structure
2948 * @param {string|number|function|object} recordKey - Record key to normalize to string accessor for hash map
2949 * @returns {number|false} - Returns either a index to access map._keys and map._values, or false if not found
2950 */
2951 var getRecordIndex = function(map, recordKey) {
2952 var hashedKey = hashKey(recordKey); // Casts key to unique string (unless already string or number)
2953 if (hashedKey === false) {
2954 // We have to iterate through our Map structure because `recordKey` is non-primitive and not extensible
2955 return getRecordIndexSlow(map, recordKey);
2956 }
2957 var recordIndex = map._table[hashedKey]; // O(1) access to record
2958 return recordIndex !== undefined ? recordIndex : false;
2959 };
2960
2961 /**
2962 * getRecordIndexSlow()
2963 * Alternative (and slower) function to `getRecordIndex()`. Necessary for looking up non-extensible object keys.
2964 * @param {Map} map - Map structure
2965 * @param {string|number|function|object} recordKey - Record key to normalize to string accessor for hash map
2966 * @returns {number|false} - Returns either a index to access map._keys and map._values, or false if not found
2967 */
2968 var getRecordIndexSlow = function(map, recordKey) {
2969 // We have to iterate through our Map structure because `recordKey` is non-primitive and not extensible
2970 for (var i = 0; i < map._keys.length; i++) {
2971 var _recordKey = map._keys[i];
2972 if (_recordKey !== undefMarker && SameValueZero(_recordKey, recordKey)) {
2973 return i;
2974 }
2975 }
2976 return false;
2977 };
2978
2979 /**
2980 * setHashIndex()
2981 * Function that given a map, key of `any` type, and a value, creates a new entry in Map hash table
2982 * @param {Map} map
2983 * @param {string|number|function|object} recordKey - Key to translate into normalized key for hash map
2984 * @param {number} recordIndex - record index
2985 * @returns {bool} - indicates success of operation
2986 */
2987 var setHashIndex = function(map, recordKey, recordIndex) {
2988 var hashedKey = hashKey(recordKey);
2989 if (!hashedKey) {
2990 // If hashed key is false, the recordKey is an object which is not extensible.
2991 // That indicates we cannot use the hash map for it, so this operation becomes no-op.
2992 return false;
2993 }
2994 if (recordIndex === false) {
2995 delete map._table[hashedKey];
2996 } else {
2997 map._table[hashedKey] = recordIndex;
2998 }
2999 return true;
3000 };
3001
3002 // Deleted map items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol.
3003 var undefMarker = Symbol('undef');
3004 // 23.1.1.1 Map ( [ iterable ] )
3005 var Map = function Map(/* iterable */) {
3006 // 1. If NewTarget is undefined, throw a TypeError exception.
3007 if (!(this instanceof Map)) {
3008 throw new TypeError('Constructor Map requires "new"');
3009 }
3010 // 2. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", « [[MapData]] »).
3011 var map = OrdinaryCreateFromConstructor(this, Map.prototype, {
3012 _table: {}, // O(1) access table for retrieving records
3013 _keys: [],
3014 _values: [],
3015 _size: 0,
3016 _es6Map: true
3017 });
3018
3019 // 3. Set map.[[MapData]] to a new empty List.
3020 // Polyfill.io - This step was done as part of step two.
3021
3022 // Some old engines do not support ES5 getters/setters. Since Map only requires these for the size property, we can fall back to setting the size property statically each time the size of the map changes.
3023 if (!supportsGetters) {
3024 Object.defineProperty(map, 'size', {
3025 configurable: true,
3026 enumerable: false,
3027 writable: true,
3028 value: 0
3029 });
3030 }
3031
3032 // 4. If iterable is not present, let iterable be undefined.
3033 var iterable = arguments.length > 0 ? arguments[0] : undefined;
3034
3035 // 5. If iterable is either undefined or null, return map.
3036 if (iterable === null || iterable === undefined) {
3037 return map;
3038 }
3039
3040 // 6. Let adder be ? Get(map, "set").
3041 var adder = map.set;
3042
3043 // 7. If IsCallable(adder) is false, throw a TypeError exception.
3044 if (!IsCallable(adder)) {
3045 throw new TypeError("Map.prototype.set is not a function");
3046 }
3047
3048 // 8. Let iteratorRecord be ? GetIterator(iterable).
3049 try {
3050 var iteratorRecord = GetIterator(iterable);
3051 // 9. Repeat,
3052 // eslint-disable-next-line no-constant-condition
3053 while (true) {
3054 // a. Let next be ? IteratorStep(iteratorRecord).
3055 var next = IteratorStep(iteratorRecord);
3056 // b. If next is false, return map.
3057 if (next === false) {
3058 return map;
3059 }
3060 // c. Let nextItem be ? IteratorValue(next).
3061 var nextItem = IteratorValue(next);
3062 // d. If Type(nextItem) is not Object, then
3063 if (Type(nextItem) !== 'object') {
3064 // i. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}.
3065 try {
3066 throw new TypeError('Iterator value ' + nextItem + ' is not an entry object');
3067 } catch (error) {
3068 // ii. Return ? IteratorClose(iteratorRecord, error).
3069 return IteratorClose(iteratorRecord, error);
3070 }
3071 }
3072 try {
3073 // Polyfill.io - The try catch accounts for steps: f, h, and j.
3074
3075 // e. Let k be Get(nextItem, "0").
3076 var k = nextItem[0];
3077 // f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k).
3078 // g. Let v be Get(nextItem, "1").
3079 var v = nextItem[1];
3080 // h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v).
3081 // i. Let status be Call(adder, map, « k.[[Value]], v.[[Value]] »).
3082 adder.call(map, k, v);
3083 } catch (e) {
3084 // j. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status).
3085 return IteratorClose(iteratorRecord, e);
3086 }
3087 }
3088 } catch (e) {
3089 // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those.
3090 if (Array.isArray(iterable) ||
3091 Object.prototype.toString.call(iterable) === '[object Arguments]' ||
3092 // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property
3093 (!!iterable.callee)) {
3094 var index;
3095 var length = iterable.length;
3096 for (index = 0; index < length; index++) {
3097 adder.call(map, iterable[index][0], iterable[index][1]);
3098 }
3099 }
3100 }
3101 return map;
3102 };
3103
3104 // 23.1.2.1. Map.prototype
3105 // The initial value of Map.prototype is the intrinsic object %MapPrototype%.
3106 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
3107 Object.defineProperty(Map, 'prototype', {
3108 configurable: false,
3109 enumerable: false,
3110 writable: false,
3111 value: {}
3112 });
3113
3114 // 23.1.2.2 get Map [ @@species ]
3115 if (supportsGetters) {
3116 Object.defineProperty(Map, Symbol.species, {
3117 configurable: true,
3118 enumerable: false,
3119 get: function () {
3120 // 1. Return the this value.
3121 return this;
3122 },
3123 set: undefined
3124 });
3125 } else {
3126 CreateMethodProperty(Map, Symbol.species, Map);
3127 }
3128
3129 // 23.1.3.1 Map.prototype.clear ( )
3130 CreateMethodProperty(Map.prototype, 'clear', function clear() {
3131 // 1. Let M be the this value.
3132 var M = this;
3133 // 2. If Type(M) is not Object, throw a TypeError exception.
3134 if (Type(M) !== 'object') {
3135 throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
3136 }
3137 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3138 if (M._es6Map !== true) {
3139 throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
3140 }
3141 // 4. Let entries be the List that is M.[[MapData]].
3142 var entries = M._keys;
3143 // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3144 for (var i = 0; i < entries.length; i++) {
3145 // 5.a. Set p.[[Key]] to empty.
3146 M._keys[i] = undefMarker;
3147 // 5.b. Set p.[[Value]] to empty.
3148 M._values[i] = undefMarker;
3149 }
3150 this._size = 0;
3151 if (!supportsGetters) {
3152 this.size = this._size;
3153 }
3154 // 5a. Clear lookup table
3155 this._table = {};
3156 // 6. Return undefined.
3157 return undefined;
3158 }
3159 );
3160
3161 // 23.1.3.2. Map.prototype.constructor
3162 CreateMethodProperty(Map.prototype, 'constructor', Map);
3163
3164 // 23.1.3.3. Map.prototype.delete ( key )
3165 CreateMethodProperty(Map.prototype, 'delete', function (key) {
3166 // 1. Let M be the this value.
3167 var M = this;
3168 // 2. If Type(M) is not Object, throw a TypeError exception.
3169 if (Type(M) !== 'object') {
3170 throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
3171 }
3172 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3173 if (M._es6Map !== true) {
3174 throw new TypeError('Method Map.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(M));
3175 }
3176 // 4. Let entries be the List that is M.[[MapData]].
3177 // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3178 // 5a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then
3179 // i. Set p.[[Key]] to empty.
3180 // ii. Set p.[[Value]] to empty.
3181 // ii-a. Remove key from lookup table
3182 // iii. Return true.
3183 // 6. Return false.
3184
3185 // Implement steps 4-6 with a more optimal algo
3186
3187 // Steps 4-5: Access record
3188 var recordIndex = getRecordIndex(M, key); // O(1) access to record index
3189
3190 if (recordIndex !== false) {
3191 // Get record's `key` (could be `any` type);
3192 var recordKey = M._keys[recordIndex];
3193 // 5a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, then
3194 if (recordKey !== undefMarker && SameValueZero(recordKey, key)) {
3195 // i. Set p.[[Key]] to empty.
3196 this._keys[recordIndex] = undefMarker;
3197 // ii. Set p.[[Value]] to empty.
3198 this._values[recordIndex] = undefMarker;
3199 this._size = --this._size;
3200 if (!supportsGetters) {
3201 this.size = this._size;
3202 }
3203 // iia. Remove key from lookup table
3204 setHashIndex(this, key, false);
3205 // iii. Return true.
3206 return true;
3207 }
3208 }
3209
3210 // 6. Return false.
3211 return false;
3212 }
3213 );
3214
3215 // 23.1.3.4. Map.prototype.entries ( )
3216 CreateMethodProperty(Map.prototype, 'entries', function entries () {
3217 // 1. Let M be the this value.
3218 var M = this;
3219 // 2. Return ? CreateMapIterator(M, "key+value").
3220 return CreateMapIterator(M, 'key+value');
3221 }
3222 );
3223
3224 // 23.1.3.5. Map.prototype.forEach ( callbackfn [ , thisArg ] )
3225 CreateMethodProperty(Map.prototype, 'forEach', function (callbackFn) {
3226 // 1. Let M be the this value.
3227 var M = this;
3228 // 2. If Type(M) is not Object, throw a TypeError exception.
3229 if (Type(M) !== 'object') {
3230 throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M));
3231 }
3232 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3233 if (M._es6Map !== true) {
3234 throw new TypeError('Method Map.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(M));
3235 }
3236 // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
3237 if (!IsCallable(callbackFn)) {
3238 throw new TypeError(Object.prototype.toString.call(callbackFn) + ' is not a function.');
3239 }
3240 // 5. If thisArg is present, let T be thisArg; else let T be undefined.
3241 if (arguments[1]) {
3242 var T = arguments[1];
3243 }
3244 // 6. Let entries be the List that is M.[[MapData]].
3245 var entries = M._keys;
3246 // 7. For each Record {[[Key]], [[Value]]} e that is an element of entries, in original key insertion order, do
3247 for (var i = 0; i < entries.length; i++) {
3248 // a. If e.[[Key]] is not empty, then
3249 if (M._keys[i] !== undefMarker && M._values[i] !== undefMarker ) {
3250 // i. Perform ? Call(callbackfn, T, « e.[[Value]], e.[[Key]], M »).
3251 callbackFn.call(T, M._values[i], M._keys[i], M);
3252 }
3253 }
3254 // 8. Return undefined.
3255 return undefined;
3256 }
3257 );
3258
3259 // 23.1.3.6. Map.prototype.get ( key )
3260 CreateMethodProperty(Map.prototype, 'get', function get(key) {
3261 // 1. Let M be the this value.
3262 var M = this;
3263 // 2. If Type(M) is not Object, throw a TypeError exception.
3264 if (Type(M) !== 'object') {
3265 throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M));
3266 }
3267 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3268 if (M._es6Map !== true) {
3269 throw new TypeError('Method Map.prototype.get called on incompatible receiver ' + Object.prototype.toString.call(M));
3270 }
3271 // 4. Let entries be the List that is M.[[MapData]].
3272 // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3273 // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return p.[[Value]].
3274 // 6. Return undefined.
3275
3276 // Implement steps 4-6 with a more optimal algo
3277 var recordIndex = getRecordIndex(M, key); // O(1) access to record index
3278 if (recordIndex !== false) {
3279 var recordKey = M._keys[recordIndex];
3280 if (recordKey !== undefMarker && SameValueZero(recordKey, key)) {
3281 return M._values[recordIndex];
3282 }
3283 }
3284
3285 return undefined;
3286 });
3287
3288 // 23.1.3.7. Map.prototype.has ( key )
3289 CreateMethodProperty(Map.prototype, 'has', function has (key) {
3290 // 1. Let M be the this value.
3291 var M = this;
3292 // 2. If Type(M) is not Object, throw a TypeError exception.
3293 if (typeof M !== 'object') {
3294 throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M));
3295 }
3296 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3297 if (M._es6Map !== true) {
3298 throw new TypeError('Method Map.prototype.has called on incompatible receiver ' + Object.prototype.toString.call(M));
3299 }
3300 // 4. Let entries be the List that is M.[[MapData]].
3301 // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3302 // a. If p.[[Key]] is not empty and SameValueZero(p.[[Key]], key) is true, return true.
3303 // 6. Return false.
3304
3305 // Implement steps 4-6 with a more optimal algo
3306 var recordIndex = getRecordIndex(M, key); // O(1) access to record index
3307 if (recordIndex !== false) {
3308 var recordKey = M._keys[recordIndex];
3309 if (recordKey !== undefMarker && SameValueZero(recordKey, key)) {
3310 return true;
3311 }
3312 }
3313
3314 return false;
3315 });
3316
3317 // 23.1.3.8. Map.prototype.keys ( )
3318 CreateMethodProperty(Map.prototype, 'keys', function keys () {
3319 // 1. Let M be the this value.
3320 var M = this;
3321 // 2. Return ? CreateMapIterator(M, "key").
3322 return CreateMapIterator(M, "key");
3323 });
3324
3325 // 23.1.3.9. Map.prototype.set ( key, value )
3326 CreateMethodProperty(Map.prototype, 'set', function set(key, value) {
3327 // 1. Let M be the this value.
3328 var M = this;
3329 // 2. If Type(M) is not Object, throw a TypeError exception.
3330 if (Type(M) !== 'object') {
3331 throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M));
3332 }
3333 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3334 if (M._es6Map !== true) {
3335 throw new TypeError('Method Map.prototype.set called on incompatible receiver ' + Object.prototype.toString.call(M));
3336 }
3337 // 4. Let entries be the List that is M.[[MapData]].
3338 // 5. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3339 // 6. If key is -0, let key be +0.
3340 // 7. Let p be the Record {[[Key]]: key, [[Value]]: value}.
3341 // 8. Append p as the last element of entries.
3342 // 9. Return M.
3343
3344 // Strictly following the above steps 4-9 will lead to an inefficient algorithm.
3345 // Step 8 also doesn't seem to be required if an entry already exists
3346 var recordIndex = getRecordIndex(M, key); // O(1) access to record index
3347 if (recordIndex !== false) {
3348 // update path
3349 M._values[recordIndex] = value;
3350 } else {
3351 // eslint-disable-next-line no-compare-neg-zero
3352 if (key === -0) {
3353 key = 0;
3354 }
3355 var p = {
3356 '[[Key]]': key,
3357 '[[Value]]': value
3358 };
3359 M._keys.push(p['[[Key]]']);
3360 M._values.push(p['[[Value]]']);
3361 setHashIndex(M, key, M._keys.length - 1); // update lookup table
3362 ++M._size;
3363 if (!supportsGetters) {
3364 M.size = M._size;
3365 }
3366 }
3367 return M;
3368 });
3369
3370 // 23.1.3.10. get Map.prototype.size
3371 if (supportsGetters) {
3372 Object.defineProperty(Map.prototype, 'size', {
3373 configurable: true,
3374 enumerable: false,
3375 get: function () {
3376 // 1. Let M be the this value.
3377 var M = this;
3378 // 2. If Type(M) is not Object, throw a TypeError exception.
3379 if (Type(M) !== 'object') {
3380 throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M));
3381 }
3382 // 3. If M does not have a [[MapData]] internal slot, throw a TypeError exception.
3383 if (M._es6Map !== true) {
3384 throw new TypeError('Method Map.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(M));
3385 }
3386 // 4. Let entries be the List that is M.[[MapData]].
3387 // 5. Let count be 0.
3388 // 6. For each Record {[[Key]], [[Value]]} p that is an element of entries, do
3389 // 6a. If p.[[Key]] is not empty, set count to count+1.
3390 // 7. Return count.
3391
3392 // Implement 4-7 more efficently by returning pre-computed property
3393 return this._size;
3394 },
3395 set: undefined
3396 });
3397 }
3398
3399 // 23.1.3.11. Map.prototype.values ( )
3400 CreateMethodProperty(Map.prototype, 'values', function values () {
3401 // 1. Let M be the this value.
3402 var M = this;
3403 // 2. Return ? CreateMapIterator(M, "value").
3404 return CreateMapIterator(M, 'value');
3405 }
3406 );
3407
3408 // 23.1.3.12. Map.prototype [ @@iterator ] ( )
3409 // The initial value of the @@iterator property is the same function object as the initial value of the entries property.
3410 CreateMethodProperty(Map.prototype, Symbol.iterator, Map.prototype.entries);
3411
3412 // 23.1.3.13. Map.prototype [ @@toStringTag ]
3413 // The initial value of the @@toStringTag property is the String value "Map".
3414 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
3415
3416 // Polyfill.io - Safari 8 implements Map.name but as a non-configurable property, which means it would throw an error if we try and configure it here.
3417 if (!('name' in Map)) {
3418 // 19.2.4.2 name
3419 Object.defineProperty(Map, 'name', {
3420 configurable: true,
3421 enumerable: false,
3422 writable: false,
3423 value: 'Map'
3424 });
3425 }
3426
3427 // 23.1.5.1. CreateMapIterator ( map, kind )
3428 function CreateMapIterator(map, kind) {
3429 // 1. If Type(map) is not Object, throw a TypeError exception.
3430 if (Type(map) !== 'object') {
3431 throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map));
3432 }
3433 // 2. If map does not have a [[MapData]] internal slot, throw a TypeError exception.
3434 if (map._es6Map !== true) {
3435 throw new TypeError('createMapIterator called on incompatible receiver ' + Object.prototype.toString.call(map));
3436 }
3437 // 3. Let iterator be ObjectCreate(%MapIteratorPrototype%, « [[Map]], [[MapNextIndex]], [[MapIterationKind]] »).
3438 var iterator = Object.create(MapIteratorPrototype);
3439 // 4. Set iterator.[[Map]] to map.
3440 Object.defineProperty(iterator, '[[Map]]', {
3441 configurable: true,
3442 enumerable: false,
3443 writable: true,
3444 value: map
3445 });
3446 // 5. Set iterator.[[MapNextIndex]] to 0.
3447 Object.defineProperty(iterator, '[[MapNextIndex]]', {
3448 configurable: true,
3449 enumerable: false,
3450 writable: true,
3451 value: 0
3452 });
3453 // 6. Set iterator.[[MapIterationKind]] to kind.
3454 Object.defineProperty(iterator, '[[MapIterationKind]]', {
3455 configurable: true,
3456 enumerable: false,
3457 writable: true,
3458 value: kind
3459 });
3460 // 7. Return iterator.
3461 return iterator;
3462 }
3463
3464 // 23.1.5.2. The %MapIteratorPrototype% Object
3465 var MapIteratorPrototype = {};
3466 // Polyfill.io - We use this as a quick way to check if an object is a Map Iterator instance.
3467 Object.defineProperty(MapIteratorPrototype, 'isMapIterator', {
3468 configurable: false,
3469 enumerable: false,
3470 writable: false,
3471 value: true
3472 });
3473
3474 // 23.1.5.2.1. %MapIteratorPrototype%.next ( )
3475 CreateMethodProperty(MapIteratorPrototype, 'next', function next() {
3476 // 1. Let O be the this value.
3477 var O = this;
3478 // 2. If Type(O) is not Object, throw a TypeError exception.
3479 if (Type(O) !== 'object') {
3480 throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
3481 }
3482 // 3. If O does not have all of the internal slots of a Map Iterator Instance (23.1.5.3), throw a TypeError exception.
3483 if (!O.isMapIterator) {
3484 throw new TypeError('Method %MapIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
3485 }
3486 // 4. Let m be O.[[Map]].
3487 var m = O['[[Map]]'];
3488 // 5. Let index be O.[[MapNextIndex]].
3489 var index = O['[[MapNextIndex]]'];
3490 // 6. Let itemKind be O.[[MapIterationKind]].
3491 var itemKind = O['[[MapIterationKind]]'];
3492 // 7. If m is undefined, return CreateIterResultObject(undefined, true).
3493 if (m === undefined) {
3494 return CreateIterResultObject(undefined, true);
3495 }
3496 // 8. Assert: m has a [[MapData]] internal slot.
3497 if (!m._es6Map) {
3498 throw new Error(Object.prototype.toString.call(m) + ' has a [[MapData]] internal slot.');
3499 }
3500 // 9. Let entries be the List that is m.[[MapData]].
3501 var entries = m._keys;
3502 // 10. Let numEntries be the number of elements of entries.
3503 var numEntries = entries.length;
3504 // 11. NOTE: numEntries must be redetermined each time this method is evaluated.
3505 // 12. Repeat, while index is less than numEntries,
3506 while (index < numEntries) {
3507 // a. Let e be the Record {[[Key]], [[Value]]} that is the value of entries[index].
3508 var e = Object.create(null);
3509 e['[[Key]]'] = m._keys[index];
3510 e['[[Value]]'] = m._values[index];
3511 // b. Set index to index+1.
3512 index = index + 1;
3513 // c. Set O.[[MapNextIndex]] to index.
3514 O['[[MapNextIndex]]'] = index;
3515 // d. If e.[[Key]] is not empty, then
3516 if (e['[[Key]]'] !== undefMarker) {
3517 // i. If itemKind is "key", let result be e.[[Key]].
3518 if (itemKind === 'key') {
3519 var result = e['[[Key]]'];
3520 // ii. Else if itemKind is "value", let result be e.[[Value]].
3521 } else if (itemKind === 'value') {
3522 result = e['[[Value]]'];
3523 // iii. Else,
3524 } else {
3525 // 1. Assert: itemKind is "key+value".
3526 if (itemKind !== 'key+value') {
3527 throw new Error();
3528 }
3529 // 2. Let result be CreateArrayFromList(« e.[[Key]], e.[[Value]] »).
3530 result = [
3531 e['[[Key]]'],
3532 e['[[Value]]']
3533 ];
3534 }
3535 // iv. Return CreateIterResultObject(result, false).
3536 return CreateIterResultObject(result, false);
3537 }
3538 }
3539 // 13. Set O.[[Map]] to undefined.
3540 O['[[Map]]'] = undefined;
3541 // 14. Return CreateIterResultObject(undefined, true).
3542 return CreateIterResultObject(undefined, true);
3543 }
3544 );
3545
3546 // 23.1.5.2.2 %MapIteratorPrototype% [ @@toStringTag ]
3547 // The initial value of the @@toStringTag property is the String value "Map Iterator".
3548 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
3549
3550 CreateMethodProperty(MapIteratorPrototype, Symbol.iterator, function iterator() {
3551 return this;
3552 }
3553 );
3554
3555 // Export the object
3556 try {
3557 CreateMethodProperty(global, 'Map', Map);
3558 } catch (e) {
3559 // IE8 throws an error here if we set enumerable to false.
3560 // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx
3561 global.Map = Map;
3562 }
3563}(self));
3564
3565}
3566
3567if (!("Set"in self&&function(){try{var e=new self.Set([1,2])
3568return 0===self.Set.length&&2===e.size&&"Symbol"in self&&"iterator"in self.Symbol&&"function"==typeof e[self.Symbol.iterator]}catch(t){return!1}}()
3569)) {
3570
3571// Set
3572/* global CreateIterResultObject, CreateMethodProperty, GetIterator, IsCallable, IteratorClose, IteratorStep, IteratorValue, OrdinaryCreateFromConstructor, SameValueZero, Symbol */
3573(function (global) {
3574 var supportsGetters = (function () {
3575 try {
3576 var a = {};
3577 Object.defineProperty(a, 't', {
3578 configurable: true,
3579 enumerable: false,
3580 get: function () {
3581 return true;
3582 },
3583 set: undefined
3584 });
3585 return !!a.t;
3586 } catch (e) {
3587 return false;
3588 }
3589 }());
3590
3591 // Deleted set items mess with iterator pointers, so rather than removing them mark them as deleted. Can't use undefined or null since those both valid keys so use a private symbol.
3592 var undefMarker = Symbol('undef');
3593 // 23.2.1.1. Set ( [ iterable ] )
3594 var Set = function Set(/* iterable */) {
3595 // 1. If NewTarget is undefined, throw a TypeError exception.
3596 if (!(this instanceof Set)) {
3597 throw new TypeError('Constructor Set requires "new"');
3598 }
3599 // 2. Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] »).
3600 var set = OrdinaryCreateFromConstructor(this, Set.prototype, {
3601 _values: [],
3602 _size: 0,
3603 _es6Set: true
3604 });
3605
3606 // 3. Set set.[[SetData]] to a new empty List.
3607 // Polyfill.io - This step was done as part of step two.
3608
3609 // Some old engines do not support ES5 getters/setters. Since Set only requires these for the size property, we can fall back to setting the size property statically each time the size of the set changes.
3610 if (!supportsGetters) {
3611 Object.defineProperty(set, 'size', {
3612 configurable: true,
3613 enumerable: false,
3614 writable: true,
3615 value: 0
3616 });
3617 }
3618
3619 // 4. If iterable is not present, let iterable be undefined.
3620 var iterable = arguments.length > 0 ? arguments[0] : undefined;
3621
3622 // 5. If iterable is either undefined or null, return set.
3623 if (iterable === null || iterable === undefined) {
3624 return set;
3625 }
3626
3627 // 6. Let adder be ? Get(set, "add").
3628 var adder = set.add;
3629 // 7. If IsCallable(adder) is false, throw a TypeError exception.
3630 if (!IsCallable(adder)) {
3631 throw new TypeError("Set.prototype.add is not a function");
3632 }
3633
3634 try {
3635 // 8. Let iteratorRecord be ? GetIterator(iterable).
3636 var iteratorRecord = GetIterator(iterable);
3637 // 9. Repeat,
3638 // eslint-disable-next-line no-constant-condition
3639 while (true) {
3640 // a. Let next be ? IteratorStep(iteratorRecord).
3641 var next = IteratorStep(iteratorRecord);
3642 // b. If next is false, return set.
3643 if (next === false) {
3644 return set;
3645 }
3646 // c. Let nextValue be ? IteratorValue(next).
3647 var nextValue = IteratorValue(next);
3648 // d. Let status be Call(adder, set, « nextValue.[[Value]] »).
3649 try {
3650 adder.call(set, nextValue);
3651 } catch (e) {
3652 // e. If status is an abrupt completion, return ? IteratorClose(iteratorRecord, status).
3653 return IteratorClose(iteratorRecord, e);
3654 }
3655 }
3656 } catch (e) {
3657 // Polyfill.io - For user agents which do not have iteration methods on argument objects or arrays, we can special case those.
3658 if (Array.isArray(iterable) ||
3659 Object.prototype.toString.call(iterable) === '[object Arguments]' ||
3660 // IE 7 & IE 8 return '[object Object]' for the arguments object, we can detect by checking for the existence of the callee property
3661 (!!iterable.callee)) {
3662 var index;
3663 var length = iterable.length;
3664 for (index = 0; index < length; index++) {
3665 adder.call(set, iterable[index]);
3666 }
3667 } else {
3668 throw (e);
3669 }
3670 }
3671 return set;
3672 };
3673
3674 // 23.2.2.1. Set.prototype
3675 // The initial value of Set.prototype is the intrinsic %SetPrototype% object.
3676 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
3677 Object.defineProperty(Set, 'prototype', {
3678 configurable: false,
3679 enumerable: false,
3680 writable: false,
3681 value: {}
3682 });
3683
3684 // 23.2.2.2 get Set [ @@species ]
3685 if (supportsGetters) {
3686 Object.defineProperty(Set, Symbol.species, {
3687 configurable: true,
3688 enumerable: false,
3689 get: function () {
3690 // 1. Return the this value.
3691 return this;
3692 },
3693 set: undefined
3694 });
3695 } else {
3696 CreateMethodProperty(Set, Symbol.species, Set);
3697 }
3698
3699 // 23.2.3.1. Set.prototype.add ( value )
3700 CreateMethodProperty(Set.prototype, 'add', function add(value) {
3701 // 1. Let S be the this value.
3702 var S = this;
3703 // 2. If Type(S) is not Object, throw a TypeError exception.
3704 if (typeof S !== 'object') {
3705 throw new TypeError('Method Set.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S));
3706 }
3707 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3708 if (S._es6Set !== true) {
3709 throw new TypeError('Method Set.prototype.add called on incompatible receiver ' + Object.prototype.toString.call(S));
3710 }
3711 // 4. Let entries be the List that is S.[[SetData]].
3712 var entries = S._values;
3713 // 5. For each e that is an element of entries, do
3714 for (var i = 0; i < entries.length; i++) {
3715 var e = entries[i];
3716 // a. If e is not empty and SameValueZero(e, value) is true, then
3717 if (e !== undefMarker && SameValueZero(e, value)) {
3718 // i. Return S.
3719 return S;
3720 }
3721 }
3722 // 6. If value is -0, let value be +0.
3723 if (value === 0 && 1/value === -Infinity) {
3724 value = 0;
3725 }
3726 // 7. Append value as the last element of entries.
3727 S._values.push(value);
3728
3729 this._size = ++this._size;
3730 if (!supportsGetters) {
3731 this.size = this._size;
3732 }
3733 // 8. Return S.
3734 return S;
3735 });
3736
3737 // 23.2.3.2. Set.prototype.clear ( )
3738 CreateMethodProperty(Set.prototype, 'clear', function clear() {
3739 // 1. Let S be the this value.
3740 var S = this;
3741 // 2. If Type(S) is not Object, throw a TypeError exception.
3742 if (typeof S !== 'object') {
3743 throw new TypeError('Method Set.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(S));
3744 }
3745 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3746 if (S._es6Set !== true) {
3747 throw new TypeError('Method Set.prototype.clear called on incompatible receiver ' + Object.prototype.toString.call(S));
3748 }
3749 // 4. Let entries be the List that is S.[[SetData]].
3750 var entries = S._values;
3751 // 5. For each e that is an element of entries, do
3752 for (var i = 0; i < entries.length; i++) {
3753 // a. Replace the element of entries whose value is e with an element whose value is empty.
3754 entries[i] = undefMarker;
3755 }
3756 this._size = 0;
3757 if (!supportsGetters) {
3758 this.size = this._size;
3759 }
3760 // 6. Return undefined.
3761 return undefined;
3762 });
3763
3764 // 23.2.3.3. Set.prototype.constructor
3765 CreateMethodProperty(Set.prototype, 'constructor', Set);
3766
3767 // 23.2.3.4. Set.prototype.delete ( value )
3768 CreateMethodProperty(Set.prototype, 'delete', function (value) {
3769 // 1. Let S be the this value.
3770 var S = this;
3771 // 2. If Type(S) is not Object, throw a TypeError exception.
3772 if (typeof S !== 'object') {
3773 throw new TypeError('Method Set.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S));
3774 }
3775 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3776 if (S._es6Set !== true) {
3777 throw new TypeError('Method Set.prototype.delete called on incompatible receiver ' + Object.prototype.toString.call(S));
3778 }
3779 // 4. Let entries be the List that is S.[[SetData]].
3780 var entries = S._values;
3781 // 5. For each e that is an element of entries, do
3782 for (var i = 0; i < entries.length; i++) {
3783 var e = entries[i];
3784 // a. If e is not empty and SameValueZero(e, value) is true, then
3785 if (e !== undefMarker && SameValueZero(e, value)) {
3786 // i. Replace the element of entries whose value is e with an element whose value is empty.
3787 entries[i] = undefMarker;
3788
3789 this._size = --this._size;
3790 if (!supportsGetters) {
3791 this.size = this._size;
3792 }
3793 // ii. Return true.
3794 return true;
3795 }
3796 }
3797 // 6. Return false.
3798 return false;
3799 }
3800 );
3801
3802 // 23.2.3.5. Set.prototype.entries ( )
3803 CreateMethodProperty(Set.prototype, 'entries', function entries() {
3804 // 1. Let S be the this value.
3805 var S = this;
3806 // 2. Return ? CreateSetIterator(S, "key+value").
3807 return CreateSetIterator(S, 'key+value');
3808 }
3809 );
3810
3811 // 23.2.3.6. Set.prototype.forEach ( callbackfn [ , thisArg ] )
3812 CreateMethodProperty(Set.prototype, 'forEach', function forEach(callbackFn /*[ , thisArg ]*/) {
3813 // 1. Let S be the this value.
3814 var S = this;
3815 // 2. If Type(S) is not Object, throw a TypeError exception.
3816 if (typeof S !== 'object') {
3817 throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S));
3818 }
3819 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3820 if (S._es6Set !== true) {
3821 throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S));
3822 }
3823 // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
3824 if (!IsCallable(callbackFn)) {
3825 throw new TypeError(Object.prototype.toString.call(callbackFn) + ' is not a function.');
3826 }
3827 // 5. If thisArg is present, let T be thisArg; else let T be undefined.
3828 if (arguments[1]) {
3829 var T = arguments[1];
3830 }
3831 // 6. Let entries be the List that is S.[[SetData]].
3832 var entries = S._values;
3833 // 7. For each e that is an element of entries, in original insertion order, do
3834 for (var i = 0; i < entries.length; i++) {
3835 var e = entries[i];
3836 // a. If e is not empty, then
3837 if (e !== undefMarker) {
3838 // i. Perform ? Call(callbackfn, T, « e, e, S »).
3839 callbackFn.call(T, e, e, S);
3840 }
3841 }
3842 // 8. Return undefined.
3843 return undefined;
3844 }
3845 );
3846
3847 // 23.2.3.7. Set.prototype.has ( value )
3848 CreateMethodProperty(Set.prototype, 'has', function has(value) {
3849 // 1. Let S be the this value.
3850 var S = this;
3851 // 2. If Type(S) is not Object, throw a TypeError exception.
3852 if (typeof S !== 'object') {
3853 throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S));
3854 }
3855 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3856 if (S._es6Set !== true) {
3857 throw new TypeError('Method Set.prototype.forEach called on incompatible receiver ' + Object.prototype.toString.call(S));
3858 }
3859 // 4. Let entries be the List that is S.[[SetData]].
3860 var entries = S._values;
3861 // 5. For each e that is an element of entries, do
3862 for (var i = 0; i < entries.length; i++) {
3863 var e = entries[i];
3864 // a. If e is not empty and SameValueZero(e, value) is true, return true.
3865 if (e !== undefMarker && SameValueZero(e, value)) {
3866 return true;
3867 }
3868 }
3869 // 6. Return false.
3870 return false;
3871 }
3872 );
3873
3874 // Polyfill.io - We need to define Set.prototype.values before Set.prototype.keys because keys is a reference to values.
3875 // 23.2.3.10. Set.prototype.values()
3876 var values = function values() {
3877 // 1. Let S be the this value.
3878 var S = this;
3879 // 2. Return ? CreateSetIterator(S, "value").
3880 return CreateSetIterator(S, "value");
3881 };
3882 CreateMethodProperty(Set.prototype, 'values', values);
3883
3884 // 23.2.3.8 Set.prototype.keys ( )
3885 // The initial value of the keys property is the same function object as the initial value of the values property.
3886 CreateMethodProperty(Set.prototype, 'keys', values);
3887
3888 // 23.2.3.9. get Set.prototype.size
3889 if (supportsGetters) {
3890 Object.defineProperty(Set.prototype, 'size', {
3891 configurable: true,
3892 enumerable: false,
3893 get: function () {
3894 // 1. Let S be the this value.
3895 var S = this;
3896 // 2. If Type(S) is not Object, throw a TypeError exception.
3897 if (typeof S !== 'object') {
3898 throw new TypeError('Method Set.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(S));
3899 }
3900 // 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
3901 if (S._es6Set !== true) {
3902 throw new TypeError('Method Set.prototype.size called on incompatible receiver ' + Object.prototype.toString.call(S));
3903 }
3904 // 4. Let entries be the List that is S.[[SetData]].
3905 var entries = S._values;
3906 // 5. Let count be 0.
3907 var count = 0;
3908 // 6. For each e that is an element of entries, do
3909 for (var i = 0; i < entries.length; i++) {
3910 var e = entries[i];
3911 // a. If e is not empty, set count to count+1.
3912 if (e !== undefMarker) {
3913 count = count + 1;
3914 }
3915 }
3916 // 7. Return count.
3917 return count;
3918 },
3919 set: undefined
3920 });
3921 }
3922
3923 // 23.2.3.11. Set.prototype [ @@iterator ] ( )
3924 // The initial value of the @@iterator property is the same function object as the initial value of the values property.
3925 CreateMethodProperty(Set.prototype, Symbol.iterator, values);
3926
3927 // 23.2.3.12. Set.prototype [ @@toStringTag ]
3928 // The initial value of the @@toStringTag property is the String value "Set".
3929 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
3930
3931 // Polyfill.io - Safari 8 implements Set.name but as a non-configurable property, which means it would throw an error if we try and configure it here.
3932 if (!('name' in Set)) {
3933 // 19.2.4.2 name
3934 Object.defineProperty(Set, 'name', {
3935 configurable: true,
3936 enumerable: false,
3937 writable: false,
3938 value: 'Set'
3939 });
3940 }
3941
3942 // 23.2.5.1. CreateSetIterator ( set, kind )
3943 function CreateSetIterator(set, kind) {
3944 // 1. If Type(set) is not Object, throw a TypeError exception.
3945 if (typeof set !== 'object') {
3946 throw new TypeError('createSetIterator called on incompatible receiver ' + Object.prototype.toString.call(set));
3947 }
3948 // 2. If set does not have a [[SetData]] internal slot, throw a TypeError exception.
3949 if (set._es6Set !== true) {
3950 throw new TypeError('createSetIterator called on incompatible receiver ' + Object.prototype.toString.call(set));
3951 }
3952 // 3. Let iterator be ObjectCreate(%SetIteratorPrototype%, « [[IteratedSet]], [[SetNextIndex]], [[SetIterationKind]] »).
3953 var iterator = Object.create(SetIteratorPrototype);
3954 // 4. Set iterator.[[IteratedSet]] to set.
3955 Object.defineProperty(iterator, '[[IteratedSet]]', {
3956 configurable: true,
3957 enumerable: false,
3958 writable: true,
3959 value: set
3960 });
3961 // 5. Set iterator.[[SetNextIndex]] to 0.
3962 Object.defineProperty(iterator, '[[SetNextIndex]]', {
3963 configurable: true,
3964 enumerable: false,
3965 writable: true,
3966 value: 0
3967 });
3968 // 6. Set iterator.[[SetIterationKind]] to kind.
3969 Object.defineProperty(iterator, '[[SetIterationKind]]', {
3970 configurable: true,
3971 enumerable: false,
3972 writable: true,
3973 value: kind
3974 });
3975 // 7. Return iterator.
3976 return iterator;
3977 }
3978
3979 // 23.2.5.2. The %SetIteratorPrototype% Object
3980 var SetIteratorPrototype = {};
3981 //Polyfill.io - We add this property to help us identify what is a set iterator.
3982 Object.defineProperty(SetIteratorPrototype, 'isSetIterator', {
3983 configurable: false,
3984 enumerable: false,
3985 writable: false,
3986 value: true
3987 });
3988
3989 // 23.2.5.2.1. %SetIteratorPrototype%.next ( )
3990 CreateMethodProperty(SetIteratorPrototype, 'next', function next() {
3991 // 1. Let O be the this value.
3992 var O = this;
3993 // 2. If Type(O) is not Object, throw a TypeError exception.
3994 if (typeof O !== 'object') {
3995 throw new TypeError('Method %SetIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
3996 }
3997 // 3. If O does not have all of the internal slots of a Set Iterator Instance (23.2.5.3), throw a TypeError exception.
3998 if (!O.isSetIterator) {
3999 throw new TypeError('Method %SetIteratorPrototype%.next called on incompatible receiver ' + Object.prototype.toString.call(O));
4000 }
4001 // 4. Let s be O.[[IteratedSet]].
4002 var s = O['[[IteratedSet]]'];
4003 // 5. Let index be O.[[SetNextIndex]].
4004 var index = O['[[SetNextIndex]]'];
4005 // 6. Let itemKind be O.[[SetIterationKind]].
4006 var itemKind = O['[[SetIterationKind]]'];
4007 // 7. If s is undefined, return CreateIterResultObject(undefined, true).
4008 if (s === undefined) {
4009 return CreateIterResultObject(undefined, true);
4010 }
4011 // 8. Assert: s has a [[SetData]] internal slot.
4012 if (!s._es6Set) {
4013 throw new Error(Object.prototype.toString.call(s) + ' does not have [[SetData]] internal slot.');
4014 }
4015 // 9. Let entries be the List that is s.[[SetData]].
4016 var entries = s._values;
4017 // 10. Let numEntries be the number of elements of entries.
4018 var numEntries = entries.length;
4019 // 11. NOTE: numEntries must be redetermined each time this method is evaluated.
4020 // 12. Repeat, while index is less than numEntries,
4021 while (index < numEntries) {
4022 // a. Let e be entries[index].
4023 var e = entries[index];
4024 // b. Set index to index+1.
4025 index = index + 1;
4026 // c. Set O.[[SetNextIndex]] to index.
4027 O['[[SetNextIndex]]'] = index;
4028 // d. If e is not empty, then
4029 if (e !== undefMarker) {
4030 // i. If itemKind is "key+value", then
4031 if (itemKind === 'key+value') {
4032 // 1. Return CreateIterResultObject(CreateArrayFromList(« e, e »), false).
4033 return CreateIterResultObject([e, e], false);
4034 }
4035 // ii. Return CreateIterResultObject(e, false).
4036 return CreateIterResultObject(e, false);
4037 }
4038 }
4039 // 13. Set O.[[IteratedSet]] to undefined.
4040 O['[[IteratedSet]]'] = undefined;
4041 // 14. Return CreateIterResultObject(undefined, true).
4042 return CreateIterResultObject(undefined, true);
4043 });
4044
4045 // 23.2.5.2.2. %SetIteratorPrototype% [ @@toStringTag ]
4046 // The initial value of the @@toStringTag property is the String value "Set Iterator".
4047 // This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
4048
4049 CreateMethodProperty(SetIteratorPrototype, Symbol.iterator, function iterator() {
4050 return this;
4051 }
4052 );
4053
4054 // Export the object
4055 try {
4056 CreateMethodProperty(global, 'Set', Set);
4057 } catch (e) {
4058 // IE8 throws an error here if we set enumerable to false.
4059 // More info on table 2: https://msdn.microsoft.com/en-us/library/dd229916(v=vs.85).aspx
4060 global.Set = Set;
4061 }
4062
4063}(self));
4064
4065}
4066
4067if (!("from"in Array&&function(){try{return Array.from({length:-Infinity}),!0}catch(r){return!1}}()
4068)) {
4069
4070// Array.from
4071/* globals
4072 IsCallable, GetMethod, Symbol, IsConstructor, Construct, ArrayCreate, GetIterator, IteratorClose,
4073 ToString, IteratorStep, IteratorValue, Call, CreateDataPropertyOrThrow, ToObject, ToLength, Get, CreateMethodProperty
4074*/
4075(function () {
4076 var toString = Object.prototype.toString;
4077 var stringMatch = String.prototype.match;
4078 // A cross-realm friendly way to detect if a value is a String object or literal.
4079 function isString(value) {
4080 if (typeof value === 'string') { return true; }
4081 if (typeof value !== 'object') { return false; }
4082 return toString.call(value) === '[object String]';
4083 }
4084
4085 // 22.1.2.1. Array.from ( items [ , mapfn [ , thisArg ] ] )
4086 CreateMethodProperty(Array, 'from', function from(items /* [ , mapfn [ , thisArg ] ] */) { // eslint-disable-line no-undef
4087 // 1. Let C be the this value.
4088 var C = this;
4089 // 2. If mapfn is undefined, let mapping be false.
4090 var mapfn = arguments.length > 1 ? arguments[1] : undefined;
4091 if (mapfn === undefined) {
4092 var mapping = false;
4093 // 3. Else,
4094 } else {
4095 // a. If IsCallable(mapfn) is false, throw a TypeError exception.
4096 if (IsCallable(mapfn) === false) {
4097 throw new TypeError(Object.prototype.toString.call(mapfn) + ' is not a function.');
4098 }
4099 // b. If thisArg is present, let T be thisArg; else let T be undefined.
4100 var thisArg = arguments.length > 2 ? arguments[2] : undefined;
4101 if (thisArg !== undefined) {
4102 var T = thisArg;
4103 } else {
4104 T = undefined;
4105 }
4106 // c. Let mapping be true.
4107 mapping = true;
4108
4109 }
4110 // 4. Let usingIterator be ? GetMethod(items, @@iterator).
4111 var usingIterator = GetMethod(items, Symbol.iterator);
4112 // 5. If usingIterator is not undefined, then
4113 if (usingIterator !== undefined) {
4114 // a. If IsConstructor(C) is true, then
4115 if (IsConstructor(C)) {
4116 // i. Let A be ? Construct(C).
4117 var A = Construct(C);
4118 // b. Else,
4119 } else {
4120 // i. Let A be ! ArrayCreate(0).
4121 A = ArrayCreate(0);
4122 }
4123 // c. Let iteratorRecord be ? GetIterator(items, usingIterator).
4124 var iteratorRecord = GetIterator(items, usingIterator);
4125 // d. Let k be 0.
4126 var k = 0;
4127 // e. Repeat,
4128 // eslint-disable-next-line no-constant-condition
4129 while (true) {
4130 // i. If k ≥ 2^53-1, then
4131 if (k >= (Math.pow(2, 53) - 1)) {
4132 // 1. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}.
4133 var error = new TypeError('Iteration count can not be greater than or equal 9007199254740991.');
4134 // 2. Return ? IteratorClose(iteratorRecord, error).
4135 return IteratorClose(iteratorRecord, error);
4136 }
4137 // ii. Let Pk be ! ToString(k).
4138 var Pk = ToString(k);
4139 // iii. Let next be ? IteratorStep(iteratorRecord).
4140 var next = IteratorStep(iteratorRecord);
4141 // iv. If next is false, then
4142 if (next === false) {
4143 // 1. Perform ? Set(A, "length", k, true).
4144 A.length = k;
4145 // 2. Return A.
4146 return A;
4147 }
4148 // v. Let nextValue be ? IteratorValue(next).
4149 var nextValue = IteratorValue(next);
4150 // vi. If mapping is true, then
4151 if (mapping) {
4152 try {
4153 // Polyfill.io - The try catch accounts for step 2.
4154 // 1. Let mappedValue be Call(mapfn, T, « nextValue, k »).
4155 var mappedValue = Call(mapfn, T, [nextValue, k]);
4156 // 2. If mappedValue is an abrupt completion, return ? IteratorClose(iteratorRecord, mappedValue).
4157 // 3. Let mappedValue be mappedValue.[[Value]].
4158 } catch (e) {
4159 return IteratorClose(iteratorRecord, e);
4160 }
4161
4162 // vii. Else, let mappedValue be nextValue.
4163 } else {
4164 mappedValue = nextValue;
4165 }
4166 try {
4167 // Polyfill.io - The try catch accounts for step ix.
4168 // viii. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue).
4169 CreateDataPropertyOrThrow(A, Pk, mappedValue);
4170 // ix. If defineStatus is an abrupt completion, return ? IteratorClose(iteratorRecord, defineStatus).
4171 } catch (e) {
4172 return IteratorClose(iteratorRecord, e);
4173 }
4174 // x. Increase k by 1.
4175 k = k + 1;
4176 }
4177 }
4178 // 6. NOTE: items is not an Iterable so assume it is an array-like object.
4179 // 7. Let arrayLike be ! ToObject(items).
4180 // Polyfill.io - For Strings we need to split astral symbols into surrogate pairs.
4181 if (isString(items)) {
4182 var arrayLike = stringMatch.call(items, /[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || [];
4183 } else {
4184 arrayLike = ToObject(items);
4185 }
4186 // 8. Let len be ? ToLength(? Get(arrayLike, "length")).
4187 var len = ToLength(Get(arrayLike, "length"));
4188 // 9. If IsConstructor(C) is true, then
4189 if (IsConstructor(C)) {
4190 // a. Let A be ? Construct(C, « len »).
4191 A = Construct(C, [len]);
4192 // 10. Else,
4193 } else {
4194 // a. Let A be ? ArrayCreate(len).
4195 A = ArrayCreate(len);
4196 }
4197 // 11. Let k be 0.
4198 k = 0;
4199 // 12. Repeat, while k < len
4200 while (k < len) {
4201 // a. Let Pk be ! ToString(k).
4202 Pk = ToString(k);
4203 // b. Let kValue be ? Get(arrayLike, Pk).
4204 var kValue = Get(arrayLike, Pk);
4205 // c. If mapping is true, then
4206 if (mapping === true) {
4207 // i. Let mappedValue be ? Call(mapfn, T, « kValue, k »).
4208 mappedValue = Call(mapfn, T, [kValue, k]);
4209 // d. Else, let mappedValue be kValue.
4210 } else {
4211 mappedValue = kValue;
4212 }
4213 // e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
4214 CreateDataPropertyOrThrow(A, Pk, mappedValue);
4215 // f. Increase k by 1.
4216 k = k + 1;
4217 }
4218 // 13. Perform ? Set(A, "length", len, true).
4219 A.length = len;
4220 // 14. Return A.
4221 return A;
4222 });
4223}());
4224
4225}
4226
4227if (!("Symbol"in self&&"toStringTag"in self.Symbol
4228)) {
4229
4230// Symbol.toStringTag
4231/* global Symbol */
4232Object.defineProperty(Symbol, 'toStringTag', {
4233 value: Symbol('toStringTag')
4234});
4235
4236}
4237
4238if (!("Promise"in self
4239)) {
4240
4241// Promise
4242/*
4243 Yaku v0.19.3
4244 (c) 2015 Yad Smood. http://ysmood.org
4245 License MIT
4246*/
4247/*
4248 Yaku v0.17.9
4249 (c) 2015 Yad Smood. http://ysmood.org
4250 License MIT
4251*/
4252(function () {
4253 'use strict';
4254
4255 var $undefined
4256 , $null = null
4257 , isBrowser = typeof self === 'object'
4258 , root = self
4259 , nativePromise = root.Promise
4260 , process = root.process
4261 , console = root.console
4262 , isLongStackTrace = true
4263 , Arr = Array
4264 , Err = Error
4265
4266 , $rejected = 1
4267 , $resolved = 2
4268 , $pending = 3
4269
4270 , $Symbol = 'Symbol'
4271 , $iterator = 'iterator'
4272 , $species = 'species'
4273 , $speciesKey = $Symbol + '(' + $species + ')'
4274 , $return = 'return'
4275
4276 , $unhandled = '_uh'
4277 , $promiseTrace = '_pt'
4278 , $settlerTrace = '_st'
4279
4280 , $invalidThis = 'Invalid this'
4281 , $invalidArgument = 'Invalid argument'
4282 , $fromPrevious = '\nFrom previous '
4283 , $promiseCircularChain = 'Chaining cycle detected for promise'
4284 , $unhandledRejectionMsg = 'Uncaught (in promise)'
4285 , $rejectionHandled = 'rejectionHandled'
4286 , $unhandledRejection = 'unhandledRejection'
4287
4288 , $tryCatchFn
4289 , $tryCatchThis
4290 , $tryErr = { e: $null }
4291 , $noop = function () {}
4292 , $cleanStackReg = /^.+\/node_modules\/yaku\/.+\n?/mg
4293 ;
4294
4295 /**
4296 * This class follows the [Promises/A+](https://promisesaplus.com) and
4297 * [ES6](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) spec
4298 * with some extra helpers.
4299 * @param {Function} executor Function object with two arguments resolve, reject.
4300 * The first argument fulfills the promise, the second argument rejects it.
4301 * We can call these functions, once our operation is completed.
4302 */
4303 var Yaku = function (executor) {
4304 var self = this,
4305 err;
4306
4307 // "this._s" is the internao state of: pending, resolved or rejected
4308 // "this._v" is the internal value
4309
4310 if (!isObject(self) || self._s !== $undefined)
4311 throw genTypeError($invalidThis);
4312
4313 self._s = $pending;
4314
4315 if (isLongStackTrace) self[$promiseTrace] = genTraceInfo();
4316
4317 if (executor !== $noop) {
4318 if (!isFunction(executor))
4319 throw genTypeError($invalidArgument);
4320
4321 err = genTryCatcher(executor)(
4322 genSettler(self, $resolved),
4323 genSettler(self, $rejected)
4324 );
4325
4326 if (err === $tryErr)
4327 settlePromise(self, $rejected, err.e);
4328 }
4329 };
4330
4331 Yaku['default'] = Yaku;
4332
4333 extend(Yaku.prototype, {
4334 /**
4335 * Appends fulfillment and rejection handlers to the promise,
4336 * and returns a new promise resolving to the return value of the called handler.
4337 * @param {Function} onFulfilled Optional. Called when the Promise is resolved.
4338 * @param {Function} onRejected Optional. Called when the Promise is rejected.
4339 * @return {Yaku} It will return a new Yaku which will resolve or reject after
4340 * @example
4341 * the current Promise.
4342 * ```js
4343 * var Promise = require('yaku');
4344 * var p = Promise.resolve(10);
4345 *
4346 * p.then((v) => {
4347 * console.log(v);
4348 * });
4349 * ```
4350 */
4351 then: function (onFulfilled, onRejected) {
4352 if (this._s === undefined) throw genTypeError();
4353
4354 return addHandler(
4355 this,
4356 newCapablePromise(Yaku.speciesConstructor(this, Yaku)),
4357 onFulfilled,
4358 onRejected
4359 );
4360 },
4361
4362 /**
4363 * The `catch()` method returns a Promise and deals with rejected cases only.
4364 * It behaves the same as calling `Promise.prototype.then(undefined, onRejected)`.
4365 * @param {Function} onRejected A Function called when the Promise is rejected.
4366 * This function has one argument, the rejection reason.
4367 * @return {Yaku} A Promise that deals with rejected cases only.
4368 * @example
4369 * ```js
4370 * var Promise = require('yaku');
4371 * var p = Promise.reject(new Error("ERR"));
4372 *
4373 * p['catch']((v) => {
4374 * console.log(v);
4375 * });
4376 * ```
4377 */
4378 'catch': function (onRejected) {
4379 return this.then($undefined, onRejected);
4380 },
4381
4382 /**
4383 * Register a callback to be invoked when a promise is settled (either fulfilled or rejected).
4384 * Similar with the try-catch-finally, it's often used for cleanup.
4385 * @param {Function} onFinally A Function called when the Promise is settled.
4386 * It will not receive any argument.
4387 * @return {Yaku} A Promise that will reject if onFinally throws an error or returns a rejected promise.
4388 * Else it will resolve previous promise's final state (either fulfilled or rejected).
4389 * @example
4390 * ```js
4391 * var Promise = require('yaku');
4392 * var p = Math.random() > 0.5 ? Promise.resolve() : Promise.reject();
4393 * p.finally(() => {
4394 * console.log('finally');
4395 * });
4396 * ```
4397 */
4398 'finally': function (onFinally) {
4399 return this.then(function (val) {
4400 return Yaku.resolve(onFinally()).then(function () {
4401 return val;
4402 });
4403 }, function (err) {
4404 return Yaku.resolve(onFinally()).then(function () {
4405 throw err;
4406 });
4407 });
4408 },
4409
4410 // The number of current promises that attach to this Yaku instance.
4411 _c: 0,
4412
4413 // The parent Yaku.
4414 _p: $null
4415 });
4416
4417 /**
4418 * The `Promise.resolve(value)` method returns a Promise object that is resolved with the given value.
4419 * If the value is a thenable (i.e. has a then method), the returned promise will "follow" that thenable,
4420 * adopting its eventual state; otherwise the returned promise will be fulfilled with the value.
4421 * @param {Any} value Argument to be resolved by this Promise.
4422 * Can also be a Promise or a thenable to resolve.
4423 * @return {Yaku}
4424 * @example
4425 * ```js
4426 * var Promise = require('yaku');
4427 * var p = Promise.resolve(10);
4428 * ```
4429 */
4430 Yaku.resolve = function (val) {
4431 return isYaku(val) ? val : settleWithX(newCapablePromise(this), val);
4432 };
4433
4434 /**
4435 * The `Promise.reject(reason)` method returns a Promise object that is rejected with the given reason.
4436 * @param {Any} reason Reason why this Promise rejected.
4437 * @return {Yaku}
4438 * @example
4439 * ```js
4440 * var Promise = require('yaku');
4441 * var p = Promise.reject(new Error("ERR"));
4442 * ```
4443 */
4444 Yaku.reject = function (reason) {
4445 return settlePromise(newCapablePromise(this), $rejected, reason);
4446 };
4447
4448 /**
4449 * The `Promise.race(iterable)` method returns a promise that resolves or rejects
4450 * as soon as one of the promises in the iterable resolves or rejects,
4451 * with the value or reason from that promise.
4452 * @param {iterable} iterable An iterable object, such as an Array.
4453 * @return {Yaku} The race function returns a Promise that is settled
4454 * the same way as the first passed promise to settle.
4455 * It resolves or rejects, whichever happens first.
4456 * @example
4457 * ```js
4458 * var Promise = require('yaku');
4459 * Promise.race([
4460 * 123,
4461 * Promise.resolve(0)
4462 * ])
4463 * .then((value) => {
4464 * console.log(value); // => 123
4465 * });
4466 * ```
4467 */
4468 Yaku.race = function (iterable) {
4469 var self = this
4470 , p = newCapablePromise(self)
4471
4472 , resolve = function (val) {
4473 settlePromise(p, $resolved, val);
4474 }
4475
4476 , reject = function (val) {
4477 settlePromise(p, $rejected, val);
4478 }
4479
4480 , ret = genTryCatcher(each)(iterable, function (v) {
4481 self.resolve(v).then(resolve, reject);
4482 });
4483
4484 if (ret === $tryErr) return self.reject(ret.e);
4485
4486 return p;
4487 };
4488
4489 /**
4490 * The `Promise.all(iterable)` method returns a promise that resolves when
4491 * all of the promises in the iterable argument have resolved.
4492 *
4493 * The result is passed as an array of values from all the promises.
4494 * If something passed in the iterable array is not a promise,
4495 * it's converted to one by Promise.resolve. If any of the passed in promises rejects,
4496 * the all Promise immediately rejects with the value of the promise that rejected,
4497 * discarding all the other promises whether or not they have resolved.
4498 * @param {iterable} iterable An iterable object, such as an Array.
4499 * @return {Yaku}
4500 * @example
4501 * ```js
4502 * var Promise = require('yaku');
4503 * Promise.all([
4504 * 123,
4505 * Promise.resolve(0)
4506 * ])
4507 * .then((values) => {
4508 * console.log(values); // => [123, 0]
4509 * });
4510 * ```
4511 * @example
4512 * Use with iterable.
4513 * ```js
4514 * var Promise = require('yaku');
4515 * Promise.all((function * () {
4516 * yield 10;
4517 * yield new Promise(function (r) { setTimeout(r, 1000, "OK") });
4518 * })())
4519 * .then((values) => {
4520 * console.log(values); // => [123, 0]
4521 * });
4522 * ```
4523 */
4524 Yaku.all = function (iterable) {
4525 var self = this
4526 , p1 = newCapablePromise(self)
4527 , res = []
4528 , ret
4529 ;
4530
4531 function reject (reason) {
4532 settlePromise(p1, $rejected, reason);
4533 }
4534
4535 ret = genTryCatcher(each)(iterable, function (item, i) {
4536 self.resolve(item).then(function (value) {
4537 res[i] = value;
4538 if (!--ret) settlePromise(p1, $resolved, res);
4539 }, reject);
4540 });
4541
4542 if (ret === $tryErr) return self.reject(ret.e);
4543
4544 if (!ret) settlePromise(p1, $resolved, []);
4545
4546 return p1;
4547 };
4548
4549 /**
4550 * The ES6 Symbol object that Yaku should use, by default it will use the
4551 * global one.
4552 * @type {Object}
4553 * @example
4554 * ```js
4555 * var core = require("core-js/library");
4556 * var Promise = require("yaku");
4557 * Promise.Symbol = core.Symbol;
4558 * ```
4559 */
4560 Yaku.Symbol = root[$Symbol] || {};
4561
4562 // To support browsers that don't support `Object.defineProperty`.
4563 genTryCatcher(function () {
4564 Object.defineProperty(Yaku, getSpecies(), {
4565 get: function () { return this; }
4566 });
4567 })();
4568
4569 /**
4570 * Use this api to custom the species behavior.
4571 * https://tc39.github.io/ecma262/#sec-speciesconstructor
4572 * @param {Any} O The current this object.
4573 * @param {Function} defaultConstructor
4574 */
4575 Yaku.speciesConstructor = function (O, D) {
4576 var C = O.constructor;
4577
4578 return C ? (C[getSpecies()] || D) : D;
4579 };
4580
4581 /**
4582 * Catch all possibly unhandled rejections. If you want to use specific
4583 * format to display the error stack, overwrite it.
4584 * If it is set, auto `console.error` unhandled rejection will be disabled.
4585 * @param {Any} reason The rejection reason.
4586 * @param {Yaku} p The promise that was rejected.
4587 * @example
4588 * ```js
4589 * var Promise = require('yaku');
4590 * Promise.unhandledRejection = (reason) => {
4591 * console.error(reason);
4592 * };
4593 *
4594 * // The console will log an unhandled rejection error message.
4595 * Promise.reject('my reason');
4596 *
4597 * // The below won't log the unhandled rejection error message.
4598 * Promise.reject('v')["catch"](() => {});
4599 * ```
4600 */
4601 Yaku.unhandledRejection = function (reason, p) {
4602 console && console.error(
4603 $unhandledRejectionMsg,
4604 isLongStackTrace ? p.longStack : genStackInfo(reason, p)
4605 );
4606 };
4607
4608 /**
4609 * Emitted whenever a Promise was rejected and an error handler was
4610 * attached to it (for example with `["catch"]()`) later than after an event loop turn.
4611 * @param {Any} reason The rejection reason.
4612 * @param {Yaku} p The promise that was rejected.
4613 */
4614 Yaku.rejectionHandled = $noop;
4615
4616 /**
4617 * It is used to enable the long stack trace.
4618 * Once it is enabled, it can't be reverted.
4619 * While it is very helpful in development and testing environments,
4620 * it is not recommended to use it in production. It will slow down
4621 * application and eat up memory.
4622 * It will add an extra property `longStack` to the Error object.
4623 * @example
4624 * ```js
4625 * var Promise = require('yaku');
4626 * Promise.enableLongStackTrace();
4627 * Promise.reject(new Error("err"))["catch"]((err) => {
4628 * console.log(err.longStack);
4629 * });
4630 * ```
4631 */
4632 Yaku.enableLongStackTrace = function () {
4633 isLongStackTrace = true;
4634 };
4635
4636 /**
4637 * Only Node has `process.nextTick` function. For browser there are
4638 * so many ways to polyfill it. Yaku won't do it for you, instead you
4639 * can choose what you prefer. For example, this project
4640 * [next-tick](https://github.com/medikoo/next-tick).
4641 * By default, Yaku will use `process.nextTick` on Node, `setTimeout` on browser.
4642 * @type {Function}
4643 * @example
4644 * ```js
4645 * var Promise = require('yaku');
4646 * Promise.nextTick = require('next-tick');
4647 * ```
4648 * @example
4649 * You can even use sync resolution if you really know what you are doing.
4650 * ```js
4651 * var Promise = require('yaku');
4652 * Promise.nextTick = fn => fn();
4653 * ```
4654 */
4655 Yaku.nextTick = isBrowser ?
4656 function (fn) {
4657 nativePromise ?
4658 new nativePromise(function (resolve) { resolve(); }).then(fn) :
4659 setTimeout(fn);
4660 } :
4661 process.nextTick;
4662
4663 // ********************** Private **********************
4664
4665 Yaku._s = 1;
4666
4667 /**
4668 * All static variable name will begin with `$`. Such as `$rejected`.
4669 * @private
4670 */
4671
4672 // ******************************* Utils ********************************
4673
4674 function getSpecies () {
4675 return Yaku[$Symbol][$species] || $speciesKey;
4676 }
4677
4678 function extend (src, target) {
4679 for (var k in target) {
4680 src[k] = target[k];
4681 }
4682 }
4683
4684 function isObject (obj) {
4685 return obj && typeof obj === 'object';
4686 }
4687
4688 function isFunction (obj) {
4689 return typeof obj === 'function';
4690 }
4691
4692 function isInstanceOf (a, b) {
4693 return a instanceof b;
4694 }
4695
4696 function isError (obj) {
4697 return isInstanceOf(obj, Err);
4698 }
4699
4700 function ensureType (obj, fn, msg) {
4701 if (!fn(obj)) throw genTypeError(msg);
4702 }
4703
4704 /**
4705 * Wrap a function into a try-catch.
4706 * @private
4707 * @return {Any | $tryErr}
4708 */
4709 function tryCatcher () {
4710 try {
4711 return $tryCatchFn.apply($tryCatchThis, arguments);
4712 } catch (e) {
4713 $tryErr.e = e;
4714 return $tryErr;
4715 }
4716 }
4717
4718 /**
4719 * Generate a try-catch wrapped function.
4720 * @private
4721 * @param {Function} fn
4722 * @return {Function}
4723 */
4724 function genTryCatcher (fn, self) {
4725 $tryCatchFn = fn;
4726 $tryCatchThis = self;
4727 return tryCatcher;
4728 }
4729
4730 /**
4731 * Generate a scheduler.
4732 * @private
4733 * @param {Integer} initQueueSize
4734 * @param {Function} fn `(Yaku, Value) ->` The schedule handler.
4735 * @return {Function} `(Yaku, Value) ->` The scheduler.
4736 */
4737 function genScheduler (initQueueSize, fn) {
4738 /**
4739 * All async promise will be scheduled in
4740 * here, so that they can be execute on the next tick.
4741 * @private
4742 */
4743 var fnQueue = Arr(initQueueSize)
4744 , fnQueueLen = 0;
4745
4746 /**
4747 * Run all queued functions.
4748 * @private
4749 */
4750 function flush () {
4751 var i = 0;
4752 while (i < fnQueueLen) {
4753 fn(fnQueue[i], fnQueue[i + 1]);
4754 fnQueue[i++] = $undefined;
4755 fnQueue[i++] = $undefined;
4756 }
4757
4758 fnQueueLen = 0;
4759 if (fnQueue.length > initQueueSize) fnQueue.length = initQueueSize;
4760 }
4761
4762 return function (v, arg) {
4763 fnQueue[fnQueueLen++] = v;
4764 fnQueue[fnQueueLen++] = arg;
4765
4766 if (fnQueueLen === 2) Yaku.nextTick(flush);
4767 };
4768 }
4769
4770 /**
4771 * Generate a iterator
4772 * @param {Any} obj
4773 * @private
4774 * @return {Object || TypeError}
4775 */
4776 function each (iterable, fn) {
4777 var len
4778 , i = 0
4779 , iter
4780 , item
4781 , ret
4782 ;
4783
4784 if (!iterable) throw genTypeError($invalidArgument);
4785
4786 var gen = iterable[Yaku[$Symbol][$iterator]];
4787 if (isFunction(gen))
4788 iter = gen.call(iterable);
4789 else if (isFunction(iterable.next)) {
4790 iter = iterable;
4791 }
4792 else if (isInstanceOf(iterable, Arr)) {
4793 len = iterable.length;
4794 while (i < len) {
4795 fn(iterable[i], i++);
4796 }
4797 return i;
4798 } else
4799 throw genTypeError($invalidArgument);
4800
4801 while (!(item = iter.next()).done) {
4802 ret = genTryCatcher(fn)(item.value, i++);
4803 if (ret === $tryErr) {
4804 isFunction(iter[$return]) && iter[$return]();
4805 throw ret.e;
4806 }
4807 }
4808
4809 return i;
4810 }
4811
4812 /**
4813 * Generate type error object.
4814 * @private
4815 * @param {String} msg
4816 * @return {TypeError}
4817 */
4818 function genTypeError (msg) {
4819 return new TypeError(msg);
4820 }
4821
4822 function genTraceInfo (noTitle) {
4823 return (noTitle ? '' : $fromPrevious) + new Err().stack;
4824 }
4825
4826
4827 // *************************** Promise Helpers ****************************
4828
4829 /**
4830 * Resolve the value returned by onFulfilled or onRejected.
4831 * @private
4832 * @param {Yaku} p1
4833 * @param {Yaku} p2
4834 */
4835 var scheduleHandler = genScheduler(999, function (p1, p2) {
4836 var x, handler;
4837
4838 // 2.2.2
4839 // 2.2.3
4840 handler = p1._s !== $rejected ? p2._onFulfilled : p2._onRejected;
4841
4842 // 2.2.7.3
4843 // 2.2.7.4
4844 if (handler === $undefined) {
4845 settlePromise(p2, p1._s, p1._v);
4846 return;
4847 }
4848
4849 // 2.2.7.1
4850 x = genTryCatcher(callHanler)(handler, p1._v);
4851 if (x === $tryErr) {
4852 // 2.2.7.2
4853 settlePromise(p2, $rejected, x.e);
4854 return;
4855 }
4856
4857 settleWithX(p2, x);
4858 });
4859
4860 var scheduleUnhandledRejection = genScheduler(9, function (p) {
4861 if (!hashOnRejected(p)) {
4862 p[$unhandled] = 1;
4863 emitEvent($unhandledRejection, p);
4864 }
4865 });
4866
4867 function emitEvent (name, p) {
4868 var browserEventName = 'on' + name.toLowerCase()
4869 , browserHandler = root[browserEventName];
4870
4871 if (process && process.listeners(name).length)
4872 name === $unhandledRejection ?
4873 process.emit(name, p._v, p) : process.emit(name, p);
4874 else if (browserHandler)
4875 browserHandler({ reason: p._v, promise: p });
4876 else
4877 Yaku[name](p._v, p);
4878 }
4879
4880 function isYaku (val) { return val && val._s; }
4881
4882 function newCapablePromise (Constructor) {
4883 if (isYaku(Constructor)) return new Constructor($noop);
4884
4885 var p, r, j;
4886 p = new Constructor(function (resolve, reject) {
4887 if (p) throw genTypeError();
4888
4889 r = resolve;
4890 j = reject;
4891 });
4892
4893 ensureType(r, isFunction);
4894 ensureType(j, isFunction);
4895
4896 return p;
4897 }
4898
4899 /**
4900 * It will produce a settlePromise function to user.
4901 * Such as the resolve and reject in this `new Yaku (resolve, reject) ->`.
4902 * @private
4903 * @param {Yaku} self
4904 * @param {Integer} state The value is one of `$pending`, `$resolved` or `$rejected`.
4905 * @return {Function} `(value) -> undefined` A resolve or reject function.
4906 */
4907 function genSettler (self, state) {
4908 var isCalled = false;
4909 return function (value) {
4910 if (isCalled) return;
4911 isCalled = true;
4912
4913 if (isLongStackTrace)
4914 self[$settlerTrace] = genTraceInfo(true);
4915
4916 if (state === $resolved)
4917 settleWithX(self, value);
4918 else
4919 settlePromise(self, state, value);
4920 };
4921 }
4922
4923 /**
4924 * Link the promise1 to the promise2.
4925 * @private
4926 * @param {Yaku} p1
4927 * @param {Yaku} p2
4928 * @param {Function} onFulfilled
4929 * @param {Function} onRejected
4930 */
4931 function addHandler (p1, p2, onFulfilled, onRejected) {
4932 // 2.2.1
4933 if (isFunction(onFulfilled))
4934 p2._onFulfilled = onFulfilled;
4935 if (isFunction(onRejected)) {
4936 if (p1[$unhandled]) emitEvent($rejectionHandled, p1);
4937
4938 p2._onRejected = onRejected;
4939 }
4940
4941 if (isLongStackTrace) p2._p = p1;
4942 p1[p1._c++] = p2;
4943
4944 // 2.2.6
4945 if (p1._s !== $pending)
4946 scheduleHandler(p1, p2);
4947
4948 // 2.2.7
4949 return p2;
4950 }
4951
4952 // iterate tree
4953 function hashOnRejected (node) {
4954 // A node shouldn't be checked twice.
4955 if (node._umark)
4956 return true;
4957 else
4958 node._umark = true;
4959
4960 var i = 0
4961 , len = node._c
4962 , child;
4963
4964 while (i < len) {
4965 child = node[i++];
4966 if (child._onRejected || hashOnRejected(child)) return true;
4967 }
4968 }
4969
4970 function genStackInfo (reason, p) {
4971 var stackInfo = [];
4972
4973 function push (trace) {
4974 return stackInfo.push(trace.replace(/^\s+|\s+$/g, ''));
4975 }
4976
4977 if (isLongStackTrace) {
4978 if (p[$settlerTrace])
4979 push(p[$settlerTrace]);
4980
4981 // Hope you guys could understand how the back trace works.
4982 // We only have to iterate through the tree from the bottom to root.
4983 (function iter (node) {
4984 if (node && $promiseTrace in node) {
4985 iter(node._next);
4986 push(node[$promiseTrace] + '');
4987 iter(node._p);
4988 }
4989 })(p);
4990 }
4991
4992 return (reason && reason.stack ? reason.stack : reason) +
4993 ('\n' + stackInfo.join('\n')).replace($cleanStackReg, '');
4994 }
4995
4996 function callHanler (handler, value) {
4997 // 2.2.5
4998 return handler(value);
4999 }
5000
5001 /**
5002 * Resolve or reject a promise.
5003 * @private
5004 * @param {Yaku} p
5005 * @param {Integer} state
5006 * @param {Any} value
5007 */
5008 function settlePromise (p, state, value) {
5009 var i = 0
5010 , len = p._c;
5011
5012 // 2.1.2
5013 // 2.1.3
5014 if (p._s === $pending) {
5015 // 2.1.1.1
5016 p._s = state;
5017 p._v = value;
5018
5019 if (state === $rejected) {
5020 if (isLongStackTrace && isError(value)) {
5021 value.longStack = genStackInfo(value, p);
5022 }
5023
5024 scheduleUnhandledRejection(p);
5025 }
5026
5027 // 2.2.4
5028 while (i < len) {
5029 scheduleHandler(p, p[i++]);
5030 }
5031 }
5032
5033 return p;
5034 }
5035
5036 /**
5037 * Resolve or reject promise with value x. The x can also be a thenable.
5038 * @private
5039 * @param {Yaku} p
5040 * @param {Any | Thenable} x A normal value or a thenable.
5041 */
5042 function settleWithX (p, x) {
5043 // 2.3.1
5044 if (x === p && x) {
5045 settlePromise(p, $rejected, genTypeError($promiseCircularChain));
5046 return p;
5047 }
5048
5049 // 2.3.2
5050 // 2.3.3
5051 if (x !== $null && (isFunction(x) || isObject(x))) {
5052 // 2.3.2.1
5053 var xthen = genTryCatcher(getThen)(x);
5054
5055 if (xthen === $tryErr) {
5056 // 2.3.3.2
5057 settlePromise(p, $rejected, xthen.e);
5058 return p;
5059 }
5060
5061 if (isFunction(xthen)) {
5062 if (isLongStackTrace && isYaku(x))
5063 p._next = x;
5064
5065 // Fix https://bugs.chromium.org/p/v8/issues/detail?id=4162
5066 if (isYaku(x))
5067 settleXthen(p, x, xthen);
5068 else
5069 Yaku.nextTick(function () {
5070 settleXthen(p, x, xthen);
5071 });
5072 } else
5073 // 2.3.3.4
5074 settlePromise(p, $resolved, x);
5075 } else
5076 // 2.3.4
5077 settlePromise(p, $resolved, x);
5078
5079 return p;
5080 }
5081
5082 /**
5083 * Try to get a promise's then method.
5084 * @private
5085 * @param {Thenable} x
5086 * @return {Function}
5087 */
5088 function getThen (x) { return x.then; }
5089
5090 /**
5091 * Resolve then with its promise.
5092 * @private
5093 * @param {Yaku} p
5094 * @param {Thenable} x
5095 * @param {Function} xthen
5096 */
5097 function settleXthen (p, x, xthen) {
5098 // 2.3.3.3
5099 var err = genTryCatcher(xthen, x)(function (y) {
5100 // 2.3.3.3.3
5101 // 2.3.3.3.1
5102 x && (x = $null, settleWithX(p, y));
5103 }, function (r) {
5104 // 2.3.3.3.3
5105 // 2.3.3.3.2
5106 x && (x = $null, settlePromise(p, $rejected, r));
5107 });
5108
5109 // 2.3.3.3.4.1
5110 if (err === $tryErr && x) {
5111 // 2.3.3.3.4.2
5112 settlePromise(p, $rejected, err.e);
5113 x = $null;
5114 }
5115 }
5116
5117 root.Promise = Yaku;
5118})();
5119
5120}
5121
5122if (!("fetch"in self
5123)) {
5124
5125// fetch
5126(function (global, factory) {
5127 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5128 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5129 (factory((global.WHATWGFetch = {})));
5130}(this, (function (exports) { 'use strict';
5131
5132 var support = {
5133 searchParams: 'URLSearchParams' in self,
5134 iterable: 'Symbol' in self && 'iterator' in Symbol,
5135 blob:
5136 'FileReader' in self &&
5137 'Blob' in self &&
5138 (function() {
5139 try {
5140 new Blob();
5141 return true
5142 } catch (e) {
5143 return false
5144 }
5145 })(),
5146 formData: 'FormData' in self,
5147 arrayBuffer: 'ArrayBuffer' in self
5148 };
5149
5150 function isDataView(obj) {
5151 return obj && DataView.prototype.isPrototypeOf(obj)
5152 }
5153
5154 if (support.arrayBuffer) {
5155 var viewClasses = [
5156 '[object Int8Array]',
5157 '[object Uint8Array]',
5158 '[object Uint8ClampedArray]',
5159 '[object Int16Array]',
5160 '[object Uint16Array]',
5161 '[object Int32Array]',
5162 '[object Uint32Array]',
5163 '[object Float32Array]',
5164 '[object Float64Array]'
5165 ];
5166
5167 var isArrayBufferView =
5168 ArrayBuffer.isView ||
5169 function(obj) {
5170 return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
5171 };
5172 }
5173
5174 function normalizeName(name) {
5175 if (typeof name !== 'string') {
5176 name = String(name);
5177 }
5178 if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
5179 throw new TypeError('Invalid character in header field name')
5180 }
5181 return name.toLowerCase()
5182 }
5183
5184 function normalizeValue(value) {
5185 if (typeof value !== 'string') {
5186 value = String(value);
5187 }
5188 return value
5189 }
5190
5191 // Build a destructive iterator for the value list
5192 function iteratorFor(items) {
5193 var iterator = {
5194 next: function() {
5195 var value = items.shift();
5196 return {done: value === undefined, value: value}
5197 }
5198 };
5199
5200 if (support.iterable) {
5201 iterator[Symbol.iterator] = function() {
5202 return iterator
5203 };
5204 }
5205
5206 return iterator
5207 }
5208
5209 function Headers(headers) {
5210 this.map = {};
5211
5212 if (headers instanceof Headers) {
5213 headers.forEach(function(value, name) {
5214 this.append(name, value);
5215 }, this);
5216 } else if (Array.isArray(headers)) {
5217 headers.forEach(function(header) {
5218 this.append(header[0], header[1]);
5219 }, this);
5220 } else if (headers) {
5221 Object.getOwnPropertyNames(headers).forEach(function(name) {
5222 this.append(name, headers[name]);
5223 }, this);
5224 }
5225 }
5226
5227 Headers.prototype.append = function(name, value) {
5228 name = normalizeName(name);
5229 value = normalizeValue(value);
5230 var oldValue = this.map[name];
5231 this.map[name] = oldValue ? oldValue + ', ' + value : value;
5232 };
5233
5234 Headers.prototype['delete'] = function(name) {
5235 delete this.map[normalizeName(name)];
5236 };
5237
5238 Headers.prototype.get = function(name) {
5239 name = normalizeName(name);
5240 return this.has(name) ? this.map[name] : null
5241 };
5242
5243 Headers.prototype.has = function(name) {
5244 return this.map.hasOwnProperty(normalizeName(name))
5245 };
5246
5247 Headers.prototype.set = function(name, value) {
5248 this.map[normalizeName(name)] = normalizeValue(value);
5249 };
5250
5251 Headers.prototype.forEach = function(callback, thisArg) {
5252 for (var name in this.map) {
5253 if (this.map.hasOwnProperty(name)) {
5254 callback.call(thisArg, this.map[name], name, this);
5255 }
5256 }
5257 };
5258
5259 Headers.prototype.keys = function() {
5260 var items = [];
5261 this.forEach(function(value, name) {
5262 items.push(name);
5263 });
5264 return iteratorFor(items)
5265 };
5266
5267 Headers.prototype.values = function() {
5268 var items = [];
5269 this.forEach(function(value) {
5270 items.push(value);
5271 });
5272 return iteratorFor(items)
5273 };
5274
5275 Headers.prototype.entries = function() {
5276 var items = [];
5277 this.forEach(function(value, name) {
5278 items.push([name, value]);
5279 });
5280 return iteratorFor(items)
5281 };
5282
5283 if (support.iterable) {
5284 Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
5285 }
5286
5287 function consumed(body) {
5288 if (body.bodyUsed) {
5289 return Promise.reject(new TypeError('Already read'))
5290 }
5291 body.bodyUsed = true;
5292 }
5293
5294 function fileReaderReady(reader) {
5295 return new Promise(function(resolve, reject) {
5296 reader.onload = function() {
5297 resolve(reader.result);
5298 };
5299 reader.onerror = function() {
5300 reject(reader.error);
5301 };
5302 })
5303 }
5304
5305 function readBlobAsArrayBuffer(blob) {
5306 var reader = new FileReader();
5307 var promise = fileReaderReady(reader);
5308 reader.readAsArrayBuffer(blob);
5309 return promise
5310 }
5311
5312 function readBlobAsText(blob) {
5313 var reader = new FileReader();
5314 var promise = fileReaderReady(reader);
5315 reader.readAsText(blob);
5316 return promise
5317 }
5318
5319 function readArrayBufferAsText(buf) {
5320 var view = new Uint8Array(buf);
5321 var chars = new Array(view.length);
5322
5323 for (var i = 0; i < view.length; i++) {
5324 chars[i] = String.fromCharCode(view[i]);
5325 }
5326 return chars.join('')
5327 }
5328
5329 function bufferClone(buf) {
5330 if (buf.slice) {
5331 return buf.slice(0)
5332 } else {
5333 var view = new Uint8Array(buf.byteLength);
5334 view.set(new Uint8Array(buf));
5335 return view.buffer
5336 }
5337 }
5338
5339 function Body() {
5340 this.bodyUsed = false;
5341
5342 this._initBody = function(body) {
5343 this._bodyInit = body;
5344 if (!body) {
5345 this._bodyText = '';
5346 } else if (typeof body === 'string') {
5347 this._bodyText = body;
5348 } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
5349 this._bodyBlob = body;
5350 } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
5351 this._bodyFormData = body;
5352 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
5353 this._bodyText = body.toString();
5354 } else if (support.arrayBuffer && support.blob && isDataView(body)) {
5355 this._bodyArrayBuffer = bufferClone(body.buffer);
5356 // IE 10-11 can't handle a DataView body.
5357 this._bodyInit = new Blob([this._bodyArrayBuffer]);
5358 } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
5359 this._bodyArrayBuffer = bufferClone(body);
5360 } else {
5361 this._bodyText = body = Object.prototype.toString.call(body);
5362 }
5363
5364 if (!this.headers.get('content-type')) {
5365 if (typeof body === 'string') {
5366 this.headers.set('content-type', 'text/plain;charset=UTF-8');
5367 } else if (this._bodyBlob && this._bodyBlob.type) {
5368 this.headers.set('content-type', this._bodyBlob.type);
5369 } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
5370 this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
5371 }
5372 }
5373 };
5374
5375 if (support.blob) {
5376 this.blob = function() {
5377 var rejected = consumed(this);
5378 if (rejected) {
5379 return rejected
5380 }
5381
5382 if (this._bodyBlob) {
5383 return Promise.resolve(this._bodyBlob)
5384 } else if (this._bodyArrayBuffer) {
5385 return Promise.resolve(new Blob([this._bodyArrayBuffer]))
5386 } else if (this._bodyFormData) {
5387 throw new Error('could not read FormData body as blob')
5388 } else {
5389 return Promise.resolve(new Blob([this._bodyText]))
5390 }
5391 };
5392
5393 this.arrayBuffer = function() {
5394 if (this._bodyArrayBuffer) {
5395 return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
5396 } else {
5397 return this.blob().then(readBlobAsArrayBuffer)
5398 }
5399 };
5400 }
5401
5402 this.text = function() {
5403 var rejected = consumed(this);
5404 if (rejected) {
5405 return rejected
5406 }
5407
5408 if (this._bodyBlob) {
5409 return readBlobAsText(this._bodyBlob)
5410 } else if (this._bodyArrayBuffer) {
5411 return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
5412 } else if (this._bodyFormData) {
5413 throw new Error('could not read FormData body as text')
5414 } else {
5415 return Promise.resolve(this._bodyText)
5416 }
5417 };
5418
5419 if (support.formData) {
5420 this.formData = function() {
5421 return this.text().then(decode)
5422 };
5423 }
5424
5425 this.json = function() {
5426 return this.text().then(JSON.parse)
5427 };
5428
5429 return this
5430 }
5431
5432 // HTTP methods whose capitalization should be normalized
5433 var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
5434
5435 function normalizeMethod(method) {
5436 var upcased = method.toUpperCase();
5437 return methods.indexOf(upcased) > -1 ? upcased : method
5438 }
5439
5440 function Request(input, options) {
5441 options = options || {};
5442 var body = options.body;
5443
5444 if (input instanceof Request) {
5445 if (input.bodyUsed) {
5446 throw new TypeError('Already read')
5447 }
5448 this.url = input.url;
5449 this.credentials = input.credentials;
5450 if (!options.headers) {
5451 this.headers = new Headers(input.headers);
5452 }
5453 this.method = input.method;
5454 this.mode = input.mode;
5455 this.signal = input.signal;
5456 if (!body && input._bodyInit != null) {
5457 body = input._bodyInit;
5458 input.bodyUsed = true;
5459 }
5460 } else {
5461 this.url = String(input);
5462 }
5463
5464 this.credentials = options.credentials || this.credentials || 'same-origin';
5465 if (options.headers || !this.headers) {
5466 this.headers = new Headers(options.headers);
5467 }
5468 this.method = normalizeMethod(options.method || this.method || 'GET');
5469 this.mode = options.mode || this.mode || null;
5470 this.signal = options.signal || this.signal;
5471 this.referrer = null;
5472
5473 if ((this.method === 'GET' || this.method === 'HEAD') && body) {
5474 throw new TypeError('Body not allowed for GET or HEAD requests')
5475 }
5476 this._initBody(body);
5477 }
5478
5479 Request.prototype.clone = function() {
5480 return new Request(this, {body: this._bodyInit})
5481 };
5482
5483 function decode(body) {
5484 var form = new FormData();
5485 body
5486 .trim()
5487 .split('&')
5488 .forEach(function(bytes) {
5489 if (bytes) {
5490 var split = bytes.split('=');
5491 var name = split.shift().replace(/\+/g, ' ');
5492 var value = split.join('=').replace(/\+/g, ' ');
5493 form.append(decodeURIComponent(name), decodeURIComponent(value));
5494 }
5495 });
5496 return form
5497 }
5498
5499 function parseHeaders(rawHeaders) {
5500 var headers = new Headers();
5501 // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
5502 // https://tools.ietf.org/html/rfc7230#section-3.2
5503 var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
5504 preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
5505 var parts = line.split(':');
5506 var key = parts.shift().trim();
5507 if (key) {
5508 var value = parts.join(':').trim();
5509 headers.append(key, value);
5510 }
5511 });
5512 return headers
5513 }
5514
5515 Body.call(Request.prototype);
5516
5517 function Response(bodyInit, options) {
5518 if (!options) {
5519 options = {};
5520 }
5521
5522 this.type = 'default';
5523 this.status = options.status === undefined ? 200 : options.status;
5524 this.ok = this.status >= 200 && this.status < 300;
5525 this.statusText = 'statusText' in options ? options.statusText : 'OK';
5526 this.headers = new Headers(options.headers);
5527 this.url = options.url || '';
5528 this._initBody(bodyInit);
5529 }
5530
5531 Body.call(Response.prototype);
5532
5533 Response.prototype.clone = function() {
5534 return new Response(this._bodyInit, {
5535 status: this.status,
5536 statusText: this.statusText,
5537 headers: new Headers(this.headers),
5538 url: this.url
5539 })
5540 };
5541
5542 Response.error = function() {
5543 var response = new Response(null, {status: 0, statusText: ''});
5544 response.type = 'error';
5545 return response
5546 };
5547
5548 var redirectStatuses = [301, 302, 303, 307, 308];
5549
5550 Response.redirect = function(url, status) {
5551 if (redirectStatuses.indexOf(status) === -1) {
5552 throw new RangeError('Invalid status code')
5553 }
5554
5555 return new Response(null, {status: status, headers: {location: url}})
5556 };
5557
5558 exports.DOMException = self.DOMException;
5559 try {
5560 new exports.DOMException();
5561 } catch (err) {
5562 exports.DOMException = function(message, name) {
5563 this.message = message;
5564 this.name = name;
5565 var error = Error(message);
5566 this.stack = error.stack;
5567 };
5568 exports.DOMException.prototype = Object.create(Error.prototype);
5569 exports.DOMException.prototype.constructor = exports.DOMException;
5570 }
5571
5572 function fetch(input, init) {
5573 return new Promise(function(resolve, reject) {
5574 var request = new Request(input, init);
5575
5576 if (request.signal && request.signal.aborted) {
5577 return reject(new exports.DOMException('Aborted', 'AbortError'))
5578 }
5579
5580 var xhr = new XMLHttpRequest();
5581
5582 function abortXhr() {
5583 xhr.abort();
5584 }
5585
5586 xhr.onload = function() {
5587 var options = {
5588 status: xhr.status,
5589 statusText: xhr.statusText,
5590 headers: parseHeaders(xhr.getAllResponseHeaders() || '')
5591 };
5592 options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
5593 var body = 'response' in xhr ? xhr.response : xhr.responseText;
5594 resolve(new Response(body, options));
5595 };
5596
5597 xhr.onerror = function() {
5598 reject(new TypeError('Network request failed'));
5599 };
5600
5601 xhr.ontimeout = function() {
5602 reject(new TypeError('Network request failed'));
5603 };
5604
5605 xhr.onabort = function() {
5606 reject(new exports.DOMException('Aborted', 'AbortError'));
5607 };
5608
5609 xhr.open(request.method, request.url, true);
5610
5611 if (request.credentials === 'include') {
5612 xhr.withCredentials = true;
5613 } else if (request.credentials === 'omit') {
5614 xhr.withCredentials = false;
5615 }
5616
5617 if ('responseType' in xhr && support.blob) {
5618 xhr.responseType = 'blob';
5619 }
5620
5621 request.headers.forEach(function(value, name) {
5622 xhr.setRequestHeader(name, value);
5623 });
5624
5625 if (request.signal) {
5626 request.signal.addEventListener('abort', abortXhr);
5627
5628 xhr.onreadystatechange = function() {
5629 // DONE (success or failure)
5630 if (xhr.readyState === 4) {
5631 request.signal.removeEventListener('abort', abortXhr);
5632 }
5633 };
5634 }
5635
5636 xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
5637 })
5638 }
5639
5640 fetch.polyfill = true;
5641
5642 self.fetch = fetch;
5643 self.Headers = Headers;
5644 self.Request = Request;
5645 self.Response = Response;
5646
5647 exports.Headers = Headers;
5648 exports.Request = Request;
5649 exports.Response = Response;
5650 exports.fetch = fetch;
5651
5652 Object.defineProperty(exports, '__esModule', { value: true });
5653
5654})));
5655
5656}
5657
5658if (!((function(e){"use strict"
5659try{var a=new e.URL("http://example.com")
5660if("href"in a&&"searchParams"in a){var r=new URL("http://example.com")
5661if(r.search="a=1&b=2","http://example.com/?a=1&b=2"===r.href&&(r.search="","http://example.com/"===r.href)){var t=new e.URLSearchParams("a=1"),c=new e.URLSearchParams(t)
5662if("a=1"===String(c))return!0}}return!1}catch(h){return!1}})(self)
5663)) {
5664
5665// URL
5666/* global Symbol */
5667// URL Polyfill
5668// Draft specification: https://url.spec.whatwg.org
5669
5670// Notes:
5671// - Primarily useful for parsing URLs and modifying query parameters
5672// - Should work in IE8+ and everything more modern, with es5.js polyfills
5673
5674(function (global) {
5675 'use strict';
5676
5677 function isSequence(o) {
5678 if (!o) return false;
5679 if ('Symbol' in global && 'iterator' in global.Symbol &&
5680 typeof o[Symbol.iterator] === 'function') return true;
5681 if (Array.isArray(o)) return true;
5682 return false;
5683 }
5684
5685 function toArray(iter) {
5686 return ('from' in Array) ? Array.from(iter) : Array.prototype.slice.call(iter);
5687 }
5688
5689 (function() {
5690
5691 // Browsers may have:
5692 // * No global URL object
5693 // * URL with static methods only - may have a dummy constructor
5694 // * URL with members except searchParams
5695 // * Full URL API support
5696 var origURL = global.URL;
5697 var nativeURL;
5698 try {
5699 if (origURL) {
5700 nativeURL = new global.URL('http://example.com');
5701 if ('searchParams' in nativeURL) {
5702 var url = new URL('http://example.com');
5703 url.search = 'a=1&b=2';
5704 if (url.href === 'http://example.com/?a=1&b=2') {
5705 url.search = '';
5706 if (url.href === 'http://example.com/') {
5707 return;
5708 }
5709 }
5710 }
5711 if (!('href' in nativeURL)) {
5712 nativeURL = undefined;
5713 }
5714 nativeURL = undefined;
5715 }
5716 // eslint-disable-next-line no-empty
5717 } catch (_) {}
5718
5719 // NOTE: Doesn't do the encoding/decoding dance
5720 function urlencoded_serialize(pairs) {
5721 var output = '', first = true;
5722 pairs.forEach(function (pair) {
5723 var name = encodeURIComponent(pair.name);
5724 var value = encodeURIComponent(pair.value);
5725 if (!first) output += '&';
5726 output += name + '=' + value;
5727 first = false;
5728 });
5729 return output.replace(/%20/g, '+');
5730 }
5731
5732 // NOTE: Doesn't do the encoding/decoding dance
5733 function urlencoded_parse(input, isindex) {
5734 var sequences = input.split('&');
5735 if (isindex && sequences[0].indexOf('=') === -1)
5736 sequences[0] = '=' + sequences[0];
5737 var pairs = [];
5738 sequences.forEach(function (bytes) {
5739 if (bytes.length === 0) return;
5740 var index = bytes.indexOf('=');
5741 if (index !== -1) {
5742 var name = bytes.substring(0, index);
5743 var value = bytes.substring(index + 1);
5744 } else {
5745 name = bytes;
5746 value = '';
5747 }
5748 name = name.replace(/\+/g, ' ');
5749 value = value.replace(/\+/g, ' ');
5750 pairs.push({ name: name, value: value });
5751 });
5752 var output = [];
5753 pairs.forEach(function (pair) {
5754 output.push({
5755 name: decodeURIComponent(pair.name),
5756 value: decodeURIComponent(pair.value)
5757 });
5758 });
5759 return output;
5760 }
5761
5762 function URLUtils(url) {
5763 if (nativeURL)
5764 return new origURL(url);
5765 var anchor = document.createElement('a');
5766 anchor.href = url;
5767 return anchor;
5768 }
5769
5770 function URLSearchParams(init) {
5771 var $this = this;
5772 this._list = [];
5773
5774 if (init === undefined || init === null) {
5775 // no-op
5776 } else if (init instanceof URLSearchParams) {
5777 // In ES6 init would be a sequence, but special case for ES5.
5778 this._list = urlencoded_parse(String(init));
5779 } else if (typeof init === 'object' && isSequence(init)) {
5780 toArray(init).forEach(function(e) {
5781 if (!isSequence(e)) throw TypeError();
5782 var nv = toArray(e);
5783 if (nv.length !== 2) throw TypeError();
5784 $this._list.push({name: String(nv[0]), value: String(nv[1])});
5785 });
5786 } else if (typeof init === 'object' && init) {
5787 Object.keys(init).forEach(function(key) {
5788 $this._list.push({name: String(key), value: String(init[key])});
5789 });
5790 } else {
5791 init = String(init);
5792 if (init.substring(0, 1) === '?')
5793 init = init.substring(1);
5794 this._list = urlencoded_parse(init);
5795 }
5796
5797 this._url_object = null;
5798 this._setList = function (list) { if (!updating) $this._list = list; };
5799
5800 var updating = false;
5801 this._update_steps = function() {
5802 if (updating) return;
5803 updating = true;
5804
5805 if (!$this._url_object) return;
5806
5807 // Partial workaround for IE issue with 'about:'
5808 if ($this._url_object.protocol === 'about:' &&
5809 $this._url_object.pathname.indexOf('?') !== -1) {
5810 $this._url_object.pathname = $this._url_object.pathname.split('?')[0];
5811 }
5812
5813 $this._url_object.search = urlencoded_serialize($this._list);
5814
5815 updating = false;
5816 };
5817 }
5818
5819
5820 Object.defineProperties(URLSearchParams.prototype, {
5821 append: {
5822 value: function (name, value) {
5823 this._list.push({ name: name, value: value });
5824 this._update_steps();
5825 }, writable: true, enumerable: true, configurable: true
5826 },
5827
5828 'delete': {
5829 value: function (name) {
5830 for (var i = 0; i < this._list.length;) {
5831 if (this._list[i].name === name)
5832 this._list.splice(i, 1);
5833 else
5834 ++i;
5835 }
5836 this._update_steps();
5837 }, writable: true, enumerable: true, configurable: true
5838 },
5839
5840 get: {
5841 value: function (name) {
5842 for (var i = 0; i < this._list.length; ++i) {
5843 if (this._list[i].name === name)
5844 return this._list[i].value;
5845 }
5846 return null;
5847 }, writable: true, enumerable: true, configurable: true
5848 },
5849
5850 getAll: {
5851 value: function (name) {
5852 var result = [];
5853 for (var i = 0; i < this._list.length; ++i) {
5854 if (this._list[i].name === name)
5855 result.push(this._list[i].value);
5856 }
5857 return result;
5858 }, writable: true, enumerable: true, configurable: true
5859 },
5860
5861 has: {
5862 value: function (name) {
5863 for (var i = 0; i < this._list.length; ++i) {
5864 if (this._list[i].name === name)
5865 return true;
5866 }
5867 return false;
5868 }, writable: true, enumerable: true, configurable: true
5869 },
5870
5871 set: {
5872 value: function (name, value) {
5873 var found = false;
5874 for (var i = 0; i < this._list.length;) {
5875 if (this._list[i].name === name) {
5876 if (!found) {
5877 this._list[i].value = value;
5878 found = true;
5879 ++i;
5880 } else {
5881 this._list.splice(i, 1);
5882 }
5883 } else {
5884 ++i;
5885 }
5886 }
5887
5888 if (!found)
5889 this._list.push({ name: name, value: value });
5890
5891 this._update_steps();
5892 }, writable: true, enumerable: true, configurable: true
5893 },
5894
5895 entries: {
5896 value: function() { return new Iterator(this._list, 'key+value'); },
5897 writable: true, enumerable: true, configurable: true
5898 },
5899
5900 keys: {
5901 value: function() { return new Iterator(this._list, 'key'); },
5902 writable: true, enumerable: true, configurable: true
5903 },
5904
5905 values: {
5906 value: function() { return new Iterator(this._list, 'value'); },
5907 writable: true, enumerable: true, configurable: true
5908 },
5909
5910 forEach: {
5911 value: function(callback) {
5912 var thisArg = (arguments.length > 1) ? arguments[1] : undefined;
5913 this._list.forEach(function(pair) {
5914 callback.call(thisArg, pair.value, pair.name);
5915 });
5916
5917 }, writable: true, enumerable: true, configurable: true
5918 },
5919
5920 toString: {
5921 value: function () {
5922 return urlencoded_serialize(this._list);
5923 }, writable: true, enumerable: false, configurable: true
5924 }
5925 });
5926
5927 function Iterator(source, kind) {
5928 var index = 0;
5929 this.next = function() {
5930 if (index >= source.length)
5931 return {done: true, value: undefined};
5932 var pair = source[index++];
5933 return {done: false, value:
5934 kind === 'key' ? pair.name :
5935 kind === 'value' ? pair.value :
5936 [pair.name, pair.value]};
5937 };
5938 }
5939
5940 if ('Symbol' in global && 'iterator' in global.Symbol) {
5941 Object.defineProperty(URLSearchParams.prototype, global.Symbol.iterator, {
5942 value: URLSearchParams.prototype.entries,
5943 writable: true, enumerable: true, configurable: true});
5944 Object.defineProperty(Iterator.prototype, global.Symbol.iterator, {
5945 value: function() { return this; },
5946 writable: true, enumerable: true, configurable: true});
5947 }
5948
5949 function URL(url, base) {
5950 if (!(this instanceof global.URL))
5951 throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");
5952
5953 if (base) {
5954 url = (function () {
5955 if (nativeURL) return new origURL(url, base).href;
5956 var iframe;
5957 try {
5958 var doc;
5959 // Use another document/base tag/anchor for relative URL resolution, if possible
5960 if (Object.prototype.toString.call(window.operamini) === "[object OperaMini]") {
5961 iframe = document.createElement('iframe');
5962 iframe.style.display = 'none';
5963 document.documentElement.appendChild(iframe);
5964 doc = iframe.contentWindow.document;
5965 } else if (document.implementation && document.implementation.createHTMLDocument) {
5966 doc = document.implementation.createHTMLDocument('');
5967 } else if (document.implementation && document.implementation.createDocument) {
5968 doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
5969 doc.documentElement.appendChild(doc.createElement('head'));
5970 doc.documentElement.appendChild(doc.createElement('body'));
5971 } else if (window.ActiveXObject) {
5972 doc = new window.ActiveXObject('htmlfile');
5973 doc.write('<head></head><body></body>');
5974 doc.close();
5975 }
5976
5977 if (!doc) throw Error('base not supported');
5978
5979 var baseTag = doc.createElement('base');
5980 baseTag.href = base;
5981 doc.getElementsByTagName('head')[0].appendChild(baseTag);
5982 var anchor = doc.createElement('a');
5983 anchor.href = url;
5984 return anchor.href;
5985 } finally {
5986 if (iframe)
5987 iframe.parentNode.removeChild(iframe);
5988 }
5989 }());
5990 }
5991
5992 // An inner object implementing URLUtils (either a native URL
5993 // object or an HTMLAnchorElement instance) is used to perform the
5994 // URL algorithms. With full ES5 getter/setter support, return a
5995 // regular object For IE8's limited getter/setter support, a
5996 // different HTMLAnchorElement is returned with properties
5997 // overridden
5998
5999 var instance = URLUtils(url || '');
6000
6001 // Detect for ES5 getter/setter support
6002 // (an Object.defineProperties polyfill that doesn't support getters/setters may throw)
6003 var ES5_GET_SET = (function() {
6004 if (!('defineProperties' in Object)) return false;
6005 try {
6006 var obj = {};
6007 Object.defineProperties(obj, { prop: { get: function () { return true; } } });
6008 return obj.prop;
6009 } catch (_) {
6010 return false;
6011 }
6012 }());
6013
6014 var self = ES5_GET_SET ? this : document.createElement('a');
6015
6016
6017
6018 var query_object = new URLSearchParams(
6019 instance.search ? instance.search.substring(1) : null);
6020 query_object._url_object = self;
6021
6022 Object.defineProperties(self, {
6023 href: {
6024 get: function () { return instance.href; },
6025 set: function (v) { instance.href = v; tidy_instance(); update_steps(); },
6026 enumerable: true, configurable: true
6027 },
6028 origin: {
6029 get: function () {
6030 if ('origin' in instance) return instance.origin;
6031 return this.protocol + '//' + this.host;
6032 },
6033 enumerable: true, configurable: true
6034 },
6035 protocol: {
6036 get: function () { return instance.protocol; },
6037 set: function (v) { instance.protocol = v; },
6038 enumerable: true, configurable: true
6039 },
6040 username: {
6041 get: function () { return instance.username; },
6042 set: function (v) { instance.username = v; },
6043 enumerable: true, configurable: true
6044 },
6045 password: {
6046 get: function () { return instance.password; },
6047 set: function (v) { instance.password = v; },
6048 enumerable: true, configurable: true
6049 },
6050 host: {
6051 get: function () {
6052 // IE returns default port in |host|
6053 var re = {'http:': /:80$/, 'https:': /:443$/, 'ftp:': /:21$/}[instance.protocol];
6054 return re ? instance.host.replace(re, '') : instance.host;
6055 },
6056 set: function (v) { instance.host = v; },
6057 enumerable: true, configurable: true
6058 },
6059 hostname: {
6060 get: function () { return instance.hostname; },
6061 set: function (v) { instance.hostname = v; },
6062 enumerable: true, configurable: true
6063 },
6064 port: {
6065 get: function () { return instance.port; },
6066 set: function (v) { instance.port = v; },
6067 enumerable: true, configurable: true
6068 },
6069 pathname: {
6070 get: function () {
6071 // IE does not include leading '/' in |pathname|
6072 if (instance.pathname.charAt(0) !== '/') return '/' + instance.pathname;
6073 return instance.pathname;
6074 },
6075 set: function (v) { instance.pathname = v; },
6076 enumerable: true, configurable: true
6077 },
6078 search: {
6079 get: function () { return instance.search; },
6080 set: function (v) {
6081 if (instance.search === v) return;
6082 instance.search = v; tidy_instance(); update_steps();
6083 },
6084 enumerable: true, configurable: true
6085 },
6086 searchParams: {
6087 get: function () { return query_object; },
6088 enumerable: true, configurable: true
6089 },
6090 hash: {
6091 get: function () { return instance.hash; },
6092 set: function (v) { instance.hash = v; tidy_instance(); },
6093 enumerable: true, configurable: true
6094 },
6095 toString: {
6096 value: function() { return instance.toString(); },
6097 enumerable: false, configurable: true
6098 },
6099 valueOf: {
6100 value: function() { return instance.valueOf(); },
6101 enumerable: false, configurable: true
6102 }
6103 });
6104
6105 function tidy_instance() {
6106 var href = instance.href.replace(/#$|\?$|\?(?=#)/g, '');
6107 if (instance.href !== href)
6108 instance.href = href;
6109 }
6110
6111 function update_steps() {
6112 query_object._setList(instance.search ? urlencoded_parse(instance.search.substring(1)) : []);
6113 query_object._update_steps();
6114 }
6115
6116 return self;
6117 }
6118
6119 if (origURL) {
6120 for (var i in origURL) {
6121 if (Object.prototype.hasOwnProperty.call(origURL, i) && typeof origURL[i] === 'function')
6122 URL[i] = origURL[i];
6123 }
6124 }
6125
6126 global.URL = URL;
6127 global.URLSearchParams = URLSearchParams;
6128 }());
6129
6130 // Patch native URLSearchParams constructor to handle sequences/records
6131 // if necessary.
6132 (function() {
6133 if (new global.URLSearchParams([['a', 1]]).get('a') === '1' &&
6134 new global.URLSearchParams({a: 1}).get('a') === '1')
6135 return;
6136 var orig = global.URLSearchParams;
6137 global.URLSearchParams = function(init) {
6138 if (init && typeof init === 'object' && isSequence(init)) {
6139 var o = new orig();
6140 toArray(init).forEach(function(e) {
6141 if (!isSequence(e)) throw TypeError();
6142 var nv = toArray(e);
6143 if (nv.length !== 2) throw TypeError();
6144 o.append(nv[0], nv[1]);
6145 });
6146 return o;
6147 } else if (init && typeof init === 'object') {
6148 o = new orig();
6149 Object.keys(init).forEach(function(key) {
6150 o.set(key, init[key]);
6151 });
6152 return o;
6153 } else {
6154 return new orig(init);
6155 }
6156 };
6157 }());
6158
6159}(self));
6160
6161}
6162
6163})
6164('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});