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

buffer: refactor redeclared variables #4886

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 14 additions & 13 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function fromString(string, encoding) {

function fromObject(obj) {
if (obj instanceof Buffer) {
var b = allocate(obj.length);
const b = allocate(obj.length);

if (b.length === 0)
return b;
Expand All @@ -135,9 +135,9 @@ function fromObject(obj) {
}

if (Array.isArray(obj)) {
var length = obj.length;
var b = allocate(length);
for (var i = 0; i < length; i++)
const length = obj.length;
const b = allocate(length);
for (let i = 0; i < length; i++)
b[i] = obj[i] & 255;
return b;
}
Expand All @@ -151,22 +151,22 @@ function fromObject(obj) {
}

if (obj.buffer instanceof ArrayBuffer || obj.length) {
var length;
let length;
if (typeof obj.length !== 'number' || obj.length !== obj.length)
length = 0;
else
length = obj.length;
var b = allocate(length);
for (var i = 0; i < length; i++) {
const b = allocate(length);
for (let i = 0; i < length; i++) {
b[i] = obj[i] & 255;
}
return b;
}

if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
var array = obj.data;
var b = allocate(array.length);
for (var i = 0; i < array.length; i++)
const b = allocate(array.length);
for (let i = 0; i < array.length; i++)
b[i] = array[i] & 255;
return b;
}
Expand Down Expand Up @@ -231,15 +231,15 @@ Buffer.concat = function(list, length) {

if (length === undefined) {
length = 0;
for (var i = 0; i < list.length; i++)
for (let i = 0; i < list.length; i++)
length += list[i].length;
} else {
length = length >>> 0;
}

var buffer = new Buffer(length);
var pos = 0;
for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
var buf = list[i];
buf.copy(buffer, pos);
pos += buf.length;
Expand Down Expand Up @@ -401,10 +401,11 @@ function slowToString(encoding, start, end) {


Buffer.prototype.toString = function() {
let result;
if (arguments.length === 0) {
var result = this.utf8Slice(0, this.length);
result = this.utf8Slice(0, this.length);
} else {
var result = slowToString.apply(this, arguments);
result = slowToString.apply(this, arguments);
}
if (result === undefined)
throw new Error('"toString()" failed');
Expand Down