Skip to content

Commit c49a144

Browse files
committed
used primordial getter for safety
1 parent 7c8b68d commit c49a144

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/buffer.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ Buffer.copyBytesFrom = function copyBytesFrom(view, offset, length) {
399399

400400
if (end <= start) return new FastBuffer();
401401

402-
const byteLength = TypedArrayPrototypeGetByteLength(view);
403-
const elementSize = byteLength / viewLength;
402+
const viewByteLength = TypedArrayPrototypeGetByteLength(view);
403+
const elementSize = viewByteLength / viewLength;
404404
const srcByteOffset = TypedArrayPrototypeGetByteOffset(view) +
405405
start * elementSize;
406406
const srcByteLength = (end - start) * elementSize;
@@ -1171,7 +1171,7 @@ function _fill(buf, value, offset, end, encoding) {
11711171
}
11721172

11731173
Buffer.prototype.write = function write(string, offset, length, encoding) {
1174-
const bufferLength = this.length;
1174+
const bufferLength = TypedArrayPrototypeGetLength(this);
11751175
// Buffer#write(string);
11761176
if (offset === undefined) {
11771177
return utf8Write(this, string, 0, bufferLength);
@@ -1212,10 +1212,10 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
12121212
};
12131213

12141214
Buffer.prototype.toJSON = function toJSON() {
1215-
const len = this.length;
1216-
if (len > 0) {
1217-
const data = new Array(len);
1218-
for (let i = 0; i < len; ++i)
1215+
const bufferLength = TypedArrayPrototypeGetLength(this);
1216+
if (bufferLength > 0) {
1217+
const data = new Array(bufferLength);
1218+
for (let i = 0; i < bufferLength; ++i)
12191219
data[i] = this[i];
12201220
return { type: 'Buffer', data };
12211221
}

0 commit comments

Comments
 (0)