3DSTownSquare/docs/polyfill.js
2022-05-08 12:35:26 -05:00

466 lines
22 KiB
JavaScript

/* Polyfill service v3.111.0
* For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
*
* Features requested: String.prototype.includes
*
* - _ESAbstract.Call, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
* - _ESAbstract.Get, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
* - _ESAbstract.IsCallable, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
* - _ESAbstract.RequireObjectCoercible, License: CC0 (required by "String.prototype.includes")
* - _ESAbstract.ToBoolean, License: CC0 (required by "String.prototype.includes", "_ESAbstract.IsRegExp")
* - _ESAbstract.ToObject, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.GetMethod", "_ESAbstract.GetV")
* - _ESAbstract.GetV, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.GetMethod")
* - _ESAbstract.GetMethod, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive")
* - _ESAbstract.Type, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
* - _ESAbstract.IsRegExp, License: CC0 (required by "String.prototype.includes")
* - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive")
* - _ESAbstract.ToInteger, License: CC0 (required by "String.prototype.includes")
* - _ESAbstract.ToPrimitive, License: CC0 (required by "String.prototype.includes", "_ESAbstract.ToString")
* - _ESAbstract.ToString, License: CC0 (required by "String.prototype.includes")
* - Object.defineProperty, License: CC0 (required by "String.prototype.includes", "_ESAbstract.CreateMethodProperty")
* - _ESAbstract.CreateMethodProperty, License: CC0 (required by "String.prototype.includes")
* - String.prototype.includes, License: CC0 */
(function(self, undefined) {
// _ESAbstract.Call
/* global IsCallable */
// 7.3.12. Call ( F, V [ , argumentsList ] )
function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars
// 1. If argumentsList is not present, set argumentsList to a new empty List.
var argumentsList = arguments.length > 2 ? arguments[2] : [];
// 2. If IsCallable(F) is false, throw a TypeError exception.
if (IsCallable(F) === false) {
throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.');
}
// 3. Return ? F.[[Call]](V, argumentsList).
return F.apply(V, argumentsList);
}
// _ESAbstract.Get
// 7.3.1. Get ( O, P )
function Get(O, P) { // eslint-disable-line no-unused-vars
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
// 3. Return ? O.[[Get]](P, O).
return O[P];
}
// _ESAbstract.IsCallable
// 7.2.3. IsCallable ( argument )
function IsCallable(argument) { // eslint-disable-line no-unused-vars
// 1. If Type(argument) is not Object, return false.
// 2. If argument has a [[Call]] internal method, return true.
// 3. Return false.
// 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.
return typeof argument === 'function';
}
// _ESAbstract.RequireObjectCoercible
// 7.2.1. RequireObjectCoercible ( argument )
// The abstract operation ToObject converts argument to a value of type Object according to Table 12:
// Table 12: ToObject Conversions
/*
|----------------------------------------------------------------------------------------------------------------------------------------------------|
| Argument Type | Result |
|----------------------------------------------------------------------------------------------------------------------------------------------------|
| Undefined | Throw a TypeError exception. |
| Null | Throw a TypeError exception. |
| Boolean | Return argument. |
| Number | Return argument. |
| String | Return argument. |
| Symbol | Return argument. |
| Object | Return argument. |
|----------------------------------------------------------------------------------------------------------------------------------------------------|
*/
function RequireObjectCoercible(argument) { // eslint-disable-line no-unused-vars
if (argument === null || argument === undefined) {
throw TypeError(Object.prototype.toString.call(argument) + ' is not coercible to Object.');
}
return argument;
}
// _ESAbstract.ToBoolean
// 7.1.2. ToBoolean ( argument )
// The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 9:
/*
--------------------------------------------------------------------------------------------------------------
| Argument Type | Result |
--------------------------------------------------------------------------------------------------------------
| Undefined | Return false. |
| Null | Return false. |
| Boolean | Return argument. |
| Number | If argument is +0, -0, or NaN, return false; otherwise return true. |
| String | If argument is the empty String (its length is zero), return false; otherwise return true. |
| Symbol | Return true. |
| Object | Return true. |
--------------------------------------------------------------------------------------------------------------
*/
function ToBoolean(argument) { // eslint-disable-line no-unused-vars
return Boolean(argument);
}
// _ESAbstract.ToObject
// 7.1.13 ToObject ( argument )
// The abstract operation ToObject converts argument to a value of type Object according to Table 12:
// Table 12: ToObject Conversions
/*
|----------------------------------------------------------------------------------------------------------------------------------------------------|
| Argument Type | Result |
|----------------------------------------------------------------------------------------------------------------------------------------------------|
| Undefined | Throw a TypeError exception. |
| Null | Throw a TypeError exception. |
| Boolean | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. |
| Number | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects. |
| String | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects. |
| Symbol | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects. |
| Object | Return argument. |
|----------------------------------------------------------------------------------------------------------------------------------------------------|
*/
function ToObject(argument) { // eslint-disable-line no-unused-vars
if (argument === null || argument === undefined) {
throw TypeError();
}
return Object(argument);
}
// _ESAbstract.GetV
/* global ToObject */
// 7.3.2 GetV (V, P)
function GetV(v, p) { // eslint-disable-line no-unused-vars
// 1. Assert: IsPropertyKey(P) is true.
// 2. Let O be ? ToObject(V).
var o = ToObject(v);
// 3. Return ? O.[[Get]](P, V).
return o[p];
}
// _ESAbstract.GetMethod
/* global GetV, IsCallable */
// 7.3.9. GetMethod ( V, P )
function GetMethod(V, P) { // eslint-disable-line no-unused-vars
// 1. Assert: IsPropertyKey(P) is true.
// 2. Let func be ? GetV(V, P).
var func = GetV(V, P);
// 3. If func is either undefined or null, return undefined.
if (func === null || func === undefined) {
return undefined;
}
// 4. If IsCallable(func) is false, throw a TypeError exception.
if (IsCallable(func) === false) {
throw new TypeError('Method not callable: ' + P);
}
// 5. Return func.
return func;
}
// _ESAbstract.Type
// "Type(x)" is used as shorthand for "the type of x"...
function Type(x) { // eslint-disable-line no-unused-vars
switch (typeof x) {
case 'undefined':
return 'undefined';
case 'boolean':
return 'boolean';
case 'number':
return 'number';
case 'string':
return 'string';
case 'symbol':
return 'symbol';
default:
// typeof null is 'object'
if (x === null) return 'null';
// Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`.
if ('Symbol' in self && (x instanceof self.Symbol || x.constructor === self.Symbol)) return 'symbol';
return 'object';
}
}
// _ESAbstract.IsRegExp
/* global Type, Get, ToBoolean */
// 7.2.8. IsRegExp ( argument )
function IsRegExp(argument) { // eslint-disable-line no-unused-vars
// 1. If Type(argument) is not Object, return false.
if (Type(argument) !== 'object') {
return false;
}
// 2. Let matcher be ? Get(argument, @@match).
var matcher = 'Symbol' in self && 'match' in self.Symbol ? Get(argument, self.Symbol.match) : undefined;
// 3. If matcher is not undefined, return ToBoolean(matcher).
if (matcher !== undefined) {
return ToBoolean(matcher);
}
// 4. If argument has a [[RegExpMatcher]] internal slot, return true.
try {
var lastIndex = argument.lastIndex;
argument.lastIndex = 0;
RegExp.prototype.exec.call(argument);
return true;
// eslint-disable-next-line no-empty
} catch (e) {} finally {
argument.lastIndex = lastIndex;
}
// 5. Return false.
return false;
}
// _ESAbstract.OrdinaryToPrimitive
/* global Get, IsCallable, Call, Type */
// 7.1.1.1. OrdinaryToPrimitive ( O, hint )
function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars
// 1. Assert: Type(O) is Object.
// 2. Assert: Type(hint) is String and its value is either "string" or "number".
// 3. If hint is "string", then
if (hint === 'string') {
// a. Let methodNames be « "toString", "valueOf" ».
var methodNames = ['toString', 'valueOf'];
// 4. Else,
} else {
// a. Let methodNames be « "valueOf", "toString" ».
methodNames = ['valueOf', 'toString'];
}
// 5. For each name in methodNames in List order, do
for (var i = 0; i < methodNames.length; ++i) {
var name = methodNames[i];
// a. Let method be ? Get(O, name).
var method = Get(O, name);
// b. If IsCallable(method) is true, then
if (IsCallable(method)) {
// i. Let result be ? Call(method, O).
var result = Call(method, O);
// ii. If Type(result) is not Object, return result.
if (Type(result) !== 'object') {
return result;
}
}
}
// 6. Throw a TypeError exception.
throw new TypeError('Cannot convert to primitive.');
}
// _ESAbstract.ToInteger
/* global Type */
// 7.1.4. ToInteger ( argument )
function ToInteger(argument) { // eslint-disable-line no-unused-vars
if (Type(argument) === 'symbol') {
throw new TypeError('Cannot convert a Symbol value to a number');
}
// 1. Let number be ? ToNumber(argument).
var number = Number(argument);
// 2. If number is NaN, return +0.
if (isNaN(number)) {
return 0;
}
// 3. If number is +0, -0, +∞, or -∞, return number.
if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
return number;
}
// 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number));
}
// _ESAbstract.ToPrimitive
/* global Type, GetMethod, Call, OrdinaryToPrimitive */
// 7.1.1. ToPrimitive ( input [ , PreferredType ] )
function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars
var PreferredType = arguments.length > 1 ? arguments[1] : undefined;
// 1. Assert: input is an ECMAScript language value.
// 2. If Type(input) is Object, then
if (Type(input) === 'object') {
// a. If PreferredType is not present, let hint be "default".
if (arguments.length < 2) {
var hint = 'default';
// b. Else if PreferredType is hint String, let hint be "string".
} else if (PreferredType === String) {
hint = 'string';
// c. Else PreferredType is hint Number, let hint be "number".
} else if (PreferredType === Number) {
hint = 'number';
}
// d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
var exoticToPrim = typeof self.Symbol === 'function' && typeof self.Symbol.toPrimitive === 'symbol' ? GetMethod(input, self.Symbol.toPrimitive) : undefined;
// e. If exoticToPrim is not undefined, then
if (exoticToPrim !== undefined) {
// i. Let result be ? Call(exoticToPrim, input, « hint »).
var result = Call(exoticToPrim, input, [hint]);
// ii. If Type(result) is not Object, return result.
if (Type(result) !== 'object') {
return result;
}
// iii. Throw a TypeError exception.
throw new TypeError('Cannot convert exotic object to primitive.');
}
// f. If hint is "default", set hint to "number".
if (hint === 'default') {
hint = 'number';
}
// g. Return ? OrdinaryToPrimitive(input, hint).
return OrdinaryToPrimitive(input, hint);
}
// 3. Return input
return input;
}
// _ESAbstract.ToString
/* global Type, ToPrimitive */
// 7.1.12. ToString ( argument )
// The abstract operation ToString converts argument to a value of type String according to Table 11:
// Table 11: ToString Conversions
/*
|---------------|--------------------------------------------------------|
| Argument Type | Result |
|---------------|--------------------------------------------------------|
| Undefined | Return "undefined". |
|---------------|--------------------------------------------------------|
| Null | Return "null". |
|---------------|--------------------------------------------------------|
| Boolean | If argument is true, return "true". |
| | If argument is false, return "false". |
|---------------|--------------------------------------------------------|
| Number | Return NumberToString(argument). |
|---------------|--------------------------------------------------------|
| String | Return argument. |
|---------------|--------------------------------------------------------|
| Symbol | Throw a TypeError exception. |
|---------------|--------------------------------------------------------|
| Object | Apply the following steps: |
| | Let primValue be ? ToPrimitive(argument, hint String). |
| | Return ? ToString(primValue). |
|---------------|--------------------------------------------------------|
*/
function ToString(argument) { // eslint-disable-line no-unused-vars
switch(Type(argument)) {
case 'symbol':
throw new TypeError('Cannot convert a Symbol value to a string');
case 'object':
var primValue = ToPrimitive(argument, String);
return ToString(primValue); // eslint-disable-line no-unused-vars
default:
return String(argument);
}
}
// Object.defineProperty
(function (nativeDefineProperty) {
var supportsAccessors = Object.prototype.hasOwnProperty.call(Object.prototype, '__defineGetter__');
var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
// Polyfill.io - This does not use CreateMethodProperty because our CreateMethodProperty function uses Object.defineProperty.
Object.defineProperty = function defineProperty(object, property, descriptor) {
// Where native support exists, assume it
if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
return nativeDefineProperty(object, property, descriptor);
}
if (object === null || !(object instanceof Object || typeof object === 'object')) {
throw new TypeError('Object.defineProperty called on non-object');
}
if (!(descriptor instanceof Object)) {
throw new TypeError('Property description must be an object');
}
var propertyString = String(property);
var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
var getterType = 'get' in descriptor && typeof descriptor.get;
var setterType = 'set' in descriptor && typeof descriptor.set;
// handle descriptor.get
if (getterType) {
if (getterType === undefined) {
return object;
}
if (getterType !== 'function') {
throw new TypeError('Getter must be a function');
}
if (!supportsAccessors) {
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
}
if (hasValueOrWritable) {
throw new TypeError(ERR_VALUE_ACCESSORS);
}
Object.__defineGetter__.call(object, propertyString, descriptor.get);
} else {
object[propertyString] = descriptor.value;
}
// handle descriptor.set
if (setterType) {
if (setterType === undefined) {
return object;
}
if (setterType !== 'function') {
throw new TypeError('Setter must be a function');
}
if (!supportsAccessors) {
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
}
if (hasValueOrWritable) {
throw new TypeError(ERR_VALUE_ACCESSORS);
}
Object.__defineSetter__.call(object, propertyString, descriptor.set);
}
// OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
if ('value' in descriptor) {
object[propertyString] = descriptor.value;
}
return object;
};
}(Object.defineProperty));
// _ESAbstract.CreateMethodProperty
// 7.3.5. CreateMethodProperty ( O, P, V )
function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars
// 1. Assert: Type(O) is Object.
// 2. Assert: IsPropertyKey(P) is true.
// 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
var newDesc = {
value: V,
writable: true,
enumerable: false,
configurable: true
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
Object.defineProperty(O, P, newDesc);
}
// String.prototype.includes
/* global CreateMethodProperty, IsRegExp, RequireObjectCoercible, ToInteger, ToString */
// 21.1.3.7. String.prototype.includes ( searchString [ , position ] )
CreateMethodProperty(String.prototype, 'includes', function includes(searchString /* [ , position ] */) {
'use strict';
var position = arguments.length > 1 ? arguments[1] : undefined;
// 1. Let O be ? RequireObjectCoercible(this value).
var O = RequireObjectCoercible(this);
// 2. Let S be ? ToString(O).
var S = ToString(O);
// 3. Let isRegExp be ? IsRegExp(searchString).
var isRegExp = IsRegExp(searchString);
// 4. If isRegExp is true, throw a TypeError exception.
if (isRegExp) {
throw new TypeError('First argument to String.prototype.includes must not be a regular expression');
}
// 5. Let searchStr be ? ToString(searchString).
var searchStr = ToString(searchString);
// 6. Let pos be ? ToInteger(position). (If position is undefined, this step produces the value 0.)
var pos = ToInteger(position);
// 7. Let len be the length of S.
var len = S.length;
// 8. Let start be min(max(pos, 0), len).
var start = Math.min(Math.max(pos, 0), len);
// 9. Let searchLen be the length of searchStr.
// var searchLength = searchStr.length;
// 10. If there exists any integer k not smaller than start such that k + searchLen is not greater than len, and for all nonnegative integers j less than searchLen, the code unit at index k+j within S is the same as the code unit at index j within searchStr, return true; but if there is no such integer k, return false.
return String.prototype.indexOf.call(S, searchStr, start) !== -1;
});
})
('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});