1 /* Polyfill service v3.27.1
2 * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
4 * Features requested: es5
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") */
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() {
60 Object.defineProperty(a, 'test', {value:42});
67 // Object.defineProperty
68 (function (nativeDefineProperty) {
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';
74 // Polyfill.io - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty.
75 Object['defineProperty'] = function defineProperty(object, property, descriptor) {
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);
82 if (object === null || !(object instanceof Object || typeof object === 'object')) {
83 throw new TypeError('Object.defineProperty called on non-object');
86 if (!(descriptor instanceof Object)) {
87 throw new TypeError('Property description must be an object');
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;
95 // handle descriptor.get
97 if (getterType !== 'function') {
98 throw new TypeError('Getter must be a function');
100 if (!supportsAccessors) {
101 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
103 if (hasValueOrWritable) {
104 throw new TypeError(ERR_VALUE_ACCESSORS);
106 Object.__defineGetter__.call(object, propertyString, descriptor.get);
108 object[propertyString] = descriptor.value;
111 // handle descriptor.set
113 if (setterType !== 'function') {
114 throw new TypeError('Setter must be a function');
116 if (!supportsAccessors) {
117 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
119 if (hasValueOrWritable) {
120 throw new TypeError(ERR_VALUE_ACCESSORS);
122 Object.__defineSetter__.call(object, propertyString, descriptor.set);
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;
132 }(Object.defineProperty));
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}.
149 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
150 Object.defineProperty(O, P, newDesc);
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).
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]';
167 if (!('isArray' in Array)) {
170 /* global CreateMethodProperty, IsArray */
171 // 22.1.2.2. Array.isArray ( arg )
172 CreateMethodProperty(Array, 'isArray', function isArray(arg) {
173 // 1. Return ? IsArray(arg).
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
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 |----------------------------------------------------------------------------------------------------------------------------------------------------|
197 function ToObject(argument) { // eslint-disable-line no-unused-vars
198 if (argument === null || argument === undefined) {
201 return Object(argument);
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.
213 // 3. If number is +0, -0, +∞, or -∞, return number.
214 if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
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));
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.
231 // 3. Return min(len, 253-1).
232 return Math.min(len, Math.pow(2, 53) -1);
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).
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.
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';
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.');
265 // 3. Return ? F.[[Call]](V, argumentsList).
266 return F.apply(V, argumentsList);
270 /* global ToObject */
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).
276 // 3. Return ? O.[[Get]](P, V).
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) {
291 // 4. If IsCallable(func) is false, throw a TypeError exception.
292 if (IsCallable(func) === false) {
293 throw new TypeError('Method not callable: ' + P);
300 // "Type(x)" is used as shorthand for "the type of x"...
301 function Type(x) { // eslint-disable-line no-unused-vars
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';
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'];
334 // a. Let methodNames be « "valueOf", "toString" ».
335 methodNames = ['valueOf', 'toString'];
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') {
352 // 6. Throw a TypeError exception.
353 throw new TypeError('Cannot convert to primitive.');
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) {
370 // c. Else PreferredType is hint Number, let hint be "number".
371 } else if (PreferredType === Number) {
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') {
384 // iii. Throw a TypeError exception.
385 throw new TypeError('Cannot convert exotic object to primitive.');
387 // f. If hint is "default", set hint to "number".
388 if (hint === 'default') {
391 // g. Return ? OrdinaryToPrimitive(input, hint).
392 return OrdinaryToPrimitive(input, hint);
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
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 |---------------|--------------------------------------------------------|
425 function ToString(argument) { // eslint-disable-line no-unused-vars
426 switch(Type(argument)) {
428 throw new TypeError('Cannot convert a Symbol value to a string');
431 var primValue = ToPrimitive(argument, 'string');
432 return ToString(primValue);
434 return String(argument);
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).
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:
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 --------------------------------------------------------------------------------------------------------------
463 function ToBoolean(argument) { // eslint-disable-line no-unused-vars
464 return Boolean(argument);
466 if (!('every' in Array.prototype)) {
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');
480 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
481 var T = arguments.length > 1 ? arguments[1] : undefined;
484 // 6. Repeat, 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
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) {
501 // d. Increase k by 1.
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) {
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');
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.
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}).
536 // _ESAbstract.IsConstructor
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') {
544 // 2. If argument has a [[Construct]] internal method, return true.
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;
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;
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 () {
576 // In ES6 Object.keys works on all object except `null` and `undefined`.
585 Object.keys = (function() {
588 // modified from https://github.com/es-shims/object-keys
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');
601 'propertyIsEnumerable',
604 var equalsConstructorPrototype = function (o) {
605 var ctor = o.constructor;
606 return ctor && ctor.prototype === o;
626 $webkitIndexedDB: true,
627 $webkitStorageInfo: true,
630 var hasAutomationEqualityBug = (function () {
632 if (typeof window === 'undefined') { return false; }
633 for (var k in window) {
635 if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
637 equalsConstructorPrototype(window[k]);
648 var equalsConstructorPrototypeIfNotBuggy = function (o) {
650 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
651 return equalsConstructorPrototype(o);
654 return equalsConstructorPrototype(o);
660 function isArgumentsObject(value) {
661 var str = toStr.call(value);
662 var isArgs = str === '[object Arguments]';
664 isArgs = str !== '[object Array]' &&
666 typeof value === 'object' &&
667 typeof value.length === 'number' &&
669 toStr.call(value.callee) === '[object Function]';
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]';
680 if (object === undefined || object === null) {
681 throw new TypeError('Cannot convert undefined or null to object');
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));
691 if (isArguments && object.length > 0) {
692 for (var j = 0; j < object.length; ++j) {
693 theKeys.push(String(j));
696 for (var name in object) {
697 if (!(skipProto && name === 'prototype') && has.call(object, name)) {
698 theKeys.push(String(name));
703 if (hasDontEnumBug) {
704 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
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]);
718 if (!('bind' in Function.prototype)) {
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
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;
734 // /add necessary es5-shim utilities
736 // 1. Let Target be the this value.
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);
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
751 // 13. Set the [[Construct]] internal property of F as described in
753 // 14. Set the [[HasInstance]] internal property of F as described in
756 var binder = function () {
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
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.
775 var result = target.apply(
777 array_concat.call(args, array_slice.call(arguments))
779 if ($Object(result) === result) {
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
790 // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
792 // 2. Let boundThis be the value of F's [[BoundThis]] internal
794 // 3. Let target be the value of F's [[TargetFunction]] internal
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.
803 // equiv: target.call(this, ...boundArgs, ...args)
806 array_concat.call(args, array_slice.call(arguments))
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
817 // 16. Else set the length own property of F to 0.
819 var boundLength = max(0, target.length - args.length);
821 // 17. Set the attributes of the length own property of F to the values
822 // specified in 15.3.5.1.
824 for (var i = 0; i < boundLength; i++) {
825 array_push.call(boundArgs, '$' + i);
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);
836 if (target.prototype) {
837 Empty.prototype = target.prototype;
838 bound.prototype = new Empty();
839 // Clean up dangling references.
840 Empty.prototype = null;
844 // 18. Set the [[Extensible]] internal property of F to true.
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
852 // 21. Call the [[DefineOwnProperty]] internal method of F with
853 // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
854 // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
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.
869 if (!('getOwnPropertyDescriptor' in Object && typeof Object.getOwnPropertyDescriptor === 'function' && (function() {
873 return Object.getOwnPropertyDescriptor(
877 } catch (exception) {
882 // Object.getOwnPropertyDescriptor
883 /* global CreateMethodProperty */
885 var call = Function.prototype.call;
886 var prototypeOfObject = Object.prototype;
887 var owns = call.bind(prototypeOfObject.hasOwnProperty);
891 var supportsAccessors;
892 if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
893 lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
894 lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
896 function doesGetOwnPropertyDescriptorWork(object) {
899 return Object.getOwnPropertyDescriptor(
903 } catch (exception) {
907 // check whether getOwnPropertyDescriptor works if it's given. Otherwise,
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
917 var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
921 if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
922 var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: ";
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);
929 // make a valiant attempt to use the real getOwnPropertyDescriptor
930 // for I8's DOM elements.
931 if (getOwnPropertyDescriptorFallback) {
933 return getOwnPropertyDescriptorFallback.call(Object, object, property);
934 } catch (exception) {
935 // try the shim if the real one doesn't work
939 // If object does not owns property return undefined immediately.
940 if (!owns(object, property)) {
944 // If object has a property then it's for sure both `enumerable` and
946 var descriptor = { enumerable: true, configurable: true };
948 // If JS engine supports accessor properties then property may be a
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;
959 var getter = lookupGetter(object, property);
960 var setter = lookupSetter(object, property);
962 // Once we have getter and setter we can put values back.
963 object.__proto__ = prototype;
965 if (getter || setter) {
967 descriptor.get = getter;
970 descriptor.set = setter;
972 // If it was accessor property we're done and return here
973 // in order to avoid adding `value` to the descriptor.
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;
989 if (!('defineProperties' in Object)) {
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');
999 // 2. Let props be ? ToObject(Properties).
1000 var props = ToObject(Properties);
1001 // 3. Let keys be ? props.[[OwnPropertyKeys]]().
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]].
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?
1023 // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
1024 descriptors.push([nextKey, desc]);
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);
1042 if (!('create' in Object)) {
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');
1051 // 2. Let obj be ObjectCreate(O).
1052 var obj = new Function('e', 'function Object() {}Object.prototype=e;return new Object')(O);
1054 obj.constructor.prototype = O;
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);
1067 if (!('getPrototypeOf' in Object)) {
1069 // Object.getPrototypeOf
1070 /* global CreateMethodProperty */
1071 // Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js
1073 // https://github.com/es-shims/es5-shim/issues#issue/2
1074 // http://ejohn.org/blog/objectgetprototypeof/
1075 // recommended by fschaefer on github
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');
1084 var proto = object.__proto__;
1085 if (proto || proto === null) {
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;
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.
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.
1111 // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
1112 var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
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, {
1123 value: internalSlotsList[name]
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;
1137 // 2. If argumentsList is not present, set argumentsList to a new empty List.
1138 var argumentsList = arguments.length > 1 ? arguments[1] : [];
1140 // 3. Assert: IsConstructor(F) is true.
1141 if (!IsConstructor(F)) {
1142 throw new TypeError('F must be a constructor.');
1145 // 4. Assert: IsConstructor(newTarget) is true.
1146 if (!IsConstructor(newTarget)) {
1147 throw new TypeError('newTarget must be a constructor.');
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)))();
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);
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) {
1171 // 3. Let isArray be ? IsArray(originalArray).
1172 var isArray = IsArray(originalArray);
1174 // 4. If isArray is false, return ? ArrayCreate(length).
1175 if (isArray === false) {
1176 return ArrayCreate(length);
1179 // 5. Let C be ? Get(originalArray, "constructor").
1180 var C = Get(originalArray, 'constructor');
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.
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.
1199 // 8. If C is undefined, return ? ArrayCreate(length).
1200 if (C === undefined) {
1201 return ArrayCreate(length);
1203 // 9. If IsConstructor(C) is false, throw a TypeError exception.
1204 if (!IsConstructor(C)) {
1205 throw new TypeError('C must be a constructor');
1207 // 10. Return ? Construct(C, « length »).
1208 return Construct(C, [length]);
1211 // _ESAbstract.CreateDataProperty
1212 // 7.3.4. CreateDataProperty ( O, P, V )
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 }.
1226 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
1228 Object.defineProperty(O, P, newDesc);
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.
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) + '`');
1247 // 5. Return success.
1250 if (!('filter' in Array.prototype)) {
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');
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);
1272 // 8. Repeat, 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
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
1286 // 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue)
1287 CreateDataPropertyOrThrow(A, ToString(to), kValue);
1288 // 2. Increase to by 1.
1293 // d. Increase k by 1.
1302 if (!('forEach' in Array.prototype)) {
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');
1319 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1320 var T = arguments.length > 1 ? arguments[1] : undefined;
1323 // 6. Repeat, 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
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]);
1336 // d. Increase k by 1.
1339 // 7. Return undefined.
1345 if (!('indexOf' in Array.prototype)) {
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.
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.
1365 // 6. If n ≥ 0, then
1367 // a. If n is -0, let k be +0; else let k be n.
1368 var k = n === -0 ? 0 : n;
1371 // a. Let k be len + n.
1373 // b. If k < 0, let k be 0.
1378 // 8. Repeat, 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
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.
1393 // c. Increase k by 1.
1402 if (!('lastIndexOf' in Array.prototype)) {
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.
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
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);
1424 // a. Let k be len + n.
1427 // 7. Repeat, 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
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.
1442 // c. Decrease k by 1.
1451 if (!('map' in Array.prototype)) {
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');
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);
1472 // 7. Repeat, 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
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);
1487 // d. Increase k by 1.
1496 if (!('reduce' in Array.prototype)) {
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');
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');
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,
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
1538 // 1. Set accumulator to ? Get(O, Pk).
1539 var accumulator = Get(arraylike, Pk);
1541 // iv. Increase k by 1.
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');
1549 // 9. Repeat, 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
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]);
1562 // d. Increase k by 1.
1565 // 10. Return accumulator.
1571 if (!('reduceRight' in Array.prototype)) {
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');
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');
1593 // 5. Let k be 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,
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
1613 // 1. Set accumulator to ? Get(O, Pk).
1614 accumulator = Get(arraylike, Pk);
1616 // iv. Decrease k by 1.
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');
1624 // 9. Repeat, 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
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]);
1637 // d. Decrease k by 1.
1640 // 10 Return accumulator.
1646 if (!('some' in Array.prototype)) {
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');
1660 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1661 var T = arguments.length > 1 ? arguments[1] : undefined;
1664 // 6. Repeat, 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
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.
1681 // d. Increase k by 1.
1690 if (!('Date' in this && 'now' in this.Date && 'getTime' in this.Date.prototype)) {
1693 Date.now = function now() {
1694 return new Date().getTime();
1699 if (!('Date' in this && 'toISOString' in Date.prototype)) {
1701 // Date.prototype.toISOString
1702 Date.prototype.toISOString = function toISOString() {
1705 function pad(str, len) {
1708 return pad.substr(0, len - str.length) + str;
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);
1719 return y +'-'+ m +'-'+ d + 'T' + h +':'+ i +':'+ s +'.'+ ms +'Z';
1724 if (!('freeze' in Object)) {
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.
1738 if (!('getOwnPropertyNames' in Object)) {
1740 // Object.getOwnPropertyNames
1741 /* global CreateMethodProperty */
1743 var toString = ({}).toString;
1744 var split = ''.split;
1746 CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) {
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"];
1754 if (typeof object === 'undefined' || object === null) {
1755 throw new TypeError('Cannot convert undefined or null to object');
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);
1761 // Enumerable properties only
1762 for (key in object) {
1763 if (Object.prototype.hasOwnProperty.call(object, key)) {
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]);
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
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 |----------------------------------------------------------------------------------------------------------------------------------------------------|
1796 function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars
1797 if (argument === null || argument === undefined) {
1802 if (!('trim' in String.prototype)) {
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, '');
1821 .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});