]> git.openstreetmap.org Git - rails.git/blob - vendor/assets/polyfill/es5.js
Merge remote-tracking branch 'upstream/pull/2204'
[rails.git] / vendor / assets / polyfill / es5.js
1 /* Polyfill service v3.34.0
2  * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
3  * 
4  * Features requested: es5
5  * 
6  * - _ESAbstract.ArrayCreate, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
7  * - _ESAbstract.Call, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.OrdinaryToPrimitive")
8  * - _ESAbstract.Get, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct")
9  * - _ESAbstract.HasProperty, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
10  * - _ESAbstract.IsArray, License: CC0 (required by "Array.isArray", "es5", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
11  * - _ESAbstract.IsCallable, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive")
12  * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.trim", "es5")
13  * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.some")
14  * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.indexOf", "es5", "Array.prototype.lastIndexOf", "_ESAbstract.ToLength", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
15  * - _ESAbstract.ToLength, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
16  * - _ESAbstract.ToObject, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.GetV", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
17  * - _ESAbstract.GetV, License: CC0 (required by "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
18  * - _ESAbstract.GetMethod, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
19  * - _ESAbstract.Type, License: CC0 (required by "Object.create", "es5", "Object.defineProperties", "_ESAbstract.ToString", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.ToPrimitive", "_ESAbstract.IsConstructor", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct")
20  * - _ESAbstract.GetPrototypeFromConstructor, License: CC0 (required by "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
21  * - _ESAbstract.IsConstructor, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map", "_ESAbstract.Construct")
22  * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
23  * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
24  * - _ESAbstract.ToString, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
25  * - Date.now, License: CC0 (required by "es5")
26  * - Date.prototype.toISOString, License: CC0 (required by "es5")
27  * - Object.defineProperty, License: CC0 (required by "es5", "Object.defineProperties", "Object.create", "_ESAbstract.CreateMethodProperty", "Array.isArray", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "Object.keys", "String.prototype.trim", "_ESAbstract.CreateDataProperty", "_ESAbstract.CreateDataPropertyOrThrow", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate")
28  * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.prototype.filter", "es5", "Array.prototype.map")
29  * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map")
30  * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.isArray", "es5", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.create", "Object.defineProperties", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "Object.keys", "String.prototype.trim")
31  * - Array.isArray, License: CC0 (required by "es5")
32  * - Array.prototype.every, License: CC0 (required by "es5")
33  * - Array.prototype.forEach, License: CC0 (required by "es5")
34  * - Array.prototype.indexOf, License: CC0 (required by "es5")
35  * - Array.prototype.lastIndexOf, License: CC0 (required by "es5")
36  * - Array.prototype.reduce, License: CC0 (required by "es5")
37  * - Array.prototype.reduceRight, License: CC0 (required by "es5")
38  * - Array.prototype.some, License: CC0 (required by "es5")
39  * - Function.prototype.bind, License: MIT (required by "es5", "Object.getOwnPropertyDescriptor", "Object.defineProperties", "Object.create", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
40  * - Object.freeze, License: CC0 (required by "es5")
41  * - Object.getOwnPropertyDescriptor, License: CC0 (required by "es5", "Object.defineProperties", "Object.create")
42  * - Object.getOwnPropertyNames, License: CC0 (required by "es5")
43  * - Object.getPrototypeOf, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
44  * - Object.keys, License: MIT (required by "es5", "Object.defineProperties", "Object.create")
45  * - Object.defineProperties, License: CC0 (required by "es5", "Object.create")
46  * - Object.create, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
47  * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
48  * - _ESAbstract.Construct, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
49  * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map")
50  * - Array.prototype.filter, License: CC0 (required by "es5")
51  * - Array.prototype.map, License: CC0 (required by "es5")
52  * - String.prototype.trim, License: CC0 (required by "es5") */
53
54 (function(undefined) {
55
56 // _ESAbstract.ArrayCreate
57 // 9.4.2.2. ArrayCreate ( length [ , proto ] )
58 function ArrayCreate(length /* [, proto] */) { // eslint-disable-line no-unused-vars
59         // 1. Assert: length is an integer Number ≥ 0.
60         // 2. If length is -0, set length to +0.
61         if (1 / length === -Infinity) {
62                 length = 0;
63         }
64         // 3. If length>2^32-1, throw a RangeError exception.
65         if (length > (Math.pow(2, 32) - 1)) {
66                 throw new RangeError('Invalid array length');
67         }
68         // 4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%.
69         // 5. Let A be a newly created Array exotic object.
70         var A = [];
71         // 6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1.
72         // 7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1.
73         // 8. Set A.[[Prototype]] to proto.
74         // 9. Set A.[[Extensible]] to true.
75         // 10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
76         A.length = length;
77         // 11. Return A.
78         return A;
79 }
80
81 // _ESAbstract.Call
82 /* global IsCallable */
83 // 7.3.12. Call ( F, V [ , argumentsList ] )
84 function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars
85         // 1. If argumentsList is not present, set argumentsList to a new empty List.
86         var argumentsList = arguments.length > 2 ? arguments[2] : [];
87         // 2. If IsCallable(F) is false, throw a TypeError exception.
88         if (IsCallable(F) === false) {
89                 throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.');
90         }
91         // 3. Return ? F.[[Call]](V, argumentsList).
92         return F.apply(V, argumentsList);
93 }
94
95 // _ESAbstract.Get
96 // 7.3.1. Get ( O, P )
97 function Get(O, P) { // eslint-disable-line no-unused-vars
98         // 1. Assert: Type(O) is Object.
99         // 2. Assert: IsPropertyKey(P) is true.
100         // 3. Return ? O.[[Get]](P, O).
101         return O[P];
102 }
103
104 // _ESAbstract.HasProperty
105 // 7.3.10. HasProperty ( O, P )
106 function HasProperty(O, P) { // eslint-disable-line no-unused-vars
107         // Assert: Type(O) is Object.
108         // Assert: IsPropertyKey(P) is true.
109         // Return ? O.[[HasProperty]](P).
110         return P in O;
111 }
112
113 // _ESAbstract.IsArray
114 // 7.2.2. IsArray ( argument )
115 function IsArray(argument) { // eslint-disable-line no-unused-vars
116         // 1. If Type(argument) is not Object, return false.
117         // 2. If argument is an Array exotic object, return true.
118         // 3. If argument is a Proxy exotic object, then
119                 // a. If argument.[[ProxyHandler]] is null, throw a TypeError exception.
120                 // b. Let target be argument.[[ProxyTarget]].
121                 // c. Return ? IsArray(target).
122         // 4. Return false.
123
124         // Polyfill.io - We can skip all the above steps and check the string returned from Object.prototype.toString().
125         return Object.prototype.toString.call(argument) === '[object Array]';
126 }
127
128 // _ESAbstract.IsCallable
129 // 7.2.3. IsCallable ( argument )
130 function IsCallable(argument) { // eslint-disable-line no-unused-vars
131         // 1. If Type(argument) is not Object, return false.
132         // 2. If argument has a [[Call]] internal method, return true.
133         // 3. Return false.
134
135         // 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.
136         return typeof argument === 'function';
137 }
138
139 // _ESAbstract.RequireObjectCoercible
140 // 7.2.1. RequireObjectCoercible ( argument )
141 // The abstract operation ToObject converts argument to a value of type Object according to Table 12:
142 // Table 12: ToObject Conversions
143 /*
144 |----------------------------------------------------------------------------------------------------------------------------------------------------|
145 | Argument Type | Result                                                                                                                             |
146 |----------------------------------------------------------------------------------------------------------------------------------------------------|
147 | Undefined     | Throw a TypeError exception.                                                                                                       |
148 | Null          | Throw a TypeError exception.                                                                                                       |
149 | Boolean       | Return argument.                                                                                                                   |
150 | Number        | Return argument.                                                                                                                   |
151 | String        | Return argument.                                                                                                                   |
152 | Symbol        | Return argument.                                                                                                                   |
153 | Object        | Return argument.                                                                                                                   |
154 |----------------------------------------------------------------------------------------------------------------------------------------------------|
155 */
156 function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars
157         if (argument === null || argument === undefined) {
158                 throw TypeError();
159         }
160   return argument;
161 }
162
163 // _ESAbstract.ToBoolean
164 // 7.1.2. ToBoolean ( argument )
165 // The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9:
166 /*
167 --------------------------------------------------------------------------------------------------------------
168 | Argument Type | Result                                                                                     |
169 --------------------------------------------------------------------------------------------------------------
170 | Undefined     | Return false.                                                                              |
171 | Null          | Return false.                                                                              |
172 | Boolean       | Return argument.                                                                           |
173 | Number        | If argument is +0, -0, or NaN, return false; otherwise return true.                        |
174 | String        | If argument is the empty String (its length is zero), return false; otherwise return true. |
175 | Symbol        | Return true.                                                                               |
176 | Object        | Return true.                                                                               |
177 --------------------------------------------------------------------------------------------------------------
178 */
179 function ToBoolean(argument) { // eslint-disable-line no-unused-vars
180         return Boolean(argument);
181 }
182
183 // _ESAbstract.ToInteger
184 // 7.1.4. ToInteger ( argument )
185 function ToInteger(argument) { // eslint-disable-line no-unused-vars
186         // 1. Let number be ? ToNumber(argument).
187         var number = Number(argument);
188         // 2. If number is NaN, return +0.
189         if (isNaN(number)) {
190                 return 0;
191         }
192         // 3. If number is +0, -0, +∞, or -∞, return number.
193         if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
194                 return number;
195         }
196         // 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
197         return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number));
198 }
199
200 // _ESAbstract.ToLength
201 /* global ToInteger */
202 // 7.1.15. ToLength ( argument )
203 function ToLength(argument) { // eslint-disable-line no-unused-vars
204         // 1. Let len be ? ToInteger(argument).
205         var len = ToInteger(argument);
206         // 2. If len ≤ +0, return +0.
207         if (len <= 0) {
208                 return 0;
209         }
210         // 3. Return min(len, 253-1).
211         return Math.min(len, Math.pow(2, 53) -1);
212 }
213
214 // _ESAbstract.ToObject
215 // 7.1.13 ToObject ( argument )
216 // The abstract operation ToObject converts argument to a value of type Object according to Table 12:
217 // Table 12: ToObject Conversions
218 /*
219 |----------------------------------------------------------------------------------------------------------------------------------------------------|
220 | Argument Type | Result                                                                                                                             |
221 |----------------------------------------------------------------------------------------------------------------------------------------------------|
222 | Undefined     | Throw a TypeError exception.                                                                                                       |
223 | Null          | Throw a TypeError exception.                                                                                                       |
224 | Boolean       | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. |
225 | Number        | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects.    |
226 | String        | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects.    |
227 | Symbol        | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects.    |
228 | Object        | Return argument.                                                                                                                   |
229 |----------------------------------------------------------------------------------------------------------------------------------------------------|
230 */
231 function ToObject(argument) { // eslint-disable-line no-unused-vars
232         if (argument === null || argument === undefined) {
233                 throw TypeError();
234         }
235   return Object(argument);
236 }
237
238 // _ESAbstract.GetV
239 /* global ToObject */
240 // 7.3.2 GetV (V, P)
241 function GetV(v, p) { // eslint-disable-line no-unused-vars
242         // 1. Assert: IsPropertyKey(P) is true.
243         // 2. Let O be ? ToObject(V).
244         var o = ToObject(v);
245         // 3. Return ? O.[[Get]](P, V).
246         return o[p];
247 }
248
249 // _ESAbstract.GetMethod
250 /* global GetV, IsCallable */
251 // 7.3.9. GetMethod ( V, P )
252 function GetMethod(V, P) { // eslint-disable-line no-unused-vars
253         // 1. Assert: IsPropertyKey(P) is true.
254         // 2. Let func be ? GetV(V, P).
255         var func = GetV(V, P);
256         // 3. If func is either undefined or null, return undefined.
257         if (func === null || func === undefined) {
258                 return undefined;
259         }
260         // 4. If IsCallable(func) is false, throw a TypeError exception.
261         if (IsCallable(func) === false) {
262                 throw new TypeError('Method not callable: ' + P);
263         }
264         // 5. Return func.
265         return func;
266 }
267
268 // _ESAbstract.Type
269 // "Type(x)" is used as shorthand for "the type of x"...
270 function Type(x) { // eslint-disable-line no-unused-vars
271         switch (typeof x) {
272                 case 'undefined':
273                         return 'undefined';
274                 case 'boolean':
275                         return 'boolean';
276                 case 'number':
277                         return 'number';
278                 case 'string':
279                         return 'string';
280                 case 'symbol':
281                         return 'symbol';
282                 default:
283                         // typeof null is 'object'
284                         if (x === null) return 'null';
285                         // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`.
286                         if ('Symbol' in this && x instanceof this.Symbol) return 'symbol';
287                         return 'object';
288         }
289 }
290
291 // _ESAbstract.GetPrototypeFromConstructor
292 /* global Get, Type */
293 // 9.1.14. GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
294 function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
295         // 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.
296         // 2. Assert: IsCallable(constructor) is true.
297         // 3. Let proto be ? Get(constructor, "prototype").
298         var proto = Get(constructor, "prototype");
299         // 4. If Type(proto) is not Object, then
300         if (Type(proto) !== 'object') {
301                 // a. Let realm be ? GetFunctionRealm(constructor).
302                 // b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
303                 proto = intrinsicDefaultProto;
304         }
305         // 5. Return proto.
306         return proto;
307 }
308
309 // _ESAbstract.IsConstructor
310 /* global Type */
311 // 7.2.4. IsConstructor ( argument )
312 function IsConstructor(argument) { // eslint-disable-line no-unused-vars
313         // 1. If Type(argument) is not Object, return false.
314         if (Type(argument) !== 'object') {
315                 return false;
316         }
317         // 2. If argument has a [[Construct]] internal method, return true.
318         // 3. Return false.
319
320         // Polyfill.io - `new argument` is the only way  to truly test if a function is a constructor.
321         // We choose to not use`new argument` because the argument could have side effects when called.
322         // Instead we check to see if the argument is a function and if it has a prototype.
323         // Arrow functions do not have a [[Construct]] internal method, nor do they have a prototype.
324         return typeof argument === 'function' && !!argument.prototype;
325 }
326
327 // _ESAbstract.OrdinaryToPrimitive
328 /* global Get, IsCallable, Call, Type */
329 // 7.1.1.1. OrdinaryToPrimitive ( O, hint )
330 function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars
331         // 1. Assert: Type(O) is Object.
332         // 2. Assert: Type(hint) is String and its value is either "string" or "number".
333         // 3. If hint is "string", then
334         if (hint === 'string') {
335                 // a. Let methodNames be « "toString", "valueOf" ».
336                 var methodNames = ['toString', 'valueOf'];
337                 // 4. Else,
338         } else {
339                 // a. Let methodNames be « "valueOf", "toString" ».
340                 methodNames = ['valueOf', 'toString'];
341         }
342         // 5. For each name in methodNames in List order, do
343         for (var i = 0; i < methodNames.length; ++i) {
344                 var name = methodNames[i];
345                 // a. Let method be ? Get(O, name).
346                 var method = Get(O, name);
347                 // b. If IsCallable(method) is true, then
348                 if (IsCallable(method)) {
349                         // i. Let result be ? Call(method, O).
350                         var result = Call(method, O);
351                         // ii. If Type(result) is not Object, return result.
352                         if (Type(result) !== 'object') {
353                                 return result;
354                         }
355                 }
356         }
357         // 6. Throw a TypeError exception.
358         throw new TypeError('Cannot convert to primitive.');
359 }
360
361 // _ESAbstract.ToPrimitive
362 /* global Type, GetMethod, Call, OrdinaryToPrimitive */
363 // 7.1.1. ToPrimitive ( input [ , PreferredType ] )
364 function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars
365         var PreferredType = arguments.length > 1 ? arguments[1] : undefined;
366         // 1. Assert: input is an ECMAScript language value.
367         // 2. If Type(input) is Object, then
368         if (Type(input) === 'object') {
369                 // a. If PreferredType is not present, let hint be "default".
370                 if (arguments.length < 2) {
371                         var hint = 'default';
372                         // b. Else if PreferredType is hint String, let hint be "string".
373                 } else if (PreferredType === String) {
374                         hint = 'string';
375                         // c. Else PreferredType is hint Number, let hint be "number".
376                 } else if (PreferredType === Number) {
377                         hint = 'number';
378                 }
379                 // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
380                 var exoticToPrim = typeof this.Symbol === 'function' && typeof this.Symbol.toPrimitive === 'symbol' ? GetMethod(input, this.Symbol.toPrimitive) : undefined;
381                 // e. If exoticToPrim is not undefined, then
382                 if (exoticToPrim !== undefined) {
383                         // i. Let result be ? Call(exoticToPrim, input, « hint »).
384                         var result = Call(exoticToPrim, input, [hint]);
385                         // ii. If Type(result) is not Object, return result.
386                         if (Type(result) !== 'object') {
387                                 return result;
388                         }
389                         // iii. Throw a TypeError exception.
390                         throw new TypeError('Cannot convert exotic object to primitive.');
391                 }
392                 // f. If hint is "default", set hint to "number".
393                 if (hint === 'default') {
394                         hint = 'number';
395                 }
396                 // g. Return ? OrdinaryToPrimitive(input, hint).
397                 return OrdinaryToPrimitive(input, hint);
398         }
399         // 3. Return input
400         return input;
401 }
402
403 // _ESAbstract.ToString
404 /* global Type, ToPrimitive */
405 // 7.1.12. ToString ( argument )
406 // The abstract operation ToString converts argument to a value of type String according to Table 11:
407 // Table 11: ToString Conversions
408 /*
409 |---------------|--------------------------------------------------------|
410 | Argument Type | Result                                                 |
411 |---------------|--------------------------------------------------------|
412 | Undefined     | Return "undefined".                                    |
413 |---------------|--------------------------------------------------------|
414 | Null          | Return "null".                                         |
415 |---------------|--------------------------------------------------------|
416 | Boolean       | If argument is true, return "true".                    |
417 |               | If argument is false, return "false".                  |
418 |---------------|--------------------------------------------------------|
419 | Number        | Return NumberToString(argument).                       |
420 |---------------|--------------------------------------------------------|
421 | String        | Return argument.                                       |
422 |---------------|--------------------------------------------------------|
423 | Symbol        | Throw a TypeError exception.                           |
424 |---------------|--------------------------------------------------------|
425 | Object        | Apply the following steps:                             |
426 |               | Let primValue be ? ToPrimitive(argument, hint String). |
427 |               | Return ? ToString(primValue).                          |
428 |---------------|--------------------------------------------------------|
429 */
430 function ToString(argument) { // eslint-disable-line no-unused-vars
431         switch(Type(argument)) {
432                 case 'symbol':
433                         throw new TypeError('Cannot convert a Symbol value to a string');
434                         break;
435                 case 'object':
436                         var primValue = ToPrimitive(argument, 'string');
437                         return ToString(primValue);
438                 default:
439                         return String(argument);
440         }
441 }
442 if (!("Date"in this&&"now"in this.Date&&"getTime"in this.Date.prototype
443 )) {
444
445 // Date.now
446 Date.now = function now() {
447         return new Date().getTime();
448 };
449
450 }
451
452 if (!("Date"in this&&"toISOString"in Date.prototype
453 )) {
454
455 // Date.prototype.toISOString
456 Date.prototype.toISOString = function toISOString() {
457         var date = this;
458
459         function pad(str, len) {
460                 var pad = "0000";
461                 str = '' + str;
462                 return pad.substr(0, len - str.length) + str;
463         }
464
465         var y = date.getUTCFullYear(),
466         m = pad(date.getUTCMonth() + 1, 2),
467         d = pad(date.getUTCDate(), 2),
468         h = pad(date.getUTCHours(), 2),
469         i = pad(date.getUTCMinutes(), 2),
470         s = pad(date.getUTCSeconds(), 2),
471         ms = pad(date.getUTCMilliseconds(), 3);
472
473         return y +'-'+ m +'-'+ d + 'T' + h +':'+ i +':'+ s +'.'+ ms +'Z';
474 };
475
476 }
477
478 if (!("defineProperty"in Object&&function(){try{var e={}
479 return Object.defineProperty(e,"test",{value:42}),!0}catch(t){return!1}}()
480 )) {
481
482 // Object.defineProperty
483 (function (nativeDefineProperty) {
484
485         var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
486         var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
487         var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
488
489         // Polyfill.io - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty.
490         Object['defineProperty'] = function defineProperty(object, property, descriptor) {
491
492                 // Where native support exists, assume it
493                 if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
494                         return nativeDefineProperty(object, property, descriptor);
495                 }
496
497                 if (object === null || !(object instanceof Object || typeof object === 'object')) {
498                         throw new TypeError('Object.defineProperty called on non-object');
499                 }
500
501                 if (!(descriptor instanceof Object)) {
502                         throw new TypeError('Property description must be an object');
503                 }
504
505                 var propertyString = String(property);
506                 var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
507                 var getterType = 'get' in descriptor && typeof descriptor.get;
508                 var setterType = 'set' in descriptor && typeof descriptor.set;
509
510                 // handle descriptor.get
511                 if (getterType) {
512                         if (getterType !== 'function') {
513                                 throw new TypeError('Getter must be a function');
514                         }
515                         if (!supportsAccessors) {
516                                 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
517                         }
518                         if (hasValueOrWritable) {
519                                 throw new TypeError(ERR_VALUE_ACCESSORS);
520                         }
521                         Object.__defineGetter__.call(object, propertyString, descriptor.get);
522                 } else {
523                         object[propertyString] = descriptor.value;
524                 }
525
526                 // handle descriptor.set
527                 if (setterType) {
528                         if (setterType !== 'function') {
529                                 throw new TypeError('Setter must be a function');
530                         }
531                         if (!supportsAccessors) {
532                                 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
533                         }
534                         if (hasValueOrWritable) {
535                                 throw new TypeError(ERR_VALUE_ACCESSORS);
536                         }
537                         Object.__defineSetter__.call(object, propertyString, descriptor.set);
538                 }
539
540                 // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
541                 if ('value' in descriptor) {
542                         object[propertyString] = descriptor.value;
543                 }
544
545                 return object;
546         };
547 }(Object.defineProperty));
548
549 }
550
551
552 // _ESAbstract.CreateDataProperty
553 // 7.3.4. CreateDataProperty ( O, P, V )
554 // NOTE
555 // This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator.
556 // 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.
557 function CreateDataProperty(O, P, V) { // eslint-disable-line no-unused-vars
558         // 1. Assert: Type(O) is Object.
559         // 2. Assert: IsPropertyKey(P) is true.
560         // 3. Let newDesc be the PropertyDescriptor{ [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
561         var newDesc = {
562                 value: V,
563                 writable: true,
564                 enumerable: true,
565                 configurable: true
566         };
567         // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
568         try {
569                 Object.defineProperty(O, P, newDesc);
570                 return true;
571         } catch (e) {
572                 return false;
573         }
574 }
575
576 // _ESAbstract.CreateDataPropertyOrThrow
577 /* global CreateDataProperty */
578 // 7.3.6. CreateDataPropertyOrThrow ( O, P, V )
579 function CreateDataPropertyOrThrow(O, P, V) { // eslint-disable-line no-unused-vars
580         // 1. Assert: Type(O) is Object.
581         // 2. Assert: IsPropertyKey(P) is true.
582         // 3. Let success be ? CreateDataProperty(O, P, V).
583         var success = CreateDataProperty(O, P, V);
584         // 4. If success is false, throw a TypeError exception.
585         if (!success) {
586                 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) + '`');
587         }
588         // 5. Return success.
589         return success;
590 }
591
592 // _ESAbstract.CreateMethodProperty
593 // 7.3.5. CreateMethodProperty ( O, P, V )
594 function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars
595         // 1. Assert: Type(O) is Object.
596         // 2. Assert: IsPropertyKey(P) is true.
597         // 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
598         var newDesc = {
599                 value: V,
600                 writable: true,
601                 enumerable: false,
602                 configurable: true
603         };
604         // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
605         Object.defineProperty(O, P, newDesc);
606 }
607 if (!("isArray"in Array
608 )) {
609
610 // Array.isArray
611 /* global CreateMethodProperty, IsArray */
612 // 22.1.2.2. Array.isArray ( arg )
613 CreateMethodProperty(Array, 'isArray', function isArray(arg) {
614         // 1. Return ? IsArray(arg).
615         return IsArray(arg);
616 });
617
618 }
619
620 if (!("every"in Array.prototype
621 )) {
622
623 // Array.prototype.every
624 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */
625 // 22.1.3.5. Array.prototype.every ( callbackfn [ , thisArg ] )
626 CreateMethodProperty(Array.prototype, 'every', function every(callbackfn /* [ , thisArg ] */) {
627         // 1. Let O be ? ToObject(this value).
628         var O = ToObject(this);
629         // 2. Let len be ? ToLength(? Get(O, "length")).
630         var len = ToLength(Get(O, "length"));
631         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
632         if (IsCallable(callbackfn) === false) {
633                 throw new TypeError(callbackfn + ' is not a function');
634         }
635         // 4. If thisArg is present, let T be thisArg; else let T be undefined.
636         var T = arguments.length > 1 ? arguments[1] : undefined;
637         // 5. Let k be 0.
638         var k = 0;
639         // 6. Repeat, while k < len
640         while (k < len) {
641                 // a. Let Pk be ! ToString(k).
642                 var Pk = ToString(k);
643                 // b. Let kPresent be ? HasProperty(O, Pk).
644                 var kPresent = HasProperty(O, Pk);
645                 // c. If kPresent is true, then
646                 if (kPresent) {
647                         // i. Let kValue be ? Get(O, Pk).
648                         var kValue = Get(O, Pk);
649                         // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
650                         var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
651                         // iii. If testResult is false, return false.
652                         if (testResult === false) {
653                                 return false;
654                         }
655                 }
656                 // d. Increase k by 1.
657                 var k = k + 1;
658         }
659         // 7. Return true.
660         return true;
661 });
662
663 }
664
665 if (!("forEach"in Array.prototype
666 )) {
667
668 // Array.prototype.forEach
669 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
670 // 22.1.3.10. Array.prototype.forEach ( callbackfn [ , thisArg ] )
671 CreateMethodProperty(Array.prototype, 'forEach', function forEach(callbackfn /* [ , thisArg ] */) {
672         // 1. Let O be ? ToObject(this value).
673         var O = ToObject(this);
674         // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
675         // We will use arrayLike in place of O when we are iterating through the list.
676         var arraylike = O instanceof String ? O.split('') : O;
677         // 2. Let len be ? ToLength(? Get(O, "length")).
678         var len = ToLength(Get(O, "length"));
679         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
680         if (IsCallable(callbackfn) === false) {
681                 throw new TypeError(callbackfn + ' is not a function');
682         }
683         // 4. If thisArg is present, let T be thisArg; else let T be undefined.
684         var T = arguments.length > 1 ? arguments[1] : undefined;
685         // 5. Let k be 0.
686         var k = 0;
687         // 6. Repeat, while k < len
688         while (k < len) {
689                 // a. Let Pk be ! ToString(k).
690                 var Pk = ToString(k);
691                 // b. Let kPresent be ? HasProperty(O, Pk).
692                 var kPresent = HasProperty(arraylike, Pk);
693                 // c. If kPresent is true, then
694                 if (kPresent) {
695                         // i. Let kValue be ? Get(O, Pk).
696                         var kValue = Get(arraylike, Pk);
697                         // ii. Perform ? Call(callbackfn, T, « kValue, k, O »).
698                         Call(callbackfn, T, [kValue, k, O]);
699                 }
700                 // d. Increase k by 1.
701                 k = k + 1;
702         }
703         // 7. Return undefined.
704         return undefined;
705 });
706
707 }
708
709 if (!("indexOf"in Array.prototype
710 )) {
711
712 // Array.prototype.indexOf
713 /* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */
714 // 22.1.3.12. Array.prototype.indexOf ( searchElement [ , fromIndex ] )
715 CreateMethodProperty(Array.prototype, 'indexOf', function indexOf(searchElement /* [ , fromIndex ] */) {
716         // 1. Let O be ? ToObject(this value).
717         var O = ToObject(this);
718         // 2. Let len be ? ToLength(? Get(O, "length")).
719         var len = ToLength(Get(O, "length"));
720         // 3. If len is 0, return -1.
721         if (len === 0) {
722                 return -1;
723         }
724         // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.)
725         var n = ToInteger(arguments[1]);
726         // 5. If n ≥ len, return -1.
727         if (n >= len) {
728                 return -1;
729         }
730         // 6. If n ≥ 0, then
731         if (n >= 0) {
732                 // a. If n is -0, let k be +0; else let k be n.
733                 var k = n === -0 ? 0 : n;
734                 // 7. Else n < 0,
735         } else {
736                 // a. Let k be len + n.
737                 var k = len + n;
738                 // b. If k < 0, let k be 0.
739                 if (k < 0) {
740                         k = 0;
741                 }
742         }
743         // 8. Repeat, while k < len
744         while (k < len) {
745                 // a. Let kPresent be ? HasProperty(O, ! ToString(k)).
746                 var kPresent = HasProperty(O, ToString(k));
747                 // b. If kPresent is true, then
748                 if (kPresent) {
749                         // i. Let elementK be ? Get(O, ! ToString(k)).
750                         var elementK = Get(O, ToString(k));
751                         // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK.
752                         var same = searchElement === elementK;
753                         // iii. If same is true, return k.
754                         if (same) {
755                                 return k;
756                         }
757                 }
758                 // c. Increase k by 1.
759                 k = k + 1;
760         }
761         // 9. Return -1.
762         return -1;
763 });
764
765 }
766
767 if (!("lastIndexOf"in Array.prototype
768 )) {
769
770 // Array.prototype.lastIndexOf
771 /* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */
772 // 22.1.3.15. Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
773 CreateMethodProperty(Array.prototype, 'lastIndexOf', function lastIndexOf(searchElement /* [ , fromIndex ] */) {
774         // 1. Let O be ? ToObject(this value).
775         var O = ToObject(this);
776         // 2. Let len be ? ToLength(? Get(O, "length")).
777         var len = ToLength(Get(O, "length"));
778         // 3. If len is 0, return -1.
779         if (len === 0) {
780                 return -1;
781         }
782         // 4. If fromIndex is present, let n be ? ToInteger(fromIndex); else let n be len-1.
783         var n = arguments.length > 1 ? ToInteger(arguments[1]) : len - 1;
784         // 5. If n ≥ 0, then
785         if (n >= 0) {
786                 // a. If n is -0, let k be +0; else let k be min(n, len - 1).
787                 var k = n === -0 ? 0 : Math.min(n, len - 1);
788                 // 6. Else n < 0,
789         } else {
790                 // a. Let k be len + n.
791                 k = len + n;
792         }
793         // 7. Repeat, while k ≥ 0
794         while (k >= 0) {
795                 // a. Let kPresent be ? HasProperty(O, ! ToString(k)).
796                 var kPresent = HasProperty(O, ToString(k));
797                 // b. If kPresent is true, then
798                 if (kPresent) {
799                         // i. Let elementK be ? Get(O, ! ToString(k)).
800                         var elementK = Get(O, ToString(k));
801                         // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK.
802                         var same = searchElement === elementK;
803                         // iii. If same is true, return k.
804                         if (same) {
805                                 return k;
806                         }
807                 }
808                 // c. Decrease k by 1.
809                 k = k - 1;
810         }
811         // 9. Return -1.
812         return -1;
813 });
814
815 }
816
817 if (!("reduce"in Array.prototype
818 )) {
819
820 // Array.prototype.reduce
821 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
822 // 22.1.3.19. Array.prototype.reduce ( callbackfn [ , initialValue ] )
823 CreateMethodProperty(Array.prototype, 'reduce', function reduce(callbackfn /* [ , initialValue ] */) {
824         // 1. Let O be ? ToObject(this value).
825         var O = ToObject(this);
826         // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
827         // We will use arrayLike in place of O when we are iterating through the list.
828         var arraylike = O instanceof String ? O.split('') : O;
829         // 2. Let len be ? ToLength(? Get(O, "length")).
830         var len = ToLength(Get(arraylike, "length"));
831         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
832         if (IsCallable(callbackfn) === false) {
833                 throw new TypeError(callbackfn + ' is not a function');
834         }
835         // 4. If len is 0 and initialValue is not present, throw a TypeError exception.
836         var initialValue = arguments.length > 1 ? arguments[1] : undefined;
837         if (len === 0 && arguments.length < 2) {
838                 throw new TypeError('Reduce of empty array with no initial value');
839         }
840         // 5. Let k be 0.
841         var k = 0;
842         // 6. Let accumulator be undefined.
843         var accumulator = undefined;
844         // 7. If initialValue is present, then
845         if (arguments.length > 1) {
846                 // a. Set accumulator to initialValue.
847                 accumulator = initialValue;
848                 // 8. Else initialValue is not present,
849         } else {
850                 // a. Let kPresent be false.
851                 var kPresent = false;
852                 // b. Repeat, while kPresent is false and k < len
853                 while (kPresent === false && k < len) {
854                         // i. Let Pk be ! ToString(k).
855                         var Pk = ToString(k);
856                         // ii. Let kPresent be ? HasProperty(O, Pk).
857                         var kPresent = HasProperty(arraylike, Pk);
858                         // iii. If kPresent is true, then
859                         if (kPresent) {
860                                 // 1. Set accumulator to ? Get(O, Pk).
861                                 var accumulator = Get(arraylike, Pk);
862                         }
863                         // iv. Increase k by 1.
864                         k = k + 1;
865                 }
866                 // c. If kPresent is false, throw a TypeError exception.
867                 if (kPresent === false) {
868                         throw new TypeError('Reduce of empty array with no initial value');
869                 }
870         }
871         // 9. Repeat, while k < len
872         while (k < len) {
873                 // a. Let Pk be ! ToString(k).
874                 var Pk = ToString(k);
875                 // b. Let kPresent be ? HasProperty(O, Pk).
876                 var kPresent = HasProperty(arraylike, Pk);
877                 // c. If kPresent is true, then
878                 if (kPresent) {
879                         // i. Let kValue be ? Get(O, Pk).
880                         var kValue = Get(arraylike, Pk);
881                         // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »).
882                         accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]);
883                 }
884                 // d. Increase k by 1.
885                 k = k + 1;
886         }
887         // 10. Return accumulator.
888         return accumulator;
889 });
890
891 }
892
893 if (!("reduceRight"in Array.prototype
894 )) {
895
896 // Array.prototype.reduceRight
897 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
898 // 22.1.3.20. Array.prototype.reduceRight ( callbackfn [ , initialValue ] )
899 CreateMethodProperty(Array.prototype, 'reduceRight', function reduceRight(callbackfn /* [ , initialValue ] */) {
900         // 1. Let O be ? ToObject(this value).
901         var O = ToObject(this);
902         // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
903         // We will use arrayLike in place of O when we are iterating through the list.
904         var arraylike = O instanceof String ? O.split('') : O;
905         // 2. Let len be ? ToLength(? Get(O, "length")).
906         var len = ToLength(Get(arraylike, "length"));
907         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
908         if (IsCallable(callbackfn) === false) {
909                 throw new TypeError(callbackfn + ' is not a function');
910         }
911         // 4. If len is 0 and initialValue is not present, throw a TypeError exception.
912         var initialValue = arguments.length > 1 ? arguments[1] : undefined;
913         if (len === 0 && arguments.length < 2) {
914                 throw new TypeError('Reduce of empty array with no initial value');
915         }
916         // 5. Let k be len-1.
917         var k = len - 1;
918         // 6. Let accumulator be undefined.
919         var accumulator = undefined;
920         // 7. If initialValue is present, then
921         if (arguments.length > 1) {
922                 // a. Set accumulator to initialValue.
923                 accumulator = initialValue;
924                 // 8.Else initialValue is not present,
925         } else {
926                 // a. Let kPresent be false.
927                 var kPresent = false;
928                 // b. Repeat, while kPresent is false and k ≥ 0
929                 while (kPresent === false && k >= 0) {
930                         // i. Let Pk be ! ToString(k).
931                         var Pk = ToString(k);
932                         // ii. Let kPresent be ? HasProperty(O, Pk).
933                         var kPresent = HasProperty(arraylike, Pk);
934                         // iii. If kPresent is true, then
935                         if (kPresent) {
936                                 // 1. Set accumulator to ? Get(O, Pk).
937                                 accumulator = Get(arraylike, Pk);
938                         }
939                         // iv. Decrease k by 1.
940                         k = k - 1;
941                 }
942                 // c. If kPresent is false, throw a TypeError exception.
943                 if (kPresent === false) {
944                         throw new TypeError('Reduce of empty array with no initial value');
945                 }
946         }
947         // 9. Repeat, while k ≥ 0
948         while (k >= 0) {
949                 // a. Let Pk be ! ToString(k).
950                 var Pk = ToString(k);
951                 // b. Let kPresent be ? HasProperty(O, Pk).
952                 var kPresent = HasProperty(arraylike, Pk);
953                 // c. If kPresent is true, then
954                 if (kPresent) {
955                         // i. Let kValue be ? Get(O, Pk).
956                         var kValue = Get(arraylike, Pk);
957                         // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »).
958                         accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]);
959                 }
960                 // d. Decrease k by 1.
961                 k = k - 1;
962         }
963         // 10 Return accumulator.
964         return accumulator;
965 });
966
967 }
968
969 if (!("some"in Array.prototype
970 )) {
971
972 // Array.prototype.some
973 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */
974 // 22.1.3.24. Array.prototype.some ( callbackfn [ , thisArg ] )
975 CreateMethodProperty(Array.prototype, 'some', function some(callbackfn /* [ , thisArg ] */) {
976         // 1. Let O be ? ToObject(this value).
977         var O = ToObject(this);
978         // 2. Let len be ? ToLength(? Get(O, "length")).
979         var len = ToLength(Get(O, "length"));
980         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
981         if (IsCallable(callbackfn) === false) {
982                 throw new TypeError(callbackfn + ' is not a function');
983         }
984         // 4. If thisArg is present, let T be thisArg; else let T be undefined.
985         var T = arguments.length > 1 ? arguments[1] : undefined;
986         // 5. Let k be 0.
987         var k = 0;
988         // 6. Repeat, while k < len
989         while (k < len) {
990                 // a. Let Pk be ! ToString(k).
991                 var Pk = ToString(k);
992                 // b. Let kPresent be ? HasProperty(O, Pk).
993                 var kPresent = HasProperty(O, Pk);
994                 // c. If kPresent is true, then
995                 if (kPresent) {
996                         // i. Let kValue be ? Get(O, Pk).
997                         var kValue = Get(O, Pk);
998                         // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
999                         var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
1000                         // iii. If testResult is true, return true.
1001                         if (testResult) {
1002                                 return true;
1003                         }
1004                 }
1005                 // d. Increase k by 1.
1006                 k = k + 1;
1007         }
1008         // 7. Return false.
1009         return false;
1010 });
1011
1012 }
1013
1014 if (!("bind"in Function.prototype
1015 )) {
1016
1017 // Function.prototype.bind
1018 /* global CreateMethodProperty, IsCallable */
1019 // 19.2.3.2. Function.prototype.bind ( thisArg, ...args )
1020 // https://github.com/es-shims/es5-shim/blob/d6d7ff1b131c7ba14c798cafc598bb6780d37d3b/es5-shim.js#L182
1021 CreateMethodProperty(Function.prototype, 'bind', function bind(that) { // .length is 1
1022         // add necessary es5-shim utilities
1023         var $Array = Array;
1024         var $Object = Object;
1025         var ArrayPrototype = $Array.prototype;
1026         var Empty = function Empty() { };
1027         var array_slice = ArrayPrototype.slice;
1028         var array_concat = ArrayPrototype.concat;
1029         var array_push = ArrayPrototype.push;
1030         var max = Math.max;
1031         // /add necessary es5-shim utilities
1032
1033         // 1. Let Target be the this value.
1034         var target = this;
1035         // 2. If IsCallable(Target) is false, throw a TypeError exception.
1036         if (!IsCallable(target)) {
1037                 throw new TypeError('Function.prototype.bind called on incompatible ' + target);
1038         }
1039         // 3. Let A be a new (possibly empty) internal list of all of the
1040         //   argument values provided after thisArg (arg1, arg2 etc), in order.
1041         // XXX slicedArgs will stand in for "A" if used
1042         var args = array_slice.call(arguments, 1); // for normal call
1043         // 4. Let F be a new native ECMAScript object.
1044         // 11. Set the [[Prototype]] internal property of F to the standard
1045         //   built-in Function prototype object as specified in 15.3.3.1.
1046         // 12. Set the [[Call]] internal property of F as described in
1047         //   15.3.4.5.1.
1048         // 13. Set the [[Construct]] internal property of F as described in
1049         //   15.3.4.5.2.
1050         // 14. Set the [[HasInstance]] internal property of F as described in
1051         //   15.3.4.5.3.
1052         var bound;
1053         var binder = function () {
1054
1055                 if (this instanceof bound) {
1056                         // 15.3.4.5.2 [[Construct]]
1057                         // When the [[Construct]] internal method of a function object,
1058                         // F that was created using the bind function is called with a
1059                         // list of arguments ExtraArgs, the following steps are taken:
1060                         // 1. Let target be the value of F's [[TargetFunction]]
1061                         //   internal property.
1062                         // 2. If target has no [[Construct]] internal method, a
1063                         //   TypeError exception is thrown.
1064                         // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
1065                         //   property.
1066                         // 4. Let args be a new list containing the same values as the
1067                         //   list boundArgs in the same order followed by the same
1068                         //   values as the list ExtraArgs in the same order.
1069                         // 5. Return the result of calling the [[Construct]] internal
1070                         //   method of target providing args as the arguments.
1071
1072                         var result = target.apply(
1073                                 this,
1074                                 array_concat.call(args, array_slice.call(arguments))
1075                         );
1076                         if ($Object(result) === result) {
1077                                 return result;
1078                         }
1079                         return this;
1080
1081                 } else {
1082                         // 15.3.4.5.1 [[Call]]
1083                         // When the [[Call]] internal method of a function object, F,
1084                         // which was created using the bind function is called with a
1085                         // this value and a list of arguments ExtraArgs, the following
1086                         // steps are taken:
1087                         // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
1088                         //   property.
1089                         // 2. Let boundThis be the value of F's [[BoundThis]] internal
1090                         //   property.
1091                         // 3. Let target be the value of F's [[TargetFunction]] internal
1092                         //   property.
1093                         // 4. Let args be a new list containing the same values as the
1094                         //   list boundArgs in the same order followed by the same
1095                         //   values as the list ExtraArgs in the same order.
1096                         // 5. Return the result of calling the [[Call]] internal method
1097                         //   of target providing boundThis as the this value and
1098                         //   providing args as the arguments.
1099
1100                         // equiv: target.call(this, ...boundArgs, ...args)
1101                         return target.apply(
1102                                 that,
1103                                 array_concat.call(args, array_slice.call(arguments))
1104                         );
1105
1106                 }
1107
1108         };
1109
1110         // 15. If the [[Class]] internal property of Target is "Function", then
1111         //     a. Let L be the length property of Target minus the length of A.
1112         //     b. Set the length own property of F to either 0 or L, whichever is
1113         //       larger.
1114         // 16. Else set the length own property of F to 0.
1115
1116         var boundLength = max(0, target.length - args.length);
1117
1118         // 17. Set the attributes of the length own property of F to the values
1119         //   specified in 15.3.5.1.
1120         var boundArgs = [];
1121         for (var i = 0; i < boundLength; i++) {
1122                 array_push.call(boundArgs, '$' + i);
1123         }
1124
1125         // XXX Build a dynamic function with desired amount of arguments is the only
1126         // way to set the length property of a function.
1127         // In environments where Content Security Policies enabled (Chrome extensions,
1128         // for ex.) all use of eval or Function costructor throws an exception.
1129         // However in all of these environments Function.prototype.bind exists
1130         // and so this code will never be executed.
1131         bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
1132
1133         if (target.prototype) {
1134                 Empty.prototype = target.prototype;
1135                 bound.prototype = new Empty();
1136                 // Clean up dangling references.
1137                 Empty.prototype = null;
1138         }
1139
1140         // TODO
1141         // 18. Set the [[Extensible]] internal property of F to true.
1142
1143         // TODO
1144         // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
1145         // 20. Call the [[DefineOwnProperty]] internal method of F with
1146         //   arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
1147         //   thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
1148         //   false.
1149         // 21. Call the [[DefineOwnProperty]] internal method of F with
1150         //   arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1151         //   [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1152         //   and false.
1153
1154         // TODO
1155         // NOTE Function objects created using Function.prototype.bind do not
1156         // have a prototype property or the [[Code]], [[FormalParameters]], and
1157         // [[Scope]] internal properties.
1158         // XXX can't delete prototype in pure-js.
1159
1160         // 22. Return F.
1161         return bound;
1162 });
1163
1164 }
1165
1166 if (!("freeze"in Object
1167 )) {
1168
1169 // Object.freeze
1170 /* global CreateMethodProperty */
1171 // 19.1.2.6. Object.freeze ( O )
1172 CreateMethodProperty(Object, 'freeze', function freeze(O) {
1173         // This feature cannot be implemented fully as a polyfill.
1174         // We choose to silently fail which allows "securable" code
1175         // to "gracefully" degrade to working but insecure code.
1176         return O;
1177 });
1178
1179 }
1180
1181 if (!("getOwnPropertyDescriptor"in Object&&"function"==typeof Object.getOwnPropertyDescriptor&&function(){try{var t={}
1182 return t.test=0,0===Object.getOwnPropertyDescriptor(t,"test").value}catch(e){return!1}}()
1183 )) {
1184
1185 // Object.getOwnPropertyDescriptor
1186 /* global CreateMethodProperty */
1187 (function () {
1188         var call = Function.prototype.call;
1189         var prototypeOfObject = Object.prototype;
1190         var owns = call.bind(prototypeOfObject.hasOwnProperty);
1191
1192         var lookupGetter;
1193         var lookupSetter;
1194         var supportsAccessors;
1195         if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
1196             lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
1197             lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
1198         }
1199         function doesGetOwnPropertyDescriptorWork(object) {
1200             try {
1201                 object.sentinel = 0;
1202                 return Object.getOwnPropertyDescriptor(
1203                     object,
1204                     "sentinel"
1205                 ).value === 0;
1206             } catch (exception) {
1207                 // returns falsy
1208             }
1209         }
1210         // check whether getOwnPropertyDescriptor works if it's given. Otherwise,
1211         // shim partially.
1212         if (Object.defineProperty) {
1213             var getOwnPropertyDescriptorWorksOnObject =
1214                 doesGetOwnPropertyDescriptorWork({});
1215             var getOwnPropertyDescriptorWorksOnDom = typeof document == "undefined" ||
1216                 doesGetOwnPropertyDescriptorWork(document.createElement("div"));
1217             if (!getOwnPropertyDescriptorWorksOnDom ||
1218                 !getOwnPropertyDescriptorWorksOnObject
1219             ) {
1220                 var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
1221             }
1222         }
1223
1224         if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
1225             var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: ";
1226
1227             CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(object, property) {
1228                 if ((typeof object != "object" && typeof object != "function") || object === null) {
1229                     throw new TypeError(ERR_NON_OBJECT + object);
1230                 }
1231
1232                 // make a valiant attempt to use the real getOwnPropertyDescriptor
1233                 // for I8's DOM elements.
1234                 if (getOwnPropertyDescriptorFallback) {
1235                     try {
1236                         return getOwnPropertyDescriptorFallback.call(Object, object, property);
1237                     } catch (exception) {
1238                         // try the shim if the real one doesn't work
1239                     }
1240                 }
1241
1242                 // If object does not owns property return undefined immediately.
1243                 if (!owns(object, property)) {
1244                     return;
1245                 }
1246
1247                 // If object has a property then it's for sure both `enumerable` and
1248                 // `configurable`.
1249                 var descriptor = { enumerable: true, configurable: true };
1250
1251                 // If JS engine supports accessor properties then property may be a
1252                 // getter or setter.
1253                 if (supportsAccessors) {
1254                     // Unfortunately `__lookupGetter__` will return a getter even
1255                     // if object has own non getter property along with a same named
1256                     // inherited getter. To avoid misbehavior we temporary remove
1257                     // `__proto__` so that `__lookupGetter__` will return getter only
1258                     // if it's owned by an object.
1259                     var prototype = object.__proto__;
1260                     object.__proto__ = prototypeOfObject;
1261
1262                     var getter = lookupGetter(object, property);
1263                     var setter = lookupSetter(object, property);
1264
1265                     // Once we have getter and setter we can put values back.
1266                     object.__proto__ = prototype;
1267
1268                     if (getter || setter) {
1269                         if (getter) {
1270                             descriptor.get = getter;
1271                         }
1272                         if (setter) {
1273                             descriptor.set = setter;
1274                         }
1275                         // If it was accessor property we're done and return here
1276                         // in order to avoid adding `value` to the descriptor.
1277                         return descriptor;
1278                     }
1279                 }
1280
1281                 // If we got this far we know that object has an own property that is
1282                 // not an accessor so we set it as a value and return descriptor.
1283                 descriptor.value = object[property];
1284                         descriptor.writable = true;
1285                 return descriptor;
1286             });
1287         }
1288 }());
1289
1290 }
1291
1292 if (!("getOwnPropertyNames"in Object
1293 )) {
1294
1295 // Object.getOwnPropertyNames
1296 /* global CreateMethodProperty */
1297
1298 var toString = ({}).toString;
1299 var split = ''.split;
1300
1301 CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) {
1302         var buffer = [];
1303         var key;
1304
1305         // Non-enumerable properties cannot be discovered but can be checked for by name.
1306         // Define those used internally by JS to allow an incomplete solution
1307         var commonProps = ['length', "name", "arguments", "caller", "prototype", "observe", "unobserve"];
1308
1309         if (typeof object === 'undefined' || object === null) {
1310                 throw new TypeError('Cannot convert undefined or null to object');
1311         }
1312
1313         // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8)
1314         object = toString.call(object) == '[object String]' ? split.call(object, '') : Object(object);
1315
1316         // Enumerable properties only
1317         for (key in object) {
1318                 if (Object.prototype.hasOwnProperty.call(object, key)) {
1319                         buffer.push(key);
1320                 }
1321         }
1322
1323         // Check for and add the common non-enumerable properties
1324         for (var i=0, s=commonProps.length; i<s; i++) {
1325                 if (commonProps[i] in object) buffer.push(commonProps[i]);
1326         }
1327
1328         return buffer;
1329 });
1330
1331 }
1332
1333 if (!("getPrototypeOf"in Object
1334 )) {
1335
1336 // Object.getPrototypeOf
1337 /* global CreateMethodProperty */
1338 // Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js
1339
1340 // https://github.com/es-shims/es5-shim/issues#issue/2
1341 // http://ejohn.org/blog/objectgetprototypeof/
1342 // recommended by fschaefer on github
1343 //
1344 // sure, and webreflection says ^_^
1345 // ... this will nerever possibly return null
1346 // ... Opera Mini breaks here with infinite loops
1347 CreateMethodProperty(Object, 'getPrototypeOf', function getPrototypeOf(object) {
1348         if (object !== Object(object)) {
1349                 throw new TypeError('Object.getPrototypeOf called on non-object');
1350         }
1351         var proto = object.__proto__;
1352         if (proto || proto === null) {
1353                 return proto;
1354         } else if (typeof object.constructor == 'function' && object instanceof object.constructor) {
1355     return object.constructor.prototype;
1356   } else if (object instanceof Object) {
1357                 return Object.prototype;
1358         } else {
1359                 // Correctly return null for Objects created with `Object.create(null)`
1360                 // (shammed or native) or `{ __proto__: null}`.  Also returns null for
1361                 // cross-realm objects on browsers that lack `__proto__` support (like
1362                 // IE <11), but that's the best we can do.
1363                 return null;
1364         }
1365 });
1366
1367 }
1368
1369 if (!("keys"in Object&&function(){return 2===Object.keys(arguments).length}(1,2)&&function(){try{return Object.keys(""),!0}catch(t){return!1}}()
1370 )) {
1371
1372 // Object.keys
1373 /* global CreateMethodProperty */
1374 CreateMethodProperty(Object, "keys", (function() {
1375         'use strict';
1376
1377         // modified from https://github.com/es-shims/object-keys
1378
1379         var has = Object.prototype.hasOwnProperty;
1380         var toStr = Object.prototype.toString;
1381         var isEnumerable = Object.prototype.propertyIsEnumerable;
1382         var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
1383         var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
1384         var dontEnums = [
1385                 'toString',
1386                 'toLocaleString',
1387                 'valueOf',
1388                 'hasOwnProperty',
1389                 'isPrototypeOf',
1390                 'propertyIsEnumerable',
1391                 'constructor'
1392         ];
1393         var equalsConstructorPrototype = function (o) {
1394                 var ctor = o.constructor;
1395                 return ctor && ctor.prototype === o;
1396         };
1397         var excludedKeys = {
1398                 $console: true,
1399                 $external: true,
1400                 $frame: true,
1401                 $frameElement: true,
1402                 $frames: true,
1403                 $innerHeight: true,
1404                 $innerWidth: true,
1405                 $outerHeight: true,
1406                 $outerWidth: true,
1407                 $pageXOffset: true,
1408                 $pageYOffset: true,
1409                 $parent: true,
1410                 $scrollLeft: true,
1411                 $scrollTop: true,
1412                 $scrollX: true,
1413                 $scrollY: true,
1414                 $self: true,
1415                 $webkitIndexedDB: true,
1416                 $webkitStorageInfo: true,
1417                 $window: true
1418         };
1419         var hasAutomationEqualityBug = (function () {
1420                 /* global window */
1421                 if (typeof window === 'undefined') { return false; }
1422                 for (var k in window) {
1423                         try {
1424                                 if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
1425                                         try {
1426                                                 equalsConstructorPrototype(window[k]);
1427                                         } catch (e) {
1428                                                 return true;
1429                                         }
1430                                 }
1431                         } catch (e) {
1432                                 return true;
1433                         }
1434                 }
1435                 return false;
1436         }());
1437         var equalsConstructorPrototypeIfNotBuggy = function (o) {
1438                 /* global window */
1439                 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
1440                         return equalsConstructorPrototype(o);
1441                 }
1442                 try {
1443                         return equalsConstructorPrototype(o);
1444                 } catch (e) {
1445                         return false;
1446                 }
1447         };
1448
1449         function isArgumentsObject(value) {
1450                 var str = toStr.call(value);
1451                 var isArgs = str === '[object Arguments]';
1452                 if (!isArgs) {
1453                         isArgs = str !== '[object Array]' &&
1454                                 value !== null &&
1455                                 typeof value === 'object' &&
1456                                 typeof value.length === 'number' &&
1457                                 value.length >= 0 &&
1458                                 toStr.call(value.callee) === '[object Function]';
1459                 }
1460                 return isArgs;
1461         }
1462
1463         return function keys(object) {
1464                 var isFunction = toStr.call(object) === '[object Function]';
1465                 var isArguments = isArgumentsObject(object);
1466                 var isString = toStr.call(object) === '[object String]';
1467                 var theKeys = [];
1468
1469                 if (object === undefined || object === null) {
1470                         throw new TypeError('Cannot convert undefined or null to object');
1471                 }
1472
1473                 var skipProto = hasProtoEnumBug && isFunction;
1474                 if (isString && object.length > 0 && !has.call(object, 0)) {
1475                         for (var i = 0; i < object.length; ++i) {
1476                                 theKeys.push(String(i));
1477                         }
1478                 }
1479
1480                 if (isArguments && object.length > 0) {
1481                         for (var j = 0; j < object.length; ++j) {
1482                                 theKeys.push(String(j));
1483                         }
1484                 } else {
1485                         for (var name in object) {
1486                                 if (!(skipProto && name === 'prototype') && has.call(object, name)) {
1487                                         theKeys.push(String(name));
1488                                 }
1489                         }
1490                 }
1491
1492                 if (hasDontEnumBug) {
1493                         var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1494
1495                         for (var k = 0; k < dontEnums.length; ++k) {
1496                                 if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
1497                                         theKeys.push(dontEnums[k]);
1498                                 }
1499                         }
1500                 }
1501                 return theKeys;
1502         };
1503 }()));
1504
1505 }
1506
1507 if (!("defineProperties"in Object
1508 )) {
1509
1510 // Object.defineProperties
1511 /* global CreateMethodProperty, Get, ToObject, Type */
1512 // 19.1.2.3. Object.defineProperties ( O, Properties )
1513 CreateMethodProperty(Object, 'defineProperties', function defineProperties(O, Properties) {
1514         // 1. If Type(O) is not Object, throw a TypeError exception.
1515         if (Type(O) !== 'object') {
1516                 throw new TypeError('Object.defineProperties called on non-object');
1517         }
1518         // 2. Let props be ? ToObject(Properties).
1519         var props = ToObject(Properties);
1520         // 3. Let keys be ? props.[[OwnPropertyKeys]]().
1521         /*
1522                 Polyfill.io - This step in our polyfill is not complying with the specification.
1523                 [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols.
1524                 TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]].
1525         */
1526         var keys = Object.keys(props);
1527         // 4. Let descriptors be a new empty List.
1528         var descriptors = [];
1529         // 5. For each element nextKey of keys in List order, do
1530         for (var i = 0; i < keys.length; i++) {
1531                 var nextKey = keys[i];
1532                 // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
1533                 var propDesc = Object.getOwnPropertyDescriptor(props, nextKey);
1534                 // b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
1535                 if (propDesc !== undefined && propDesc.enumerable) {
1536                         // i. Let descObj be ? Get(props, nextKey).
1537                         var descObj = Get(props, nextKey);
1538                         // ii. Let desc be ? ToPropertyDescriptor(descObj).
1539                         // Polyfill.io - We skip this step because Object.defineProperty deals with it.
1540                         // TODO: Implement this step?
1541                         var desc = descObj;
1542                         // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
1543                         descriptors.push([nextKey, desc]);
1544                 }
1545         }
1546         // 6. For each pair from descriptors in list order, do
1547         for (var i = 0; i < descriptors.length; i++){
1548                 // a. Let P be the first element of pair.
1549                 var P = descriptors[i][0];
1550                 // b. Let desc be the second element of pair.
1551                 var desc = descriptors[i][1];
1552                 // c. Perform ? DefinePropertyOrThrow(O, P, desc).
1553                 Object.defineProperty(O, P, desc);
1554         }
1555         // 7. Return O.
1556         return O;
1557 });
1558
1559 }
1560
1561 if (!("create"in Object
1562 )) {
1563
1564 // Object.create
1565 /* global CreateMethodProperty, Type */
1566 CreateMethodProperty(Object, 'create', function create(O, properties) {
1567         // 1. If Type(O) is neither Object nor Null, throw a TypeError exception.
1568         if (Type(O) !== 'object' && Type(O) !== 'null') {
1569                 throw new TypeError('Object prototype may only be an Object or null');
1570         }
1571         // 2. Let obj be ObjectCreate(O).
1572         var obj = new Function('e', 'function Object() {}Object.prototype=e;return new Object')(O);
1573
1574         obj.constructor.prototype = O;
1575
1576         // 3. If Properties is not undefined, then
1577         if (1 in arguments) {
1578                 // a. Return ? ObjectDefineProperties(obj, Properties).
1579                 return Object.defineProperties(obj, properties);
1580         }
1581
1582         return obj;
1583 });
1584
1585 }
1586
1587
1588 // _ESAbstract.OrdinaryCreateFromConstructor
1589 /* global GetPrototypeFromConstructor */
1590 // 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
1591 function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
1592         var internalSlotsList = arguments[2] || {};
1593         // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object.
1594         // The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object.
1595
1596         // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
1597         var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
1598
1599         // 3. Return ObjectCreate(proto, internalSlotsList).
1600         // 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.
1601         var obj = Object.create(proto);
1602         for (var name in internalSlotsList) {
1603                 if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) {
1604                         Object.defineProperty(obj, name, {
1605                                 configurable: true,
1606                                 enumerable: false,
1607                                 writable: true,
1608                                 value: internalSlotsList[name]
1609                         });
1610                 }
1611         }
1612         return obj;
1613 }
1614
1615 // _ESAbstract.Construct
1616 /* global IsConstructor, OrdinaryCreateFromConstructor, Call */
1617 // 7.3.13. Construct ( F [ , argumentsList [ , newTarget ]] )
1618 function Construct(F /* [ , argumentsList [ , newTarget ]] */) { // eslint-disable-line no-unused-vars
1619         // 1. If newTarget is not present, set newTarget to F.
1620         var newTarget = arguments.length > 2 ? arguments[2] : F;
1621
1622         // 2. If argumentsList is not present, set argumentsList to a new empty List.
1623         var argumentsList = arguments.length > 1 ? arguments[1] : [];
1624
1625         // 3. Assert: IsConstructor(F) is true.
1626         if (!IsConstructor(F)) {
1627                 throw new TypeError('F must be a constructor.');
1628         }
1629
1630         // 4. Assert: IsConstructor(newTarget) is true.
1631         if (!IsConstructor(newTarget)) {
1632                 throw new TypeError('newTarget must be a constructor.');
1633         }
1634
1635         // 5. Return ? F.[[Construct]](argumentsList, newTarget).
1636         // Polyfill.io - If newTarget is the same as F, it is equivalent to new F(...argumentsList).
1637         if (newTarget === F) {
1638                 return new (Function.prototype.bind.apply(F, [null].concat(argumentsList)))();
1639         } else {
1640                 // Polyfill.io - This is mimicking section 9.2.2 step 5.a.
1641                 var obj = OrdinaryCreateFromConstructor(newTarget, Object.prototype);
1642                 return Call(F, obj, argumentsList);
1643         }
1644 }
1645
1646 // _ESAbstract.ArraySpeciesCreate
1647 /* global IsArray, ArrayCreate, Get, Type, IsConstructor, Construct */
1648 // 9.4.2.3. ArraySpeciesCreate ( originalArray, length )
1649 function ArraySpeciesCreate(originalArray, length) { // eslint-disable-line no-unused-vars
1650         // 1. Assert: length is an integer Number ≥ 0.
1651         // 2. If length is -0, set length to +0.
1652         if (1/length === -Infinity) {
1653                 length = 0;
1654         }
1655
1656         // 3. Let isArray be ? IsArray(originalArray).
1657         var isArray = IsArray(originalArray);
1658
1659         // 4. If isArray is false, return ? ArrayCreate(length).
1660         if (isArray === false) {
1661                 return ArrayCreate(length);
1662         }
1663
1664         // 5. Let C be ? Get(originalArray, "constructor").
1665         var C = Get(originalArray, 'constructor');
1666
1667         // Polyfill.io - We skip this section as not sure how to make a cross-realm normal Array, a same-realm Array.
1668         // 6. If IsConstructor(C) is true, then
1669         // if (IsConstructor(C)) {
1670                 // a. Let thisRealm be the current Realm Record.
1671                 // b. Let realmC be ? GetFunctionRealm(C).
1672                 // c. If thisRealm and realmC are not the same Realm Record, then
1673                         // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
1674         // }
1675         // 7. If Type(C) is Object, then
1676         if (Type(C) === 'object') {
1677                 // a. Set C to ? Get(C, @@species).
1678                 C = 'Symbol' in this && 'species' in this.Symbol ? Get(C, this.Symbol.species) : undefined;
1679                 // b. If C is null, set C to undefined.
1680                 if (C === null) {
1681                         C = undefined;
1682                 }
1683         }
1684         // 8. If C is undefined, return ? ArrayCreate(length).
1685         if (C === undefined) {
1686                 return ArrayCreate(length);
1687         }
1688         // 9. If IsConstructor(C) is false, throw a TypeError exception.
1689         if (!IsConstructor(C)) {
1690                 throw new TypeError('C must be a constructor');
1691         }
1692         // 10. Return ? Construct(C, « length »).
1693         return Construct(C, [length]);
1694 }
1695 if (!("filter"in Array.prototype
1696 )) {
1697
1698 // Array.prototype.filter
1699 /* global CreateMethodProperty, ToObject, ToLength, Get, IsCallable, ArraySpeciesCreate, ToString, HasProperty, ToBoolean, Call, CreateDataPropertyOrThrow */
1700 // 22.1.3.7. Array.prototype.filter ( callbackfn [ , thisArg ] )
1701 CreateMethodProperty(Array.prototype, 'filter', function filter(callbackfn /* [ , thisArg ] */) {
1702         // 1. Let O be ? ToObject(this value).
1703         var O = ToObject(this);
1704         // 2. Let len be ? ToLength(? Get(O, "length")).
1705         var len = ToLength(Get(O, "length"));
1706         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
1707         if (IsCallable(callbackfn) === false) {
1708                 throw new TypeError(callbackfn + ' is not a function');
1709         }
1710         // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1711         var T = arguments.length > 1 ? arguments[1] : undefined;
1712         // 5. Let A be ? ArraySpeciesCreate(O, 0).
1713         var A = ArraySpeciesCreate(O, 0);
1714         // 6. Let k be 0.
1715         var k = 0;
1716         // 7. Let to be 0.
1717         var to = 0;
1718         // 8. Repeat, while k < len
1719         while (k < len) {
1720                 // a. Let Pk be ! ToString(k).
1721                 var Pk = ToString(k);
1722                 // b. Let kPresent be ? HasProperty(O, Pk).
1723                 var kPresent = HasProperty(O, Pk);
1724                 // c. If kPresent is true, then
1725                 if (kPresent) {
1726                         // i. Let kValue be ? Get(O, Pk).
1727                         var kValue = Get(O, Pk);
1728                         // ii. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
1729                         var selected = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
1730                         // iii. If selected is true, then
1731                         if (selected) {
1732                                 // 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue)
1733                                 CreateDataPropertyOrThrow(A, ToString(to), kValue);
1734                                 // 2. Increase to by 1.
1735                                 to = to + 1;
1736                         }
1737
1738                 }
1739                 // d. Increase k by 1.
1740                 k = k + 1;
1741         }
1742         // 9. Return A.
1743         return A;
1744 });
1745
1746 }
1747
1748 if (!("map"in Array.prototype
1749 )) {
1750
1751 // Array.prototype.map
1752 /* global ArraySpeciesCreate, Call, CreateDataPropertyOrThrow, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
1753 /* global CreateMethodProperty, ToObject, ToLength, Get, ArraySpeciesCreate, ToString, HasProperty, Call, CreateDataPropertyOrThrow */
1754 // 22.1.3.16. Array.prototype.map ( callbackfn [ , thisArg ] )
1755 CreateMethodProperty(Array.prototype, 'map', function map(callbackfn /* [ , thisArg ] */) {
1756         // 1. Let O be ? ToObject(this value).
1757         var O = ToObject(this);
1758         // 2. Let len be ? ToLength(? Get(O, "length")).
1759         var len = ToLength(Get(O, "length"));
1760         // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
1761         if (IsCallable(callbackfn) === false) {
1762                 throw new TypeError(callbackfn + ' is not a function');
1763         }
1764         // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1765         var T = arguments.length > 1 ? arguments[1] : undefined;
1766         // 5. Let A be ? ArraySpeciesCreate(O, len).
1767         var A = ArraySpeciesCreate(O, len);
1768         // 6. Let k be 0.
1769         var k = 0;
1770         // 7. Repeat, while k < len
1771         while (k < len) {
1772                 // a. Let Pk be ! ToString(k).
1773                 var Pk = ToString(k);
1774                 // b. Let kPresent be ? HasProperty(O, Pk).
1775                 var kPresent = HasProperty(O, Pk);
1776                 // c. If kPresent is true, then
1777                 if (kPresent) {
1778                         // i. Let kValue be ? Get(O, Pk).
1779                         var kValue = Get(O, Pk);
1780                         // ii. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »).
1781                         var mappedValue = Call(callbackfn, T, [kValue, k, O]);
1782                         // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
1783                         CreateDataPropertyOrThrow(A, Pk, mappedValue);
1784                 }
1785                 // d. Increase k by 1.
1786                 k = k + 1;
1787         }
1788         // 8. Return A.
1789         return A;
1790 });
1791
1792 }
1793
1794 if (!("trim"in String.prototype
1795 )) {
1796
1797 // String.prototype.trim
1798 /* global CreateMethodProperty, RequireObjectCoercible, ToString */
1799 // 21.1.3.27. String.prototype.trim ( )
1800 CreateMethodProperty(String.prototype, 'trim', function trim() {
1801         // 1. Let O be ? RequireObjectCoercible(this value).
1802         var O = RequireObjectCoercible(this);
1803         // 2. Let S be ? ToString(O).
1804         var S = ToString(O);
1805         // 3. Let T be the String value that is a copy of S with both leading and trailing white space removed. 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.
1806         var T = String.prototype.replace.call(S, /^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+|[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/g, '');
1807         // 4. Return T.
1808         return T;
1809 });
1810
1811 }
1812
1813 })
1814 .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});