Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from ljharb:main #61

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 2024/GetViewByteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ module.exports = function GetViewByteLength(viewRecord) {

var view = viewRecord['[[Object]]']; // step 2

var viewByteLength = dataViewByteLength(view); // view.[[ByteLength]]
var isFixed = IsFixedLengthArrayBuffer(dataViewBuffer(view));

var viewByteLength = isFixed ? dataViewByteLength(view) : 'AUTO'; // view.[[ByteLength]]
if (viewByteLength !== 'AUTO') {
return viewByteLength; // step 3
}

if (IsFixedLengthArrayBuffer(dataViewBuffer(view))) {
if (isFixed) {
throw new $TypeError('Assertion failed: DataView’s ArrayBuffer is not fixed length'); // step 4
}

Expand Down
6 changes: 5 additions & 1 deletion 2024/TypedArrayByteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

var $TypeError = require('es-errors/type');

var IsFixedLengthArrayBuffer = require('./IsFixedLengthArrayBuffer');
var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
var TypedArrayElementSize = require('./TypedArrayElementSize');
var TypedArrayLength = require('./TypedArrayLength');

var isTypedArrayWithBufferWitnessRecord = require('../helpers/records/typed-array-with-buffer-witness-record');

var typedArrayByffer = require('typed-array-buffer');
var typedArrayByteLength = require('typed-array-byte-length');

// https://262.ecma-international.org/15.0/#sec-typedarraybytelength
Expand All @@ -28,7 +30,9 @@ module.exports = function TypedArrayByteLength(taRecord) {

var O = taRecord['[[Object]]']; // step 4

var byteLength = typedArrayByteLength(O);
var isFixed = IsFixedLengthArrayBuffer(typedArrayByffer(O));

var byteLength = isFixed ? typedArrayByteLength(O) : 'AUTO';
if (byteLength !== 'AUTO') {
return byteLength; // step 5
}
Expand Down
8 changes: 5 additions & 3 deletions 2024/TypedArrayLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var typedArrayBuffer = require('typed-array-buffer');
var typedArrayByteOffset = require('typed-array-byte-offset');
var typedArrayLength = require('typed-array-length');

// http://www.ecma-international.org/ecma-262/15.0/#sec-typedarraylength
// https://www.ecma-international.org/ecma-262/15.0/#sec-typedarraylength

module.exports = function TypedArrayLength(taRecord) {
if (!isTypedArrayWithBufferWitnessRecord(taRecord)) {
Expand All @@ -26,12 +26,14 @@ module.exports = function TypedArrayLength(taRecord) {

var O = taRecord['[[Object]]']; // step 2

var length = typedArrayLength(O);
var isFixed = IsFixedLengthArrayBuffer(typedArrayBuffer(O));

var length = isFixed ? typedArrayLength(O) : 'AUTO';
if (length !== 'AUTO') {
return length; // step 3
}

if (IsFixedLengthArrayBuffer(typedArrayBuffer(O))) {
if (isFixed) {
throw new $TypeError('Assertion failed: array buffer is not fixed length'); // step 4
}

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@
"has-strict-mode": "^1.0.1",
"in-publish": "^2.0.1",
"is-core-module": "^2.16.1",
"is-registered-symbol": "^1.1.1",
"jackspeak": "=2.1.1",
"make-arrow-function": "^1.2.0",
"make-async-function": "^1.0.0",
"make-async-generator-function": "^1.0.0",
"make-generator-function": "^2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/clearBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function clearBuffer(buffer) {
new DataView(buffer).setFloat64(0, 0, true); // clear the buffer
};
9 changes: 9 additions & 0 deletions test/helpers/getNamelessFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = function getNamelessFunction() {
var f = Object(function () {});
try {
delete f.name;
} catch (e) { /**/ }
return f;
};
18 changes: 18 additions & 0 deletions test/helpers/kludgeMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var assign = require('object.assign');

var hasLastIndex = 'lastIndex' in (/a/).exec('a'); // IE 8
var hasGroups = 'groups' in (/a/).exec('a'); // modern engines

module.exports = function kludgeMatch(R, matchObject) {
if (hasGroups) {
assign(matchObject, { groups: matchObject.groups });
}
if (hasLastIndex) {
assign(matchObject, { lastIndex: matchObject.lastIndex || R.lastIndex });
} else {
delete matchObject.lastIndex; // eslint-disable-line no-param-reassign
}
return matchObject;
};
24 changes: 24 additions & 0 deletions test/helpers/makeAsyncFromSyncIterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

var makeIteratorRecord = require('./makeIteratorRecord');

module.exports = function makeAsyncFromSyncIterator(CreateAsyncFromSyncIterator, end, throwMethod, returnMethod) {
var i = 0;
var iterator = {
next: function next() {
try {
return {
done: i > end,
value: i
};
} finally {
i += 1;
}
},
'return': returnMethod,
'throw': throwMethod
};
var syncIteratorRecord = makeIteratorRecord(iterator);

return CreateAsyncFromSyncIterator(syncIteratorRecord);
};
9 changes: 9 additions & 0 deletions test/helpers/makeIteratorRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = function makeIteratorRecord(iterator) {
return {
'[[Iterator]]': iterator,
'[[NextMethod]]': iterator.next,
'[[Done]]': false
};
};
18 changes: 18 additions & 0 deletions test/helpers/testAsyncIterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = function testAsyncIterator(t, asyncIterator, expected) {
var results = arguments.length > 3 ? arguments[3] : [];

var nextResult = asyncIterator.next();

return Promise.resolve(nextResult).then(function (result) {
results.push(result);
if (!result.done && results.length < expected.length) {
t.deepEqual(result, { done: false, value: expected[results.length - 1] }, 'result ' + (results.length - 1));
return testAsyncIterator(t, asyncIterator, expected, results);
}

t.equal(results.length, expected.length, 'expected ' + expected.length + ', got ' + (result.done ? '' : 'more than ') + results.length);
return results.length;
});
};
11 changes: 11 additions & 0 deletions test/helpers/testIterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = function testIterator(t, iterator, expected) {
var resultCount = 0;
var result;
while (result = iterator.next(), !result.done && resultCount < expected.length + 1) { // eslint-disable-line no-sequences
t.deepEqual(result, { done: false, value: expected[resultCount] }, 'result ' + resultCount);
resultCount += 1;
}
t.equal(resultCount, expected.length, 'expected ' + expected.length + ', got ' + (result.done ? '' : 'more than ') + resultCount);
};
18 changes: 18 additions & 0 deletions test/helpers/testRESIterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var v = require('es-value-fixtures');

var testIterator = require('./testIterator');

module.exports = function testRegExpStringIterator(CreateRegExpStringIterator, t, regex, str, global, unicode, expected) {
var iterator = CreateRegExpStringIterator(regex, str, global, unicode);
t.equal(typeof iterator, 'object', 'iterator is an object');
t.equal(typeof iterator.next, 'function', '`.next` is a function');

t.test('has symbols', { skip: !v.hasSymbols }, function (st) {
st.equal(typeof iterator[Symbol.iterator], 'function', '[`Symbol.iterator`] is a function');
st.end();
});

testIterator(t, iterator, expected);
};
10 changes: 10 additions & 0 deletions test/helpers/throwsSentinel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

module.exports = function throwsSentinel(fn, sentinel, message) {
try {
fn();
this.fail('did not throw: ' + message);
} catch (e) {
this.equal(e, sentinel, message);
}
};
164 changes: 164 additions & 0 deletions test/helpers/v.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
'use strict';

var v = require('es-value-fixtures');
var hasBigInts = require('has-bigints')();
var isCore = require('is-core-module');

var leadingPoo = '\uD83D';
var trailingPoo = '\uDCA9';
var wholePoo = leadingPoo + trailingPoo;

var msPerSecond = 1e3;
var msPerMinute = 60 * msPerSecond;
var msPerHour = 60 * msPerMinute;
var msPerDay = 24 * msPerHour;

var unknowns = [].concat(
v.primitives,
v.objects
);
var allButSyms = [].concat(
v.objects,
v.nonSymbolPrimitives
);
var invalidTATypes = [].concat(
v.nonStrings,
'not a valid type'
);
var nonFiniteNumbers = [].concat(
v.infinities,
NaN
);
var notInts = [].concat(
v.nonNumbers,
v.nonIntegerNumbers,
nonFiniteNumbers,
[],
new Date()
);

var elementSizes = {
__proto__: null,
$Int8Array: 1,
$Uint8Array: 1,
$Uint8ClampedArray: 1,
$Int16Array: 2,
$Uint16Array: 2,
$Int32Array: 4,
$Uint32Array: 4,
$BigInt64Array: 8,
$BigUint64Array: 8,
$Float32Array: 4,
$Float64Array: 8
};

var unclampedUnsignedIntegerTypes = [
'Int8',
'Int16',
'Int32'
];
var clampedTypes = [
'Uint8C'
];
var unclampedSignedIntegerTypes = [
'Uint8',
'Uint16',
'Uint32'
];
var unclampedIntegerTypes = [].concat(
unclampedUnsignedIntegerTypes,
unclampedSignedIntegerTypes
);
var floatTypes = [
'Float32',
'Float64'
];
var integerTypes = [].concat(
unclampedIntegerTypes,
clampedTypes
);
var bigIntTypes = [
'BigInt64',
'BigUint64'
];
var numberTypes = [].concat(
floatTypes,
integerTypes
);
var nonUnclampedIntegerTypes = [].concat(
floatTypes,
bigIntTypes
);
var unsignedElementTypes = [].concat(
unclampedSignedIntegerTypes,
hasBigInts ? 'BigUint64' : []
);
var signedElementTypes = [].concat(
unclampedUnsignedIntegerTypes,
floatTypes,
hasBigInts ? 'BigInt64' : []
);
var allTypes = [].concat(
numberTypes,
hasBigInts ? bigIntTypes : []
);
var nonTATypes = [].concat(
v.nonStrings,
'',
'Byte'
);

var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false

// 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;
}());

var isBigIntTAType = function isBigIntTAType(type) {
return type.slice(0, 3) === 'Big';
};

/* globals postMessage */
var canDetach = typeof structuredClone === 'function' || typeof postMessage === 'function' || isCore('worker_threads');

module.exports = {
poo: {
leading: leadingPoo,
trailing: trailingPoo,
whole: wholePoo
},
hasBigInts: hasBigInts,
msPerSecond: msPerSecond,
msPerMinute: msPerMinute,
msPerHour: msPerHour,
msPerDay: msPerDay,
unknowns: unknowns,
allButSyms: allButSyms,
invalidTATypes: invalidTATypes,
nonFiniteNumbers: nonFiniteNumbers,
notInts: notInts,
elementSizes: elementSizes,
unclampedUnsignedIntegerTypes: unclampedUnsignedIntegerTypes,
clampedTypes: clampedTypes,
unclampedSignedIntegerTypes: unclampedSignedIntegerTypes,
unclampedIntegerTypes: unclampedIntegerTypes,
floatTypes: floatTypes,
integerTypes: integerTypes,
bigIntTypes: bigIntTypes,
numberTypes: numberTypes,
nonUnclampedIntegerTypes: nonUnclampedIntegerTypes,
unsignedElementTypes: unsignedElementTypes,
signedElementTypes: signedElementTypes,
allTypes: allTypes,
nonTATypes: nonTATypes,
canDistinguishSparseFromUndefined: canDistinguishSparseFromUndefined,
noThrowOnStrictViolation: noThrowOnStrictViolation,
isBigIntTAType: isBigIntTAType,
canDetach: canDetach
};
Loading
Loading