Ajout de promotion et de commande
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
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 ThrowCompletion = require('./ThrowCompletion');
|
||||
|
||||
// https://262.ecma-international.org/14.0/#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, 'sync');
|
||||
while (true) {
|
||||
var next = IteratorStep(iteratorRecord);
|
||||
if (!next) {
|
||||
return target;
|
||||
}
|
||||
var nextItem = IteratorValue(next);
|
||||
if (!isObject(nextItem)) {
|
||||
var error = ThrowCompletion(new $TypeError('iterator next must return an Object, got ' + inspect(nextItem)));
|
||||
return IteratorClose(iteratorRecord, error);
|
||||
}
|
||||
try {
|
||||
var k = Get(nextItem, '0');
|
||||
var v = Get(nextItem, '1');
|
||||
Call(adder, target, [k, v]);
|
||||
} catch (e) {
|
||||
return IteratorClose(iteratorRecord, ThrowCompletion(e));
|
||||
}
|
||||
}
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
|
||||
var ClearKeptObjects = require('./ClearKeptObjects');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-addtokeptobjects
|
||||
|
||||
module.exports = function AddToKeptObjects(object) {
|
||||
if (!isObject(object)) {
|
||||
throw new $TypeError('Assertion failed: `object` must be an Object');
|
||||
}
|
||||
var arr = SLOT.get(ClearKeptObjects, '[[es-abstract internal: KeptAlive]]');
|
||||
arr[arr.length] = object;
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var CodePointAt = require('./CodePointAt');
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
var MAX_SAFE_INTEGER = require('math-intrinsics/constants/maxSafeInteger');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-advancestringindex
|
||||
|
||||
module.exports = function AdvanceStringIndex(S, index, unicode) {
|
||||
if (typeof 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 (typeof 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 cp = CodePointAt(S, index);
|
||||
return index + cp['[[CodeUnitCount]]'];
|
||||
};
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var HasOwnProperty = require('./HasOwnProperty');
|
||||
var ToNumeric = require('./ToNumeric');
|
||||
var ToPrimitive = require('./ToPrimitive');
|
||||
var ToString = require('./ToString');
|
||||
var Type = require('./Type');
|
||||
|
||||
var NumberAdd = require('./Number/add');
|
||||
var NumberBitwiseAND = require('./Number/bitwiseAND');
|
||||
var NumberBitwiseOR = require('./Number/bitwiseOR');
|
||||
var NumberBitwiseXOR = require('./Number/bitwiseXOR');
|
||||
var NumberDivide = require('./Number/divide');
|
||||
var NumberExponentiate = require('./Number/exponentiate');
|
||||
var NumberLeftShift = require('./Number/leftShift');
|
||||
var NumberMultiply = require('./Number/multiply');
|
||||
var NumberRemainder = require('./Number/remainder');
|
||||
var NumberSignedRightShift = require('./Number/signedRightShift');
|
||||
var NumberSubtract = require('./Number/subtract');
|
||||
var NumberUnsignedRightShift = require('./Number/unsignedRightShift');
|
||||
var BigIntAdd = require('./BigInt/add');
|
||||
var BigIntBitwiseAND = require('./BigInt/bitwiseAND');
|
||||
var BigIntBitwiseOR = require('./BigInt/bitwiseOR');
|
||||
var BigIntBitwiseXOR = require('./BigInt/bitwiseXOR');
|
||||
var BigIntDivide = require('./BigInt/divide');
|
||||
var BigIntExponentiate = require('./BigInt/exponentiate');
|
||||
var BigIntLeftShift = require('./BigInt/leftShift');
|
||||
var BigIntMultiply = require('./BigInt/multiply');
|
||||
var BigIntRemainder = require('./BigInt/remainder');
|
||||
var BigIntSignedRightShift = require('./BigInt/signedRightShift');
|
||||
var BigIntSubtract = require('./BigInt/subtract');
|
||||
var BigIntUnsignedRightShift = require('./BigInt/unsignedRightShift');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-applystringornumericbinaryoperator
|
||||
|
||||
// https://262.ecma-international.org/12.0/#step-applystringornumericbinaryoperator-operations-table
|
||||
var table = {
|
||||
'**': [NumberExponentiate, BigIntExponentiate],
|
||||
'*': [NumberMultiply, BigIntMultiply],
|
||||
'/': [NumberDivide, BigIntDivide],
|
||||
'%': [NumberRemainder, BigIntRemainder],
|
||||
'+': [NumberAdd, BigIntAdd],
|
||||
'-': [NumberSubtract, BigIntSubtract],
|
||||
'<<': [NumberLeftShift, BigIntLeftShift],
|
||||
'>>': [NumberSignedRightShift, BigIntSignedRightShift],
|
||||
'>>>': [NumberUnsignedRightShift, BigIntUnsignedRightShift],
|
||||
'&': [NumberBitwiseAND, BigIntBitwiseAND],
|
||||
'^': [NumberBitwiseXOR, BigIntBitwiseXOR],
|
||||
'|': [NumberBitwiseOR, BigIntBitwiseOR]
|
||||
};
|
||||
|
||||
module.exports = function ApplyStringOrNumericBinaryOperator(lval, opText, rval) {
|
||||
if (typeof opText !== 'string' || !HasOwnProperty(table, opText)) {
|
||||
throw new $TypeError('Assertion failed: `opText` must be a valid operation string');
|
||||
}
|
||||
if (opText === '+') {
|
||||
var lprim = ToPrimitive(lval);
|
||||
var rprim = ToPrimitive(rval);
|
||||
if (typeof lprim === 'string' || typeof rprim === 'string') {
|
||||
var lstr = ToString(lprim);
|
||||
var rstr = ToString(rprim);
|
||||
return lstr + rstr;
|
||||
}
|
||||
/* eslint no-param-reassign: 1 */
|
||||
lval = lprim;
|
||||
rval = rprim;
|
||||
}
|
||||
var lnum = ToNumeric(lval);
|
||||
var rnum = ToNumeric(rval);
|
||||
if (Type(lnum) !== Type(rnum)) {
|
||||
throw new $TypeError('types of ' + lnum + ' and ' + rnum + ' differ');
|
||||
}
|
||||
var Operation = table[opText][typeof lnum === 'bigint' ? 1 : 0];
|
||||
return Operation(lnum, rnum);
|
||||
};
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $ArrayPrototype = GetIntrinsic('%Array.prototype%');
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
var MAX_ARRAY_LENGTH = require('math-intrinsics/constants/maxArrayLength');
|
||||
var $setProto = require('set-proto');
|
||||
|
||||
// https://262.ecma-international.org/12.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 3, 5
|
||||
if (proto !== $ArrayPrototype) { // step 4
|
||||
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 6
|
||||
A.length = length;
|
||||
}
|
||||
/* step 6, the above as a shortcut for the below
|
||||
OrdinaryDefineOwnProperty(A, 'length', {
|
||||
'[[Configurable]]': false,
|
||||
'[[Enumerable]]': false,
|
||||
'[[Value]]': length,
|
||||
'[[Writable]]': true
|
||||
});
|
||||
*/
|
||||
return A;
|
||||
};
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var assign = require('object.assign');
|
||||
|
||||
var isPropertyDescriptor = require('../helpers/records/property-descriptor');
|
||||
|
||||
var IsArray = require('./IsArray');
|
||||
var IsDataDescriptor = require('./IsDataDescriptor');
|
||||
var OrdinaryDefineOwnProperty = require('./OrdinaryDefineOwnProperty');
|
||||
var OrdinaryGetOwnProperty = require('./OrdinaryGetOwnProperty');
|
||||
var ToNumber = require('./ToNumber');
|
||||
var ToString = require('./ToString');
|
||||
var ToUint32 = require('./ToUint32');
|
||||
|
||||
// https://262.ecma-international.org/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(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;
|
||||
};
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $species = GetIntrinsic('%Symbol.species%', true);
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
|
||||
var ArrayCreate = require('./ArrayCreate');
|
||||
var Get = require('./Get');
|
||||
var IsArray = require('./IsArray');
|
||||
var IsConstructor = require('./IsConstructor');
|
||||
|
||||
// https://262.ecma-international.org/12.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 isArray = IsArray(originalArray);
|
||||
if (!isArray) {
|
||||
return ArrayCreate(length);
|
||||
}
|
||||
|
||||
var 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 && isObject(C)) {
|
||||
C = Get(C, $species);
|
||||
if (C === null) {
|
||||
C = void 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof C === 'undefined') {
|
||||
return ArrayCreate(length);
|
||||
}
|
||||
if (!IsConstructor(C)) {
|
||||
throw new $TypeError('C must be a constructor');
|
||||
}
|
||||
return new C(length); // Construct(C, length);
|
||||
};
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
var $Promise = GetIntrinsic('%Promise%', true);
|
||||
|
||||
var callBound = require('call-bound');
|
||||
|
||||
var CreateIterResultObject = require('./CreateIterResultObject');
|
||||
var IteratorComplete = require('./IteratorComplete');
|
||||
var IteratorValue = require('./IteratorValue');
|
||||
var PromiseResolve = require('./PromiseResolve');
|
||||
|
||||
var $then = callBound('Promise.prototype.then', true);
|
||||
|
||||
// https://262.ecma-international.org/10.0/#sec-asyncfromsynciteratorcontinuation
|
||||
|
||||
module.exports = function AsyncFromSyncIteratorContinuation(result) {
|
||||
if (!isObject(result)) {
|
||||
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
||||
}
|
||||
|
||||
if (arguments.length > 1) {
|
||||
throw new $SyntaxError('although AsyncFromSyncIteratorContinuation should take a second argument, it is not used in this implementation');
|
||||
}
|
||||
|
||||
if (!$Promise) {
|
||||
throw new $SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
|
||||
return new $Promise(function (resolve) {
|
||||
var done = IteratorComplete(result); // step 2
|
||||
var value = IteratorValue(result); // step 4
|
||||
var valueWrapper = PromiseResolve($Promise, value); // step 6
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
var onFulfilled = function (value) { // steps 8-9
|
||||
return CreateIterResultObject(value, done); // step 8.a
|
||||
};
|
||||
resolve($then(valueWrapper, onFulfilled)); // step 11
|
||||
}); // step 12
|
||||
};
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
var $Promise = GetIntrinsic('%Promise%', true);
|
||||
|
||||
var Call = require('./Call');
|
||||
var CompletionRecord = require('./CompletionRecord');
|
||||
var GetMethod = require('./GetMethod');
|
||||
|
||||
var isIteratorRecord = require('../helpers/records/iterator-record-2023');
|
||||
|
||||
var callBound = require('call-bound');
|
||||
|
||||
var $then = callBound('Promise.prototype.then', true);
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-asynciteratorclose
|
||||
|
||||
module.exports = function AsyncIteratorClose(iteratorRecord, completion) {
|
||||
if (!isIteratorRecord(iteratorRecord)) {
|
||||
throw new $TypeError('Assertion failed: `iteratorRecord` must be an Iterator Record'); // step 1
|
||||
}
|
||||
|
||||
if (!(completion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('Assertion failed: completion is not a Completion Record instance'); // step 2
|
||||
}
|
||||
|
||||
if (!$then) {
|
||||
throw new $SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
|
||||
var iterator = iteratorRecord['[[Iterator]]']; // step 3
|
||||
|
||||
return $then(
|
||||
$then(
|
||||
$then(
|
||||
new $Promise(function (resolve) {
|
||||
resolve(GetMethod(iterator, 'return')); // step 4
|
||||
// resolve(Call(ret, iterator, [])); // step 6
|
||||
}),
|
||||
function (returnV) { // step 5.a
|
||||
if (typeof returnV === 'undefined') {
|
||||
return completion; // step 5.b
|
||||
}
|
||||
return Call(returnV, iterator); // step 5.c, 5.d.
|
||||
}
|
||||
),
|
||||
null,
|
||||
function (e) {
|
||||
if (completion.type() === 'throw') {
|
||||
completion['?'](); // step 6
|
||||
} else {
|
||||
throw e; // step 7
|
||||
}
|
||||
}
|
||||
),
|
||||
function (innerResult) { // step 8
|
||||
if (completion.type() === 'throw') {
|
||||
completion['?'](); // step 6
|
||||
}
|
||||
if (!isObject(innerResult)) {
|
||||
throw new $TypeError('`innerResult` must be an Object'); // step 10
|
||||
}
|
||||
return completion;
|
||||
}
|
||||
);
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-add
|
||||
|
||||
module.exports = function BigIntAdd(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return x + y;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var BigIntBitwiseOp = require('../BigIntBitwiseOp');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-bitwiseAND
|
||||
|
||||
module.exports = function BigIntBitwiseAND(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
return BigIntBitwiseOp('&', x, y);
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-bitwiseNOT
|
||||
|
||||
module.exports = function BigIntBitwiseNOT(x) {
|
||||
if (typeof x !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` argument must be a BigInt');
|
||||
}
|
||||
return -x - $BigInt(1);
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var BigIntBitwiseOp = require('../BigIntBitwiseOp');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-bitwiseOR
|
||||
|
||||
module.exports = function BigIntBitwiseOR(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
return BigIntBitwiseOp('|', x, y);
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var BigIntBitwiseOp = require('../BigIntBitwiseOp');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-bitwiseXOR
|
||||
|
||||
module.exports = function BigIntBitwiseXOR(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
return BigIntBitwiseOp('^', x, y);
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-divide
|
||||
|
||||
module.exports = function BigIntDivide(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
if (y === $BigInt(0)) {
|
||||
throw new $RangeError('Division by zero');
|
||||
}
|
||||
// shortcut for the actual spec mechanics
|
||||
return x / y;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-equal
|
||||
|
||||
module.exports = function BigIntEqual(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
// shortcut for the actual spec mechanics
|
||||
return x === y;
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-exponentiate
|
||||
|
||||
module.exports = function BigIntExponentiate(base, exponent) {
|
||||
if (typeof base !== 'bigint' || typeof exponent !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `base` and `exponent` arguments must be BigInts');
|
||||
}
|
||||
if (exponent < $BigInt(0)) {
|
||||
throw new $RangeError('Exponent must be positive');
|
||||
}
|
||||
if (/* base === $BigInt(0) && */ exponent === $BigInt(0)) {
|
||||
return $BigInt(1);
|
||||
}
|
||||
|
||||
var square = base;
|
||||
var remaining = exponent;
|
||||
while (remaining > $BigInt(0)) {
|
||||
square += exponent;
|
||||
--remaining; // eslint-disable-line no-plusplus
|
||||
}
|
||||
return square;
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var add = require('./add');
|
||||
var bitwiseAND = require('./bitwiseAND');
|
||||
var bitwiseNOT = require('./bitwiseNOT');
|
||||
var bitwiseOR = require('./bitwiseOR');
|
||||
var bitwiseXOR = require('./bitwiseXOR');
|
||||
var divide = require('./divide');
|
||||
var equal = require('./equal');
|
||||
var exponentiate = require('./exponentiate');
|
||||
var leftShift = require('./leftShift');
|
||||
var lessThan = require('./lessThan');
|
||||
var multiply = require('./multiply');
|
||||
var remainder = require('./remainder');
|
||||
var signedRightShift = require('./signedRightShift');
|
||||
var subtract = require('./subtract');
|
||||
var toString = require('./toString');
|
||||
var unaryMinus = require('./unaryMinus');
|
||||
var unsignedRightShift = require('./unsignedRightShift');
|
||||
|
||||
module.exports = {
|
||||
add: add,
|
||||
bitwiseAND: bitwiseAND,
|
||||
bitwiseNOT: bitwiseNOT,
|
||||
bitwiseOR: bitwiseOR,
|
||||
bitwiseXOR: bitwiseXOR,
|
||||
divide: divide,
|
||||
equal: equal,
|
||||
exponentiate: exponentiate,
|
||||
leftShift: leftShift,
|
||||
lessThan: lessThan,
|
||||
multiply: multiply,
|
||||
remainder: remainder,
|
||||
signedRightShift: signedRightShift,
|
||||
subtract: subtract,
|
||||
toString: toString,
|
||||
unaryMinus: unaryMinus,
|
||||
unsignedRightShift: unsignedRightShift
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-leftShift
|
||||
|
||||
module.exports = function BigIntLeftShift(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return x << y;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-lessThan
|
||||
|
||||
module.exports = function BigIntLessThan(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return x < y;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-multiply
|
||||
|
||||
module.exports = function BigIntMultiply(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return x * y;
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var zero = $BigInt && $BigInt(0);
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-remainder
|
||||
|
||||
module.exports = function BigIntRemainder(n, d) {
|
||||
if (typeof n !== 'bigint' || typeof d !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `n` and `d` arguments must be BigInts');
|
||||
}
|
||||
|
||||
if (d === zero) {
|
||||
throw new $RangeError('Division by zero');
|
||||
}
|
||||
|
||||
if (n === zero) {
|
||||
return zero;
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return n % d;
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var BigIntLeftShift = require('./leftShift');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-signedRightShift
|
||||
|
||||
module.exports = function BigIntSignedRightShift(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
return BigIntLeftShift(x, -y);
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-subtract
|
||||
|
||||
module.exports = function BigIntSubtract(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
// shortcut for the actual spec mechanics
|
||||
return x - y;
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var callBound = require('call-bound');
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
|
||||
var $BigIntToString = callBound('BigInt.prototype.toString', true);
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-numeric-types-bigint-tostring
|
||||
|
||||
module.exports = function BigIntToString(x, radix) {
|
||||
if (typeof x !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` must be a BigInt');
|
||||
}
|
||||
|
||||
if (!isInteger(radix) || radix < 2 || radix > 36) {
|
||||
throw new $TypeError('Assertion failed: `radix` must be an integer >= 2 and <= 36');
|
||||
}
|
||||
|
||||
if (!$BigIntToString) {
|
||||
throw new $SyntaxError('BigInt is not supported');
|
||||
}
|
||||
|
||||
return $BigIntToString(x, radix); // steps 1 - 12
|
||||
};
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var zero = $BigInt && $BigInt(0);
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-unaryMinus
|
||||
|
||||
module.exports = function BigIntUnaryMinus(x) {
|
||||
if (typeof x !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` argument must be a BigInt');
|
||||
}
|
||||
|
||||
if (x === zero) {
|
||||
return zero;
|
||||
}
|
||||
|
||||
return -x;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-unsignedRightShift
|
||||
|
||||
module.exports = function BigIntUnsignedRightShift(x, y) {
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
|
||||
}
|
||||
|
||||
throw new $TypeError('BigInts have no unsigned right shift, use >> instead');
|
||||
};
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
// var $BigInt = GetIntrinsic('%BigInt%', true);
|
||||
// var $pow = require('math-intrinsics/pow');
|
||||
|
||||
// var BinaryAnd = require('./BinaryAnd');
|
||||
// var BinaryOr = require('./BinaryOr');
|
||||
// var BinaryXor = require('./BinaryXor');
|
||||
// var modulo = require('./modulo');
|
||||
|
||||
// var zero = $BigInt && $BigInt(0);
|
||||
// var negOne = $BigInt && $BigInt(-1);
|
||||
// var two = $BigInt && $BigInt(2);
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-bigintbitwiseop
|
||||
|
||||
module.exports = function BigIntBitwiseOp(op, x, y) {
|
||||
if (op !== '&' && op !== '|' && op !== '^') {
|
||||
throw new $TypeError('Assertion failed: `op` must be `&`, `|`, or `^`');
|
||||
}
|
||||
if (typeof x !== 'bigint' || typeof y !== 'bigint') {
|
||||
throw new $TypeError('`x` and `y` must be BigInts');
|
||||
}
|
||||
|
||||
if (op === '&') {
|
||||
return x & y;
|
||||
}
|
||||
if (op === '|') {
|
||||
return x | y;
|
||||
}
|
||||
return x ^ y;
|
||||
/*
|
||||
var result = zero;
|
||||
var shift = 0;
|
||||
while (x !== zero && x !== negOne && y !== zero && y !== negOne) {
|
||||
var xDigit = modulo(x, two);
|
||||
var yDigit = modulo(y, two);
|
||||
if (op === '&') {
|
||||
result += $pow(2, shift) * BinaryAnd(xDigit, yDigit);
|
||||
} else if (op === '|') {
|
||||
result += $pow(2, shift) * BinaryOr(xDigit, yDigit);
|
||||
} else if (op === '^') {
|
||||
result += $pow(2, shift) * BinaryXor(xDigit, yDigit);
|
||||
}
|
||||
shift += 1;
|
||||
x = (x - xDigit) / two;
|
||||
y = (y - yDigit) / two;
|
||||
}
|
||||
var tmp;
|
||||
if (op === '&') {
|
||||
tmp = BinaryAnd(modulo(x, two), modulo(y, two));
|
||||
} else if (op === '|') {
|
||||
tmp = BinaryAnd(modulo(x, two), modulo(y, two));
|
||||
} else {
|
||||
tmp = BinaryXor(modulo(x, two), modulo(y, two));
|
||||
}
|
||||
if (tmp !== 0) {
|
||||
result -= $pow(2, shift);
|
||||
}
|
||||
return result;
|
||||
*/
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-binaryand
|
||||
|
||||
module.exports = function BinaryAnd(x, y) {
|
||||
if ((x !== 0 && x !== 1) || (y !== 0 && y !== 1)) {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` must be either 0 or 1');
|
||||
}
|
||||
return x & y;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-binaryor
|
||||
|
||||
module.exports = function BinaryOr(x, y) {
|
||||
if ((x !== 0 && x !== 1) || (y !== 0 && y !== 1)) {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` must be either 0 or 1');
|
||||
}
|
||||
return x | y;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-binaryxor
|
||||
|
||||
module.exports = function BinaryXor(x, y) {
|
||||
if ((x !== 0 && x !== 1) || (y !== 0 && y !== 1)) {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` must be either 0 or 1');
|
||||
}
|
||||
return x ^ y;
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var IsArray = require('./IsArray');
|
||||
|
||||
var isByteValue = require('../helpers/isByteValue');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-bytelistbitwiseop
|
||||
|
||||
module.exports = function ByteListBitwiseOp(op, xBytes, yBytes) {
|
||||
if (op !== '&' && op !== '^' && op !== '|') {
|
||||
throw new $TypeError('Assertion failed: `op` must be `&`, `^`, or `|`');
|
||||
}
|
||||
if (!IsArray(xBytes) || !IsArray(yBytes) || xBytes.length !== yBytes.length) {
|
||||
throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
||||
}
|
||||
|
||||
var result = [];
|
||||
|
||||
for (var i = 0; i < xBytes.length; i += 1) {
|
||||
var xByte = xBytes[i];
|
||||
var yByte = yBytes[i];
|
||||
if (!isByteValue(xByte) || !isByteValue(yByte)) {
|
||||
throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
||||
}
|
||||
var resultByte;
|
||||
if (op === '&') {
|
||||
resultByte = xByte & yByte;
|
||||
} else if (op === '^') {
|
||||
resultByte = xByte ^ yByte;
|
||||
} else {
|
||||
resultByte = xByte | yByte;
|
||||
}
|
||||
result[result.length] = resultByte;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var IsArray = require('./IsArray');
|
||||
|
||||
var isByteValue = require('../helpers/isByteValue');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-bytelistequal
|
||||
|
||||
module.exports = function ByteListEqual(xBytes, yBytes) {
|
||||
if (!IsArray(xBytes) || !IsArray(yBytes)) {
|
||||
throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be sequences of byte values (an integer 0-255, inclusive)');
|
||||
}
|
||||
|
||||
if (xBytes.length !== yBytes.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < xBytes.length; i += 1) {
|
||||
var xByte = xBytes[i];
|
||||
var yByte = yBytes[i];
|
||||
if (!isByteValue(xByte) || !isByteValue(yByte)) {
|
||||
throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be sequences of byte values (an integer 0-255, inclusive)');
|
||||
}
|
||||
if (xByte !== yByte) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
var callBound = require('call-bound');
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var IsArray = require('./IsArray');
|
||||
|
||||
var $apply = GetIntrinsic('%Reflect.apply%', true) || callBound('Function.prototype.apply');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-call
|
||||
|
||||
module.exports = function Call(F, V) {
|
||||
var argumentsList = arguments.length > 2 ? arguments[2] : [];
|
||||
if (!IsArray(argumentsList)) {
|
||||
throw new $TypeError('Assertion failed: optional `argumentsList`, if provided, must be a List');
|
||||
}
|
||||
return $apply(F, V, argumentsList);
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
|
||||
var KeyForSymbol = require('./KeyForSymbol');
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-canbeheldweakly
|
||||
|
||||
module.exports = function CanBeHeldWeakly(v) {
|
||||
if (isObject(v)) {
|
||||
return true; // step 1
|
||||
}
|
||||
if (typeof v === 'symbol' && typeof KeyForSymbol(v) === 'undefined') {
|
||||
return true; // step 2
|
||||
}
|
||||
return false; // step 3
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var SameValue = require('./SameValue');
|
||||
var ToNumber = require('./ToNumber');
|
||||
var ToString = require('./ToString');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-canonicalnumericindexstring
|
||||
|
||||
module.exports = function CanonicalNumericIndexString(argument) {
|
||||
if (typeof 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;
|
||||
};
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var callBound = require('call-bound');
|
||||
var hasOwn = require('hasown');
|
||||
|
||||
var $charCodeAt = callBound('String.prototype.charCodeAt');
|
||||
var $toUpperCase = callBound('String.prototype.toUpperCase');
|
||||
|
||||
var isRegExpRecord = require('../helpers/records/regexp-record');
|
||||
var caseFolding = require('../helpers/caseFolding.json');
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-runtime-semantics-canonicalize-ch
|
||||
|
||||
module.exports = function Canonicalize(rer, ch) {
|
||||
if (!isRegExpRecord(rer)) {
|
||||
throw new $TypeError('Assertion failed: `rer` must be a RegExp Record');
|
||||
}
|
||||
|
||||
if (typeof ch !== 'string') {
|
||||
throw new $TypeError('Assertion failed: `ch` must be a character');
|
||||
}
|
||||
|
||||
if (rer['[[Unicode]]'] && rer['[[IgnoreCase]]']) { // step 1
|
||||
if (hasOwn(caseFolding.C, ch)) {
|
||||
return caseFolding.C[ch];
|
||||
}
|
||||
if (hasOwn(caseFolding.S, ch)) {
|
||||
return caseFolding.S[ch];
|
||||
}
|
||||
return ch; // step 1.b
|
||||
}
|
||||
|
||||
if (!rer['[[IgnoreCase]]']) {
|
||||
return ch; // step 2
|
||||
}
|
||||
|
||||
var u = $toUpperCase(ch); // step 5
|
||||
|
||||
if (u.length !== 1) {
|
||||
return ch; // step 7
|
||||
}
|
||||
|
||||
var cu = u; // step 8
|
||||
|
||||
if ($charCodeAt(ch, 0) >= 128 && $charCodeAt(cu, 0) < 128) {
|
||||
return ch; // step 9
|
||||
}
|
||||
|
||||
return cu; // step 10
|
||||
};
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
var callBound = require('call-bound');
|
||||
|
||||
var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var $charCodeAt = callBound('String.prototype.charCodeAt');
|
||||
|
||||
var CharSet = require('../helpers/CharSet').CharSet;
|
||||
|
||||
module.exports = function CharacterRange(A, B) {
|
||||
var a;
|
||||
var b;
|
||||
|
||||
if (A instanceof CharSet || B instanceof CharSet) {
|
||||
if (!(A instanceof CharSet) || !(B instanceof CharSet)) {
|
||||
throw new $TypeError('Assertion failed: CharSets A and B are not both CharSets');
|
||||
}
|
||||
|
||||
A.yield(function (c) {
|
||||
if (typeof a !== 'undefined') {
|
||||
throw new $TypeError('Assertion failed: CharSet A has more than one character');
|
||||
}
|
||||
a = c;
|
||||
});
|
||||
B.yield(function (c) {
|
||||
if (typeof b !== 'undefined') {
|
||||
throw new $TypeError('Assertion failed: CharSet B has more than one character');
|
||||
}
|
||||
b = c;
|
||||
});
|
||||
} else {
|
||||
if (A.length !== 1 || B.length !== 1) {
|
||||
throw new $TypeError('Assertion failed: CharSets A and B contain exactly one character');
|
||||
}
|
||||
a = A[0];
|
||||
b = B[0];
|
||||
}
|
||||
|
||||
var i = $charCodeAt(a, 0);
|
||||
var j = $charCodeAt(b, 0);
|
||||
|
||||
if (!(i <= j)) {
|
||||
throw new $TypeError('Assertion failed: i is not <= j');
|
||||
}
|
||||
|
||||
var arr = [];
|
||||
for (var k = i; k <= j; k += 1) {
|
||||
arr[arr.length] = $fromCharCode(k);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
var keptObjects = [];
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-clear-kept-objects
|
||||
|
||||
module.exports = function ClearKeptObjects() {
|
||||
keptObjects.length = 0;
|
||||
};
|
||||
|
||||
SLOT.set(module.exports, '[[es-abstract internal: KeptAlive]]', keptObjects);
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var GetPrototypeFromConstructor = require('./GetPrototypeFromConstructor');
|
||||
var IsConstructor = require('./IsConstructor');
|
||||
var IsDetachedBuffer = require('./IsDetachedBuffer');
|
||||
var OrdinarySetPrototypeOf = require('./OrdinarySetPrototypeOf');
|
||||
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
var isArrayBuffer = require('is-array-buffer');
|
||||
var arrayBufferSlice = require('arraybuffer.prototype.slice');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-clonearraybuffer
|
||||
|
||||
module.exports = function CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) {
|
||||
if (!isArrayBuffer(srcBuffer)) {
|
||||
throw new $TypeError('Assertion failed: `srcBuffer` must be an ArrayBuffer instance');
|
||||
}
|
||||
if (!isInteger(srcByteOffset) || srcByteOffset < 0) {
|
||||
throw new $TypeError('Assertion failed: `srcByteOffset` must be a non-negative integer');
|
||||
}
|
||||
if (!isInteger(srcLength) || srcLength < 0) {
|
||||
throw new $TypeError('Assertion failed: `srcLength` must be a non-negative integer');
|
||||
}
|
||||
if (!IsConstructor(cloneConstructor)) {
|
||||
throw new $TypeError('Assertion failed: `cloneConstructor` must be a constructor');
|
||||
}
|
||||
|
||||
// 3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
|
||||
var proto = GetPrototypeFromConstructor(cloneConstructor, '%ArrayBufferPrototype%'); // step 3, kinda
|
||||
|
||||
if (IsDetachedBuffer(srcBuffer)) {
|
||||
throw new $TypeError('`srcBuffer` must not be a detached ArrayBuffer'); // step 4
|
||||
}
|
||||
|
||||
/*
|
||||
5. Let srcBlock be srcBuffer.[[ArrayBufferData]].
|
||||
6. Let targetBlock be targetBuffer.[[ArrayBufferData]].
|
||||
7. Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, srcLength).
|
||||
*/
|
||||
var targetBuffer = arrayBufferSlice(srcBuffer, srcByteOffset, srcByteOffset + srcLength); // steps 5-7
|
||||
OrdinarySetPrototypeOf(targetBuffer, proto); // step 3
|
||||
|
||||
return targetBuffer; // step 8
|
||||
};
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var callBound = require('call-bound');
|
||||
var isLeadingSurrogate = require('../helpers/isLeadingSurrogate');
|
||||
var isTrailingSurrogate = require('../helpers/isTrailingSurrogate');
|
||||
|
||||
var UTF16SurrogatePairToCodePoint = require('./UTF16SurrogatePairToCodePoint');
|
||||
|
||||
var $charAt = callBound('String.prototype.charAt');
|
||||
var $charCodeAt = callBound('String.prototype.charCodeAt');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-codepointat
|
||||
|
||||
module.exports = function CodePointAt(string, position) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new $TypeError('Assertion failed: `string` must be a String');
|
||||
}
|
||||
var size = string.length;
|
||||
if (position < 0 || position >= size) {
|
||||
throw new $TypeError('Assertion failed: `position` must be >= 0, and < the length of `string`');
|
||||
}
|
||||
var first = $charCodeAt(string, position);
|
||||
var cp = $charAt(string, position);
|
||||
var firstIsLeading = isLeadingSurrogate(first);
|
||||
var firstIsTrailing = isTrailingSurrogate(first);
|
||||
if (!firstIsLeading && !firstIsTrailing) {
|
||||
return {
|
||||
'[[CodePoint]]': cp,
|
||||
'[[CodeUnitCount]]': 1,
|
||||
'[[IsUnpairedSurrogate]]': false
|
||||
};
|
||||
}
|
||||
if (firstIsTrailing || (position + 1 === size)) {
|
||||
return {
|
||||
'[[CodePoint]]': cp,
|
||||
'[[CodeUnitCount]]': 1,
|
||||
'[[IsUnpairedSurrogate]]': true
|
||||
};
|
||||
}
|
||||
var second = $charCodeAt(string, position + 1);
|
||||
if (!isTrailingSurrogate(second)) {
|
||||
return {
|
||||
'[[CodePoint]]': cp,
|
||||
'[[CodeUnitCount]]': 1,
|
||||
'[[IsUnpairedSurrogate]]': true
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
'[[CodePoint]]': UTF16SurrogatePairToCodePoint(first, second),
|
||||
'[[CodeUnitCount]]': 2,
|
||||
'[[IsUnpairedSurrogate]]': false
|
||||
};
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var UTF16EncodeCodePoint = require('./UTF16EncodeCodePoint');
|
||||
var IsArray = require('./IsArray');
|
||||
|
||||
var forEach = require('../helpers/forEach');
|
||||
var isCodePoint = require('../helpers/isCodePoint');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-codepointstostring
|
||||
|
||||
module.exports = function CodePointsToString(text) {
|
||||
if (!IsArray(text)) {
|
||||
throw new $TypeError('Assertion failed: `text` must be a sequence of Unicode Code Points');
|
||||
}
|
||||
var result = '';
|
||||
forEach(text, function (cp) {
|
||||
if (!isCodePoint(cp)) {
|
||||
throw new $TypeError('Assertion failed: `text` must be a sequence of Unicode Code Points');
|
||||
}
|
||||
result += UTF16EncodeCodePoint(cp);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('./Call');
|
||||
var IsLessThan = require('./IsLessThan');
|
||||
var ToNumber = require('./ToNumber');
|
||||
var ToString = require('./ToString');
|
||||
|
||||
var isNaN = require('math-intrinsics/isNaN');
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-comparearrayelements
|
||||
|
||||
module.exports = function CompareArrayElements(x, y, compareFn) {
|
||||
if (typeof compareFn !== 'function' && typeof compareFn !== 'undefined') {
|
||||
throw new $TypeError('Assertion failed: `compareFn` must be a function or undefined');
|
||||
}
|
||||
|
||||
if (typeof x === 'undefined' && typeof y === 'undefined') {
|
||||
return 0; // step 1
|
||||
}
|
||||
|
||||
if (typeof x === 'undefined') {
|
||||
return 1; // step 2
|
||||
}
|
||||
|
||||
if (typeof y === 'undefined') {
|
||||
return -1; // step 3
|
||||
}
|
||||
|
||||
if (typeof compareFn !== 'undefined') { // step 4
|
||||
var v = ToNumber(Call(compareFn, void undefined, [x, y])); // step 4.a
|
||||
if (isNaN(v)) {
|
||||
return 0; // step 4.b
|
||||
}
|
||||
return v; // step 4.c
|
||||
}
|
||||
|
||||
var xString = ToString(x); // step 5
|
||||
var yString = ToString(y); // step 6
|
||||
var xSmaller = IsLessThan(xString, yString, true); // step 7
|
||||
if (xSmaller) {
|
||||
return -1; // step 8
|
||||
}
|
||||
var ySmaller = IsLessThan(yString, xString, true); // step 9
|
||||
if (ySmaller) {
|
||||
return 1; // step 10
|
||||
}
|
||||
return 0; // step 11
|
||||
};
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('./Call');
|
||||
var SameValue = require('./SameValue');
|
||||
var ToNumber = require('./ToNumber');
|
||||
|
||||
var isNaN = require('math-intrinsics/isNaN');
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-comparetypedarrayelements
|
||||
|
||||
module.exports = function CompareTypedArrayElements(x, y, compareFn) {
|
||||
if ((typeof x !== 'number' && typeof x !== 'bigint') || typeof x !== typeof y) {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` must be either a BigInt or a Number, and both must be the same type');
|
||||
}
|
||||
if (typeof compareFn !== 'function' && typeof compareFn !== 'undefined') {
|
||||
throw new $TypeError('Assertion failed: `compareFn` must be a function or undefined');
|
||||
}
|
||||
|
||||
if (typeof compareFn !== 'undefined') { // step 2
|
||||
var v = ToNumber(Call(compareFn, void undefined, [x, y])); // step 2.a
|
||||
if (isNaN(v)) {
|
||||
return 0; // step 2.b
|
||||
}
|
||||
return v; // step 2.c
|
||||
}
|
||||
|
||||
var xNaN = isNaN(x);
|
||||
var yNaN = isNaN(y);
|
||||
if (xNaN && yNaN) {
|
||||
return 0; // step 3
|
||||
}
|
||||
|
||||
if (xNaN) {
|
||||
return 1; // step 4
|
||||
}
|
||||
|
||||
if (yNaN) {
|
||||
return -1; // step 5
|
||||
}
|
||||
|
||||
if (x < y) {
|
||||
return -1; // step 6
|
||||
}
|
||||
|
||||
if (x > y) {
|
||||
return 1; // step 7
|
||||
}
|
||||
|
||||
if (SameValue(x, -0) && SameValue(y, 0)) {
|
||||
return -1; // step 8
|
||||
}
|
||||
|
||||
if (SameValue(x, 0) && SameValue(y, -0)) {
|
||||
return 1; // step 9
|
||||
}
|
||||
|
||||
return 0; // step 10
|
||||
};
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var hasOwn = require('hasown');
|
||||
|
||||
var IsDataDescriptor = require('./IsDataDescriptor');
|
||||
var IsGenericDescriptor = require('./IsGenericDescriptor');
|
||||
|
||||
var isPropertyDescriptor = require('../helpers/records/property-descriptor');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-completepropertydescriptor
|
||||
|
||||
module.exports = function CompletePropertyDescriptor(Desc) {
|
||||
if (!isPropertyDescriptor(Desc)) {
|
||||
throw new $TypeError('Assertion failed: `Desc` must be a Property Descriptor');
|
||||
}
|
||||
|
||||
/* eslint no-param-reassign: 0 */
|
||||
|
||||
if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) {
|
||||
if (!hasOwn(Desc, '[[Value]]')) {
|
||||
Desc['[[Value]]'] = void 0;
|
||||
}
|
||||
if (!hasOwn(Desc, '[[Writable]]')) {
|
||||
Desc['[[Writable]]'] = false;
|
||||
}
|
||||
} else {
|
||||
if (!hasOwn(Desc, '[[Get]]')) {
|
||||
Desc['[[Get]]'] = void 0;
|
||||
}
|
||||
if (!hasOwn(Desc, '[[Set]]')) {
|
||||
Desc['[[Set]]'] = void 0;
|
||||
}
|
||||
}
|
||||
if (!hasOwn(Desc, '[[Enumerable]]')) {
|
||||
Desc['[[Enumerable]]'] = false;
|
||||
}
|
||||
if (!hasOwn(Desc, '[[Configurable]]')) {
|
||||
Desc['[[Configurable]]'] = false;
|
||||
}
|
||||
return Desc;
|
||||
};
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
// https://262.ecma-international.org/7.0/#sec-completion-record-specification-type
|
||||
|
||||
var CompletionRecord = function CompletionRecord(type, value) {
|
||||
if (!(this instanceof CompletionRecord)) {
|
||||
return new CompletionRecord(type, value);
|
||||
}
|
||||
if (type !== 'normal' && type !== 'break' && type !== 'continue' && type !== 'return' && type !== 'throw') {
|
||||
throw new $SyntaxError('Assertion failed: `type` must be one of "normal", "break", "continue", "return", or "throw"');
|
||||
}
|
||||
SLOT.set(this, '[[Type]]', type);
|
||||
SLOT.set(this, '[[Value]]', value);
|
||||
// [[Target]] slot?
|
||||
};
|
||||
|
||||
CompletionRecord.prototype.type = function Type() {
|
||||
return SLOT.get(this, '[[Type]]');
|
||||
};
|
||||
|
||||
CompletionRecord.prototype.value = function Value() {
|
||||
return SLOT.get(this, '[[Value]]');
|
||||
};
|
||||
|
||||
CompletionRecord.prototype['?'] = function ReturnIfAbrupt() {
|
||||
var type = SLOT.get(this, '[[Type]]');
|
||||
var value = SLOT.get(this, '[[Value]]');
|
||||
|
||||
if (type === 'throw') {
|
||||
throw value;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
CompletionRecord.prototype['!'] = function assert() {
|
||||
var type = SLOT.get(this, '[[Type]]');
|
||||
|
||||
if (type !== 'normal') {
|
||||
throw new $SyntaxError('Assertion failed: Completion Record is not of type "normal"');
|
||||
}
|
||||
return SLOT.get(this, '[[Value]]');
|
||||
};
|
||||
|
||||
module.exports = CompletionRecord;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
var callBound = require('call-bound');
|
||||
var OwnPropertyKeys = require('own-keys');
|
||||
|
||||
var forEach = require('../helpers/forEach');
|
||||
var every = require('../helpers/every');
|
||||
var some = require('../helpers/some');
|
||||
|
||||
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
||||
|
||||
var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow');
|
||||
var Get = require('./Get');
|
||||
var IsArray = require('./IsArray');
|
||||
var isPropertyKey = require('../helpers/isPropertyKey');
|
||||
var SameValue = require('./SameValue');
|
||||
var ToNumber = require('./ToNumber');
|
||||
var ToObject = require('./ToObject');
|
||||
|
||||
var isInteger = require('math-intrinsics/isInteger');
|
||||
|
||||
// https://262.ecma-international.org/12.0/#sec-copydataproperties
|
||||
|
||||
module.exports = function CopyDataProperties(target, source, excludedItems) {
|
||||
if (!isObject(target)) {
|
||||
throw new $TypeError('Assertion failed: "target" must be an Object');
|
||||
}
|
||||
|
||||
if (!IsArray(excludedItems) || !every(excludedItems, isPropertyKey)) {
|
||||
throw new $TypeError('Assertion failed: "excludedItems" must be a List of Property Keys');
|
||||
}
|
||||
|
||||
if (typeof source === 'undefined' || source === null) {
|
||||
return target;
|
||||
}
|
||||
|
||||
var from = ToObject(source);
|
||||
|
||||
var keys = OwnPropertyKeys(from);
|
||||
forEach(keys, function (nextKey) {
|
||||
var excluded = some(excludedItems, function (e) {
|
||||
return SameValue(e, nextKey) === true;
|
||||
});
|
||||
/*
|
||||
var excluded = false;
|
||||
|
||||
forEach(excludedItems, function (e) {
|
||||
if (SameValue(e, nextKey) === true) {
|
||||
excluded = true;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
var enumerable = $isEnumerable(from, 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(from, nextKey);
|
||||
CreateDataPropertyOrThrow(target, nextKey, propValue);
|
||||
}
|
||||
});
|
||||
|
||||
return target;
|
||||
};
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $SyntaxError = require('es-errors/syntax');
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
var $Promise = GetIntrinsic('%Promise%', true);
|
||||
|
||||
var AsyncFromSyncIteratorContinuation = require('./AsyncFromSyncIteratorContinuation');
|
||||
var Call = require('./Call');
|
||||
var CreateIterResultObject = require('./CreateIterResultObject');
|
||||
var Get = require('./Get');
|
||||
var GetMethod = require('./GetMethod');
|
||||
var IteratorNext = require('./IteratorNext');
|
||||
var OrdinaryObjectCreate = require('./OrdinaryObjectCreate');
|
||||
|
||||
var isIteratorRecord = require('../helpers/records/iterator-record-2023');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
var $AsyncFromSyncIteratorPrototype = GetIntrinsic('%AsyncFromSyncIteratorPrototype%', true) || {
|
||||
next: function next(value) {
|
||||
if (!$Promise) {
|
||||
throw new $SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
|
||||
SLOT.assert(O, '[[SyncIteratorRecord]]'); // step 2
|
||||
|
||||
var argsLength = arguments.length;
|
||||
|
||||
return new $Promise(function (resolve) { // step 3
|
||||
var syncIteratorRecord = SLOT.get(O, '[[SyncIteratorRecord]]'); // step 4
|
||||
var result;
|
||||
if (argsLength > 0) {
|
||||
result = IteratorNext(syncIteratorRecord, value); // step 5.a
|
||||
} else { // step 6
|
||||
result = IteratorNext(syncIteratorRecord);// step 6.a
|
||||
}
|
||||
resolve(AsyncFromSyncIteratorContinuation(result)); // step 8
|
||||
});
|
||||
},
|
||||
'return': function () {
|
||||
if (!$Promise) {
|
||||
throw new $SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
|
||||
SLOT.assert(O, '[[SyncIteratorRecord]]'); // step 2
|
||||
|
||||
var valueIsPresent = arguments.length > 0;
|
||||
var value = valueIsPresent ? arguments[0] : void undefined;
|
||||
|
||||
return new $Promise(function (resolve, reject) { // step 3
|
||||
var syncIterator = SLOT.get(O, '[[SyncIteratorRecord]]')['[[Iterator]]']; // step 4
|
||||
var iteratorReturn = GetMethod(syncIterator, 'return'); // step 5
|
||||
|
||||
if (typeof iteratorReturn === 'undefined') { // step 7
|
||||
var iterResult = CreateIterResultObject(value, true); // step 7.a
|
||||
Call(resolve, undefined, [iterResult]); // step 7.b
|
||||
return;
|
||||
}
|
||||
var result;
|
||||
if (valueIsPresent) { // step 8
|
||||
result = Call(iteratorReturn, syncIterator, [value]); // step 8.a
|
||||
} else { // step 9
|
||||
result = Call(iteratorReturn, syncIterator); // step 9.a
|
||||
}
|
||||
if (!isObject(result)) { // step 11
|
||||
Call(reject, undefined, [new $TypeError('Iterator `return` method returned a non-object value.')]); // step 11.a
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(AsyncFromSyncIteratorContinuation(result)); // step 12
|
||||
});
|
||||
},
|
||||
'throw': function () {
|
||||
if (!$Promise) {
|
||||
throw new $SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
|
||||
SLOT.assert(O, '[[SyncIteratorRecord]]'); // step 2
|
||||
|
||||
var valueIsPresent = arguments.length > 0;
|
||||
var value = valueIsPresent ? arguments[0] : void undefined;
|
||||
|
||||
return new $Promise(function (resolve, reject) { // step 3
|
||||
var syncIterator = SLOT.get(O, '[[SyncIteratorRecord]]')['[[Iterator]]']; // step 4
|
||||
|
||||
var throwMethod = GetMethod(syncIterator, 'throw'); // step 5
|
||||
|
||||
if (typeof throwMethod === 'undefined') { // step 7
|
||||
Call(reject, undefined, [value]); // step 7.a
|
||||
return;
|
||||
}
|
||||
|
||||
var result;
|
||||
if (valueIsPresent) { // step 8
|
||||
result = Call(throwMethod, syncIterator, [value]); // step 8.a
|
||||
} else { // step 9
|
||||
result = Call(throwMethod, syncIterator); // step 9.a
|
||||
}
|
||||
if (!isObject(result)) { // step 11
|
||||
Call(reject, undefined, [new $TypeError('Iterator `throw` method returned a non-object value.')]); // step 11.a
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(AsyncFromSyncIteratorContinuation(result/* , promiseCapability */)); // step 12
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// https://262.ecma-international.org/14.0/#sec-createasyncfromsynciterator
|
||||
|
||||
module.exports = function CreateAsyncFromSyncIterator(syncIteratorRecord) {
|
||||
if (!isIteratorRecord(syncIteratorRecord)) {
|
||||
throw new $TypeError('Assertion failed: `syncIteratorRecord` must be an Iterator Record');
|
||||
}
|
||||
|
||||
// var asyncIterator = OrdinaryObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »); // step 1
|
||||
var asyncIterator = OrdinaryObjectCreate($AsyncFromSyncIteratorPrototype);
|
||||
|
||||
SLOT.set(asyncIterator, '[[SyncIteratorRecord]]', syncIteratorRecord); // step 2
|
||||
|
||||
var nextMethod = Get(asyncIterator, 'next'); // step 3
|
||||
|
||||
return { // steps 3-4
|
||||
'[[Iterator]]': asyncIterator,
|
||||
'[[NextMethod]]': nextMethod,
|
||||
'[[Done]]': false
|
||||
};
|
||||
};
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
|
||||
var isPropertyKey = require('../helpers/isPropertyKey');
|
||||
var OrdinaryDefineOwnProperty = require('./OrdinaryDefineOwnProperty');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-createdataproperty
|
||||
|
||||
module.exports = function CreateDataProperty(O, P, V) {
|
||||
if (!isObject(O)) {
|
||||
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
||||
}
|
||||
if (!isPropertyKey(P)) {
|
||||
throw new $TypeError('Assertion failed: P is not a Property Key');
|
||||
}
|
||||
var newDesc = {
|
||||
'[[Configurable]]': true,
|
||||
'[[Enumerable]]': true,
|
||||
'[[Value]]': V,
|
||||
'[[Writable]]': true
|
||||
};
|
||||
return OrdinaryDefineOwnProperty(O, P, newDesc);
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var isObject = require('es-object-atoms/isObject');
|
||||
|
||||
var CreateDataProperty = require('./CreateDataProperty');
|
||||
|
||||
var isPropertyKey = require('../helpers/isPropertyKey');
|
||||
|
||||
// // https://262.ecma-international.org/14.0/#sec-createdatapropertyorthrow
|
||||
|
||||
module.exports = function CreateDataPropertyOrThrow(O, P, V) {
|
||||
if (!isObject(O)) {
|
||||
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
||||
}
|
||||
if (!isPropertyKey(P)) {
|
||||
throw new $TypeError('Assertion failed: P is not a Property Key');
|
||||
}
|
||||
var success = CreateDataProperty(O, P, V);
|
||||
if (!success) {
|
||||
throw new $TypeError('unable to create data property');
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user