Skip to content

Commit

Permalink
Revert "buffer: convert offset & length to int properly"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trott committed Nov 26, 2016
1 parent 951ba0d commit 6b2aa1a
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 108 deletions.
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function fromArrayLike(obj) {
}

function fromArrayBuffer(obj, byteOffset, length) {
byteOffset = internalUtil.toInteger(byteOffset);
byteOffset >>>= 0;

const maxLength = obj.byteLength - byteOffset;

Expand All @@ -248,7 +248,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
if (length === undefined) {
length = maxLength;
} else {
length = internalUtil.toLength(length);
length >>>= 0;
if (length > maxLength)
throw new RangeError("'length' is out of bounds");
}
Expand Down
18 changes: 0 additions & 18 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,3 @@ exports.cachedResult = function cachedResult(fn) {
return result;
};
};

/*
* Implementation of ToInteger as per ECMAScript Specification
* Refer: http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger
*/
const toInteger = exports.toInteger = function toInteger(argument) {
const number = +argument;
return Number.isNaN(number) ? 0 : Math.trunc(number);
};

/*
* Implementation of ToLength as per ECMAScript Specification
* Refer: http://www.ecma-international.org/ecma-262/6.0/#sec-tolength
*/
exports.toLength = function toLength(argument) {
const len = toInteger(argument);
return len <= 0 ? 0 : Math.min(len, Number.MAX_SAFE_INTEGER);
};
21 changes: 0 additions & 21 deletions test/parallel/test-buffer-creation-regression.js

This file was deleted.

32 changes: 0 additions & 32 deletions test/parallel/test-internal-util-toInteger.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/parallel/test-internal-util-toLength.js

This file was deleted.

0 comments on commit 6b2aa1a

Please sign in to comment.