diff options
Diffstat (limited to 'node_modules/es-abstract/2019')
121 files changed, 3488 insertions, 0 deletions
diff --git a/node_modules/es-abstract/2019/AbstractEqualityComparison.js b/node_modules/es-abstract/2019/AbstractEqualityComparison.js new file mode 100644 index 000000000..40b390986 --- /dev/null +++ b/node_modules/es-abstract/2019/AbstractEqualityComparison.js @@ -0,0 +1,37 @@ +'use strict'; + +var ToNumber = require('./ToNumber'); +var ToPrimitive = require('./ToPrimitive'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison + +module.exports = function AbstractEqualityComparison(x, y) { + var xType = Type(x); + var yType = Type(y); + if (xType === yType) { + return x === y; // ES6+ specified this shortcut anyways. + } + if (x == null && y == null) { + return true; + } + if (xType === 'Number' && yType === 'String') { + return AbstractEqualityComparison(x, ToNumber(y)); + } + if (xType === 'String' && yType === 'Number') { + return AbstractEqualityComparison(ToNumber(x), y); + } + if (xType === 'Boolean') { + return AbstractEqualityComparison(ToNumber(x), y); + } + if (yType === 'Boolean') { + return AbstractEqualityComparison(x, ToNumber(y)); + } + if ((xType === 'String' || xType === 'Number' || xType === 'Symbol') && yType === 'Object') { + return AbstractEqualityComparison(x, ToPrimitive(y)); + } + if (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol')) { + return AbstractEqualityComparison(ToPrimitive(x), y); + } + return false; +}; diff --git a/node_modules/es-abstract/2019/AbstractRelationalComparison.js b/node_modules/es-abstract/2019/AbstractRelationalComparison.js new file mode 100644 index 000000000..bc7ca8324 --- /dev/null +++ b/node_modules/es-abstract/2019/AbstractRelationalComparison.js @@ -0,0 +1,66 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Number = GetIntrinsic('%Number%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var $isNaN = require('../helpers/isNaN'); +var $isFinite = require('../helpers/isFinite'); +var isPrefixOf = require('../helpers/isPrefixOf'); + +var ToNumber = require('./ToNumber'); +var ToPrimitive = require('./ToPrimitive'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/5.1/#sec-11.8.5 + +// eslint-disable-next-line max-statements +module.exports = function AbstractRelationalComparison(x, y, LeftFirst) { + if (Type(LeftFirst) !== 'Boolean') { + throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean'); + } + var px; + var py; + if (LeftFirst) { + px = ToPrimitive(x, $Number); + py = ToPrimitive(y, $Number); + } else { + py = ToPrimitive(y, $Number); + px = ToPrimitive(x, $Number); + } + var bothStrings = Type(px) === 'String' && Type(py) === 'String'; + if (!bothStrings) { + var nx = ToNumber(px); + var ny = ToNumber(py); + if ($isNaN(nx) || $isNaN(ny)) { + return undefined; + } + if ($isFinite(nx) && $isFinite(ny) && nx === ny) { + return false; + } + if (nx === 0 && ny === 0) { + return false; + } + if (nx === Infinity) { + return false; + } + if (ny === Infinity) { + return true; + } + if (ny === -Infinity) { + return false; + } + if (nx === -Infinity) { + return true; + } + return nx < ny; // by now, these are both nonzero, finite, and not equal + } + if (isPrefixOf(py, px)) { + return false; + } + if (isPrefixOf(px, py)) { + return true; + } + return px < py; // both strings, neither a prefix of the other. shortcut for steps c-f +}; diff --git a/node_modules/es-abstract/2019/AddEntriesFromIterable.js b/node_modules/es-abstract/2019/AddEntriesFromIterable.js new file mode 100644 index 000000000..5aed44753 --- /dev/null +++ b/node_modules/es-abstract/2019/AddEntriesFromIterable.js @@ -0,0 +1,52 @@ +'use strict'; + +var inspect = require('object-inspect'); + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Call = require('./Call'); +var Get = require('./Get'); +var GetIterator = require('./GetIterator'); +var IsCallable = require('./IsCallable'); +var IteratorClose = require('./IteratorClose'); +var IteratorStep = require('./IteratorStep'); +var IteratorValue = require('./IteratorValue'); +var Type = require('./Type'); + +// https://tc39.es/ecma262/#sec-add-entries-from-iterable + +module.exports = function AddEntriesFromIterable(target, iterable, adder) { + if (!IsCallable(adder)) { + throw new $TypeError('Assertion failed: `adder` is not callable'); + } + if (iterable == null) { + throw new $TypeError('Assertion failed: `iterable` is present, and not nullish'); + } + var iteratorRecord = GetIterator(iterable); + while (true) { // eslint-disable-line no-constant-condition + var next = IteratorStep(iteratorRecord); + if (!next) { + return target; + } + var nextItem = IteratorValue(next); + if (Type(nextItem) !== 'Object') { + var error = new $TypeError('iterator next must return an Object, got ' + inspect(nextItem)); + return IteratorClose( + iteratorRecord, + function () { throw error; } // eslint-disable-line no-loop-func + ); + } + try { + var k = Get(nextItem, '0'); + var v = Get(nextItem, '1'); + Call(adder, target, [k, v]); + } catch (e) { + return IteratorClose( + iteratorRecord, + function () { throw e; } + ); + } + } +}; diff --git a/node_modules/es-abstract/2019/AdvanceStringIndex.js b/node_modules/es-abstract/2019/AdvanceStringIndex.js new file mode 100644 index 000000000..666f578b1 --- /dev/null +++ b/node_modules/es-abstract/2019/AdvanceStringIndex.js @@ -0,0 +1,45 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var IsInteger = require('./IsInteger'); +var Type = require('./Type'); + +var MAX_SAFE_INTEGER = require('../helpers/maxSafeInteger'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $charCodeAt = require('../helpers/callBound')('String.prototype.charCodeAt'); + +// https://ecma-international.org/ecma-262/6.0/#sec-advancestringindex + +module.exports = function AdvanceStringIndex(S, index, unicode) { + if (Type(S) !== 'String') { + throw new $TypeError('Assertion failed: `S` must be a String'); + } + if (!IsInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) { + throw new $TypeError('Assertion failed: `length` must be an integer >= 0 and <= 2**53'); + } + if (Type(unicode) !== 'Boolean') { + throw new $TypeError('Assertion failed: `unicode` must be a Boolean'); + } + if (!unicode) { + return index + 1; + } + var length = S.length; + if ((index + 1) >= length) { + return index + 1; + } + + var first = $charCodeAt(S, index); + if (first < 0xD800 || first > 0xDBFF) { + return index + 1; + } + + var second = $charCodeAt(S, index + 1); + if (second < 0xDC00 || second > 0xDFFF) { + return index + 1; + } + + return index + 2; +}; diff --git a/node_modules/es-abstract/2019/ArrayCreate.js b/node_modules/es-abstract/2019/ArrayCreate.js new file mode 100644 index 000000000..fc9a7cf82 --- /dev/null +++ b/node_modules/es-abstract/2019/ArrayCreate.js @@ -0,0 +1,53 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $ArrayPrototype = GetIntrinsic('%Array.prototype%'); +var $RangeError = GetIntrinsic('%RangeError%'); +var $SyntaxError = GetIntrinsic('%SyntaxError%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsInteger = require('./IsInteger'); + +var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1; + +var $setProto = GetIntrinsic('%Object.setPrototypeOf%', true) || ( + // eslint-disable-next-line no-proto, no-negated-condition + [].__proto__ !== $ArrayPrototype + ? null + : function (O, proto) { + O.__proto__ = proto; // eslint-disable-line no-proto, no-param-reassign + return O; + } +); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-arraycreate + +module.exports = function ArrayCreate(length) { + if (!IsInteger(length) || length < 0) { + throw new $TypeError('Assertion failed: `length` must be an integer Number >= 0'); + } + if (length > MAX_ARRAY_LENGTH) { + throw new $RangeError('length is greater than (2**32 - 1)'); + } + var proto = arguments.length > 1 ? arguments[1] : $ArrayPrototype; + var A = []; // steps 5 - 7, and 9 + if (proto !== $ArrayPrototype) { // step 8 + if (!$setProto) { + throw new $SyntaxError('ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]'); + } + $setProto(A, proto); + } + if (length !== 0) { // bypasses the need for step 2 + A.length = length; + } + /* step 10, the above as a shortcut for the below + OrdinaryDefineOwnProperty(A, 'length', { + '[[Configurable]]': false, + '[[Enumerable]]': false, + '[[Value]]': length, + '[[Writable]]': true + }); + */ + return A; +}; diff --git a/node_modules/es-abstract/2019/ArraySetLength.js b/node_modules/es-abstract/2019/ArraySetLength.js new file mode 100644 index 000000000..c9134c6e6 --- /dev/null +++ b/node_modules/es-abstract/2019/ArraySetLength.js @@ -0,0 +1,85 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $RangeError = GetIntrinsic('%RangeError%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var assign = require('object.assign'); + +var isPropertyDescriptor = require('../helpers/isPropertyDescriptor'); + +var IsArray = require('./IsArray'); +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var OrdinaryDefineOwnProperty = require('./OrdinaryDefineOwnProperty'); +var OrdinaryGetOwnProperty = require('./OrdinaryGetOwnProperty'); +var ToNumber = require('./ToNumber'); +var ToString = require('./ToString'); +var ToUint32 = require('./ToUint32'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-arraysetlength + +// eslint-disable-next-line max-statements, max-lines-per-function +module.exports = function ArraySetLength(A, Desc) { + if (!IsArray(A)) { + throw new $TypeError('Assertion failed: A must be an Array'); + } + if (!isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, Desc)) { + throw new $TypeError('Assertion failed: Desc must be a Property Descriptor'); + } + if (!('[[Value]]' in Desc)) { + return OrdinaryDefineOwnProperty(A, 'length', Desc); + } + var newLenDesc = assign({}, Desc); + var newLen = ToUint32(Desc['[[Value]]']); + var numberLen = ToNumber(Desc['[[Value]]']); + if (newLen !== numberLen) { + throw new $RangeError('Invalid array length'); + } + newLenDesc['[[Value]]'] = newLen; + var oldLenDesc = OrdinaryGetOwnProperty(A, 'length'); + if (!IsDataDescriptor(oldLenDesc)) { + throw new $TypeError('Assertion failed: an array had a non-data descriptor on `length`'); + } + var oldLen = oldLenDesc['[[Value]]']; + if (newLen >= oldLen) { + return OrdinaryDefineOwnProperty(A, 'length', newLenDesc); + } + if (!oldLenDesc['[[Writable]]']) { + return false; + } + var newWritable; + if (!('[[Writable]]' in newLenDesc) || newLenDesc['[[Writable]]']) { + newWritable = true; + } else { + newWritable = false; + newLenDesc['[[Writable]]'] = true; + } + var succeeded = OrdinaryDefineOwnProperty(A, 'length', newLenDesc); + if (!succeeded) { + return false; + } + while (newLen < oldLen) { + oldLen -= 1; + // eslint-disable-next-line no-param-reassign + var deleteSucceeded = delete A[ToString(oldLen)]; + if (!deleteSucceeded) { + newLenDesc['[[Value]]'] = oldLen + 1; + if (!newWritable) { + newLenDesc['[[Writable]]'] = false; + OrdinaryDefineOwnProperty(A, 'length', newLenDesc); + return false; + } + } + } + if (!newWritable) { + return OrdinaryDefineOwnProperty(A, 'length', { '[[Writable]]': false }); + } + return true; +}; diff --git a/node_modules/es-abstract/2019/ArraySpeciesCreate.js b/node_modules/es-abstract/2019/ArraySpeciesCreate.js new file mode 100644 index 000000000..98b9b561d --- /dev/null +++ b/node_modules/es-abstract/2019/ArraySpeciesCreate.js @@ -0,0 +1,46 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Array = GetIntrinsic('%Array%'); +var $species = GetIntrinsic('%Symbol.species%', true); +var $TypeError = GetIntrinsic('%TypeError%'); + +var Get = require('./Get'); +var IsArray = require('./IsArray'); +var IsConstructor = require('./IsConstructor'); +var IsInteger = require('./IsInteger'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-arrayspeciescreate + +module.exports = function ArraySpeciesCreate(originalArray, length) { + if (!IsInteger(length) || length < 0) { + throw new $TypeError('Assertion failed: length must be an integer >= 0'); + } + var len = length === 0 ? 0 : length; + var C; + var isArray = IsArray(originalArray); + if (isArray) { + C = Get(originalArray, 'constructor'); + // TODO: figure out how to make a cross-realm normal Array, a same-realm Array + // if (IsConstructor(C)) { + // if C is another realm's Array, C = undefined + // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ? + // } + if ($species && Type(C) === 'Object') { + C = Get(C, $species); + if (C === null) { + C = void 0; + } + } + } + if (typeof C === 'undefined') { + return $Array(len); + } + if (!IsConstructor(C)) { + throw new $TypeError('C must be a constructor'); + } + return new C(len); // Construct(C, len); +}; + diff --git a/node_modules/es-abstract/2019/Call.js b/node_modules/es-abstract/2019/Call.js new file mode 100644 index 000000000..f0f045174 --- /dev/null +++ b/node_modules/es-abstract/2019/Call.js @@ -0,0 +1,13 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); +var callBound = require('../helpers/callBound'); + +var $apply = GetIntrinsic('%Reflect.apply%', true) || callBound('%Function.prototype.apply%'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-call + +module.exports = function Call(F, V) { + var args = arguments.length > 2 ? arguments[2] : []; + return $apply(F, V, args); +}; diff --git a/node_modules/es-abstract/2019/CanonicalNumericIndexString.js b/node_modules/es-abstract/2019/CanonicalNumericIndexString.js new file mode 100644 index 000000000..625f8539a --- /dev/null +++ b/node_modules/es-abstract/2019/CanonicalNumericIndexString.js @@ -0,0 +1,22 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var SameValue = require('./SameValue'); +var ToNumber = require('./ToNumber'); +var ToString = require('./ToString'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-canonicalnumericindexstring + +module.exports = function CanonicalNumericIndexString(argument) { + if (Type(argument) !== 'String') { + throw new $TypeError('Assertion failed: `argument` must be a String'); + } + if (argument === '-0') { return -0; } + var n = ToNumber(argument); + if (SameValue(ToString(n), argument)) { return n; } + return void 0; +}; diff --git a/node_modules/es-abstract/2019/CompletePropertyDescriptor.js b/node_modules/es-abstract/2019/CompletePropertyDescriptor.js new file mode 100644 index 000000000..548bf415a --- /dev/null +++ b/node_modules/es-abstract/2019/CompletePropertyDescriptor.js @@ -0,0 +1,39 @@ +'use strict'; + +var has = require('has'); + +var assertRecord = require('../helpers/assertRecord'); + +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsGenericDescriptor = require('./IsGenericDescriptor'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-completepropertydescriptor + +module.exports = function CompletePropertyDescriptor(Desc) { + /* eslint no-param-reassign: 0 */ + assertRecord(Type, 'Property Descriptor', 'Desc', Desc); + + if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) { + if (!has(Desc, '[[Value]]')) { + Desc['[[Value]]'] = void 0; + } + if (!has(Desc, '[[Writable]]')) { + Desc['[[Writable]]'] = false; + } + } else { + if (!has(Desc, '[[Get]]')) { + Desc['[[Get]]'] = void 0; + } + if (!has(Desc, '[[Set]]')) { + Desc['[[Set]]'] = void 0; + } + } + if (!has(Desc, '[[Enumerable]]')) { + Desc['[[Enumerable]]'] = false; + } + if (!has(Desc, '[[Configurable]]')) { + Desc['[[Configurable]]'] = false; + } + return Desc; +}; diff --git a/node_modules/es-abstract/2019/CopyDataProperties.js b/node_modules/es-abstract/2019/CopyDataProperties.js new file mode 100644 index 000000000..842709903 --- /dev/null +++ b/node_modules/es-abstract/2019/CopyDataProperties.js @@ -0,0 +1,64 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); +var forEach = require('../helpers/forEach'); +var OwnPropertyKeys = require('../helpers/OwnPropertyKeys'); + +var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); + +var CreateDataProperty = require('./CreateDataProperty'); +var Get = require('./Get'); +var IsArray = require('./IsArray'); +var IsInteger = require('./IsInteger'); +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var ToNumber = require('./ToNumber'); +var ToObject = require('./ToObject'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/9.0/#sec-copydataproperties + +module.exports = function CopyDataProperties(target, source, excludedItems) { + if (Type(target) !== 'Object') { + throw new TypeError('Assertion failed: "target" must be an Object'); + } + + if (!IsArray(excludedItems)) { + throw new TypeError('Assertion failed: "excludedItems" must be a List of Property Keys'); + } + for (var i = 0; i < excludedItems.length; i += 1) { + if (!IsPropertyKey(excludedItems[i])) { + throw new TypeError('Assertion failed: "excludedItems" must be a List of Property Keys'); + } + } + + if (typeof source === 'undefined' || source === null) { + return target; + } + + var fromObj = ToObject(source); + + var sourceKeys = OwnPropertyKeys(fromObj); + forEach(sourceKeys, function (nextKey) { + var excluded = false; + + forEach(excludedItems, function (e) { + if (SameValue(e, nextKey) === true) { + excluded = true; + } + }); + + var enumerable = $isEnumerable(fromObj, nextKey) || ( + // this is to handle string keys being non-enumerable in older engines + typeof source === 'string' + && nextKey >= 0 + && IsInteger(ToNumber(nextKey)) + ); + if (excluded === false && enumerable) { + var propValue = Get(fromObj, nextKey); + CreateDataProperty(target, nextKey, propValue); + } + }); + + return target; +}; diff --git a/node_modules/es-abstract/2019/CreateDataProperty.js b/node_modules/es-abstract/2019/CreateDataProperty.js new file mode 100644 index 000000000..32a86ef04 --- /dev/null +++ b/node_modules/es-abstract/2019/CreateDataProperty.js @@ -0,0 +1,45 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var DefineOwnProperty = require('../helpers/DefineOwnProperty'); + +var FromPropertyDescriptor = require('./FromPropertyDescriptor'); +var OrdinaryGetOwnProperty = require('./OrdinaryGetOwnProperty'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsExtensible = require('./IsExtensible'); +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-createdataproperty + +module.exports = function CreateDataProperty(O, P, V) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + var oldDesc = OrdinaryGetOwnProperty(O, P); + var extensible = !oldDesc || IsExtensible(O); + var immutable = oldDesc && (!oldDesc['[[Writable]]'] || !oldDesc['[[Configurable]]']); + if (immutable || !extensible) { + return false; + } + return DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + { + '[[Configurable]]': true, + '[[Enumerable]]': true, + '[[Value]]': V, + '[[Writable]]': true + } + ); +}; diff --git a/node_modules/es-abstract/2019/CreateDataPropertyOrThrow.js b/node_modules/es-abstract/2019/CreateDataPropertyOrThrow.js new file mode 100644 index 000000000..9feaec8d8 --- /dev/null +++ b/node_modules/es-abstract/2019/CreateDataPropertyOrThrow.js @@ -0,0 +1,25 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var CreateDataProperty = require('./CreateDataProperty'); +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +// // https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow + +module.exports = function CreateDataPropertyOrThrow(O, P, V) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + var success = CreateDataProperty(O, P, V); + if (!success) { + throw new $TypeError('unable to create data property'); + } + return success; +}; diff --git a/node_modules/es-abstract/2019/CreateHTML.js b/node_modules/es-abstract/2019/CreateHTML.js new file mode 100644 index 000000000..536c92db8 --- /dev/null +++ b/node_modules/es-abstract/2019/CreateHTML.js @@ -0,0 +1,30 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var callBound = require('../helpers/callBound'); + +var $replace = callBound('String.prototype.replace'); + +var RequireObjectCoercible = require('./RequireObjectCoercible'); +var ToString = require('./ToString'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-createhtml + +module.exports = function CreateHTML(string, tag, attribute, value) { + if (Type(tag) !== 'String' || Type(attribute) !== 'String') { + throw new $TypeError('Assertion failed: `tag` and `attribute` must be strings'); + } + var str = RequireObjectCoercible(string); + var S = ToString(str); + var p1 = '<' + tag; + if (attribute !== '') { + var V = ToString(value); + var escapedV = $replace(V, /\x22/g, '"'); + p1 += '\x20' + attribute + '\x3D\x22' + escapedV + '\x22'; + } + return p1 + '>' + S + '</' + tag + '>'; +}; diff --git a/node_modules/es-abstract/2019/CreateIterResultObject.js b/node_modules/es-abstract/2019/CreateIterResultObject.js new file mode 100644 index 000000000..aef1d2200 --- /dev/null +++ b/node_modules/es-abstract/2019/CreateIterResultObject.js @@ -0,0 +1,19 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-createiterresultobject + +module.exports = function CreateIterResultObject(value, done) { + if (Type(done) !== 'Boolean') { + throw new $TypeError('Assertion failed: Type(done) is not Boolean'); + } + return { + value: value, + done: done + }; +}; diff --git a/node_modules/es-abstract/2019/CreateListFromArrayLike.js b/node_modules/es-abstract/2019/CreateListFromArrayLike.js new file mode 100644 index 000000000..d6b44b5dc --- /dev/null +++ b/node_modules/es-abstract/2019/CreateListFromArrayLike.js @@ -0,0 +1,43 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var callBound = require('../helpers/callBound'); + +var $TypeError = GetIntrinsic('%TypeError%'); +var $indexOf = callBound('Array.prototype.indexOf', true) || callBound('String.prototype.indexOf'); +var $push = callBound('Array.prototype.push'); + +var Get = require('./Get'); +var IsArray = require('./IsArray'); +var ToLength = require('./ToLength'); +var ToString = require('./ToString'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-createlistfromarraylike +module.exports = function CreateListFromArrayLike(obj) { + var elementTypes = arguments.length > 1 + ? arguments[1] + : ['Undefined', 'Null', 'Boolean', 'String', 'Symbol', 'Number', 'Object']; + + if (Type(obj) !== 'Object') { + throw new $TypeError('Assertion failed: `obj` must be an Object'); + } + if (!IsArray(elementTypes)) { + throw new $TypeError('Assertion failed: `elementTypes`, if provided, must be an array'); + } + var len = ToLength(Get(obj, 'length')); + var list = []; + var index = 0; + while (index < len) { + var indexName = ToString(index); + var next = Get(obj, indexName); + var nextType = Type(next); + if ($indexOf(elementTypes, nextType) < 0) { + throw new $TypeError('item type ' + nextType + ' is not a valid elementType'); + } + $push(list, next); + index += 1; + } + return list; +}; diff --git a/node_modules/es-abstract/2019/CreateMethodProperty.js b/node_modules/es-abstract/2019/CreateMethodProperty.js new file mode 100644 index 000000000..5b599aea1 --- /dev/null +++ b/node_modules/es-abstract/2019/CreateMethodProperty.js @@ -0,0 +1,40 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var DefineOwnProperty = require('../helpers/DefineOwnProperty'); + +var FromPropertyDescriptor = require('./FromPropertyDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-createmethodproperty + +module.exports = function CreateMethodProperty(O, P, V) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + + var newDesc = { + '[[Configurable]]': true, + '[[Enumerable]]': false, + '[[Value]]': V, + '[[Writable]]': true + }; + return DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + newDesc + ); +}; diff --git a/node_modules/es-abstract/2019/DateFromTime.js b/node_modules/es-abstract/2019/DateFromTime.js new file mode 100644 index 000000000..962dba168 --- /dev/null +++ b/node_modules/es-abstract/2019/DateFromTime.js @@ -0,0 +1,54 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $EvalError = GetIntrinsic('%EvalError%'); + +var DayWithinYear = require('./DayWithinYear'); +var InLeapYear = require('./InLeapYear'); +var MonthFromTime = require('./MonthFromTime'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.5 + +module.exports = function DateFromTime(t) { + var m = MonthFromTime(t); + var d = DayWithinYear(t); + if (m === 0) { + return d + 1; + } + if (m === 1) { + return d - 30; + } + var leap = InLeapYear(t); + if (m === 2) { + return d - 58 - leap; + } + if (m === 3) { + return d - 89 - leap; + } + if (m === 4) { + return d - 119 - leap; + } + if (m === 5) { + return d - 150 - leap; + } + if (m === 6) { + return d - 180 - leap; + } + if (m === 7) { + return d - 211 - leap; + } + if (m === 8) { + return d - 242 - leap; + } + if (m === 9) { + return d - 272 - leap; + } + if (m === 10) { + return d - 303 - leap; + } + if (m === 11) { + return d - 333 - leap; + } + throw new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m); +}; diff --git a/node_modules/es-abstract/2019/DateString.js b/node_modules/es-abstract/2019/DateString.js new file mode 100644 index 000000000..fc3032906 --- /dev/null +++ b/node_modules/es-abstract/2019/DateString.js @@ -0,0 +1,30 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + +var $isNaN = require('../helpers/isNaN'); +var padTimeComponent = require('../helpers/padTimeComponent'); + +var Type = require('./Type'); +var WeekDay = require('./WeekDay'); +var MonthFromTime = require('./MonthFromTime'); +var YearFromTime = require('./YearFromTime'); +var DateFromTime = require('./DateFromTime'); + +// https://www.ecma-international.org/ecma-262/9.0/#sec-datestring + +module.exports = function DateString(tv) { + if (Type(tv) !== 'Number' || $isNaN(tv)) { + throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number'); + } + var weekday = weekdays[WeekDay(tv)]; + var month = months[MonthFromTime(tv)]; + var day = padTimeComponent(DateFromTime(tv)); + var year = padTimeComponent(YearFromTime(tv), 4); + return weekday + '\x20' + month + '\x20' + day + '\x20' + year; +}; diff --git a/node_modules/es-abstract/2019/Day.js b/node_modules/es-abstract/2019/Day.js new file mode 100644 index 000000000..00df81342 --- /dev/null +++ b/node_modules/es-abstract/2019/Day.js @@ -0,0 +1,13 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); + +var msPerDay = require('../helpers/timeConstants').msPerDay; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2 + +module.exports = function Day(t) { + return $floor(t / msPerDay); +}; diff --git a/node_modules/es-abstract/2019/DayFromYear.js b/node_modules/es-abstract/2019/DayFromYear.js new file mode 100644 index 000000000..08dd5af60 --- /dev/null +++ b/node_modules/es-abstract/2019/DayFromYear.js @@ -0,0 +1,12 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3 + +module.exports = function DayFromYear(y) { + return (365 * (y - 1970)) + $floor((y - 1969) / 4) - $floor((y - 1901) / 100) + $floor((y - 1601) / 400); +}; + diff --git a/node_modules/es-abstract/2019/DayWithinYear.js b/node_modules/es-abstract/2019/DayWithinYear.js new file mode 100644 index 000000000..cfc400288 --- /dev/null +++ b/node_modules/es-abstract/2019/DayWithinYear.js @@ -0,0 +1,11 @@ +'use strict'; + +var Day = require('./Day'); +var DayFromYear = require('./DayFromYear'); +var YearFromTime = require('./YearFromTime'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4 + +module.exports = function DayWithinYear(t) { + return Day(t) - DayFromYear(YearFromTime(t)); +}; diff --git a/node_modules/es-abstract/2019/DaysInYear.js b/node_modules/es-abstract/2019/DaysInYear.js new file mode 100644 index 000000000..db32251ff --- /dev/null +++ b/node_modules/es-abstract/2019/DaysInYear.js @@ -0,0 +1,18 @@ +'use strict'; + +var mod = require('../helpers/mod'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3 + +module.exports = function DaysInYear(y) { + if (mod(y, 4) !== 0) { + return 365; + } + if (mod(y, 100) !== 0) { + return 366; + } + if (mod(y, 400) !== 0) { + return 365; + } + return 366; +}; diff --git a/node_modules/es-abstract/2019/DefinePropertyOrThrow.js b/node_modules/es-abstract/2019/DefinePropertyOrThrow.js new file mode 100644 index 000000000..7977f6e18 --- /dev/null +++ b/node_modules/es-abstract/2019/DefinePropertyOrThrow.js @@ -0,0 +1,50 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var isPropertyDescriptor = require('../helpers/isPropertyDescriptor'); +var DefineOwnProperty = require('../helpers/DefineOwnProperty'); + +var FromPropertyDescriptor = require('./FromPropertyDescriptor'); +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var ToPropertyDescriptor = require('./ToPropertyDescriptor'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-definepropertyorthrow + +module.exports = function DefinePropertyOrThrow(O, P, desc) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + + var Desc = isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, desc) ? desc : ToPropertyDescriptor(desc); + if (!isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, Desc)) { + throw new $TypeError('Assertion failed: Desc is not a valid Property Descriptor'); + } + + return DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + Desc + ); +}; diff --git a/node_modules/es-abstract/2019/DeletePropertyOrThrow.js b/node_modules/es-abstract/2019/DeletePropertyOrThrow.js new file mode 100644 index 000000000..b47681797 --- /dev/null +++ b/node_modules/es-abstract/2019/DeletePropertyOrThrow.js @@ -0,0 +1,27 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-deletepropertyorthrow + +module.exports = function DeletePropertyOrThrow(O, P) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + + // eslint-disable-next-line no-param-reassign + var success = delete O[P]; + if (!success) { + throw new $TypeError('Attempt to delete property failed.'); + } + return success; +}; diff --git a/node_modules/es-abstract/2019/EnumerableOwnPropertyNames.js b/node_modules/es-abstract/2019/EnumerableOwnPropertyNames.js new file mode 100644 index 000000000..e2ed7226c --- /dev/null +++ b/node_modules/es-abstract/2019/EnumerableOwnPropertyNames.js @@ -0,0 +1,43 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var objectKeys = require('object-keys'); + +var callBound = require('../helpers/callBound'); + +var callBind = require('../helpers/callBind'); + +var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); +var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%')); + +var forEach = require('../helpers/forEach'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/8.0/#sec-enumerableownproperties + +module.exports = function EnumerableOwnProperties(O, kind) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + + var keys = objectKeys(O); + if (kind === 'key') { + return keys; + } + if (kind === 'value' || kind === 'key+value') { + var results = []; + forEach(keys, function (key) { + if ($isEnumerable(O, key)) { + $pushApply(results, [ + kind === 'value' ? O[key] : [key, O[key]] + ]); + } + }); + return results; + } + throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind); +}; diff --git a/node_modules/es-abstract/2019/FlattenIntoArray.js b/node_modules/es-abstract/2019/FlattenIntoArray.js new file mode 100644 index 000000000..313a6ed9b --- /dev/null +++ b/node_modules/es-abstract/2019/FlattenIntoArray.js @@ -0,0 +1,58 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var MAX_SAFE_INTEGER = require('../helpers/maxSafeInteger'); + +var Call = require('./Call'); +var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow'); +var Get = require('./Get'); +var HasProperty = require('./HasProperty'); +var IsArray = require('./IsArray'); +var ToLength = require('./ToLength'); +var ToString = require('./ToString'); + +// https://ecma-international.org/ecma-262/10.0/#sec-flattenintoarray + +// eslint-disable-next-line max-params, max-statements +module.exports = function FlattenIntoArray(target, source, sourceLen, start, depth) { + var mapperFunction; + if (arguments.length > 5) { + mapperFunction = arguments[5]; + } + + var targetIndex = start; + var sourceIndex = 0; + while (sourceIndex < sourceLen) { + var P = ToString(sourceIndex); + var exists = HasProperty(source, P); + if (exists === true) { + var element = Get(source, P); + if (typeof mapperFunction !== 'undefined') { + if (arguments.length <= 6) { + throw new $TypeError('Assertion failed: thisArg is required when mapperFunction is provided'); + } + element = Call(mapperFunction, arguments[6], [element, sourceIndex, source]); + } + var shouldFlatten = false; + if (depth > 0) { + shouldFlatten = IsArray(element); + } + if (shouldFlatten) { + var elementLen = ToLength(Get(element, 'length')); + targetIndex = FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1); + } else { + if (targetIndex >= MAX_SAFE_INTEGER) { + throw new $TypeError('index too large'); + } + CreateDataPropertyOrThrow(target, ToString(targetIndex), element); + targetIndex += 1; + } + } + sourceIndex += 1; + } + + return targetIndex; +}; diff --git a/node_modules/es-abstract/2019/FromPropertyDescriptor.js b/node_modules/es-abstract/2019/FromPropertyDescriptor.js new file mode 100644 index 000000000..5ec200edb --- /dev/null +++ b/node_modules/es-abstract/2019/FromPropertyDescriptor.js @@ -0,0 +1,36 @@ +'use strict'; + +var assertRecord = require('../helpers/assertRecord'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor + +module.exports = function FromPropertyDescriptor(Desc) { + if (typeof Desc === 'undefined') { + return Desc; + } + + assertRecord(Type, 'Property Descriptor', 'Desc', Desc); + + var obj = {}; + if ('[[Value]]' in Desc) { + obj.value = Desc['[[Value]]']; + } + if ('[[Writable]]' in Desc) { + obj.writable = Desc['[[Writable]]']; + } + if ('[[Get]]' in Desc) { + obj.get = Desc['[[Get]]']; + } + if ('[[Set]]' in Desc) { + obj.set = Desc['[[Set]]']; + } + if ('[[Enumerable]]' in Desc) { + obj.enumerable = Desc['[[Enumerable]]']; + } + if ('[[Configurable]]' in Desc) { + obj.configurable = Desc['[[Configurable]]']; + } + return obj; +}; diff --git a/node_modules/es-abstract/2019/Get.js b/node_modules/es-abstract/2019/Get.js new file mode 100644 index 000000000..5b9ad7860 --- /dev/null +++ b/node_modules/es-abstract/2019/Get.js @@ -0,0 +1,30 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var inspect = require('object-inspect'); + +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +/** + * 7.3.1 Get (O, P) - https://ecma-international.org/ecma-262/6.0/#sec-get-o-p + * 1. Assert: Type(O) is Object. + * 2. Assert: IsPropertyKey(P) is true. + * 3. Return O.[[Get]](P, O). + */ + +module.exports = function Get(O, P) { + // 7.3.1.1 + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + // 7.3.1.2 + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P)); + } + // 7.3.1.3 + return O[P]; +}; diff --git a/node_modules/es-abstract/2019/GetIterator.js b/node_modules/es-abstract/2019/GetIterator.js new file mode 100644 index 000000000..7beddacc0 --- /dev/null +++ b/node_modules/es-abstract/2019/GetIterator.js @@ -0,0 +1,35 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var getIteratorMethod = require('../helpers/getIteratorMethod'); +var AdvanceStringIndex = require('./AdvanceStringIndex'); +var Call = require('./Call'); +var GetMethod = require('./GetMethod'); +var IsArray = require('./IsArray'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-getiterator + +module.exports = function GetIterator(obj, method) { + var actualMethod = method; + if (arguments.length < 2) { + actualMethod = getIteratorMethod( + { + AdvanceStringIndex: AdvanceStringIndex, + GetMethod: GetMethod, + IsArray: IsArray, + Type: Type + }, + obj + ); + } + var iterator = Call(actualMethod, obj); + if (Type(iterator) !== 'Object') { + throw new $TypeError('iterator must return an object'); + } + + return iterator; +}; diff --git a/node_modules/es-abstract/2019/GetMethod.js b/node_modules/es-abstract/2019/GetMethod.js new file mode 100644 index 000000000..aef8cbc4a --- /dev/null +++ b/node_modules/es-abstract/2019/GetMethod.js @@ -0,0 +1,42 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var GetV = require('./GetV'); +var IsCallable = require('./IsCallable'); +var IsPropertyKey = require('./IsPropertyKey'); + +/** + * 7.3.9 - https://ecma-international.org/ecma-262/6.0/#sec-getmethod + * 1. Assert: IsPropertyKey(P) is true. + * 2. Let func be GetV(O, P). + * 3. ReturnIfAbrupt(func). + * 4. If func is either undefined or null, return undefined. + * 5. If IsCallable(func) is false, throw a TypeError exception. + * 6. Return func. + */ + +module.exports = function GetMethod(O, P) { + // 7.3.9.1 + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + + // 7.3.9.2 + var func = GetV(O, P); + + // 7.3.9.4 + if (func == null) { + return void 0; + } + + // 7.3.9.5 + if (!IsCallable(func)) { + throw new $TypeError(P + 'is not a function'); + } + + // 7.3.9.6 + return func; +}; diff --git a/node_modules/es-abstract/2019/GetOwnPropertyKeys.js b/node_modules/es-abstract/2019/GetOwnPropertyKeys.js new file mode 100644 index 000000000..8d7e5eee5 --- /dev/null +++ b/node_modules/es-abstract/2019/GetOwnPropertyKeys.js @@ -0,0 +1,31 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var hasSymbols = require('has-symbols')(); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%'); +var $gOPS = hasSymbols && GetIntrinsic('%Object.getOwnPropertySymbols%'); +var keys = require('object-keys'); + +var esType = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys + +module.exports = function GetOwnPropertyKeys(O, Type) { + if (esType(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (Type === 'Symbol') { + return $gOPS ? $gOPS(O) : []; + } + if (Type === 'String') { + if (!$gOPN) { + return keys(O); + } + return $gOPN(O); + } + throw new $TypeError('Assertion failed: `Type` must be `"String"` or `"Symbol"`'); +}; diff --git a/node_modules/es-abstract/2019/GetPrototypeFromConstructor.js b/node_modules/es-abstract/2019/GetPrototypeFromConstructor.js new file mode 100644 index 000000000..62da8fb5f --- /dev/null +++ b/node_modules/es-abstract/2019/GetPrototypeFromConstructor.js @@ -0,0 +1,28 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Function = GetIntrinsic('%Function%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var Get = require('./Get'); +var IsConstructor = require('./IsConstructor'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-getprototypefromconstructor + +module.exports = function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) { + var intrinsic = GetIntrinsic(intrinsicDefaultProto); // throws if not a valid intrinsic + if (!IsConstructor(constructor)) { + throw new $TypeError('Assertion failed: `constructor` must be a constructor'); + } + var proto = Get(constructor, 'prototype'); + if (Type(proto) !== 'Object') { + if (!(constructor instanceof $Function)) { + // ignore other realms, for now + throw new $TypeError('cross-realm constructors not currently supported'); + } + proto = intrinsic; + } + return proto; +}; diff --git a/node_modules/es-abstract/2019/GetSubstitution.js b/node_modules/es-abstract/2019/GetSubstitution.js new file mode 100644 index 000000000..2ec9ebc50 --- /dev/null +++ b/node_modules/es-abstract/2019/GetSubstitution.js @@ -0,0 +1,128 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var callBound = require('../helpers/callBound'); +var regexTester = require('../helpers/regexTester'); +var every = require('../helpers/every'); + +var $charAt = callBound('String.prototype.charAt'); +var $strSlice = callBound('String.prototype.slice'); +var $indexOf = callBound('String.prototype.indexOf'); +var $parseInt = parseInt; + +var isDigit = regexTester(/^[0-9]$/); + +var inspect = require('object-inspect'); + +var Get = require('./Get'); +var IsArray = require('./IsArray'); +var IsInteger = require('./IsInteger'); +var ToObject = require('./ToObject'); +var ToString = require('./ToString'); +var Type = require('./Type'); + +var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false + +var isStringOrHole = function (capture, index, arr) { + return Type(capture) === 'String' || (canDistinguishSparseFromUndefined ? !(index in arr) : Type(capture) === 'Undefined'); +}; + +// http://www.ecma-international.org/ecma-262/9.0/#sec-getsubstitution + +// eslint-disable-next-line max-statements, max-params, max-lines-per-function +module.exports = function GetSubstitution(matched, str, position, captures, namedCaptures, replacement) { + if (Type(matched) !== 'String') { + throw new $TypeError('Assertion failed: `matched` must be a String'); + } + var matchLength = matched.length; + + if (Type(str) !== 'String') { + throw new $TypeError('Assertion failed: `str` must be a String'); + } + var stringLength = str.length; + + if (!IsInteger(position) || position < 0 || position > stringLength) { + throw new $TypeError('Assertion failed: `position` must be a nonnegative integer, and less than or equal to the length of `string`, got ' + inspect(position)); + } + + if (!IsArray(captures) || !every(captures, isStringOrHole)) { + throw new $TypeError('Assertion failed: `captures` must be a List of Strings, got ' + inspect(captures)); + } + + if (Type(replacement) !== 'String') { + throw new $TypeError('Assertion failed: `replacement` must be a String'); + } + + var tailPos = position + matchLength; + var m = captures.length; + if (Type(namedCaptures) !== 'Undefined') { + namedCaptures = ToObject(namedCaptures); // eslint-disable-line no-param-reassign + } + + var result = ''; + for (var i = 0; i < replacement.length; i += 1) { + // if this is a $, and it's not the end of the replacement + var current = $charAt(replacement, i); + var isLast = (i + 1) >= replacement.length; + var nextIsLast = (i + 2) >= replacement.length; + if (current === '$' && !isLast) { + var next = $charAt(replacement, i + 1); + if (next === '$') { + result += '$'; + i += 1; + } else if (next === '&') { + result += matched; + i += 1; + } else if (next === '`') { + result += position === 0 ? '' : $strSlice(str, 0, position - 1); + i += 1; + } else if (next === "'") { + result += tailPos >= stringLength ? '' : $strSlice(str, tailPos); + i += 1; + } else { + var nextNext = nextIsLast ? null : $charAt(replacement, i + 2); + if (isDigit(next) && next !== '0' && (nextIsLast || !isDigit(nextNext))) { + // $1 through $9, and not followed by a digit + var n = $parseInt(next, 10); + // if (n > m, impl-defined) + result += (n <= m && Type(captures[n - 1]) === 'Undefined') ? '' : captures[n - 1]; + i += 1; + } else if (isDigit(next) && (nextIsLast || isDigit(nextNext))) { + // $00 through $99 + var nn = next + nextNext; + var nnI = $parseInt(nn, 10) - 1; + // if nn === '00' or nn > m, impl-defined + result += (nn <= m && Type(captures[nnI]) === 'Undefined') ? '' : captures[nnI]; + i += 2; + } else if (next === '<') { + // eslint-disable-next-line max-depth + if (Type(namedCaptures) === 'Undefined') { + result += '$<'; + i += 2; + } else { + var endIndex = $indexOf(replacement, '>', i); + // eslint-disable-next-line max-depth + if (endIndex > -1) { + var groupName = $strSlice(replacement, i, endIndex); + var capture = Get(namedCaptures, groupName); + // eslint-disable-next-line max-depth + if (Type(capture) !== 'Undefined') { + result += ToString(capture); + } + i += '$<' + groupName + '>'.length; + } + } + } else { + result += '$'; + } + } + } else { + // the final $, or else not a $ + result += $charAt(replacement, i); + } + } + return result; +}; diff --git a/node_modules/es-abstract/2019/GetV.js b/node_modules/es-abstract/2019/GetV.js new file mode 100644 index 000000000..7b5139ace --- /dev/null +++ b/node_modules/es-abstract/2019/GetV.js @@ -0,0 +1,29 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsPropertyKey = require('./IsPropertyKey'); +var ToObject = require('./ToObject'); + +/** + * 7.3.2 GetV (V, P) + * 1. Assert: IsPropertyKey(P) is true. + * 2. Let O be ToObject(V). + * 3. ReturnIfAbrupt(O). + * 4. Return O.[[Get]](P, V). + */ + +module.exports = function GetV(V, P) { + // 7.3.2.1 + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true'); + } + + // 7.3.2.2-3 + var O = ToObject(V); + + // 7.3.2.4 + return O[P]; +}; diff --git a/node_modules/es-abstract/2019/HasOwnProperty.js b/node_modules/es-abstract/2019/HasOwnProperty.js new file mode 100644 index 000000000..679059f2e --- /dev/null +++ b/node_modules/es-abstract/2019/HasOwnProperty.js @@ -0,0 +1,22 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var has = require('has'); + +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-hasownproperty + +module.exports = function HasOwnProperty(O, P) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: `O` must be an Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: `P` must be a Property Key'); + } + return has(O, P); +}; diff --git a/node_modules/es-abstract/2019/HasProperty.js b/node_modules/es-abstract/2019/HasProperty.js new file mode 100644 index 000000000..5f2d2122a --- /dev/null +++ b/node_modules/es-abstract/2019/HasProperty.js @@ -0,0 +1,20 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-hasproperty + +module.exports = function HasProperty(O, P) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: `O` must be an Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: `P` must be a Property Key'); + } + return P in O; +}; diff --git a/node_modules/es-abstract/2019/HourFromTime.js b/node_modules/es-abstract/2019/HourFromTime.js new file mode 100644 index 000000000..957ce321a --- /dev/null +++ b/node_modules/es-abstract/2019/HourFromTime.js @@ -0,0 +1,16 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); + +var mod = require('../helpers/mod'); +var timeConstants = require('../helpers/timeConstants'); +var msPerHour = timeConstants.msPerHour; +var HoursPerDay = timeConstants.HoursPerDay; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10 + +module.exports = function HourFromTime(t) { + return mod($floor(t / msPerHour), HoursPerDay); +}; diff --git a/node_modules/es-abstract/2019/InLeapYear.js b/node_modules/es-abstract/2019/InLeapYear.js new file mode 100644 index 000000000..38ba8fdc8 --- /dev/null +++ b/node_modules/es-abstract/2019/InLeapYear.js @@ -0,0 +1,21 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $EvalError = GetIntrinsic('%EvalError%'); + +var DaysInYear = require('./DaysInYear'); +var YearFromTime = require('./YearFromTime'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3 + +module.exports = function InLeapYear(t) { + var days = DaysInYear(YearFromTime(t)); + if (days === 365) { + return 0; + } + if (days === 366) { + return 1; + } + throw new $EvalError('Assertion failed: there are not 365 or 366 days in a year, got: ' + days); +}; diff --git a/node_modules/es-abstract/2019/InstanceofOperator.js b/node_modules/es-abstract/2019/InstanceofOperator.js new file mode 100644 index 000000000..ebd308c4b --- /dev/null +++ b/node_modules/es-abstract/2019/InstanceofOperator.js @@ -0,0 +1,30 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $hasInstance = GetIntrinsic('Symbol.hasInstance', true); + +var Call = require('./Call'); +var GetMethod = require('./GetMethod'); +var IsCallable = require('./IsCallable'); +var OrdinaryHasInstance = require('./OrdinaryHasInstance'); +var ToBoolean = require('./ToBoolean'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator + +module.exports = function InstanceofOperator(O, C) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + var instOfHandler = $hasInstance ? GetMethod(C, $hasInstance) : void 0; + if (typeof instOfHandler !== 'undefined') { + return ToBoolean(Call(instOfHandler, C, [O])); + } + if (!IsCallable(C)) { + throw new $TypeError('`C` is not Callable'); + } + return OrdinaryHasInstance(C, O); +}; diff --git a/node_modules/es-abstract/2019/Invoke.js b/node_modules/es-abstract/2019/Invoke.js new file mode 100644 index 000000000..769f0e308 --- /dev/null +++ b/node_modules/es-abstract/2019/Invoke.js @@ -0,0 +1,22 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $arraySlice = require('../helpers/callBound')('Array.prototype.slice'); + +var Call = require('./Call'); +var GetV = require('./GetV'); +var IsPropertyKey = require('./IsPropertyKey'); + +// https://ecma-international.org/ecma-262/6.0/#sec-invoke + +module.exports = function Invoke(O, P) { + if (!IsPropertyKey(P)) { + throw new $TypeError('P must be a Property Key'); + } + var argumentsList = $arraySlice(arguments, 2); + var func = GetV(O, P); + return Call(func, O, argumentsList); +}; diff --git a/node_modules/es-abstract/2019/IsAccessorDescriptor.js b/node_modules/es-abstract/2019/IsAccessorDescriptor.js new file mode 100644 index 000000000..513946462 --- /dev/null +++ b/node_modules/es-abstract/2019/IsAccessorDescriptor.js @@ -0,0 +1,23 @@ +'use strict'; + +var has = require('has'); + +var assertRecord = require('../helpers/assertRecord'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isaccessordescriptor + +module.exports = function IsAccessorDescriptor(Desc) { + if (typeof Desc === 'undefined') { + return false; + } + + assertRecord(Type, 'Property Descriptor', 'Desc', Desc); + + if (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) { + return false; + } + + return true; +}; diff --git a/node_modules/es-abstract/2019/IsArray.js b/node_modules/es-abstract/2019/IsArray.js new file mode 100644 index 000000000..7b25f37b5 --- /dev/null +++ b/node_modules/es-abstract/2019/IsArray.js @@ -0,0 +1,14 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Array = GetIntrinsic('%Array%'); + +// eslint-disable-next-line global-require +var toStr = !$Array.isArray && require('../helpers/callBound')('Object.prototype.toString'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isarray + +module.exports = $Array.isArray || function IsArray(argument) { + return toStr(argument) === '[object Array]'; +}; diff --git a/node_modules/es-abstract/2019/IsCallable.js b/node_modules/es-abstract/2019/IsCallable.js new file mode 100644 index 000000000..e4bfa365c --- /dev/null +++ b/node_modules/es-abstract/2019/IsCallable.js @@ -0,0 +1,5 @@ +'use strict'; + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.11 + +module.exports = require('is-callable'); diff --git a/node_modules/es-abstract/2019/IsConcatSpreadable.js b/node_modules/es-abstract/2019/IsConcatSpreadable.js new file mode 100644 index 000000000..dc8aae1e6 --- /dev/null +++ b/node_modules/es-abstract/2019/IsConcatSpreadable.js @@ -0,0 +1,25 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $isConcatSpreadable = GetIntrinsic('%Symbol.isConcatSpreadable%', true); + +var Get = require('./Get'); +var IsArray = require('./IsArray'); +var ToBoolean = require('./ToBoolean'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-isconcatspreadable + +module.exports = function IsConcatSpreadable(O) { + if (Type(O) !== 'Object') { + return false; + } + if ($isConcatSpreadable) { + var spreadable = Get(O, $isConcatSpreadable); + if (typeof spreadable !== 'undefined') { + return ToBoolean(spreadable); + } + } + return IsArray(O); +}; diff --git a/node_modules/es-abstract/2019/IsConstructor.js b/node_modules/es-abstract/2019/IsConstructor.js new file mode 100644 index 000000000..8ba9fe55b --- /dev/null +++ b/node_modules/es-abstract/2019/IsConstructor.js @@ -0,0 +1,40 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic.js'); + +var $construct = GetIntrinsic('%Reflect.construct%', true); + +var DefinePropertyOrThrow = require('./DefinePropertyOrThrow'); +try { + DefinePropertyOrThrow({}, '', { '[[Get]]': function () {} }); +} catch (e) { + // Accessor properties aren't supported + DefinePropertyOrThrow = null; +} + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isconstructor + +if (DefinePropertyOrThrow && $construct) { + var isConstructorMarker = {}; + var badArrayLike = {}; + DefinePropertyOrThrow(badArrayLike, 'length', { + '[[Get]]': function () { + throw isConstructorMarker; + }, + '[[Enumerable]]': true + }); + + module.exports = function IsConstructor(argument) { + try { + // `Reflect.construct` invokes `IsConstructor(target)` before `Get(args, 'length')`: + $construct(argument, badArrayLike); + } catch (err) { + return err === isConstructorMarker; + } + }; +} else { + module.exports = function IsConstructor(argument) { + // unfortunately there's no way to truly check this without try/catch `new argument` in old environments + return typeof argument === 'function' && !!argument.prototype; + }; +} diff --git a/node_modules/es-abstract/2019/IsDataDescriptor.js b/node_modules/es-abstract/2019/IsDataDescriptor.js new file mode 100644 index 000000000..0ad304585 --- /dev/null +++ b/node_modules/es-abstract/2019/IsDataDescriptor.js @@ -0,0 +1,23 @@ +'use strict'; + +var has = require('has'); + +var assertRecord = require('../helpers/assertRecord'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isdatadescriptor + +module.exports = function IsDataDescriptor(Desc) { + if (typeof Desc === 'undefined') { + return false; + } + + assertRecord(Type, 'Property Descriptor', 'Desc', Desc); + + if (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) { + return false; + } + + return true; +}; diff --git a/node_modules/es-abstract/2019/IsExtensible.js b/node_modules/es-abstract/2019/IsExtensible.js new file mode 100644 index 000000000..0c4c8a60c --- /dev/null +++ b/node_modules/es-abstract/2019/IsExtensible.js @@ -0,0 +1,20 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Object = GetIntrinsic('%Object%'); + +var isPrimitive = require('../helpers/isPrimitive'); + +var $preventExtensions = $Object.preventExtensions; +var $isExtensible = $Object.isExtensible; + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isextensible-o + +module.exports = $preventExtensions + ? function IsExtensible(obj) { + return !isPrimitive(obj) && $isExtensible(obj); + } + : function IsExtensible(obj) { + return !isPrimitive(obj); + }; diff --git a/node_modules/es-abstract/2019/IsGenericDescriptor.js b/node_modules/es-abstract/2019/IsGenericDescriptor.js new file mode 100644 index 000000000..8618ce414 --- /dev/null +++ b/node_modules/es-abstract/2019/IsGenericDescriptor.js @@ -0,0 +1,23 @@ +'use strict'; + +var assertRecord = require('../helpers/assertRecord'); + +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isgenericdescriptor + +module.exports = function IsGenericDescriptor(Desc) { + if (typeof Desc === 'undefined') { + return false; + } + + assertRecord(Type, 'Property Descriptor', 'Desc', Desc); + + if (!IsAccessorDescriptor(Desc) && !IsDataDescriptor(Desc)) { + return true; + } + + return false; +}; diff --git a/node_modules/es-abstract/2019/IsInteger.js b/node_modules/es-abstract/2019/IsInteger.js new file mode 100644 index 000000000..0f488b39a --- /dev/null +++ b/node_modules/es-abstract/2019/IsInteger.js @@ -0,0 +1,21 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Math = GetIntrinsic('%Math%'); + +var $floor = $Math.floor; +var $abs = $Math.abs; + +var $isNaN = require('../helpers/isNaN'); +var $isFinite = require('../helpers/isFinite'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-isinteger + +module.exports = function IsInteger(argument) { + if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) { + return false; + } + var abs = $abs(argument); + return $floor(abs) === abs; +}; diff --git a/node_modules/es-abstract/2019/IsPromise.js b/node_modules/es-abstract/2019/IsPromise.js new file mode 100644 index 000000000..e8e92a2b8 --- /dev/null +++ b/node_modules/es-abstract/2019/IsPromise.js @@ -0,0 +1,24 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); + +var $PromiseThen = callBound('Promise.prototype.then', true); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ispromise + +module.exports = function IsPromise(x) { + if (Type(x) !== 'Object') { + return false; + } + if (!$PromiseThen) { // Promises are not supported + return false; + } + try { + $PromiseThen(x); // throws if not a promise + } catch (e) { + return false; + } + return true; +}; diff --git a/node_modules/es-abstract/2019/IsPropertyKey.js b/node_modules/es-abstract/2019/IsPropertyKey.js new file mode 100644 index 000000000..74b8d95d4 --- /dev/null +++ b/node_modules/es-abstract/2019/IsPropertyKey.js @@ -0,0 +1,7 @@ +'use strict'; + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ispropertykey + +module.exports = function IsPropertyKey(argument) { + return typeof argument === 'string' || typeof argument === 'symbol'; +}; diff --git a/node_modules/es-abstract/2019/IsRegExp.js b/node_modules/es-abstract/2019/IsRegExp.js new file mode 100644 index 000000000..fdf2323ff --- /dev/null +++ b/node_modules/es-abstract/2019/IsRegExp.js @@ -0,0 +1,24 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $match = GetIntrinsic('%Symbol.match%', true); + +var hasRegExpMatcher = require('is-regex'); + +var ToBoolean = require('./ToBoolean'); + +// https://ecma-international.org/ecma-262/6.0/#sec-isregexp + +module.exports = function IsRegExp(argument) { + if (!argument || typeof argument !== 'object') { + return false; + } + if ($match) { + var isRegExp = argument[$match]; + if (typeof isRegExp !== 'undefined') { + return ToBoolean(isRegExp); + } + } + return hasRegExpMatcher(argument); +}; diff --git a/node_modules/es-abstract/2019/IsStringPrefix.js b/node_modules/es-abstract/2019/IsStringPrefix.js new file mode 100644 index 000000000..f5e299623 --- /dev/null +++ b/node_modules/es-abstract/2019/IsStringPrefix.js @@ -0,0 +1,47 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var isPrefixOf = require('../helpers/isPrefixOf'); + +// var callBound = require('../helpers/callBound'); + +// var $charAt = callBound('String.prototype.charAt'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/9.0/#sec-isstringprefix + +module.exports = function IsStringPrefix(p, q) { + if (Type(p) !== 'String') { + throw new $TypeError('Assertion failed: "p" must be a String'); + } + + if (Type(q) !== 'String') { + throw new $TypeError('Assertion failed: "q" must be a String'); + } + + return isPrefixOf(p, q); + /* + if (p === q || p === '') { + return true; + } + + var pLength = p.length; + var qLength = q.length; + if (pLength >= qLength) { + return false; + } + + // assert: pLength < qLength + + for (var i = 0; i < pLength; i += 1) { + if ($charAt(p, i) !== $charAt(q, i)) { + return false; + } + } + return true; + */ +}; diff --git a/node_modules/es-abstract/2019/IterableToList.js b/node_modules/es-abstract/2019/IterableToList.js new file mode 100644 index 000000000..0b8cdcfe3 --- /dev/null +++ b/node_modules/es-abstract/2019/IterableToList.js @@ -0,0 +1,24 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); +var $arrayPush = callBound('Array.prototype.push'); + +var GetIterator = require('./GetIterator'); +var IteratorStep = require('./IteratorStep'); +var IteratorValue = require('./IteratorValue'); + +// https://www.ecma-international.org/ecma-262/8.0/#sec-iterabletolist + +module.exports = function IterableToList(items, method) { + var iterator = GetIterator(items, method); + var values = []; + var next = true; + while (next) { + next = IteratorStep(iterator); + if (next) { + var nextValue = IteratorValue(next); + $arrayPush(values, nextValue); + } + } + return values; +}; diff --git a/node_modules/es-abstract/2019/IteratorClose.js b/node_modules/es-abstract/2019/IteratorClose.js new file mode 100644 index 000000000..35c8c2bea --- /dev/null +++ b/node_modules/es-abstract/2019/IteratorClose.js @@ -0,0 +1,50 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Call = require('./Call'); +var GetMethod = require('./GetMethod'); +var IsCallable = require('./IsCallable'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-iteratorclose + +module.exports = function IteratorClose(iterator, completion) { + if (Type(iterator) !== 'Object') { + throw new $TypeError('Assertion failed: Type(iterator) is not Object'); + } + if (!IsCallable(completion)) { + throw new $TypeError('Assertion failed: completion is not a thunk for a Completion Record'); + } + var completionThunk = completion; + + var iteratorReturn = GetMethod(iterator, 'return'); + + if (typeof iteratorReturn === 'undefined') { + return completionThunk(); + } + + var completionRecord; + try { + var innerResult = Call(iteratorReturn, iterator, []); + } catch (e) { + // if we hit here, then "e" is the innerResult completion that needs re-throwing + + // if the completion is of type "throw", this will throw. + completionThunk(); + completionThunk = null; // ensure it's not called twice. + + // if not, then return the innerResult completion + throw e; + } + completionRecord = completionThunk(); // if innerResult worked, then throw if the completion does + completionThunk = null; // ensure it's not called twice. + + if (Type(innerResult) !== 'Object') { + throw new $TypeError('iterator .return must return an object'); + } + + return completionRecord; +}; diff --git a/node_modules/es-abstract/2019/IteratorComplete.js b/node_modules/es-abstract/2019/IteratorComplete.js new file mode 100644 index 000000000..a62b9bfc1 --- /dev/null +++ b/node_modules/es-abstract/2019/IteratorComplete.js @@ -0,0 +1,18 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Get = require('./Get'); +var ToBoolean = require('./ToBoolean'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-iteratorcomplete + +module.exports = function IteratorComplete(iterResult) { + if (Type(iterResult) !== 'Object') { + throw new $TypeError('Assertion failed: Type(iterResult) is not Object'); + } + return ToBoolean(Get(iterResult, 'done')); +}; diff --git a/node_modules/es-abstract/2019/IteratorNext.js b/node_modules/es-abstract/2019/IteratorNext.js new file mode 100644 index 000000000..7e5991561 --- /dev/null +++ b/node_modules/es-abstract/2019/IteratorNext.js @@ -0,0 +1,18 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Invoke = require('./Invoke'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-iteratornext + +module.exports = function IteratorNext(iterator, value) { + var result = Invoke(iterator, 'next', arguments.length < 2 ? [] : [value]); + if (Type(result) !== 'Object') { + throw new $TypeError('iterator next must return an object'); + } + return result; +}; diff --git a/node_modules/es-abstract/2019/IteratorStep.js b/node_modules/es-abstract/2019/IteratorStep.js new file mode 100644 index 000000000..41b9d1b25 --- /dev/null +++ b/node_modules/es-abstract/2019/IteratorStep.js @@ -0,0 +1,13 @@ +'use strict'; + +var IteratorComplete = require('./IteratorComplete'); +var IteratorNext = require('./IteratorNext'); + +// https://ecma-international.org/ecma-262/6.0/#sec-iteratorstep + +module.exports = function IteratorStep(iterator) { + var result = IteratorNext(iterator); + var done = IteratorComplete(result); + return done === true ? false : result; +}; + diff --git a/node_modules/es-abstract/2019/IteratorValue.js b/node_modules/es-abstract/2019/IteratorValue.js new file mode 100644 index 000000000..5e71a4463 --- /dev/null +++ b/node_modules/es-abstract/2019/IteratorValue.js @@ -0,0 +1,18 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Get = require('./Get'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-iteratorvalue + +module.exports = function IteratorValue(iterResult) { + if (Type(iterResult) !== 'Object') { + throw new $TypeError('Assertion failed: Type(iterResult) is not Object'); + } + return Get(iterResult, 'value'); +}; + diff --git a/node_modules/es-abstract/2019/MakeDate.js b/node_modules/es-abstract/2019/MakeDate.js new file mode 100644 index 000000000..7b592d136 --- /dev/null +++ b/node_modules/es-abstract/2019/MakeDate.js @@ -0,0 +1,13 @@ +'use strict'; + +var $isFinite = require('../helpers/isFinite'); +var msPerDay = require('../helpers/timeConstants').msPerDay; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.13 + +module.exports = function MakeDate(day, time) { + if (!$isFinite(day) || !$isFinite(time)) { + return NaN; + } + return (day * msPerDay) + time; +}; diff --git a/node_modules/es-abstract/2019/MakeDay.js b/node_modules/es-abstract/2019/MakeDay.js new file mode 100644 index 000000000..f1ab81060 --- /dev/null +++ b/node_modules/es-abstract/2019/MakeDay.js @@ -0,0 +1,33 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); +var $DateUTC = GetIntrinsic('%Date.UTC%'); + +var mod = require('../helpers/mod'); +var $isFinite = require('../helpers/isFinite'); + +var DateFromTime = require('./DateFromTime'); +var Day = require('./Day'); +var MonthFromTime = require('./MonthFromTime'); +var ToInteger = require('./ToInteger'); +var YearFromTime = require('./YearFromTime'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.12 + +module.exports = function MakeDay(year, month, date) { + if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) { + return NaN; + } + var y = ToInteger(year); + var m = ToInteger(month); + var dt = ToInteger(date); + var ym = y + $floor(m / 12); + var mn = mod(m, 12); + var t = $DateUTC(ym, mn, 1); + if (YearFromTime(t) !== ym || MonthFromTime(t) !== mn || DateFromTime(t) !== 1) { + return NaN; + } + return Day(t) + dt - 1; +}; diff --git a/node_modules/es-abstract/2019/MakeTime.js b/node_modules/es-abstract/2019/MakeTime.js new file mode 100644 index 000000000..e11850040 --- /dev/null +++ b/node_modules/es-abstract/2019/MakeTime.js @@ -0,0 +1,23 @@ +'use strict'; + +var $isFinite = require('../helpers/isFinite'); +var timeConstants = require('../helpers/timeConstants'); +var msPerSecond = timeConstants.msPerSecond; +var msPerMinute = timeConstants.msPerMinute; +var msPerHour = timeConstants.msPerHour; + +var ToInteger = require('./ToInteger'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.11 + +module.exports = function MakeTime(hour, min, sec, ms) { + if (!$isFinite(hour) || !$isFinite(min) || !$isFinite(sec) || !$isFinite(ms)) { + return NaN; + } + var h = ToInteger(hour); + var m = ToInteger(min); + var s = ToInteger(sec); + var milli = ToInteger(ms); + var t = (h * msPerHour) + (m * msPerMinute) + (s * msPerSecond) + milli; + return t; +}; diff --git a/node_modules/es-abstract/2019/MinFromTime.js b/node_modules/es-abstract/2019/MinFromTime.js new file mode 100644 index 000000000..e80e19108 --- /dev/null +++ b/node_modules/es-abstract/2019/MinFromTime.js @@ -0,0 +1,16 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); + +var mod = require('../helpers/mod'); +var timeConstants = require('../helpers/timeConstants'); +var msPerMinute = timeConstants.msPerMinute; +var MinutesPerHour = timeConstants.MinutesPerHour; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10 + +module.exports = function MinFromTime(t) { + return mod($floor(t / msPerMinute), MinutesPerHour); +}; diff --git a/node_modules/es-abstract/2019/MonthFromTime.js b/node_modules/es-abstract/2019/MonthFromTime.js new file mode 100644 index 000000000..4f120f2c2 --- /dev/null +++ b/node_modules/es-abstract/2019/MonthFromTime.js @@ -0,0 +1,47 @@ +'use strict'; + +var DayWithinYear = require('./DayWithinYear'); +var InLeapYear = require('./InLeapYear'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4 + +module.exports = function MonthFromTime(t) { + var day = DayWithinYear(t); + if (0 <= day && day < 31) { + return 0; + } + var leap = InLeapYear(t); + if (31 <= day && day < (59 + leap)) { + return 1; + } + if ((59 + leap) <= day && day < (90 + leap)) { + return 2; + } + if ((90 + leap) <= day && day < (120 + leap)) { + return 3; + } + if ((120 + leap) <= day && day < (151 + leap)) { + return 4; + } + if ((151 + leap) <= day && day < (181 + leap)) { + return 5; + } + if ((181 + leap) <= day && day < (212 + leap)) { + return 6; + } + if ((212 + leap) <= day && day < (243 + leap)) { + return 7; + } + if ((243 + leap) <= day && day < (273 + leap)) { + return 8; + } + if ((273 + leap) <= day && day < (304 + leap)) { + return 9; + } + if ((304 + leap) <= day && day < (334 + leap)) { + return 10; + } + if ((334 + leap) <= day && day < (365 + leap)) { + return 11; + } +}; diff --git a/node_modules/es-abstract/2019/NumberToString.js b/node_modules/es-abstract/2019/NumberToString.js new file mode 100644 index 000000000..2cc70e008 --- /dev/null +++ b/node_modules/es-abstract/2019/NumberToString.js @@ -0,0 +1,18 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $String = GetIntrinsic('%String%'); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/9.0/#sec-tostring-applied-to-the-number-type + +module.exports = function NumberToString(m) { + if (Type(m) !== 'Number') { + throw new TypeError('Assertion failed: "m" must be a String'); + } + + return $String(m); +}; + diff --git a/node_modules/es-abstract/2019/ObjectCreate.js b/node_modules/es-abstract/2019/ObjectCreate.js new file mode 100644 index 000000000..e2445b022 --- /dev/null +++ b/node_modules/es-abstract/2019/ObjectCreate.js @@ -0,0 +1,37 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $ObjectCreate = GetIntrinsic('%Object.create%', true); +var $TypeError = GetIntrinsic('%TypeError%'); +var $SyntaxError = GetIntrinsic('%SyntaxError%'); + +var Type = require('./Type'); + +var hasProto = !({ __proto__: null } instanceof Object); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate + +module.exports = function ObjectCreate(proto, internalSlotsList) { + if (proto !== null && Type(proto) !== 'Object') { + throw new $TypeError('Assertion failed: `proto` must be null or an object'); + } + var slots = arguments.length < 2 ? [] : internalSlotsList; + if (slots.length > 0) { + throw new $SyntaxError('es-abstract does not yet support internal slots'); + } + + if ($ObjectCreate) { + return $ObjectCreate(proto); + } + if (hasProto) { + return { __proto__: proto }; + } + + if (proto === null) { + throw new $SyntaxError('native Object.create support is required to create null objects'); + } + var T = function T() {}; + T.prototype = proto; + return new T(); +}; diff --git a/node_modules/es-abstract/2019/OrdinaryDefineOwnProperty.js b/node_modules/es-abstract/2019/OrdinaryDefineOwnProperty.js new file mode 100644 index 000000000..59780b3bb --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinaryDefineOwnProperty.js @@ -0,0 +1,61 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $gOPD = require('../helpers/getOwnPropertyDescriptor'); +var $SyntaxError = GetIntrinsic('%SyntaxError%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var isPropertyDescriptor = require('../helpers/isPropertyDescriptor'); + +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsExtensible = require('./IsExtensible'); +var IsPropertyKey = require('./IsPropertyKey'); +var ToPropertyDescriptor = require('./ToPropertyDescriptor'); +var SameValue = require('./SameValue'); +var Type = require('./Type'); +var ValidateAndApplyPropertyDescriptor = require('./ValidateAndApplyPropertyDescriptor'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarydefineownproperty + +module.exports = function OrdinaryDefineOwnProperty(O, P, Desc) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: O must be an Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: P must be a Property Key'); + } + if (!isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, Desc)) { + throw new $TypeError('Assertion failed: Desc must be a Property Descriptor'); + } + if (!$gOPD) { + // ES3/IE 8 fallback + if (IsAccessorDescriptor(Desc)) { + throw new $SyntaxError('This environment does not support accessor property descriptors.'); + } + var creatingNormalDataProperty = !(P in O) + && Desc['[[Writable]]'] + && Desc['[[Enumerable]]'] + && Desc['[[Configurable]]'] + && '[[Value]]' in Desc; + var settingExistingDataProperty = (P in O) + && (!('[[Configurable]]' in Desc) || Desc['[[Configurable]]']) + && (!('[[Enumerable]]' in Desc) || Desc['[[Enumerable]]']) + && (!('[[Writable]]' in Desc) || Desc['[[Writable]]']) + && '[[Value]]' in Desc; + if (creatingNormalDataProperty || settingExistingDataProperty) { + O[P] = Desc['[[Value]]']; // eslint-disable-line no-param-reassign + return SameValue(O[P], Desc['[[Value]]']); + } + throw new $SyntaxError('This environment does not support defining non-writable, non-enumerable, or non-configurable properties'); + } + var desc = $gOPD(O, P); + var current = desc && ToPropertyDescriptor(desc); + var extensible = IsExtensible(O); + return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current); +}; diff --git a/node_modules/es-abstract/2019/OrdinaryGetOwnProperty.js b/node_modules/es-abstract/2019/OrdinaryGetOwnProperty.js new file mode 100644 index 000000000..b9882e5dc --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinaryGetOwnProperty.js @@ -0,0 +1,44 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $gOPD = require('../helpers/getOwnPropertyDescriptor'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var callBound = require('../helpers/callBound'); + +var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); + +var has = require('has'); + +var IsArray = require('./IsArray'); +var IsPropertyKey = require('./IsPropertyKey'); +var IsRegExp = require('./IsRegExp'); +var ToPropertyDescriptor = require('./ToPropertyDescriptor'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty + +module.exports = function OrdinaryGetOwnProperty(O, P) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: O must be an Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: P must be a Property Key'); + } + if (!has(O, P)) { + return void 0; + } + if (!$gOPD) { + // ES3 / IE 8 fallback + var arrayLength = IsArray(O) && P === 'length'; + var regexLastIndex = IsRegExp(O) && P === 'lastIndex'; + return { + '[[Configurable]]': !(arrayLength || regexLastIndex), + '[[Enumerable]]': $isEnumerable(O, P), + '[[Value]]': O[P], + '[[Writable]]': true + }; + } + return ToPropertyDescriptor($gOPD(O, P)); +}; diff --git a/node_modules/es-abstract/2019/OrdinaryGetPrototypeOf.js b/node_modules/es-abstract/2019/OrdinaryGetPrototypeOf.js new file mode 100644 index 000000000..344077a40 --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinaryGetPrototypeOf.js @@ -0,0 +1,21 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $getProto = require('../helpers/getProto'); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/7.0/#sec-ordinarygetprototypeof + +module.exports = function OrdinaryGetPrototypeOf(O) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: O must be an Object'); + } + if (!$getProto) { + throw new $TypeError('This environment does not support fetching prototypes.'); + } + return $getProto(O); +}; diff --git a/node_modules/es-abstract/2019/OrdinaryHasInstance.js b/node_modules/es-abstract/2019/OrdinaryHasInstance.js new file mode 100644 index 000000000..51abe26d5 --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinaryHasInstance.js @@ -0,0 +1,25 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Get = require('./Get'); +var IsCallable = require('./IsCallable'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasinstance + +module.exports = function OrdinaryHasInstance(C, O) { + if (IsCallable(C) === false) { + return false; + } + if (Type(O) !== 'Object') { + return false; + } + var P = Get(C, 'prototype'); + if (Type(P) !== 'Object') { + throw new $TypeError('OrdinaryHasInstance called on an object with an invalid prototype property.'); + } + return O instanceof C; +}; diff --git a/node_modules/es-abstract/2019/OrdinaryHasProperty.js b/node_modules/es-abstract/2019/OrdinaryHasProperty.js new file mode 100644 index 000000000..076c25ac5 --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinaryHasProperty.js @@ -0,0 +1,20 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsPropertyKey = require('./IsPropertyKey'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasproperty + +module.exports = function OrdinaryHasProperty(O, P) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: P must be a Property Key'); + } + return P in O; +}; diff --git a/node_modules/es-abstract/2019/OrdinarySetPrototypeOf.js b/node_modules/es-abstract/2019/OrdinarySetPrototypeOf.js new file mode 100644 index 000000000..3541331ca --- /dev/null +++ b/node_modules/es-abstract/2019/OrdinarySetPrototypeOf.js @@ -0,0 +1,53 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $setProto = require('../helpers/setProto'); + +var OrdinaryGetPrototypeOf = require('./OrdinaryGetPrototypeOf'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/7.0/#sec-ordinarysetprototypeof + +module.exports = function OrdinarySetPrototypeOf(O, V) { + if (Type(V) !== 'Object' && Type(V) !== 'Null') { + throw new $TypeError('Assertion failed: V must be Object or Null'); + } + /* + var extensible = IsExtensible(O); + var current = OrdinaryGetPrototypeOf(O); + if (SameValue(V, current)) { + return true; + } + if (!extensible) { + return false; + } + */ + try { + $setProto(O, V); + } catch (e) { + return false; + } + return OrdinaryGetPrototypeOf(O) === V; + /* + var p = V; + var done = false; + while (!done) { + if (p === null) { + done = true; + } else if (SameValue(p, O)) { + return false; + } else { + if (wat) { + done = true; + } else { + p = p.[[Prototype]]; + } + } + } + O.[[Prototype]] = V; + return true; + */ +}; diff --git a/node_modules/es-abstract/2019/PromiseResolve.js b/node_modules/es-abstract/2019/PromiseResolve.js new file mode 100644 index 000000000..f70745df7 --- /dev/null +++ b/node_modules/es-abstract/2019/PromiseResolve.js @@ -0,0 +1,15 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); + +var $PromiseResolve = callBound('Promise.resolve', true); + +// https://ecma-international.org/ecma-262/9.0/#sec-promise-resolve + +module.exports = function PromiseResolve(C, x) { + if (!$PromiseResolve) { + throw new SyntaxError('This environment does not support Promises.'); + } + return $PromiseResolve(C, x); +}; + diff --git a/node_modules/es-abstract/2019/RegExpExec.js b/node_modules/es-abstract/2019/RegExpExec.js new file mode 100644 index 000000000..15c91867d --- /dev/null +++ b/node_modules/es-abstract/2019/RegExpExec.js @@ -0,0 +1,32 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var regexExec = require('../helpers/callBound')('RegExp.prototype.exec'); + +var Call = require('./Call'); +var Get = require('./Get'); +var IsCallable = require('./IsCallable'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-regexpexec + +module.exports = function RegExpExec(R, S) { + if (Type(R) !== 'Object') { + throw new $TypeError('Assertion failed: `R` must be an Object'); + } + if (Type(S) !== 'String') { + throw new $TypeError('Assertion failed: `S` must be a String'); + } + var exec = Get(R, 'exec'); + if (IsCallable(exec)) { + var result = Call(exec, R, [S]); + if (result === null || Type(result) === 'Object') { + return result; + } + throw new $TypeError('"exec" method must return `null` or an Object'); + } + return regexExec(R, S); +}; diff --git a/node_modules/es-abstract/2019/RequireObjectCoercible.js b/node_modules/es-abstract/2019/RequireObjectCoercible.js new file mode 100644 index 000000000..9008359db --- /dev/null +++ b/node_modules/es-abstract/2019/RequireObjectCoercible.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('../5/CheckObjectCoercible'); diff --git a/node_modules/es-abstract/2019/SameValue.js b/node_modules/es-abstract/2019/SameValue.js new file mode 100644 index 000000000..47c936d76 --- /dev/null +++ b/node_modules/es-abstract/2019/SameValue.js @@ -0,0 +1,13 @@ +'use strict'; + +var $isNaN = require('../helpers/isNaN'); + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.12 + +module.exports = function SameValue(x, y) { + if (x === y) { // 0 === -0, but they are not identical. + if (x === 0) { return 1 / x === 1 / y; } + return true; + } + return $isNaN(x) && $isNaN(y); +}; diff --git a/node_modules/es-abstract/2019/SameValueNonNumber.js b/node_modules/es-abstract/2019/SameValueNonNumber.js new file mode 100644 index 000000000..5668752e3 --- /dev/null +++ b/node_modules/es-abstract/2019/SameValueNonNumber.js @@ -0,0 +1,16 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var SameValue = require('./SameValue'); + +// https://www.ecma-international.org/ecma-262/7.0/#sec-samevaluenonnumber + +module.exports = function SameValueNonNumber(x, y) { + if (typeof x === 'number' || typeof x !== typeof y) { + throw new $TypeError('SameValueNonNumber requires two non-number values of the same type.'); + } + return SameValue(x, y); +}; diff --git a/node_modules/es-abstract/2019/SameValueZero.js b/node_modules/es-abstract/2019/SameValueZero.js new file mode 100644 index 000000000..0dedcd2c3 --- /dev/null +++ b/node_modules/es-abstract/2019/SameValueZero.js @@ -0,0 +1,9 @@ +'use strict'; + +var $isNaN = require('../helpers/isNaN'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero + +module.exports = function SameValueZero(x, y) { + return (x === y) || ($isNaN(x) && $isNaN(y)); +}; diff --git a/node_modules/es-abstract/2019/SecFromTime.js b/node_modules/es-abstract/2019/SecFromTime.js new file mode 100644 index 000000000..7190011d2 --- /dev/null +++ b/node_modules/es-abstract/2019/SecFromTime.js @@ -0,0 +1,16 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $floor = GetIntrinsic('%Math.floor%'); + +var mod = require('../helpers/mod'); +var timeConstants = require('../helpers/timeConstants'); +var msPerSecond = timeConstants.msPerSecond; +var SecondsPerMinute = timeConstants.SecondsPerMinute; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10 + +module.exports = function SecFromTime(t) { + return mod($floor(t / msPerSecond), SecondsPerMinute); +}; diff --git a/node_modules/es-abstract/2019/Set.js b/node_modules/es-abstract/2019/Set.js new file mode 100644 index 000000000..9545b1325 --- /dev/null +++ b/node_modules/es-abstract/2019/Set.js @@ -0,0 +1,47 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var Type = require('./Type'); + +// IE 9 does not throw in strict mode when writability/configurability/extensibility is violated +var noThrowOnStrictViolation = (function () { + try { + delete [].length; + return true; + } catch (e) { + return false; + } +}()); + +// https://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw + +module.exports = function Set(O, P, V, Throw) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: `O` must be an Object'); + } + if (!IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: `P` must be a Property Key'); + } + if (Type(Throw) !== 'Boolean') { + throw new $TypeError('Assertion failed: `Throw` must be a Boolean'); + } + if (Throw) { + O[P] = V; // eslint-disable-line no-param-reassign + if (noThrowOnStrictViolation && !SameValue(O[P], V)) { + throw new $TypeError('Attempted to assign to readonly property.'); + } + return true; + } else { + try { + O[P] = V; // eslint-disable-line no-param-reassign + return noThrowOnStrictViolation ? SameValue(O[P], V) : true; + } catch (e) { + return false; + } + } +}; diff --git a/node_modules/es-abstract/2019/SetFunctionName.js b/node_modules/es-abstract/2019/SetFunctionName.js new file mode 100644 index 000000000..f93324a73 --- /dev/null +++ b/node_modules/es-abstract/2019/SetFunctionName.js @@ -0,0 +1,44 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var has = require('has'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var getSymbolDescription = require('../helpers/getSymbolDescription'); + +var DefinePropertyOrThrow = require('./DefinePropertyOrThrow'); +var IsExtensible = require('./IsExtensible'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-setfunctionname + +module.exports = function SetFunctionName(F, name) { + if (typeof F !== 'function') { + throw new $TypeError('Assertion failed: `F` must be a function'); + } + if (!IsExtensible(F) || has(F, 'name')) { + throw new $TypeError('Assertion failed: `F` must be extensible, and must not have a `name` own property'); + } + var nameType = Type(name); + if (nameType !== 'Symbol' && nameType !== 'String') { + throw new $TypeError('Assertion failed: `name` must be a Symbol or a String'); + } + if (nameType === 'Symbol') { + var description = getSymbolDescription(name); + // eslint-disable-next-line no-param-reassign + name = typeof description === 'undefined' ? '' : '[' + description + ']'; + } + if (arguments.length > 2) { + var prefix = arguments[2]; + // eslint-disable-next-line no-param-reassign + name = prefix + ' ' + name; + } + return DefinePropertyOrThrow(F, 'name', { + '[[Value]]': name, + '[[Writable]]': false, + '[[Enumerable]]': false, + '[[Configurable]]': true + }); +}; diff --git a/node_modules/es-abstract/2019/SetIntegrityLevel.js b/node_modules/es-abstract/2019/SetIntegrityLevel.js new file mode 100644 index 000000000..3d5c81d56 --- /dev/null +++ b/node_modules/es-abstract/2019/SetIntegrityLevel.js @@ -0,0 +1,57 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $SyntaxError = GetIntrinsic('%SyntaxError%'); +var $TypeError = GetIntrinsic('%TypeError%'); +var $preventExtensions = GetIntrinsic('%Object.preventExtensions%'); +var $gOPD = require('../helpers/getOwnPropertyDescriptor'); +var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%'); + +var forEach = require('../helpers/forEach'); + +var DefinePropertyOrThrow = require('./DefinePropertyOrThrow'); +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var ToPropertyDescriptor = require('./ToPropertyDescriptor'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-setintegritylevel + +module.exports = function SetIntegrityLevel(O, level) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (level !== 'sealed' && level !== 'frozen') { + throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`'); + } + if (!$preventExtensions) { + throw new $SyntaxError('SetIntegrityLevel requires native `Object.preventExtensions` support'); + } + var status = $preventExtensions(O); + if (!status) { + return false; + } + if (!$gOPN) { + throw new $SyntaxError('SetIntegrityLevel requires native `Object.getOwnPropertyNames` support'); + } + var theKeys = $gOPN(O); + if (level === 'sealed') { + forEach(theKeys, function (k) { + DefinePropertyOrThrow(O, k, { configurable: false }); + }); + } else if (level === 'frozen') { + forEach(theKeys, function (k) { + var currentDesc = $gOPD(O, k); + if (typeof currentDesc !== 'undefined') { + var desc; + if (IsAccessorDescriptor(ToPropertyDescriptor(currentDesc))) { + desc = { configurable: false }; + } else { + desc = { configurable: false, writable: false }; + } + DefinePropertyOrThrow(O, k, desc); + } + }); + } + return true; +}; diff --git a/node_modules/es-abstract/2019/SpeciesConstructor.js b/node_modules/es-abstract/2019/SpeciesConstructor.js new file mode 100644 index 000000000..3cdcd747d --- /dev/null +++ b/node_modules/es-abstract/2019/SpeciesConstructor.js @@ -0,0 +1,32 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $species = GetIntrinsic('%Symbol.species%', true); +var $TypeError = GetIntrinsic('%TypeError%'); + +var IsConstructor = require('./IsConstructor'); +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-speciesconstructor + +module.exports = function SpeciesConstructor(O, defaultConstructor) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + var C = O.constructor; + if (typeof C === 'undefined') { + return defaultConstructor; + } + if (Type(C) !== 'Object') { + throw new $TypeError('O.constructor is not an Object'); + } + var S = $species ? C[$species] : void 0; + if (S == null) { + return defaultConstructor; + } + if (IsConstructor(S)) { + return S; + } + throw new $TypeError('no constructor found'); +}; diff --git a/node_modules/es-abstract/2019/StrictEqualityComparison.js b/node_modules/es-abstract/2019/StrictEqualityComparison.js new file mode 100644 index 000000000..eea5df388 --- /dev/null +++ b/node_modules/es-abstract/2019/StrictEqualityComparison.js @@ -0,0 +1,17 @@ +'use strict'; + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6 + +module.exports = function StrictEqualityComparison(x, y) { + var xType = Type(x); + var yType = Type(y); + if (xType !== yType) { + return false; + } + if (xType === 'Undefined' || xType === 'Null') { + return true; + } + return x === y; // shortcut for steps 4-7 +}; diff --git a/node_modules/es-abstract/2019/SymbolDescriptiveString.js b/node_modules/es-abstract/2019/SymbolDescriptiveString.js new file mode 100644 index 000000000..7bd8191ad --- /dev/null +++ b/node_modules/es-abstract/2019/SymbolDescriptiveString.js @@ -0,0 +1,20 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var callBound = require('../helpers/callBound'); + +var $SymbolToString = callBound('Symbol.prototype.toString', true); + +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-symboldescriptivestring + +module.exports = function SymbolDescriptiveString(sym) { + if (Type(sym) !== 'Symbol') { + throw new $TypeError('Assertion failed: `sym` must be a Symbol'); + } + return $SymbolToString(sym); +}; diff --git a/node_modules/es-abstract/2019/TestIntegrityLevel.js b/node_modules/es-abstract/2019/TestIntegrityLevel.js new file mode 100644 index 000000000..7a57397d5 --- /dev/null +++ b/node_modules/es-abstract/2019/TestIntegrityLevel.js @@ -0,0 +1,42 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $gOPD = require('../helpers/getOwnPropertyDescriptor'); +var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +var every = require('../helpers/every'); + +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsExtensible = require('./IsExtensible'); +var ToPropertyDescriptor = require('./ToPropertyDescriptor'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-testintegritylevel + +module.exports = function TestIntegrityLevel(O, level) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + if (level !== 'sealed' && level !== 'frozen') { + throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`'); + } + var status = IsExtensible(O); + if (status) { + return false; + } + var theKeys = $gOPN(O); + return theKeys.length === 0 || every(theKeys, function (k) { + var currentDesc = $gOPD(O, k); + if (typeof currentDesc !== 'undefined') { + if (currentDesc.configurable) { + return false; + } + if (level === 'frozen' && IsDataDescriptor(ToPropertyDescriptor(currentDesc)) && currentDesc.writable) { + return false; + } + } + return true; + }); +}; diff --git a/node_modules/es-abstract/2019/TimeClip.js b/node_modules/es-abstract/2019/TimeClip.js new file mode 100644 index 000000000..57aa08cb9 --- /dev/null +++ b/node_modules/es-abstract/2019/TimeClip.js @@ -0,0 +1,21 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Date = GetIntrinsic('%Date%'); +var $Number = GetIntrinsic('%Number%'); +var $abs = GetIntrinsic('%Math.abs%'); + +var $isFinite = require('../helpers/isFinite'); + +var ToNumber = require('./ToNumber'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.14 + +module.exports = function TimeClip(time) { + if (!$isFinite(time) || $abs(time) > 8.64e15) { + return NaN; + } + return $Number(new $Date(ToNumber(time))); +}; + diff --git a/node_modules/es-abstract/2019/TimeFromYear.js b/node_modules/es-abstract/2019/TimeFromYear.js new file mode 100644 index 000000000..df646c36e --- /dev/null +++ b/node_modules/es-abstract/2019/TimeFromYear.js @@ -0,0 +1,11 @@ +'use strict'; + +var msPerDay = require('../helpers/timeConstants').msPerDay; + +var DayFromYear = require('./DayFromYear'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3 + +module.exports = function TimeFromYear(y) { + return msPerDay * DayFromYear(y); +}; diff --git a/node_modules/es-abstract/2019/TimeString.js b/node_modules/es-abstract/2019/TimeString.js new file mode 100644 index 000000000..87642eb54 --- /dev/null +++ b/node_modules/es-abstract/2019/TimeString.js @@ -0,0 +1,25 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $isNaN = require('../helpers/isNaN'); +var padTimeComponent = require('../helpers/padTimeComponent'); + +var HourFromTime = require('./HourFromTime'); +var MinFromTime = require('./MinFromTime'); +var SecFromTime = require('./SecFromTime'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/9.0/#sec-timestring + +module.exports = function TimeString(tv) { + if (Type(tv) !== 'Number' || $isNaN(tv)) { + throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number'); + } + var hour = HourFromTime(tv); + var minute = MinFromTime(tv); + var second = SecFromTime(tv); + return padTimeComponent(hour) + ':' + padTimeComponent(minute) + ':' + padTimeComponent(second) + '\x20GMT'; +}; diff --git a/node_modules/es-abstract/2019/TimeWithinDay.js b/node_modules/es-abstract/2019/TimeWithinDay.js new file mode 100644 index 000000000..c5b21d378 --- /dev/null +++ b/node_modules/es-abstract/2019/TimeWithinDay.js @@ -0,0 +1,11 @@ +'use strict'; + +var mod = require('../helpers/mod'); +var msPerDay = require('../helpers/timeConstants').msPerDay; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2 + +module.exports = function TimeWithinDay(t) { + return mod(t, msPerDay); +}; + diff --git a/node_modules/es-abstract/2019/ToBoolean.js b/node_modules/es-abstract/2019/ToBoolean.js new file mode 100644 index 000000000..65d87376d --- /dev/null +++ b/node_modules/es-abstract/2019/ToBoolean.js @@ -0,0 +1,5 @@ +'use strict'; + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.2 + +module.exports = function ToBoolean(value) { return !!value; }; diff --git a/node_modules/es-abstract/2019/ToDateString.js b/node_modules/es-abstract/2019/ToDateString.js new file mode 100644 index 000000000..7a6d4c4e9 --- /dev/null +++ b/node_modules/es-abstract/2019/ToDateString.js @@ -0,0 +1,22 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); +var $Date = GetIntrinsic('%Date%'); + +var $isNaN = require('../helpers/isNaN'); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-todatestring + +module.exports = function ToDateString(tv) { + if (Type(tv) !== 'Number') { + throw new $TypeError('Assertion failed: `tv` must be a Number'); + } + if ($isNaN(tv)) { + return 'Invalid Date'; + } + return $Date(tv); +}; diff --git a/node_modules/es-abstract/2019/ToIndex.js b/node_modules/es-abstract/2019/ToIndex.js new file mode 100644 index 000000000..a55398d3e --- /dev/null +++ b/node_modules/es-abstract/2019/ToIndex.js @@ -0,0 +1,26 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $RangeError = GetIntrinsic('%RangeError%'); + +var ToInteger = require('./ToInteger'); +var ToLength = require('./ToLength'); +var SameValueZero = require('./SameValueZero'); + +// https://www.ecma-international.org/ecma-262/8.0/#sec-toindex + +module.exports = function ToIndex(value) { + if (typeof value === 'undefined') { + return 0; + } + var integerIndex = ToInteger(value); + if (integerIndex < 0) { + throw new $RangeError('index must be >= 0'); + } + var index = ToLength(integerIndex); + if (!SameValueZero(integerIndex, index)) { + throw new $RangeError('index must be >= 0 and < 2 ** 53 - 1'); + } + return index; +}; diff --git a/node_modules/es-abstract/2019/ToInt16.js b/node_modules/es-abstract/2019/ToInt16.js new file mode 100644 index 000000000..5a112c237 --- /dev/null +++ b/node_modules/es-abstract/2019/ToInt16.js @@ -0,0 +1,10 @@ +'use strict'; + +var ToUint16 = require('./ToUint16'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-toint16 + +module.exports = function ToInt16(argument) { + var int16bit = ToUint16(argument); + return int16bit >= 0x8000 ? int16bit - 0x10000 : int16bit; +}; diff --git a/node_modules/es-abstract/2019/ToInt32.js b/node_modules/es-abstract/2019/ToInt32.js new file mode 100644 index 000000000..a8d268070 --- /dev/null +++ b/node_modules/es-abstract/2019/ToInt32.js @@ -0,0 +1,9 @@ +'use strict'; + +var ToNumber = require('./ToNumber'); + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.5 + +module.exports = function ToInt32(x) { + return ToNumber(x) >> 0; +}; diff --git a/node_modules/es-abstract/2019/ToInt8.js b/node_modules/es-abstract/2019/ToInt8.js new file mode 100644 index 000000000..d103123a9 --- /dev/null +++ b/node_modules/es-abstract/2019/ToInt8.js @@ -0,0 +1,10 @@ +'use strict'; + +var ToUint8 = require('./ToUint8'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-toint8 + +module.exports = function ToInt8(argument) { + var int8bit = ToUint8(argument); + return int8bit >= 0x80 ? int8bit - 0x100 : int8bit; +}; diff --git a/node_modules/es-abstract/2019/ToInteger.js b/node_modules/es-abstract/2019/ToInteger.js new file mode 100644 index 000000000..16f7db9c3 --- /dev/null +++ b/node_modules/es-abstract/2019/ToInteger.js @@ -0,0 +1,12 @@ +'use strict'; + +var ES5ToInteger = require('../5/ToInteger'); + +var ToNumber = require('./ToNumber'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-tointeger + +module.exports = function ToInteger(value) { + var number = ToNumber(value); + return ES5ToInteger(number); +}; diff --git a/node_modules/es-abstract/2019/ToLength.js b/node_modules/es-abstract/2019/ToLength.js new file mode 100644 index 000000000..1bef9bed7 --- /dev/null +++ b/node_modules/es-abstract/2019/ToLength.js @@ -0,0 +1,12 @@ +'use strict'; + +var MAX_SAFE_INTEGER = require('../helpers/maxSafeInteger'); + +var ToInteger = require('./ToInteger'); + +module.exports = function ToLength(argument) { + var len = ToInteger(argument); + if (len <= 0) { return 0; } // includes converting -0 to +0 + if (len > MAX_SAFE_INTEGER) { return MAX_SAFE_INTEGER; } + return len; +}; diff --git a/node_modules/es-abstract/2019/ToNumber.js b/node_modules/es-abstract/2019/ToNumber.js new file mode 100644 index 000000000..7a3cdc89e --- /dev/null +++ b/node_modules/es-abstract/2019/ToNumber.js @@ -0,0 +1,59 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); +var $Number = GetIntrinsic('%Number%'); +var $RegExp = GetIntrinsic('%RegExp%'); +var $parseInteger = GetIntrinsic('%parseInt%'); + +var callBound = require('../helpers/callBound'); +var regexTester = require('../helpers/regexTester'); +var isPrimitive = require('../helpers/isPrimitive'); + +var $strSlice = callBound('String.prototype.slice'); +var isBinary = regexTester(/^0b[01]+$/i); +var isOctal = regexTester(/^0o[0-7]+$/i); +var isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i); +var nonWS = ['\u0085', '\u200b', '\ufffe'].join(''); +var nonWSregex = new $RegExp('[' + nonWS + ']', 'g'); +var hasNonWS = regexTester(nonWSregex); + +// whitespace from: https://es5.github.io/#x15.5.4.20 +// implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324 +var ws = [ + '\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' +].join(''); +var trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g'); +var $replace = callBound('String.prototype.replace'); +var $trim = function (value) { + return $replace(value, trimRegex, ''); +}; + +var ToPrimitive = require('./ToPrimitive'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-tonumber + +module.exports = function ToNumber(argument) { + var value = isPrimitive(argument) ? argument : ToPrimitive(argument, $Number); + if (typeof value === 'symbol') { + throw new $TypeError('Cannot convert a Symbol value to a number'); + } + if (typeof value === 'string') { + if (isBinary(value)) { + return ToNumber($parseInteger($strSlice(value, 2), 2)); + } else if (isOctal(value)) { + return ToNumber($parseInteger($strSlice(value, 2), 8)); + } else if (hasNonWS(value) || isInvalidHexLiteral(value)) { + return NaN; + } else { + var trimmed = $trim(value); + if (trimmed !== value) { + return ToNumber(trimmed); + } + } + } + return $Number(value); +}; diff --git a/node_modules/es-abstract/2019/ToObject.js b/node_modules/es-abstract/2019/ToObject.js new file mode 100644 index 000000000..50d5b94a4 --- /dev/null +++ b/node_modules/es-abstract/2019/ToObject.js @@ -0,0 +1,14 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Object = GetIntrinsic('%Object%'); + +var RequireObjectCoercible = require('./RequireObjectCoercible'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-toobject + +module.exports = function ToObject(value) { + RequireObjectCoercible(value); + return $Object(value); +}; diff --git a/node_modules/es-abstract/2019/ToPrimitive.js b/node_modules/es-abstract/2019/ToPrimitive.js new file mode 100644 index 000000000..81c655d41 --- /dev/null +++ b/node_modules/es-abstract/2019/ToPrimitive.js @@ -0,0 +1,12 @@ +'use strict'; + +var toPrimitive = require('es-to-primitive/es2015'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive + +module.exports = function ToPrimitive(input) { + if (arguments.length > 1) { + return toPrimitive(input, arguments[1]); + } + return toPrimitive(input); +}; diff --git a/node_modules/es-abstract/2019/ToPropertyDescriptor.js b/node_modules/es-abstract/2019/ToPropertyDescriptor.js new file mode 100644 index 000000000..38e536e2d --- /dev/null +++ b/node_modules/es-abstract/2019/ToPropertyDescriptor.js @@ -0,0 +1,52 @@ +'use strict'; + +var has = require('has'); + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var Type = require('./Type'); +var ToBoolean = require('./ToBoolean'); +var IsCallable = require('./IsCallable'); + +// https://ecma-international.org/ecma-262/5.1/#sec-8.10.5 + +module.exports = function ToPropertyDescriptor(Obj) { + if (Type(Obj) !== 'Object') { + throw new $TypeError('ToPropertyDescriptor requires an object'); + } + + var desc = {}; + if (has(Obj, 'enumerable')) { + desc['[[Enumerable]]'] = ToBoolean(Obj.enumerable); + } + if (has(Obj, 'configurable')) { + desc['[[Configurable]]'] = ToBoolean(Obj.configurable); + } + if (has(Obj, 'value')) { + desc['[[Value]]'] = Obj.value; + } + if (has(Obj, 'writable')) { + desc['[[Writable]]'] = ToBoolean(Obj.writable); + } + if (has(Obj, 'get')) { + var getter = Obj.get; + if (typeof getter !== 'undefined' && !IsCallable(getter)) { + throw new TypeError('getter must be a function'); + } + desc['[[Get]]'] = getter; + } + if (has(Obj, 'set')) { + var setter = Obj.set; + if (typeof setter !== 'undefined' && !IsCallable(setter)) { + throw new $TypeError('setter must be a function'); + } + desc['[[Set]]'] = setter; + } + + if ((has(desc, '[[Get]]') || has(desc, '[[Set]]')) && (has(desc, '[[Value]]') || has(desc, '[[Writable]]'))) { + throw new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute'); + } + return desc; +}; diff --git a/node_modules/es-abstract/2019/ToPropertyKey.js b/node_modules/es-abstract/2019/ToPropertyKey.js new file mode 100644 index 000000000..38f40dd80 --- /dev/null +++ b/node_modules/es-abstract/2019/ToPropertyKey.js @@ -0,0 +1,15 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $String = GetIntrinsic('%String%'); + +var ToPrimitive = require('./ToPrimitive'); +var ToString = require('./ToString'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-topropertykey + +module.exports = function ToPropertyKey(argument) { + var key = ToPrimitive(argument, $String); + return typeof key === 'symbol' ? key : ToString(key); +}; diff --git a/node_modules/es-abstract/2019/ToString.js b/node_modules/es-abstract/2019/ToString.js new file mode 100644 index 000000000..a34543126 --- /dev/null +++ b/node_modules/es-abstract/2019/ToString.js @@ -0,0 +1,15 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $String = GetIntrinsic('%String%'); +var $TypeError = GetIntrinsic('%TypeError%'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-tostring + +module.exports = function ToString(argument) { + if (typeof argument === 'symbol') { + throw new $TypeError('Cannot convert a Symbol value to a string'); + } + return $String(argument); +}; diff --git a/node_modules/es-abstract/2019/ToUint16.js b/node_modules/es-abstract/2019/ToUint16.js new file mode 100644 index 000000000..c8a408bfa --- /dev/null +++ b/node_modules/es-abstract/2019/ToUint16.js @@ -0,0 +1,24 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Math = GetIntrinsic('%Math%'); + +var ToNumber = require('./ToNumber'); + +var $isNaN = require('../helpers/isNaN'); +var $isFinite = require('../helpers/isFinite'); +var $sign = require('../helpers/sign'); +var $mod = require('../helpers/mod'); + +var $floor = $Math.floor; +var $abs = $Math.abs; + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.7 + +module.exports = function ToUint16(value) { + var number = ToNumber(value); + if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; } + var posInt = $sign(number) * $floor($abs(number)); + return $mod(posInt, 0x10000); +}; diff --git a/node_modules/es-abstract/2019/ToUint32.js b/node_modules/es-abstract/2019/ToUint32.js new file mode 100644 index 000000000..3660f6209 --- /dev/null +++ b/node_modules/es-abstract/2019/ToUint32.js @@ -0,0 +1,9 @@ +'use strict'; + +var ToNumber = require('./ToNumber'); + +// http://www.ecma-international.org/ecma-262/5.1/#sec-9.6 + +module.exports = function ToUint32(x) { + return ToNumber(x) >>> 0; +}; diff --git a/node_modules/es-abstract/2019/ToUint8.js b/node_modules/es-abstract/2019/ToUint8.js new file mode 100644 index 000000000..bf8475321 --- /dev/null +++ b/node_modules/es-abstract/2019/ToUint8.js @@ -0,0 +1,22 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Math = GetIntrinsic('%Math%'); + +var ToNumber = require('./ToNumber'); + +var $isNaN = require('../helpers/isNaN'); +var $isFinite = require('../helpers/isFinite'); +var $sign = require('../helpers/sign'); +var $mod = require('../helpers/mod'); + +var $floor = $Math.floor; +var $abs = $Math.abs; + +module.exports = function ToUint8(argument) { + var number = ToNumber(argument); + if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; } + var posInt = $sign(number) * $floor($abs(number)); + return $mod(posInt, 0x100); +}; diff --git a/node_modules/es-abstract/2019/ToUint8Clamp.js b/node_modules/es-abstract/2019/ToUint8Clamp.js new file mode 100644 index 000000000..c7f9f5656 --- /dev/null +++ b/node_modules/es-abstract/2019/ToUint8Clamp.js @@ -0,0 +1,24 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Math = GetIntrinsic('%Math%'); + +var ToNumber = require('./ToNumber'); + +var $isNaN = require('../helpers/isNaN'); + +var $floor = $Math.floor; + +// https://www.ecma-international.org/ecma-262/6.0/#sec-touint8clamp + +module.exports = function ToUint8Clamp(argument) { + var number = ToNumber(argument); + if ($isNaN(number) || number <= 0) { return 0; } + if (number >= 0xFF) { return 0xFF; } + var f = $floor(argument); + if (f + 0.5 < number) { return f + 1; } + if (number < f + 0.5) { return f; } + if (f % 2 !== 0) { return f + 1; } + return f; +}; diff --git a/node_modules/es-abstract/2019/TrimString.js b/node_modules/es-abstract/2019/TrimString.js new file mode 100644 index 000000000..b27112cd5 --- /dev/null +++ b/node_modules/es-abstract/2019/TrimString.js @@ -0,0 +1,29 @@ +'use strict'; + +var trimStart = require('string.prototype.trimstart'); +var trimEnd = require('string.prototype.trimend'); + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var RequireObjectCoercible = require('./RequireObjectCoercible'); +var ToString = require('./ToString'); + +// https://ecma-international.org/ecma-262/10.0/#sec-trimstring + +module.exports = function TrimString(string, where) { + var str = RequireObjectCoercible(string); + var S = ToString(str); + var T; + if (where === 'start') { + T = trimStart(S); + } else if (where === 'end') { + T = trimEnd(S); + } else if (where === 'start+end') { + T = trimStart(trimEnd(S)); + } else { + throw new $TypeError('Assertion failed: invalid `where` value; must be "start", "end", or "start+end"'); + } + return T; +}; diff --git a/node_modules/es-abstract/2019/Type.js b/node_modules/es-abstract/2019/Type.js new file mode 100644 index 000000000..0bd11659c --- /dev/null +++ b/node_modules/es-abstract/2019/Type.js @@ -0,0 +1,12 @@ +'use strict'; + +var ES5Type = require('../5/Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-ecmascript-data-types-and-values + +module.exports = function Type(x) { + if (typeof x === 'symbol') { + return 'Symbol'; + } + return ES5Type(x); +}; diff --git a/node_modules/es-abstract/2019/ValidateAndApplyPropertyDescriptor.js b/node_modules/es-abstract/2019/ValidateAndApplyPropertyDescriptor.js new file mode 100644 index 000000000..d4b900700 --- /dev/null +++ b/node_modules/es-abstract/2019/ValidateAndApplyPropertyDescriptor.js @@ -0,0 +1,170 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var DefineOwnProperty = require('../helpers/DefineOwnProperty'); +var isPropertyDescriptor = require('../helpers/isPropertyDescriptor'); +var isSamePropertyDescriptor = require('../helpers/isSamePropertyDescriptor'); + +var FromPropertyDescriptor = require('./FromPropertyDescriptor'); +var IsAccessorDescriptor = require('./IsAccessorDescriptor'); +var IsDataDescriptor = require('./IsDataDescriptor'); +var IsGenericDescriptor = require('./IsGenericDescriptor'); +var IsPropertyKey = require('./IsPropertyKey'); +var SameValue = require('./SameValue'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-validateandapplypropertydescriptor +// https://www.ecma-international.org/ecma-262/8.0/#sec-validateandapplypropertydescriptor + +// eslint-disable-next-line max-lines-per-function, max-statements, max-params +module.exports = function ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current) { + // this uses the ES2017+ logic, since it fixes a number of bugs in the ES2015 logic. + var oType = Type(O); + if (oType !== 'Undefined' && oType !== 'Object') { + throw new $TypeError('Assertion failed: O must be undefined or an Object'); + } + if (Type(extensible) !== 'Boolean') { + throw new $TypeError('Assertion failed: extensible must be a Boolean'); + } + if (!isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, Desc)) { + throw new $TypeError('Assertion failed: Desc must be a Property Descriptor'); + } + if (Type(current) !== 'Undefined' && !isPropertyDescriptor({ + Type: Type, + IsDataDescriptor: IsDataDescriptor, + IsAccessorDescriptor: IsAccessorDescriptor + }, current)) { + throw new $TypeError('Assertion failed: current must be a Property Descriptor, or undefined'); + } + if (oType !== 'Undefined' && !IsPropertyKey(P)) { + throw new $TypeError('Assertion failed: if O is not undefined, P must be a Property Key'); + } + if (Type(current) === 'Undefined') { + if (!extensible) { + return false; + } + if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) { + if (oType !== 'Undefined') { + DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + { + '[[Configurable]]': Desc['[[Configurable]]'], + '[[Enumerable]]': Desc['[[Enumerable]]'], + '[[Value]]': Desc['[[Value]]'], + '[[Writable]]': Desc['[[Writable]]'] + } + ); + } + } else { + if (!IsAccessorDescriptor(Desc)) { + throw new $TypeError('Assertion failed: Desc is not an accessor descriptor'); + } + if (oType !== 'Undefined') { + return DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + Desc + ); + } + } + return true; + } + if (IsGenericDescriptor(Desc) && !('[[Configurable]]' in Desc) && !('[[Enumerable]]' in Desc)) { + return true; + } + if (isSamePropertyDescriptor({ SameValue: SameValue }, Desc, current)) { + return true; // removed by ES2017, but should still be correct + } + // "if every field in Desc is absent, return true" can't really match the assertion that it's a Property Descriptor + if (!current['[[Configurable]]']) { + if (Desc['[[Configurable]]']) { + return false; + } + if ('[[Enumerable]]' in Desc && !Desc['[[Enumerable]]'] === !!current['[[Enumerable]]']) { + return false; + } + } + if (IsGenericDescriptor(Desc)) { + // no further validation is required. + } else if (IsDataDescriptor(current) !== IsDataDescriptor(Desc)) { + if (!current['[[Configurable]]']) { + return false; + } + if (IsDataDescriptor(current)) { + if (oType !== 'Undefined') { + DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + { + '[[Configurable]]': current['[[Configurable]]'], + '[[Enumerable]]': current['[[Enumerable]]'], + '[[Get]]': undefined + } + ); + } + } else if (oType !== 'Undefined') { + DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + { + '[[Configurable]]': current['[[Configurable]]'], + '[[Enumerable]]': current['[[Enumerable]]'], + '[[Value]]': undefined + } + ); + } + } else if (IsDataDescriptor(current) && IsDataDescriptor(Desc)) { + if (!current['[[Configurable]]'] && !current['[[Writable]]']) { + if ('[[Writable]]' in Desc && Desc['[[Writable]]']) { + return false; + } + if ('[[Value]]' in Desc && !SameValue(Desc['[[Value]]'], current['[[Value]]'])) { + return false; + } + return true; + } + } else if (IsAccessorDescriptor(current) && IsAccessorDescriptor(Desc)) { + if (!current['[[Configurable]]']) { + if ('[[Set]]' in Desc && !SameValue(Desc['[[Set]]'], current['[[Set]]'])) { + return false; + } + if ('[[Get]]' in Desc && !SameValue(Desc['[[Get]]'], current['[[Get]]'])) { + return false; + } + return true; + } + } else { + throw new $TypeError('Assertion failed: current and Desc are not both data, both accessors, or one accessor and one data.'); + } + if (oType !== 'Undefined') { + return DefineOwnProperty( + IsDataDescriptor, + SameValue, + FromPropertyDescriptor, + O, + P, + Desc + ); + } + return true; +}; diff --git a/node_modules/es-abstract/2019/WeekDay.js b/node_modules/es-abstract/2019/WeekDay.js new file mode 100644 index 000000000..2973e0200 --- /dev/null +++ b/node_modules/es-abstract/2019/WeekDay.js @@ -0,0 +1,11 @@ +'use strict'; + +var mod = require('../helpers/mod'); + +var Day = require('./Day'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.6 + +module.exports = function WeekDay(t) { + return mod(Day(t) + 4, 7); +}; diff --git a/node_modules/es-abstract/2019/YearFromTime.js b/node_modules/es-abstract/2019/YearFromTime.js new file mode 100644 index 000000000..ff5339f24 --- /dev/null +++ b/node_modules/es-abstract/2019/YearFromTime.js @@ -0,0 +1,16 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $Date = GetIntrinsic('%Date%'); + +var callBound = require('../helpers/callBound'); + +var $getUTCFullYear = callBound('Date.prototype.getUTCFullYear'); + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3 + +module.exports = function YearFromTime(t) { + // largest y such that this.TimeFromYear(y) <= t + return $getUTCFullYear(new $Date(t)); +}; diff --git a/node_modules/es-abstract/2019/modulo.js b/node_modules/es-abstract/2019/modulo.js new file mode 100644 index 000000000..bc04c0628 --- /dev/null +++ b/node_modules/es-abstract/2019/modulo.js @@ -0,0 +1,9 @@ +'use strict'; + +var mod = require('../helpers/mod'); + +// https://ecma-international.org/ecma-262/5.1/#sec-5.2 + +module.exports = function modulo(x, y) { + return mod(x, y); +}; diff --git a/node_modules/es-abstract/2019/msFromTime.js b/node_modules/es-abstract/2019/msFromTime.js new file mode 100644 index 000000000..c31eda085 --- /dev/null +++ b/node_modules/es-abstract/2019/msFromTime.js @@ -0,0 +1,10 @@ +'use strict'; + +var mod = require('../helpers/mod'); +var msPerSecond = require('../helpers/timeConstants').msPerSecond; + +// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10 + +module.exports = function msFromTime(t) { + return mod(t, msPerSecond); +}; diff --git a/node_modules/es-abstract/2019/thisBooleanValue.js b/node_modules/es-abstract/2019/thisBooleanValue.js new file mode 100644 index 000000000..3ffac9cdf --- /dev/null +++ b/node_modules/es-abstract/2019/thisBooleanValue.js @@ -0,0 +1,15 @@ +'use strict'; + +var $BooleanValueOf = require('../helpers/callBound')('Boolean.prototype.valueOf'); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-boolean-prototype-object + +module.exports = function thisBooleanValue(value) { + if (Type(value) === 'Boolean') { + return value; + } + + return $BooleanValueOf(value); +}; diff --git a/node_modules/es-abstract/2019/thisNumberValue.js b/node_modules/es-abstract/2019/thisNumberValue.js new file mode 100644 index 000000000..0345e523f --- /dev/null +++ b/node_modules/es-abstract/2019/thisNumberValue.js @@ -0,0 +1,18 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); + +var Type = require('./Type'); + +var $NumberValueOf = callBound('Number.prototype.valueOf'); + +// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-number-prototype-object + +module.exports = function thisNumberValue(value) { + if (Type(value) === 'Number') { + return value; + } + + return $NumberValueOf(value); +}; + diff --git a/node_modules/es-abstract/2019/thisStringValue.js b/node_modules/es-abstract/2019/thisStringValue.js new file mode 100644 index 000000000..3b99b6e3c --- /dev/null +++ b/node_modules/es-abstract/2019/thisStringValue.js @@ -0,0 +1,15 @@ +'use strict'; + +var $StringValueOf = require('../helpers/callBound')('String.prototype.valueOf'); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-prototype-object + +module.exports = function thisStringValue(value) { + if (Type(value) === 'String') { + return value; + } + + return $StringValueOf(value); +}; diff --git a/node_modules/es-abstract/2019/thisSymbolValue.js b/node_modules/es-abstract/2019/thisSymbolValue.js new file mode 100644 index 000000000..3c3b3475d --- /dev/null +++ b/node_modules/es-abstract/2019/thisSymbolValue.js @@ -0,0 +1,19 @@ +'use strict'; + +var callBound = require('../helpers/callBound'); + +var $SymbolValueOf = callBound('Symbol.prototype.valueOf', true); + +var Type = require('./Type'); + +// https://ecma-international.org/ecma-262/9.0/#sec-thissymbolvalue + +module.exports = function thisSymbolValue(value) { + if (!$SymbolValueOf) { + throw new SyntaxError('Symbols are not supported; thisSymbolValue requires that `value` be a Symbol or a Symbol object'); + } + if (Type(value) === 'Symbol') { + return value; + } + return $SymbolValueOf(value); +}; diff --git a/node_modules/es-abstract/2019/thisTimeValue.js b/node_modules/es-abstract/2019/thisTimeValue.js new file mode 100644 index 000000000..a9a47ace2 --- /dev/null +++ b/node_modules/es-abstract/2019/thisTimeValue.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('../2018/thisTimeValue'); |