Skip to content

Commit

Permalink
[Fix] helpers/bytesAsInteger: avoid a crash in node 10.4 - 10.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 29, 2024
1 parent 7141b8c commit fc195ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helpers/bytesAsInteger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function bytesAsInteger(rawBytes, elementSize, isUnsigned, isBi
// this is common to both branches
var intValue = Z(0);
for (var i = 0; i < rawBytes.length; i++) {
intValue += Z(rawBytes[i]) * Z($pow(2, 8 * i));
intValue += Z(rawBytes[i] * $pow(2, 8 * i));
}
/*
Let intValue be the byte elements of rawBytes concatenated and interpreted as a bit string encoding of an unsigned little-endian binary number.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object.fromentries": "^2.0.8",
"safe-bigint": "^1.0.1",
"safe-bigint": "^1.1.0",
"safe-publish-latest": "^2.0.0",
"ses": "^0.18.8",
"tape": "^5.7.5"
Expand Down
9 changes: 4 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,7 @@ var es2015 = function ES2015(ES, ops, expectedMissing, skips) {
forEach(availableTypedArrays, function (typedArray) {
var isBigInt = typedArray.slice(0, 3) === 'Big';
if (isBigInt && 'ToBigInt' in ES) {
var Z = isBigInt ? BigInt : Number;
var Z = isBigInt ? safeBigInt : Number;
var TA = global[typedArray];

var arr = new TA([Z(1), Z(2), Z(3)]);
Expand Down Expand Up @@ -14608,7 +14608,7 @@ var es2023 = function ES2023(ES, ops, expectedMissing, skips) {

forEach(availableTypedArrays, function (name) {
var isBigInt = name.slice(0, 3) === 'Big';
var Z = isBigInt ? BigInt : Number;
var Z = isBigInt ? safeBigInt : Number;
var TA = global[name];

var ta = new TA([Z(1), Z(2), Z(3)]);
Expand Down Expand Up @@ -15545,7 +15545,6 @@ var es2024 = function ES2024(ES, ops, expectedMissing, skips) {

clearBuffer(view.buffer);
var littleVal = unserialize(result.setAsLittle.asLittle);
console.log(littleVal);
view['set' + method](0, isBigInt ? safeBigInt(littleVal) : littleVal, true);

try {
Expand Down Expand Up @@ -16717,7 +16716,7 @@ var es2024 = function ES2024(ES, ops, expectedMissing, skips) {
'Float64'
), function (type) {
var isBigInt = type === 'BigInt64' || type === 'BigUint64';
var Z = isBigInt ? $BigInt : Number;
var Z = isBigInt ? safeBigInt : Number;
var hasBigEndian = type !== 'Int8' && type !== 'Uint8' && type !== 'Uint8C'; // the 8-bit types are special, they don't have big-endian
var result = testCase[type === 'Uint8C' ? 'Uint8Clamped' : type];
var value = unserialize(testCase.value);
Expand Down Expand Up @@ -17134,7 +17133,7 @@ var es2024 = function ES2024(ES, ops, expectedMissing, skips) {

forEach(availableTypedArrays, function (TypedArray) {
var isBigInt = TypedArray.slice(0, 3) === 'Big';
var Z = isBigInt ? BigInt : Number;
var Z = isBigInt ? safeBigInt : Number;
var TA = global[TypedArray];

var arr = new TA([Z(1), Z(2), Z(3)]);
Expand Down

0 comments on commit fc195ed

Please sign in to comment.