1 /* Polyfill service v3.34.0
2 * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
4 * Features requested: es5
6 * - _ESAbstract.ArrayCreate, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
7 * - _ESAbstract.Call, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.OrdinaryToPrimitive")
8 * - _ESAbstract.Get, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct")
9 * - _ESAbstract.HasProperty, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
10 * - _ESAbstract.IsArray, License: CC0 (required by "Array.isArray", "es5", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
11 * - _ESAbstract.IsCallable, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.OrdinaryToPrimitive")
12 * - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.trim", "es5")
13 * - _ESAbstract.ToBoolean, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.some")
14 * - _ESAbstract.ToInteger, License: CC0 (required by "Array.prototype.indexOf", "es5", "Array.prototype.lastIndexOf", "_ESAbstract.ToLength", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
15 * - _ESAbstract.ToLength, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some")
16 * - _ESAbstract.ToObject, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Object.defineProperties", "Object.create", "_ESAbstract.GetV", "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
17 * - _ESAbstract.GetV, License: CC0 (required by "_ESAbstract.GetMethod", "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
18 * - _ESAbstract.GetMethod, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.IsConstructor", "_ESAbstract.ArraySpeciesCreate")
19 * - _ESAbstract.Type, License: CC0 (required by "Object.create", "es5", "Object.defineProperties", "_ESAbstract.ToString", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim", "_ESAbstract.ArraySpeciesCreate", "_ESAbstract.ToPrimitive", "_ESAbstract.IsConstructor", "_ESAbstract.OrdinaryToPrimitive", "_ESAbstract.GetPrototypeFromConstructor", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct")
20 * - _ESAbstract.GetPrototypeFromConstructor, License: CC0 (required by "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
21 * - _ESAbstract.IsConstructor, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map", "_ESAbstract.Construct")
22 * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "_ESAbstract.ToPrimitive", "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
23 * - _ESAbstract.ToPrimitive, License: CC0 (required by "_ESAbstract.ToString", "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
24 * - _ESAbstract.ToString, License: CC0 (required by "Array.prototype.every", "es5", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "String.prototype.trim")
25 * - Date.now, License: CC0 (required by "es5")
26 * - Date.prototype.toISOString, License: CC0 (required by "es5")
27 * - Object.defineProperty, License: CC0 (required by "es5", "Object.defineProperties", "Object.create", "_ESAbstract.CreateMethodProperty", "Array.isArray", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "Object.keys", "String.prototype.trim", "_ESAbstract.CreateDataProperty", "_ESAbstract.CreateDataPropertyOrThrow", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate")
28 * - _ESAbstract.CreateDataProperty, License: CC0 (required by "_ESAbstract.CreateDataPropertyOrThrow", "Array.prototype.filter", "es5", "Array.prototype.map")
29 * - _ESAbstract.CreateDataPropertyOrThrow, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map")
30 * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "Array.isArray", "es5", "Array.prototype.every", "Array.prototype.filter", "Array.prototype.forEach", "Array.prototype.indexOf", "Array.prototype.lastIndexOf", "Array.prototype.map", "Array.prototype.reduce", "Array.prototype.reduceRight", "Array.prototype.some", "Function.prototype.bind", "Object.create", "Object.defineProperties", "Object.freeze", "Object.getOwnPropertyDescriptor", "Object.getOwnPropertyNames", "Object.getPrototypeOf", "Object.keys", "String.prototype.trim")
31 * - Array.isArray, License: CC0 (required by "es5")
32 * - Array.prototype.every, License: CC0 (required by "es5")
33 * - Array.prototype.forEach, License: CC0 (required by "es5")
34 * - Array.prototype.indexOf, License: CC0 (required by "es5")
35 * - Array.prototype.lastIndexOf, License: CC0 (required by "es5")
36 * - Array.prototype.reduce, License: CC0 (required by "es5")
37 * - Array.prototype.reduceRight, License: CC0 (required by "es5")
38 * - Array.prototype.some, License: CC0 (required by "es5")
39 * - Function.prototype.bind, License: MIT (required by "es5", "Object.getOwnPropertyDescriptor", "Object.defineProperties", "Object.create", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
40 * - Object.freeze, License: CC0 (required by "es5")
41 * - Object.getOwnPropertyDescriptor, License: CC0 (required by "es5", "Object.defineProperties", "Object.create")
42 * - Object.getOwnPropertyNames, License: CC0 (required by "es5")
43 * - Object.getPrototypeOf, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
44 * - Object.keys, License: MIT (required by "es5", "Object.defineProperties", "Object.create")
45 * - Object.defineProperties, License: CC0 (required by "es5", "Object.create")
46 * - Object.create, License: CC0 (required by "es5", "_ESAbstract.OrdinaryCreateFromConstructor", "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "Array.prototype.map")
47 * - _ESAbstract.OrdinaryCreateFromConstructor, License: CC0 (required by "_ESAbstract.Construct", "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
48 * - _ESAbstract.Construct, License: CC0 (required by "_ESAbstract.ArraySpeciesCreate", "Array.prototype.filter", "es5", "Array.prototype.map")
49 * - _ESAbstract.ArraySpeciesCreate, License: CC0 (required by "Array.prototype.filter", "es5", "Array.prototype.map")
50 * - Array.prototype.filter, License: CC0 (required by "es5")
51 * - Array.prototype.map, License: CC0 (required by "es5")
52 * - String.prototype.trim, License: CC0 (required by "es5") */
54 (function(undefined) {
56 // _ESAbstract.ArrayCreate
57 // 9.4.2.2. ArrayCreate ( length [ , proto ] )
58 function ArrayCreate(length /* [, proto] */) { // eslint-disable-line no-unused-vars
59 // 1. Assert: length is an integer Number ≥ 0.
60 // 2. If length is -0, set length to +0.
61 if (1 / length === -Infinity) {
64 // 3. If length>2^32-1, throw a RangeError exception.
65 if (length > (Math.pow(2, 32) - 1)) {
66 throw new RangeError('Invalid array length');
68 // 4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%.
69 // 5. Let A be a newly created Array exotic object.
71 // 6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1.
72 // 7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1.
73 // 8. Set A.[[Prototype]] to proto.
74 // 9. Set A.[[Extensible]] to true.
75 // 10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor{[[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
82 /* global IsCallable */
83 // 7.3.12. Call ( F, V [ , argumentsList ] )
84 function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars
85 // 1. If argumentsList is not present, set argumentsList to a new empty List.
86 var argumentsList = arguments.length > 2 ? arguments[2] : [];
87 // 2. If IsCallable(F) is false, throw a TypeError exception.
88 if (IsCallable(F) === false) {
89 throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.');
91 // 3. Return ? F.[[Call]](V, argumentsList).
92 return F.apply(V, argumentsList);
96 // 7.3.1. Get ( O, P )
97 function Get(O, P) { // eslint-disable-line no-unused-vars
98 // 1. Assert: Type(O) is Object.
99 // 2. Assert: IsPropertyKey(P) is true.
100 // 3. Return ? O.[[Get]](P, O).
104 // _ESAbstract.HasProperty
105 // 7.3.10. HasProperty ( O, P )
106 function HasProperty(O, P) { // eslint-disable-line no-unused-vars
107 // Assert: Type(O) is Object.
108 // Assert: IsPropertyKey(P) is true.
109 // Return ? O.[[HasProperty]](P).
113 // _ESAbstract.IsArray
114 // 7.2.2. IsArray ( argument )
115 function IsArray(argument) { // eslint-disable-line no-unused-vars
116 // 1. If Type(argument) is not Object, return false.
117 // 2. If argument is an Array exotic object, return true.
118 // 3. If argument is a Proxy exotic object, then
119 // a. If argument.[[ProxyHandler]] is null, throw a TypeError exception.
120 // b. Let target be argument.[[ProxyTarget]].
121 // c. Return ? IsArray(target).
124 // Polyfill.io - We can skip all the above steps and check the string returned from Object.prototype.toString().
125 return Object.prototype.toString.call(argument) === '[object Array]';
128 // _ESAbstract.IsCallable
129 // 7.2.3. IsCallable ( argument )
130 function IsCallable(argument) { // eslint-disable-line no-unused-vars
131 // 1. If Type(argument) is not Object, return false.
132 // 2. If argument has a [[Call]] internal method, return true.
135 // Polyfill.io - Only function objects have a [[Call]] internal method. This means we can simplify this function to check that the argument has a type of function.
136 return typeof argument === 'function';
139 // _ESAbstract.RequireObjectCoercible
140 // 7.2.1. RequireObjectCoercible ( argument )
141 // The abstract operation ToObject converts argument to a value of type Object according to Table 12:
142 // Table 12: ToObject Conversions
144 |----------------------------------------------------------------------------------------------------------------------------------------------------|
145 | Argument Type | Result |
146 |----------------------------------------------------------------------------------------------------------------------------------------------------|
147 | Undefined | Throw a TypeError exception. |
148 | Null | Throw a TypeError exception. |
149 | Boolean | Return argument. |
150 | Number | Return argument. |
151 | String | Return argument. |
152 | Symbol | Return argument. |
153 | Object | Return argument. |
154 |----------------------------------------------------------------------------------------------------------------------------------------------------|
156 function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars
157 if (argument === null || argument === undefined) {
163 // _ESAbstract.ToBoolean
164 // 7.1.2. ToBoolean ( argument )
165 // The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9:
167 --------------------------------------------------------------------------------------------------------------
168 | Argument Type | Result |
169 --------------------------------------------------------------------------------------------------------------
170 | Undefined | Return false. |
171 | Null | Return false. |
172 | Boolean | Return argument. |
173 | Number | If argument is +0, -0, or NaN, return false; otherwise return true. |
174 | String | If argument is the empty String (its length is zero), return false; otherwise return true. |
175 | Symbol | Return true. |
176 | Object | Return true. |
177 --------------------------------------------------------------------------------------------------------------
179 function ToBoolean(argument) { // eslint-disable-line no-unused-vars
180 return Boolean(argument);
183 // _ESAbstract.ToInteger
184 // 7.1.4. ToInteger ( argument )
185 function ToInteger(argument) { // eslint-disable-line no-unused-vars
186 // 1. Let number be ? ToNumber(argument).
187 var number = Number(argument);
188 // 2. If number is NaN, return +0.
192 // 3. If number is +0, -0, +∞, or -∞, return number.
193 if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
196 // 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
197 return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number));
200 // _ESAbstract.ToLength
201 /* global ToInteger */
202 // 7.1.15. ToLength ( argument )
203 function ToLength(argument) { // eslint-disable-line no-unused-vars
204 // 1. Let len be ? ToInteger(argument).
205 var len = ToInteger(argument);
206 // 2. If len ≤ +0, return +0.
210 // 3. Return min(len, 253-1).
211 return Math.min(len, Math.pow(2, 53) -1);
214 // _ESAbstract.ToObject
215 // 7.1.13 ToObject ( argument )
216 // The abstract operation ToObject converts argument to a value of type Object according to Table 12:
217 // Table 12: ToObject Conversions
219 |----------------------------------------------------------------------------------------------------------------------------------------------------|
220 | Argument Type | Result |
221 |----------------------------------------------------------------------------------------------------------------------------------------------------|
222 | Undefined | Throw a TypeError exception. |
223 | Null | Throw a TypeError exception. |
224 | Boolean | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. |
225 | Number | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects. |
226 | String | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects. |
227 | Symbol | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects. |
228 | Object | Return argument. |
229 |----------------------------------------------------------------------------------------------------------------------------------------------------|
231 function ToObject(argument) { // eslint-disable-line no-unused-vars
232 if (argument === null || argument === undefined) {
235 return Object(argument);
239 /* global ToObject */
241 function GetV(v, p) { // eslint-disable-line no-unused-vars
242 // 1. Assert: IsPropertyKey(P) is true.
243 // 2. Let O be ? ToObject(V).
245 // 3. Return ? O.[[Get]](P, V).
249 // _ESAbstract.GetMethod
250 /* global GetV, IsCallable */
251 // 7.3.9. GetMethod ( V, P )
252 function GetMethod(V, P) { // eslint-disable-line no-unused-vars
253 // 1. Assert: IsPropertyKey(P) is true.
254 // 2. Let func be ? GetV(V, P).
255 var func = GetV(V, P);
256 // 3. If func is either undefined or null, return undefined.
257 if (func === null || func === undefined) {
260 // 4. If IsCallable(func) is false, throw a TypeError exception.
261 if (IsCallable(func) === false) {
262 throw new TypeError('Method not callable: ' + P);
269 // "Type(x)" is used as shorthand for "the type of x"...
270 function Type(x) { // eslint-disable-line no-unused-vars
283 // typeof null is 'object'
284 if (x === null) return 'null';
285 // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`.
286 if ('Symbol' in this && x instanceof this.Symbol) return 'symbol';
291 // _ESAbstract.GetPrototypeFromConstructor
292 /* global Get, Type */
293 // 9.1.14. GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
294 function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
295 // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
296 // 2. Assert: IsCallable(constructor) is true.
297 // 3. Let proto be ? Get(constructor, "prototype").
298 var proto = Get(constructor, "prototype");
299 // 4. If Type(proto) is not Object, then
300 if (Type(proto) !== 'object') {
301 // a. Let realm be ? GetFunctionRealm(constructor).
302 // b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
303 proto = intrinsicDefaultProto;
309 // _ESAbstract.IsConstructor
311 // 7.2.4. IsConstructor ( argument )
312 function IsConstructor(argument) { // eslint-disable-line no-unused-vars
313 // 1. If Type(argument) is not Object, return false.
314 if (Type(argument) !== 'object') {
317 // 2. If argument has a [[Construct]] internal method, return true.
320 // Polyfill.io - `new argument` is the only way to truly test if a function is a constructor.
321 // We choose to not use`new argument` because the argument could have side effects when called.
322 // Instead we check to see if the argument is a function and if it has a prototype.
323 // Arrow functions do not have a [[Construct]] internal method, nor do they have a prototype.
324 return typeof argument === 'function' && !!argument.prototype;
327 // _ESAbstract.OrdinaryToPrimitive
328 /* global Get, IsCallable, Call, Type */
329 // 7.1.1.1. OrdinaryToPrimitive ( O, hint )
330 function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars
331 // 1. Assert: Type(O) is Object.
332 // 2. Assert: Type(hint) is String and its value is either "string" or "number".
333 // 3. If hint is "string", then
334 if (hint === 'string') {
335 // a. Let methodNames be « "toString", "valueOf" ».
336 var methodNames = ['toString', 'valueOf'];
339 // a. Let methodNames be « "valueOf", "toString" ».
340 methodNames = ['valueOf', 'toString'];
342 // 5. For each name in methodNames in List order, do
343 for (var i = 0; i < methodNames.length; ++i) {
344 var name = methodNames[i];
345 // a. Let method be ? Get(O, name).
346 var method = Get(O, name);
347 // b. If IsCallable(method) is true, then
348 if (IsCallable(method)) {
349 // i. Let result be ? Call(method, O).
350 var result = Call(method, O);
351 // ii. If Type(result) is not Object, return result.
352 if (Type(result) !== 'object') {
357 // 6. Throw a TypeError exception.
358 throw new TypeError('Cannot convert to primitive.');
361 // _ESAbstract.ToPrimitive
362 /* global Type, GetMethod, Call, OrdinaryToPrimitive */
363 // 7.1.1. ToPrimitive ( input [ , PreferredType ] )
364 function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars
365 var PreferredType = arguments.length > 1 ? arguments[1] : undefined;
366 // 1. Assert: input is an ECMAScript language value.
367 // 2. If Type(input) is Object, then
368 if (Type(input) === 'object') {
369 // a. If PreferredType is not present, let hint be "default".
370 if (arguments.length < 2) {
371 var hint = 'default';
372 // b. Else if PreferredType is hint String, let hint be "string".
373 } else if (PreferredType === String) {
375 // c. Else PreferredType is hint Number, let hint be "number".
376 } else if (PreferredType === Number) {
379 // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
380 var exoticToPrim = typeof this.Symbol === 'function' && typeof this.Symbol.toPrimitive === 'symbol' ? GetMethod(input, this.Symbol.toPrimitive) : undefined;
381 // e. If exoticToPrim is not undefined, then
382 if (exoticToPrim !== undefined) {
383 // i. Let result be ? Call(exoticToPrim, input, « hint »).
384 var result = Call(exoticToPrim, input, [hint]);
385 // ii. If Type(result) is not Object, return result.
386 if (Type(result) !== 'object') {
389 // iii. Throw a TypeError exception.
390 throw new TypeError('Cannot convert exotic object to primitive.');
392 // f. If hint is "default", set hint to "number".
393 if (hint === 'default') {
396 // g. Return ? OrdinaryToPrimitive(input, hint).
397 return OrdinaryToPrimitive(input, hint);
403 // _ESAbstract.ToString
404 /* global Type, ToPrimitive */
405 // 7.1.12. ToString ( argument )
406 // The abstract operation ToString converts argument to a value of type String according to Table 11:
407 // Table 11: ToString Conversions
409 |---------------|--------------------------------------------------------|
410 | Argument Type | Result |
411 |---------------|--------------------------------------------------------|
412 | Undefined | Return "undefined". |
413 |---------------|--------------------------------------------------------|
414 | Null | Return "null". |
415 |---------------|--------------------------------------------------------|
416 | Boolean | If argument is true, return "true". |
417 | | If argument is false, return "false". |
418 |---------------|--------------------------------------------------------|
419 | Number | Return NumberToString(argument). |
420 |---------------|--------------------------------------------------------|
421 | String | Return argument. |
422 |---------------|--------------------------------------------------------|
423 | Symbol | Throw a TypeError exception. |
424 |---------------|--------------------------------------------------------|
425 | Object | Apply the following steps: |
426 | | Let primValue be ? ToPrimitive(argument, hint String). |
427 | | Return ? ToString(primValue). |
428 |---------------|--------------------------------------------------------|
430 function ToString(argument) { // eslint-disable-line no-unused-vars
431 switch(Type(argument)) {
433 throw new TypeError('Cannot convert a Symbol value to a string');
436 var primValue = ToPrimitive(argument, 'string');
437 return ToString(primValue);
439 return String(argument);
442 if (!("Date"in this&&"now"in this.Date&&"getTime"in this.Date.prototype
446 Date.now = function now() {
447 return new Date().getTime();
452 if (!("Date"in this&&"toISOString"in Date.prototype
455 // Date.prototype.toISOString
456 Date.prototype.toISOString = function toISOString() {
459 function pad(str, len) {
462 return pad.substr(0, len - str.length) + str;
465 var y = date.getUTCFullYear(),
466 m = pad(date.getUTCMonth() + 1, 2),
467 d = pad(date.getUTCDate(), 2),
468 h = pad(date.getUTCHours(), 2),
469 i = pad(date.getUTCMinutes(), 2),
470 s = pad(date.getUTCSeconds(), 2),
471 ms = pad(date.getUTCMilliseconds(), 3);
473 return y +'-'+ m +'-'+ d + 'T' + h +':'+ i +':'+ s +'.'+ ms +'Z';
478 if (!("defineProperty"in Object&&function(){try{var e={}
479 return Object.defineProperty(e,"test",{value:42}),!0}catch(t){return!1}}()
482 // Object.defineProperty
483 (function (nativeDefineProperty) {
485 var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
486 var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
487 var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
489 // Polyfill.io - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty.
490 Object['defineProperty'] = function defineProperty(object, property, descriptor) {
492 // Where native support exists, assume it
493 if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
494 return nativeDefineProperty(object, property, descriptor);
497 if (object === null || !(object instanceof Object || typeof object === 'object')) {
498 throw new TypeError('Object.defineProperty called on non-object');
501 if (!(descriptor instanceof Object)) {
502 throw new TypeError('Property description must be an object');
505 var propertyString = String(property);
506 var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
507 var getterType = 'get' in descriptor && typeof descriptor.get;
508 var setterType = 'set' in descriptor && typeof descriptor.set;
510 // handle descriptor.get
512 if (getterType !== 'function') {
513 throw new TypeError('Getter must be a function');
515 if (!supportsAccessors) {
516 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
518 if (hasValueOrWritable) {
519 throw new TypeError(ERR_VALUE_ACCESSORS);
521 Object.__defineGetter__.call(object, propertyString, descriptor.get);
523 object[propertyString] = descriptor.value;
526 // handle descriptor.set
528 if (setterType !== 'function') {
529 throw new TypeError('Setter must be a function');
531 if (!supportsAccessors) {
532 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
534 if (hasValueOrWritable) {
535 throw new TypeError(ERR_VALUE_ACCESSORS);
537 Object.__defineSetter__.call(object, propertyString, descriptor.set);
540 // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
541 if ('value' in descriptor) {
542 object[propertyString] = descriptor.value;
547 }(Object.defineProperty));
552 // _ESAbstract.CreateDataProperty
553 // 7.3.4. CreateDataProperty ( O, P, V )
555 // This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator.
556 // Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.
557 function CreateDataProperty(O, P, V) { // eslint-disable-line no-unused-vars
558 // 1. Assert: Type(O) is Object.
559 // 2. Assert: IsPropertyKey(P) is true.
560 // 3. Let newDesc be the PropertyDescriptor{ [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
567 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
569 Object.defineProperty(O, P, newDesc);
576 // _ESAbstract.CreateDataPropertyOrThrow
577 /* global CreateDataProperty */
578 // 7.3.6. CreateDataPropertyOrThrow ( O, P, V )
579 function CreateDataPropertyOrThrow(O, P, V) { // eslint-disable-line no-unused-vars
580 // 1. Assert: Type(O) is Object.
581 // 2. Assert: IsPropertyKey(P) is true.
582 // 3. Let success be ? CreateDataProperty(O, P, V).
583 var success = CreateDataProperty(O, P, V);
584 // 4. If success is false, throw a TypeError exception.
586 throw new TypeError('Cannot assign value `' + Object.prototype.toString.call(V) + '` to property `' + Object.prototype.toString.call(P) + '` on object `' + Object.prototype.toString.call(O) + '`');
588 // 5. Return success.
592 // _ESAbstract.CreateMethodProperty
593 // 7.3.5. CreateMethodProperty ( O, P, V )
594 function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars
595 // 1. Assert: Type(O) is Object.
596 // 2. Assert: IsPropertyKey(P) is true.
597 // 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
604 // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
605 Object.defineProperty(O, P, newDesc);
607 if (!("isArray"in Array
611 /* global CreateMethodProperty, IsArray */
612 // 22.1.2.2. Array.isArray ( arg )
613 CreateMethodProperty(Array, 'isArray', function isArray(arg) {
614 // 1. Return ? IsArray(arg).
620 if (!("every"in Array.prototype
623 // Array.prototype.every
624 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */
625 // 22.1.3.5. Array.prototype.every ( callbackfn [ , thisArg ] )
626 CreateMethodProperty(Array.prototype, 'every', function every(callbackfn /* [ , thisArg ] */) {
627 // 1. Let O be ? ToObject(this value).
628 var O = ToObject(this);
629 // 2. Let len be ? ToLength(? Get(O, "length")).
630 var len = ToLength(Get(O, "length"));
631 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
632 if (IsCallable(callbackfn) === false) {
633 throw new TypeError(callbackfn + ' is not a function');
635 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
636 var T = arguments.length > 1 ? arguments[1] : undefined;
639 // 6. Repeat, while k < len
641 // a. Let Pk be ! ToString(k).
642 var Pk = ToString(k);
643 // b. Let kPresent be ? HasProperty(O, Pk).
644 var kPresent = HasProperty(O, Pk);
645 // c. If kPresent is true, then
647 // i. Let kValue be ? Get(O, Pk).
648 var kValue = Get(O, Pk);
649 // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
650 var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
651 // iii. If testResult is false, return false.
652 if (testResult === false) {
656 // d. Increase k by 1.
665 if (!("forEach"in Array.prototype
668 // Array.prototype.forEach
669 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
670 // 22.1.3.10. Array.prototype.forEach ( callbackfn [ , thisArg ] )
671 CreateMethodProperty(Array.prototype, 'forEach', function forEach(callbackfn /* [ , thisArg ] */) {
672 // 1. Let O be ? ToObject(this value).
673 var O = ToObject(this);
674 // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
675 // We will use arrayLike in place of O when we are iterating through the list.
676 var arraylike = O instanceof String ? O.split('') : O;
677 // 2. Let len be ? ToLength(? Get(O, "length")).
678 var len = ToLength(Get(O, "length"));
679 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
680 if (IsCallable(callbackfn) === false) {
681 throw new TypeError(callbackfn + ' is not a function');
683 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
684 var T = arguments.length > 1 ? arguments[1] : undefined;
687 // 6. Repeat, while k < len
689 // a. Let Pk be ! ToString(k).
690 var Pk = ToString(k);
691 // b. Let kPresent be ? HasProperty(O, Pk).
692 var kPresent = HasProperty(arraylike, Pk);
693 // c. If kPresent is true, then
695 // i. Let kValue be ? Get(O, Pk).
696 var kValue = Get(arraylike, Pk);
697 // ii. Perform ? Call(callbackfn, T, « kValue, k, O »).
698 Call(callbackfn, T, [kValue, k, O]);
700 // d. Increase k by 1.
703 // 7. Return undefined.
709 if (!("indexOf"in Array.prototype
712 // Array.prototype.indexOf
713 /* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */
714 // 22.1.3.12. Array.prototype.indexOf ( searchElement [ , fromIndex ] )
715 CreateMethodProperty(Array.prototype, 'indexOf', function indexOf(searchElement /* [ , fromIndex ] */) {
716 // 1. Let O be ? ToObject(this value).
717 var O = ToObject(this);
718 // 2. Let len be ? ToLength(? Get(O, "length")).
719 var len = ToLength(Get(O, "length"));
720 // 3. If len is 0, return -1.
724 // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.)
725 var n = ToInteger(arguments[1]);
726 // 5. If n ≥ len, return -1.
732 // a. If n is -0, let k be +0; else let k be n.
733 var k = n === -0 ? 0 : n;
736 // a. Let k be len + n.
738 // b. If k < 0, let k be 0.
743 // 8. Repeat, while k < len
745 // a. Let kPresent be ? HasProperty(O, ! ToString(k)).
746 var kPresent = HasProperty(O, ToString(k));
747 // b. If kPresent is true, then
749 // i. Let elementK be ? Get(O, ! ToString(k)).
750 var elementK = Get(O, ToString(k));
751 // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK.
752 var same = searchElement === elementK;
753 // iii. If same is true, return k.
758 // c. Increase k by 1.
767 if (!("lastIndexOf"in Array.prototype
770 // Array.prototype.lastIndexOf
771 /* global CreateMethodProperty, Get, HasProperty, ToInteger, ToLength, ToObject, ToString */
772 // 22.1.3.15. Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
773 CreateMethodProperty(Array.prototype, 'lastIndexOf', function lastIndexOf(searchElement /* [ , fromIndex ] */) {
774 // 1. Let O be ? ToObject(this value).
775 var O = ToObject(this);
776 // 2. Let len be ? ToLength(? Get(O, "length")).
777 var len = ToLength(Get(O, "length"));
778 // 3. If len is 0, return -1.
782 // 4. If fromIndex is present, let n be ? ToInteger(fromIndex); else let n be len-1.
783 var n = arguments.length > 1 ? ToInteger(arguments[1]) : len - 1;
786 // a. If n is -0, let k be +0; else let k be min(n, len - 1).
787 var k = n === -0 ? 0 : Math.min(n, len - 1);
790 // a. Let k be len + n.
793 // 7. Repeat, while k ≥ 0
795 // a. Let kPresent be ? HasProperty(O, ! ToString(k)).
796 var kPresent = HasProperty(O, ToString(k));
797 // b. If kPresent is true, then
799 // i. Let elementK be ? Get(O, ! ToString(k)).
800 var elementK = Get(O, ToString(k));
801 // ii. Let same be the result of performing Strict Equality Comparison searchElement === elementK.
802 var same = searchElement === elementK;
803 // iii. If same is true, return k.
808 // c. Decrease k by 1.
817 if (!("reduce"in Array.prototype
820 // Array.prototype.reduce
821 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
822 // 22.1.3.19. Array.prototype.reduce ( callbackfn [ , initialValue ] )
823 CreateMethodProperty(Array.prototype, 'reduce', function reduce(callbackfn /* [ , initialValue ] */) {
824 // 1. Let O be ? ToObject(this value).
825 var O = ToObject(this);
826 // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
827 // We will use arrayLike in place of O when we are iterating through the list.
828 var arraylike = O instanceof String ? O.split('') : O;
829 // 2. Let len be ? ToLength(? Get(O, "length")).
830 var len = ToLength(Get(arraylike, "length"));
831 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
832 if (IsCallable(callbackfn) === false) {
833 throw new TypeError(callbackfn + ' is not a function');
835 // 4. If len is 0 and initialValue is not present, throw a TypeError exception.
836 var initialValue = arguments.length > 1 ? arguments[1] : undefined;
837 if (len === 0 && arguments.length < 2) {
838 throw new TypeError('Reduce of empty array with no initial value');
842 // 6. Let accumulator be undefined.
843 var accumulator = undefined;
844 // 7. If initialValue is present, then
845 if (arguments.length > 1) {
846 // a. Set accumulator to initialValue.
847 accumulator = initialValue;
848 // 8. Else initialValue is not present,
850 // a. Let kPresent be false.
851 var kPresent = false;
852 // b. Repeat, while kPresent is false and k < len
853 while (kPresent === false && k < len) {
854 // i. Let Pk be ! ToString(k).
855 var Pk = ToString(k);
856 // ii. Let kPresent be ? HasProperty(O, Pk).
857 var kPresent = HasProperty(arraylike, Pk);
858 // iii. If kPresent is true, then
860 // 1. Set accumulator to ? Get(O, Pk).
861 var accumulator = Get(arraylike, Pk);
863 // iv. Increase k by 1.
866 // c. If kPresent is false, throw a TypeError exception.
867 if (kPresent === false) {
868 throw new TypeError('Reduce of empty array with no initial value');
871 // 9. Repeat, while k < len
873 // a. Let Pk be ! ToString(k).
874 var Pk = ToString(k);
875 // b. Let kPresent be ? HasProperty(O, Pk).
876 var kPresent = HasProperty(arraylike, Pk);
877 // c. If kPresent is true, then
879 // i. Let kValue be ? Get(O, Pk).
880 var kValue = Get(arraylike, Pk);
881 // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »).
882 accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]);
884 // d. Increase k by 1.
887 // 10. Return accumulator.
893 if (!("reduceRight"in Array.prototype
896 // Array.prototype.reduceRight
897 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
898 // 22.1.3.20. Array.prototype.reduceRight ( callbackfn [ , initialValue ] )
899 CreateMethodProperty(Array.prototype, 'reduceRight', function reduceRight(callbackfn /* [ , initialValue ] */) {
900 // 1. Let O be ? ToObject(this value).
901 var O = ToObject(this);
902 // Polyfill.io - If O is a String object, split it into an array in order to iterate correctly.
903 // We will use arrayLike in place of O when we are iterating through the list.
904 var arraylike = O instanceof String ? O.split('') : O;
905 // 2. Let len be ? ToLength(? Get(O, "length")).
906 var len = ToLength(Get(arraylike, "length"));
907 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
908 if (IsCallable(callbackfn) === false) {
909 throw new TypeError(callbackfn + ' is not a function');
911 // 4. If len is 0 and initialValue is not present, throw a TypeError exception.
912 var initialValue = arguments.length > 1 ? arguments[1] : undefined;
913 if (len === 0 && arguments.length < 2) {
914 throw new TypeError('Reduce of empty array with no initial value');
916 // 5. Let k be len-1.
918 // 6. Let accumulator be undefined.
919 var accumulator = undefined;
920 // 7. If initialValue is present, then
921 if (arguments.length > 1) {
922 // a. Set accumulator to initialValue.
923 accumulator = initialValue;
924 // 8.Else initialValue is not present,
926 // a. Let kPresent be false.
927 var kPresent = false;
928 // b. Repeat, while kPresent is false and k ≥ 0
929 while (kPresent === false && k >= 0) {
930 // i. Let Pk be ! ToString(k).
931 var Pk = ToString(k);
932 // ii. Let kPresent be ? HasProperty(O, Pk).
933 var kPresent = HasProperty(arraylike, Pk);
934 // iii. If kPresent is true, then
936 // 1. Set accumulator to ? Get(O, Pk).
937 accumulator = Get(arraylike, Pk);
939 // iv. Decrease k by 1.
942 // c. If kPresent is false, throw a TypeError exception.
943 if (kPresent === false) {
944 throw new TypeError('Reduce of empty array with no initial value');
947 // 9. Repeat, while k ≥ 0
949 // a. Let Pk be ! ToString(k).
950 var Pk = ToString(k);
951 // b. Let kPresent be ? HasProperty(O, Pk).
952 var kPresent = HasProperty(arraylike, Pk);
953 // c. If kPresent is true, then
955 // i. Let kValue be ? Get(O, Pk).
956 var kValue = Get(arraylike, Pk);
957 // ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »).
958 accumulator = Call(callbackfn, undefined, [accumulator, kValue, k, O]);
960 // d. Decrease k by 1.
963 // 10 Return accumulator.
969 if (!("some"in Array.prototype
972 // Array.prototype.some
973 /* global Call, CreateMethodProperty, Get, HasProperty, IsCallable, ToBoolean, ToLength, ToObject, ToString */
974 // 22.1.3.24. Array.prototype.some ( callbackfn [ , thisArg ] )
975 CreateMethodProperty(Array.prototype, 'some', function some(callbackfn /* [ , thisArg ] */) {
976 // 1. Let O be ? ToObject(this value).
977 var O = ToObject(this);
978 // 2. Let len be ? ToLength(? Get(O, "length")).
979 var len = ToLength(Get(O, "length"));
980 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
981 if (IsCallable(callbackfn) === false) {
982 throw new TypeError(callbackfn + ' is not a function');
984 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
985 var T = arguments.length > 1 ? arguments[1] : undefined;
988 // 6. Repeat, while k < len
990 // a. Let Pk be ! ToString(k).
991 var Pk = ToString(k);
992 // b. Let kPresent be ? HasProperty(O, Pk).
993 var kPresent = HasProperty(O, Pk);
994 // c. If kPresent is true, then
996 // i. Let kValue be ? Get(O, Pk).
997 var kValue = Get(O, Pk);
998 // ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
999 var testResult = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
1000 // iii. If testResult is true, return true.
1005 // d. Increase k by 1.
1014 if (!("bind"in Function.prototype
1017 // Function.prototype.bind
1018 /* global CreateMethodProperty, IsCallable */
1019 // 19.2.3.2. Function.prototype.bind ( thisArg, ...args )
1020 // https://github.com/es-shims/es5-shim/blob/d6d7ff1b131c7ba14c798cafc598bb6780d37d3b/es5-shim.js#L182
1021 CreateMethodProperty(Function.prototype, 'bind', function bind(that) { // .length is 1
1022 // add necessary es5-shim utilities
1024 var $Object = Object;
1025 var ArrayPrototype = $Array.prototype;
1026 var Empty = function Empty() { };
1027 var array_slice = ArrayPrototype.slice;
1028 var array_concat = ArrayPrototype.concat;
1029 var array_push = ArrayPrototype.push;
1031 // /add necessary es5-shim utilities
1033 // 1. Let Target be the this value.
1035 // 2. If IsCallable(Target) is false, throw a TypeError exception.
1036 if (!IsCallable(target)) {
1037 throw new TypeError('Function.prototype.bind called on incompatible ' + target);
1039 // 3. Let A be a new (possibly empty) internal list of all of the
1040 // argument values provided after thisArg (arg1, arg2 etc), in order.
1041 // XXX slicedArgs will stand in for "A" if used
1042 var args = array_slice.call(arguments, 1); // for normal call
1043 // 4. Let F be a new native ECMAScript object.
1044 // 11. Set the [[Prototype]] internal property of F to the standard
1045 // built-in Function prototype object as specified in 15.3.3.1.
1046 // 12. Set the [[Call]] internal property of F as described in
1048 // 13. Set the [[Construct]] internal property of F as described in
1050 // 14. Set the [[HasInstance]] internal property of F as described in
1053 var binder = function () {
1055 if (this instanceof bound) {
1056 // 15.3.4.5.2 [[Construct]]
1057 // When the [[Construct]] internal method of a function object,
1058 // F that was created using the bind function is called with a
1059 // list of arguments ExtraArgs, the following steps are taken:
1060 // 1. Let target be the value of F's [[TargetFunction]]
1061 // internal property.
1062 // 2. If target has no [[Construct]] internal method, a
1063 // TypeError exception is thrown.
1064 // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
1066 // 4. Let args be a new list containing the same values as the
1067 // list boundArgs in the same order followed by the same
1068 // values as the list ExtraArgs in the same order.
1069 // 5. Return the result of calling the [[Construct]] internal
1070 // method of target providing args as the arguments.
1072 var result = target.apply(
1074 array_concat.call(args, array_slice.call(arguments))
1076 if ($Object(result) === result) {
1082 // 15.3.4.5.1 [[Call]]
1083 // When the [[Call]] internal method of a function object, F,
1084 // which was created using the bind function is called with a
1085 // this value and a list of arguments ExtraArgs, the following
1087 // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
1089 // 2. Let boundThis be the value of F's [[BoundThis]] internal
1091 // 3. Let target be the value of F's [[TargetFunction]] internal
1093 // 4. Let args be a new list containing the same values as the
1094 // list boundArgs in the same order followed by the same
1095 // values as the list ExtraArgs in the same order.
1096 // 5. Return the result of calling the [[Call]] internal method
1097 // of target providing boundThis as the this value and
1098 // providing args as the arguments.
1100 // equiv: target.call(this, ...boundArgs, ...args)
1101 return target.apply(
1103 array_concat.call(args, array_slice.call(arguments))
1110 // 15. If the [[Class]] internal property of Target is "Function", then
1111 // a. Let L be the length property of Target minus the length of A.
1112 // b. Set the length own property of F to either 0 or L, whichever is
1114 // 16. Else set the length own property of F to 0.
1116 var boundLength = max(0, target.length - args.length);
1118 // 17. Set the attributes of the length own property of F to the values
1119 // specified in 15.3.5.1.
1121 for (var i = 0; i < boundLength; i++) {
1122 array_push.call(boundArgs, '$' + i);
1125 // XXX Build a dynamic function with desired amount of arguments is the only
1126 // way to set the length property of a function.
1127 // In environments where Content Security Policies enabled (Chrome extensions,
1128 // for ex.) all use of eval or Function costructor throws an exception.
1129 // However in all of these environments Function.prototype.bind exists
1130 // and so this code will never be executed.
1131 bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
1133 if (target.prototype) {
1134 Empty.prototype = target.prototype;
1135 bound.prototype = new Empty();
1136 // Clean up dangling references.
1137 Empty.prototype = null;
1141 // 18. Set the [[Extensible]] internal property of F to true.
1144 // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
1145 // 20. Call the [[DefineOwnProperty]] internal method of F with
1146 // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
1147 // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
1149 // 21. Call the [[DefineOwnProperty]] internal method of F with
1150 // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1151 // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1155 // NOTE Function objects created using Function.prototype.bind do not
1156 // have a prototype property or the [[Code]], [[FormalParameters]], and
1157 // [[Scope]] internal properties.
1158 // XXX can't delete prototype in pure-js.
1166 if (!("freeze"in Object
1170 /* global CreateMethodProperty */
1171 // 19.1.2.6. Object.freeze ( O )
1172 CreateMethodProperty(Object, 'freeze', function freeze(O) {
1173 // This feature cannot be implemented fully as a polyfill.
1174 // We choose to silently fail which allows "securable" code
1175 // to "gracefully" degrade to working but insecure code.
1181 if (!("getOwnPropertyDescriptor"in Object&&"function"==typeof Object.getOwnPropertyDescriptor&&function(){try{var t={}
1182 return t.test=0,0===Object.getOwnPropertyDescriptor(t,"test").value}catch(e){return!1}}()
1185 // Object.getOwnPropertyDescriptor
1186 /* global CreateMethodProperty */
1188 var call = Function.prototype.call;
1189 var prototypeOfObject = Object.prototype;
1190 var owns = call.bind(prototypeOfObject.hasOwnProperty);
1194 var supportsAccessors;
1195 if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
1196 lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
1197 lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
1199 function doesGetOwnPropertyDescriptorWork(object) {
1201 object.sentinel = 0;
1202 return Object.getOwnPropertyDescriptor(
1206 } catch (exception) {
1210 // check whether getOwnPropertyDescriptor works if it's given. Otherwise,
1212 if (Object.defineProperty) {
1213 var getOwnPropertyDescriptorWorksOnObject =
1214 doesGetOwnPropertyDescriptorWork({});
1215 var getOwnPropertyDescriptorWorksOnDom = typeof document == "undefined" ||
1216 doesGetOwnPropertyDescriptorWork(document.createElement("div"));
1217 if (!getOwnPropertyDescriptorWorksOnDom ||
1218 !getOwnPropertyDescriptorWorksOnObject
1220 var getOwnPropertyDescriptorFallback = Object.getOwnPropertyDescriptor;
1224 if (!Object.getOwnPropertyDescriptor || getOwnPropertyDescriptorFallback) {
1225 var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a non-object: ";
1227 CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(object, property) {
1228 if ((typeof object != "object" && typeof object != "function") || object === null) {
1229 throw new TypeError(ERR_NON_OBJECT + object);
1232 // make a valiant attempt to use the real getOwnPropertyDescriptor
1233 // for I8's DOM elements.
1234 if (getOwnPropertyDescriptorFallback) {
1236 return getOwnPropertyDescriptorFallback.call(Object, object, property);
1237 } catch (exception) {
1238 // try the shim if the real one doesn't work
1242 // If object does not owns property return undefined immediately.
1243 if (!owns(object, property)) {
1247 // If object has a property then it's for sure both `enumerable` and
1249 var descriptor = { enumerable: true, configurable: true };
1251 // If JS engine supports accessor properties then property may be a
1252 // getter or setter.
1253 if (supportsAccessors) {
1254 // Unfortunately `__lookupGetter__` will return a getter even
1255 // if object has own non getter property along with a same named
1256 // inherited getter. To avoid misbehavior we temporary remove
1257 // `__proto__` so that `__lookupGetter__` will return getter only
1258 // if it's owned by an object.
1259 var prototype = object.__proto__;
1260 object.__proto__ = prototypeOfObject;
1262 var getter = lookupGetter(object, property);
1263 var setter = lookupSetter(object, property);
1265 // Once we have getter and setter we can put values back.
1266 object.__proto__ = prototype;
1268 if (getter || setter) {
1270 descriptor.get = getter;
1273 descriptor.set = setter;
1275 // If it was accessor property we're done and return here
1276 // in order to avoid adding `value` to the descriptor.
1281 // If we got this far we know that object has an own property that is
1282 // not an accessor so we set it as a value and return descriptor.
1283 descriptor.value = object[property];
1284 descriptor.writable = true;
1292 if (!("getOwnPropertyNames"in Object
1295 // Object.getOwnPropertyNames
1296 /* global CreateMethodProperty */
1298 var toString = ({}).toString;
1299 var split = ''.split;
1301 CreateMethodProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(object) {
1305 // Non-enumerable properties cannot be discovered but can be checked for by name.
1306 // Define those used internally by JS to allow an incomplete solution
1307 var commonProps = ['length', "name", "arguments", "caller", "prototype", "observe", "unobserve"];
1309 if (typeof object === 'undefined' || object === null) {
1310 throw new TypeError('Cannot convert undefined or null to object');
1313 // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8)
1314 object = toString.call(object) == '[object String]' ? split.call(object, '') : Object(object);
1316 // Enumerable properties only
1317 for (key in object) {
1318 if (Object.prototype.hasOwnProperty.call(object, key)) {
1323 // Check for and add the common non-enumerable properties
1324 for (var i=0, s=commonProps.length; i<s; i++) {
1325 if (commonProps[i] in object) buffer.push(commonProps[i]);
1333 if (!("getPrototypeOf"in Object
1336 // Object.getPrototypeOf
1337 /* global CreateMethodProperty */
1338 // Based on: https://github.com/es-shims/es5-shim/blob/master/es5-sham.js
1340 // https://github.com/es-shims/es5-shim/issues#issue/2
1341 // http://ejohn.org/blog/objectgetprototypeof/
1342 // recommended by fschaefer on github
1344 // sure, and webreflection says ^_^
1345 // ... this will nerever possibly return null
1346 // ... Opera Mini breaks here with infinite loops
1347 CreateMethodProperty(Object, 'getPrototypeOf', function getPrototypeOf(object) {
1348 if (object !== Object(object)) {
1349 throw new TypeError('Object.getPrototypeOf called on non-object');
1351 var proto = object.__proto__;
1352 if (proto || proto === null) {
1354 } else if (typeof object.constructor == 'function' && object instanceof object.constructor) {
1355 return object.constructor.prototype;
1356 } else if (object instanceof Object) {
1357 return Object.prototype;
1359 // Correctly return null for Objects created with `Object.create(null)`
1360 // (shammed or native) or `{ __proto__: null}`. Also returns null for
1361 // cross-realm objects on browsers that lack `__proto__` support (like
1362 // IE <11), but that's the best we can do.
1369 if (!("keys"in Object&&function(){return 2===Object.keys(arguments).length}(1,2)&&function(){try{return Object.keys(""),!0}catch(t){return!1}}()
1373 /* global CreateMethodProperty */
1374 CreateMethodProperty(Object, "keys", (function() {
1377 // modified from https://github.com/es-shims/object-keys
1379 var has = Object.prototype.hasOwnProperty;
1380 var toStr = Object.prototype.toString;
1381 var isEnumerable = Object.prototype.propertyIsEnumerable;
1382 var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
1383 var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
1390 'propertyIsEnumerable',
1393 var equalsConstructorPrototype = function (o) {
1394 var ctor = o.constructor;
1395 return ctor && ctor.prototype === o;
1397 var excludedKeys = {
1401 $frameElement: true,
1415 $webkitIndexedDB: true,
1416 $webkitStorageInfo: true,
1419 var hasAutomationEqualityBug = (function () {
1421 if (typeof window === 'undefined') { return false; }
1422 for (var k in window) {
1424 if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
1426 equalsConstructorPrototype(window[k]);
1437 var equalsConstructorPrototypeIfNotBuggy = function (o) {
1439 if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
1440 return equalsConstructorPrototype(o);
1443 return equalsConstructorPrototype(o);
1449 function isArgumentsObject(value) {
1450 var str = toStr.call(value);
1451 var isArgs = str === '[object Arguments]';
1453 isArgs = str !== '[object Array]' &&
1455 typeof value === 'object' &&
1456 typeof value.length === 'number' &&
1457 value.length >= 0 &&
1458 toStr.call(value.callee) === '[object Function]';
1463 return function keys(object) {
1464 var isFunction = toStr.call(object) === '[object Function]';
1465 var isArguments = isArgumentsObject(object);
1466 var isString = toStr.call(object) === '[object String]';
1469 if (object === undefined || object === null) {
1470 throw new TypeError('Cannot convert undefined or null to object');
1473 var skipProto = hasProtoEnumBug && isFunction;
1474 if (isString && object.length > 0 && !has.call(object, 0)) {
1475 for (var i = 0; i < object.length; ++i) {
1476 theKeys.push(String(i));
1480 if (isArguments && object.length > 0) {
1481 for (var j = 0; j < object.length; ++j) {
1482 theKeys.push(String(j));
1485 for (var name in object) {
1486 if (!(skipProto && name === 'prototype') && has.call(object, name)) {
1487 theKeys.push(String(name));
1492 if (hasDontEnumBug) {
1493 var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1495 for (var k = 0; k < dontEnums.length; ++k) {
1496 if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
1497 theKeys.push(dontEnums[k]);
1507 if (!("defineProperties"in Object
1510 // Object.defineProperties
1511 /* global CreateMethodProperty, Get, ToObject, Type */
1512 // 19.1.2.3. Object.defineProperties ( O, Properties )
1513 CreateMethodProperty(Object, 'defineProperties', function defineProperties(O, Properties) {
1514 // 1. If Type(O) is not Object, throw a TypeError exception.
1515 if (Type(O) !== 'object') {
1516 throw new TypeError('Object.defineProperties called on non-object');
1518 // 2. Let props be ? ToObject(Properties).
1519 var props = ToObject(Properties);
1520 // 3. Let keys be ? props.[[OwnPropertyKeys]]().
1522 Polyfill.io - This step in our polyfill is not complying with the specification.
1523 [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols.
1524 TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]].
1526 var keys = Object.keys(props);
1527 // 4. Let descriptors be a new empty List.
1528 var descriptors = [];
1529 // 5. For each element nextKey of keys in List order, do
1530 for (var i = 0; i < keys.length; i++) {
1531 var nextKey = keys[i];
1532 // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
1533 var propDesc = Object.getOwnPropertyDescriptor(props, nextKey);
1534 // b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
1535 if (propDesc !== undefined && propDesc.enumerable) {
1536 // i. Let descObj be ? Get(props, nextKey).
1537 var descObj = Get(props, nextKey);
1538 // ii. Let desc be ? ToPropertyDescriptor(descObj).
1539 // Polyfill.io - We skip this step because Object.defineProperty deals with it.
1540 // TODO: Implement this step?
1542 // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
1543 descriptors.push([nextKey, desc]);
1546 // 6. For each pair from descriptors in list order, do
1547 for (var i = 0; i < descriptors.length; i++){
1548 // a. Let P be the first element of pair.
1549 var P = descriptors[i][0];
1550 // b. Let desc be the second element of pair.
1551 var desc = descriptors[i][1];
1552 // c. Perform ? DefinePropertyOrThrow(O, P, desc).
1553 Object.defineProperty(O, P, desc);
1561 if (!("create"in Object
1565 /* global CreateMethodProperty, Type */
1566 CreateMethodProperty(Object, 'create', function create(O, properties) {
1567 // 1. If Type(O) is neither Object nor Null, throw a TypeError exception.
1568 if (Type(O) !== 'object' && Type(O) !== 'null') {
1569 throw new TypeError('Object prototype may only be an Object or null');
1571 // 2. Let obj be ObjectCreate(O).
1572 var obj = new Function('e', 'function Object() {}Object.prototype=e;return new Object')(O);
1574 obj.constructor.prototype = O;
1576 // 3. If Properties is not undefined, then
1577 if (1 in arguments) {
1578 // a. Return ? ObjectDefineProperties(obj, Properties).
1579 return Object.defineProperties(obj, properties);
1588 // _ESAbstract.OrdinaryCreateFromConstructor
1589 /* global GetPrototypeFromConstructor */
1590 // 9.1.13. OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
1591 function OrdinaryCreateFromConstructor(constructor, intrinsicDefaultProto) { // eslint-disable-line no-unused-vars
1592 var internalSlotsList = arguments[2] || {};
1593 // 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object.
1594 // The corresponding object must be an intrinsic that is intended to be used as the[[Prototype]] value of an object.
1596 // 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
1597 var proto = GetPrototypeFromConstructor(constructor, intrinsicDefaultProto);
1599 // 3. Return ObjectCreate(proto, internalSlotsList).
1600 // Polyfill.io - We do not pass internalSlotsList to Object.create because Object.create does not use the default ordinary object definitions specified in 9.1.
1601 var obj = Object.create(proto);
1602 for (var name in internalSlotsList) {
1603 if (Object.prototype.hasOwnProperty.call(internalSlotsList, name)) {
1604 Object.defineProperty(obj, name, {
1608 value: internalSlotsList[name]
1615 // _ESAbstract.Construct
1616 /* global IsConstructor, OrdinaryCreateFromConstructor, Call */
1617 // 7.3.13. Construct ( F [ , argumentsList [ , newTarget ]] )
1618 function Construct(F /* [ , argumentsList [ , newTarget ]] */) { // eslint-disable-line no-unused-vars
1619 // 1. If newTarget is not present, set newTarget to F.
1620 var newTarget = arguments.length > 2 ? arguments[2] : F;
1622 // 2. If argumentsList is not present, set argumentsList to a new empty List.
1623 var argumentsList = arguments.length > 1 ? arguments[1] : [];
1625 // 3. Assert: IsConstructor(F) is true.
1626 if (!IsConstructor(F)) {
1627 throw new TypeError('F must be a constructor.');
1630 // 4. Assert: IsConstructor(newTarget) is true.
1631 if (!IsConstructor(newTarget)) {
1632 throw new TypeError('newTarget must be a constructor.');
1635 // 5. Return ? F.[[Construct]](argumentsList, newTarget).
1636 // Polyfill.io - If newTarget is the same as F, it is equivalent to new F(...argumentsList).
1637 if (newTarget === F) {
1638 return new (Function.prototype.bind.apply(F, [null].concat(argumentsList)))();
1640 // Polyfill.io - This is mimicking section 9.2.2 step 5.a.
1641 var obj = OrdinaryCreateFromConstructor(newTarget, Object.prototype);
1642 return Call(F, obj, argumentsList);
1646 // _ESAbstract.ArraySpeciesCreate
1647 /* global IsArray, ArrayCreate, Get, Type, IsConstructor, Construct */
1648 // 9.4.2.3. ArraySpeciesCreate ( originalArray, length )
1649 function ArraySpeciesCreate(originalArray, length) { // eslint-disable-line no-unused-vars
1650 // 1. Assert: length is an integer Number ≥ 0.
1651 // 2. If length is -0, set length to +0.
1652 if (1/length === -Infinity) {
1656 // 3. Let isArray be ? IsArray(originalArray).
1657 var isArray = IsArray(originalArray);
1659 // 4. If isArray is false, return ? ArrayCreate(length).
1660 if (isArray === false) {
1661 return ArrayCreate(length);
1664 // 5. Let C be ? Get(originalArray, "constructor").
1665 var C = Get(originalArray, 'constructor');
1667 // Polyfill.io - We skip this section as not sure how to make a cross-realm normal Array, a same-realm Array.
1668 // 6. If IsConstructor(C) is true, then
1669 // if (IsConstructor(C)) {
1670 // a. Let thisRealm be the current Realm Record.
1671 // b. Let realmC be ? GetFunctionRealm(C).
1672 // c. If thisRealm and realmC are not the same Realm Record, then
1673 // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
1675 // 7. If Type(C) is Object, then
1676 if (Type(C) === 'object') {
1677 // a. Set C to ? Get(C, @@species).
1678 C = 'Symbol' in this && 'species' in this.Symbol ? Get(C, this.Symbol.species) : undefined;
1679 // b. If C is null, set C to undefined.
1684 // 8. If C is undefined, return ? ArrayCreate(length).
1685 if (C === undefined) {
1686 return ArrayCreate(length);
1688 // 9. If IsConstructor(C) is false, throw a TypeError exception.
1689 if (!IsConstructor(C)) {
1690 throw new TypeError('C must be a constructor');
1692 // 10. Return ? Construct(C, « length »).
1693 return Construct(C, [length]);
1695 if (!("filter"in Array.prototype
1698 // Array.prototype.filter
1699 /* global CreateMethodProperty, ToObject, ToLength, Get, IsCallable, ArraySpeciesCreate, ToString, HasProperty, ToBoolean, Call, CreateDataPropertyOrThrow */
1700 // 22.1.3.7. Array.prototype.filter ( callbackfn [ , thisArg ] )
1701 CreateMethodProperty(Array.prototype, 'filter', function filter(callbackfn /* [ , thisArg ] */) {
1702 // 1. Let O be ? ToObject(this value).
1703 var O = ToObject(this);
1704 // 2. Let len be ? ToLength(? Get(O, "length")).
1705 var len = ToLength(Get(O, "length"));
1706 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
1707 if (IsCallable(callbackfn) === false) {
1708 throw new TypeError(callbackfn + ' is not a function');
1710 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1711 var T = arguments.length > 1 ? arguments[1] : undefined;
1712 // 5. Let A be ? ArraySpeciesCreate(O, 0).
1713 var A = ArraySpeciesCreate(O, 0);
1718 // 8. Repeat, while k < len
1720 // a. Let Pk be ! ToString(k).
1721 var Pk = ToString(k);
1722 // b. Let kPresent be ? HasProperty(O, Pk).
1723 var kPresent = HasProperty(O, Pk);
1724 // c. If kPresent is true, then
1726 // i. Let kValue be ? Get(O, Pk).
1727 var kValue = Get(O, Pk);
1728 // ii. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
1729 var selected = ToBoolean(Call(callbackfn, T, [kValue, k, O]));
1730 // iii. If selected is true, then
1732 // 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue)
1733 CreateDataPropertyOrThrow(A, ToString(to), kValue);
1734 // 2. Increase to by 1.
1739 // d. Increase k by 1.
1748 if (!("map"in Array.prototype
1751 // Array.prototype.map
1752 /* global ArraySpeciesCreate, Call, CreateDataPropertyOrThrow, CreateMethodProperty, Get, HasProperty, IsCallable, ToLength, ToObject, ToString */
1753 /* global CreateMethodProperty, ToObject, ToLength, Get, ArraySpeciesCreate, ToString, HasProperty, Call, CreateDataPropertyOrThrow */
1754 // 22.1.3.16. Array.prototype.map ( callbackfn [ , thisArg ] )
1755 CreateMethodProperty(Array.prototype, 'map', function map(callbackfn /* [ , thisArg ] */) {
1756 // 1. Let O be ? ToObject(this value).
1757 var O = ToObject(this);
1758 // 2. Let len be ? ToLength(? Get(O, "length")).
1759 var len = ToLength(Get(O, "length"));
1760 // 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
1761 if (IsCallable(callbackfn) === false) {
1762 throw new TypeError(callbackfn + ' is not a function');
1764 // 4. If thisArg is present, let T be thisArg; else let T be undefined.
1765 var T = arguments.length > 1 ? arguments[1] : undefined;
1766 // 5. Let A be ? ArraySpeciesCreate(O, len).
1767 var A = ArraySpeciesCreate(O, len);
1770 // 7. Repeat, while k < len
1772 // a. Let Pk be ! ToString(k).
1773 var Pk = ToString(k);
1774 // b. Let kPresent be ? HasProperty(O, Pk).
1775 var kPresent = HasProperty(O, Pk);
1776 // c. If kPresent is true, then
1778 // i. Let kValue be ? Get(O, Pk).
1779 var kValue = Get(O, Pk);
1780 // ii. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »).
1781 var mappedValue = Call(callbackfn, T, [kValue, k, O]);
1782 // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
1783 CreateDataPropertyOrThrow(A, Pk, mappedValue);
1785 // d. Increase k by 1.
1794 if (!("trim"in String.prototype
1797 // String.prototype.trim
1798 /* global CreateMethodProperty, RequireObjectCoercible, ToString */
1799 // 21.1.3.27. String.prototype.trim ( )
1800 CreateMethodProperty(String.prototype, 'trim', function trim() {
1801 // 1. Let O be ? RequireObjectCoercible(this value).
1802 var O = RequireObjectCoercible(this);
1803 // 2. Let S be ? ToString(O).
1804 var S = ToString(O);
1805 // 3. Let T be the String value that is a copy of S with both leading and trailing white space removed. The definition of white space is the union of WhiteSpace and LineTerminator. When determining whether a Unicode code point is in Unicode general category “Space_Separator” (“Zs”), code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in 6.1.4.
1806 var T = String.prototype.replace.call(S, /^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+|[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/g, '');
1814 .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});