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