Skip to content

Commit eea08a5

Browse files
TrottItalo A. Casas
authored andcommitted
Revert "buffer: convert offset & length to int properly"
This reverts commit ca37fa5. A test provided by the commit fails on most (but not all) platforms on CI. PR-URL: nodejs#9814 Ref: nodejs#9492 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
1 parent 19a45f4 commit eea08a5

5 files changed

Lines changed: 2 additions & 108 deletions

File tree

‎lib/buffer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function fromArrayLike(obj) {
228228
}
229229

230230
function fromArrayBuffer(obj, byteOffset, length) {
231-
byteOffset = internalUtil.toInteger(byteOffset);
231+
byteOffset >>>= 0;
232232

233233
const maxLength = obj.byteLength - byteOffset;
234234

@@ -238,7 +238,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
238238
if (length === undefined) {
239239
length = maxLength;
240240
} else {
241-
length = internalUtil.toLength(length);
241+
length >>>= 0;
242242
if (length > maxLength)
243243
throw new RangeError("'length' is out of bounds");
244244
}

‎lib/internal/util.js‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,3 @@ exports.cachedResult = function cachedResult(fn) {
161161
return result;
162162
};
163163
};
164-
165-
/*
166-
* Implementation of ToInteger as per ECMAScript Specification
167-
* Refer: http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger
168-
*/
169-
const toInteger = exports.toInteger = function toInteger(argument) {
170-
const number = +argument;
171-
return Number.isNaN(number) ? 0 : Math.trunc(number);
172-
};
173-
174-
/*
175-
* Implementation of ToLength as per ECMAScript Specification
176-
* Refer: http://www.ecma-international.org/ecma-262/6.0/#sec-tolength
177-
*/
178-
exports.toLength = function toLength(argument) {
179-
const len = toInteger(argument);
180-
return len <= 0 ? 0 : Math.min(len, Number.MAX_SAFE_INTEGER);
181-
};

‎test/parallel/test-buffer-creation-regression.js‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎test/parallel/test-internal-util-toInteger.js‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎test/parallel/test-internal-util-toLength.js‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)