From a6c490cc8e8c848d6c4d5b8739827198055fe40f Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 30 Jan 2018 17:38:54 +0100 Subject: [PATCH] buffer: remove double ln PR-URL: https://github.com/nodejs/node/pull/18395 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Anatoli Papirovski Reviewed-By: Ben Noordhuis --- lib/buffer.js | 64 --------------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index f36bd76acdcc2e..220437f25d7534 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -90,7 +90,6 @@ const uInt8Float64Array = new Uint8Array(float64Array.buffer); Buffer.poolSize = 8 * 1024; var poolSize, poolOffset, allocPool; - setupBufferJS(Buffer.prototype, bindingObj); // |zeroFill| can be undefined when running inside an isolate where we @@ -117,7 +116,6 @@ function createPool() { } createPool(); - function alignPool() { // Ensure aligned slices if (poolOffset & 0x7) { @@ -294,7 +292,6 @@ function SlowBuffer(length) { Object.setPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype); Object.setPrototypeOf(SlowBuffer, Uint8Array); - function allocate(size) { if (size <= 0) { return new FastBuffer(); @@ -311,7 +308,6 @@ function allocate(size) { } } - function fromString(string, encoding) { var length; if (typeof encoding !== 'string' || encoding.length === 0) { @@ -405,14 +401,12 @@ function fromObject(obj) { } } - // Static methods Buffer.isBuffer = function isBuffer(b) { return b instanceof Buffer; }; - Buffer.compare = function compare(a, b) { if (!isUint8Array(a) || !isUint8Array(b)) { throw new errors.TypeError( @@ -427,7 +421,6 @@ Buffer.compare = function compare(a, b) { return _compare(a, b); }; - Buffer.isEncoding = function isEncoding(encoding) { return typeof encoding === 'string' && encoding.length !== 0 && normalizeEncoding(encoding) !== undefined; @@ -477,7 +470,6 @@ Buffer.concat = function concat(list, length) { return buffer; }; - function base64ByteLength(str, bytes) { // Handle padding if (str.charCodeAt(bytes - 1) === 0x3D) @@ -489,7 +481,6 @@ function base64ByteLength(str, bytes) { return (bytes * 3) >>> 2; } - function byteLength(string, encoding) { if (typeof string !== 'string') { if (isArrayBufferView(string) || isAnyArrayBuffer(string)) { @@ -553,7 +544,6 @@ function byteLength(string, encoding) { Buffer.byteLength = byteLength; - // For backwards compatibility. Object.defineProperty(Buffer.prototype, 'parent', { enumerable: true, @@ -572,7 +562,6 @@ Object.defineProperty(Buffer.prototype, 'offset', { } }); - function stringSlice(buf, encoding, start, end) { if (encoding === undefined) return buf.utf8Slice(start, end); encoding += ''; @@ -618,7 +607,6 @@ function stringSlice(buf, encoding, start, end) { throw new errors.TypeError('ERR_UNKNOWN_ENCODING', encoding); } - Buffer.prototype.copy = function copy(target, targetStart, sourceStart, sourceEnd) { return _copy(this, target, targetStart, sourceStart, sourceEnd); @@ -655,7 +643,6 @@ Buffer.prototype.toString = function toString(encoding, start, end) { return stringSlice(this, encoding, start, end); }; - Buffer.prototype.equals = function equals(b) { if (!isUint8Array(b)) { throw new errors.TypeError( @@ -669,7 +656,6 @@ Buffer.prototype.equals = function equals(b) { return _compare(this, b) === 0; }; - // Override how buffers are presented by util.inspect(). Buffer.prototype[customInspectSymbol] = function inspect() { var str = ''; @@ -731,7 +717,6 @@ Buffer.prototype.compare = function compare(target, return compareOffset(this, target, start, thisStart, end, thisEnd); }; - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, // OR the last index of `val` in `buffer` at offset <= `byteOffset`. // @@ -775,7 +760,6 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { ); } - function slowIndexOf(buffer, val, byteOffset, encoding, dir) { var loweredCase = false; for (;;) { @@ -807,22 +791,18 @@ function slowIndexOf(buffer, val, byteOffset, encoding, dir) { } } - Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, true); }; - Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { return bidirectionalIndexOf(this, val, byteOffset, encoding, false); }; - Buffer.prototype.includes = function includes(val, byteOffset, encoding) { return this.indexOf(val, byteOffset, encoding) !== -1; }; - // Usage: // buffer.fill(number[, offset[, end]]) // buffer.fill(buffer[, offset[, end]]) @@ -898,7 +878,6 @@ function _fill(buf, val, start, end, encoding) { return buf; } - Buffer.prototype.write = function write(string, offset, length, encoding) { // Buffer#write(string); if (offset === undefined) { @@ -983,7 +962,6 @@ Buffer.prototype.write = function write(string, offset, length, encoding) { throw new errors.TypeError('ERR_UNKNOWN_ENCODING', encoding); }; - Buffer.prototype.toJSON = function toJSON() { if (this.length > 0) { const data = new Array(this.length); @@ -995,7 +973,6 @@ Buffer.prototype.toJSON = function toJSON() { } }; - function adjustOffset(offset, length) { // Use Math.trunc() to convert offset to an integer value that can be larger // than an Int32. Hence, don't use offset | 0 or similar techniques. @@ -1013,7 +990,6 @@ function adjustOffset(offset, length) { return Number.isNaN(offset) ? 0 : length; } - Buffer.prototype.slice = function slice(start, end) { const srcLength = this.length; start = adjustOffset(start, srcLength); @@ -1022,7 +998,6 @@ Buffer.prototype.slice = function slice(start, end) { return new FastBuffer(this.buffer, this.byteOffset + start, newLength); }; - function checkOffset(offset, ext, length) { if (offset + ext > length) throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); @@ -1036,7 +1011,6 @@ function checkByteLength(byteLength) { } } - Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { offset = offset >>> 0; @@ -1055,7 +1029,6 @@ Buffer.prototype.readUIntLE = return val; }; - Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { offset = offset >>> 0; @@ -1073,7 +1046,6 @@ Buffer.prototype.readUIntBE = return val; }; - Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1081,7 +1053,6 @@ Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { return this[offset]; }; - Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1089,7 +1060,6 @@ Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { return this[offset] | (this[offset + 1] << 8); }; - Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1097,7 +1067,6 @@ Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { return (this[offset] << 8) | this[offset + 1]; }; - Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1109,7 +1078,6 @@ Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { (this[offset + 3] * 0x1000000); }; - Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1121,7 +1089,6 @@ Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { this[offset + 3]); }; - Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; @@ -1144,7 +1111,6 @@ Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { return val; }; - Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; @@ -1167,7 +1133,6 @@ Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { return val; }; - Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1176,7 +1141,6 @@ Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { return !(val & 0x80) ? val : (0xff - val + 1) * -1; }; - Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1185,7 +1149,6 @@ Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { return (val & 0x8000) ? val | 0xFFFF0000 : val; }; - Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1194,7 +1157,6 @@ Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { return (val & 0x8000) ? val | 0xFFFF0000 : val; }; - Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1206,7 +1168,6 @@ Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { (this[offset + 3] << 24); }; - Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { offset = offset >>> 0; if (!noAssert) @@ -1218,7 +1179,6 @@ Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { (this[offset + 3]); }; - // For the casual reader who has not at the current time memorized the // IEEE-754 standard in full detail: floating point numbers consist of // a fraction, an exponent and a sign bit: 23+8+1 bits for single precision @@ -1241,7 +1201,6 @@ Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { // precision that is not stored but is reconstructed by adding one after // multiplying the fraction with the result of 2**-bits_in_fraction. - function toDouble(x0, x1) { const frac = x0 + 0x100000000 * (x1 & 0xFFFFF); const expt = (x1 >>> 20) & 2047; @@ -1256,7 +1215,6 @@ function toDouble(x0, x1) { return sign * 2 ** (expt - 1023) * (1 + frac * 2 ** -52); } - function toFloat(x) { const frac = x & 0x7FFFFF; const expt = (x >>> 23) & 255; @@ -1271,7 +1229,6 @@ function toFloat(x) { return sign * 2 ** (expt - 127) * (1 + frac * 2 ** -23); } - Buffer.prototype.readDoubleBE = function(offset, noAssert) { offset = offset >>> 0; const x1 = this.readUInt32BE(offset + 0, noAssert); @@ -1279,7 +1236,6 @@ Buffer.prototype.readDoubleBE = function(offset, noAssert) { return toDouble(x0, x1); }; - Buffer.prototype.readDoubleLE = function(offset, noAssert) { offset = offset >>> 0; const x0 = this.readUInt32LE(offset + 0, noAssert); @@ -1287,13 +1243,11 @@ Buffer.prototype.readDoubleLE = function(offset, noAssert) { return toDouble(x0, x1); }; - Buffer.prototype.readFloatBE = function(offset, noAssert) { offset = offset >>> 0; return toFloat(this.readUInt32BE(offset, noAssert)); }; - Buffer.prototype.readFloatLE = function(offset, noAssert) { offset = offset >>> 0; return toFloat(this.readUInt32LE(offset, noAssert)); @@ -1304,14 +1258,12 @@ function checkOOB(buffer, offset, ext) { throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); } - function checkInt(buffer, value, offset, ext, max, min) { if (value > max || value < min) throw new errors.RangeError('ERR_INVALID_OPT_VALUE', 'value', value); checkOOB(buffer, offset, ext); } - Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { value = +value; @@ -1331,7 +1283,6 @@ Buffer.prototype.writeUIntLE = return offset + byteLength; }; - Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { value = +value; @@ -1351,7 +1302,6 @@ Buffer.prototype.writeUIntBE = return offset + byteLength; }; - Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { value = +value; @@ -1362,7 +1312,6 @@ Buffer.prototype.writeUInt8 = return offset + 1; }; - Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { value = +value; @@ -1374,7 +1323,6 @@ Buffer.prototype.writeUInt16LE = return offset + 2; }; - Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { value = +value; @@ -1386,7 +1334,6 @@ Buffer.prototype.writeUInt16BE = return offset + 2; }; - Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { value = +value; @@ -1400,7 +1347,6 @@ Buffer.prototype.writeUInt32LE = return offset + 4; }; - Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { value = +value; @@ -1414,7 +1360,6 @@ Buffer.prototype.writeUInt32BE = return offset + 4; }; - Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { value = +value; @@ -1441,7 +1386,6 @@ Buffer.prototype.writeIntLE = return offset + byteLength; }; - Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { value = +value; @@ -1468,7 +1412,6 @@ Buffer.prototype.writeIntBE = return offset + byteLength; }; - Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { value = +value; offset = offset >>> 0; @@ -1478,7 +1421,6 @@ Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { return offset + 1; }; - Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { value = +value; offset = offset >>> 0; @@ -1489,7 +1431,6 @@ Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { return offset + 2; }; - Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { value = +value; offset = offset >>> 0; @@ -1500,7 +1441,6 @@ Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { return offset + 2; }; - Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { value = +value; offset = offset >>> 0; @@ -1513,7 +1453,6 @@ Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { return offset + 4; }; - Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { value = +value; offset = offset >>> 0; @@ -1610,7 +1549,6 @@ function swap(b, n, m) { b[m] = i; } - Buffer.prototype.swap16 = function swap16() { // For Buffer.length < 128, it's generally faster to // do the swap in javascript. For larger buffers, @@ -1626,7 +1564,6 @@ Buffer.prototype.swap16 = function swap16() { return _swap16(this); }; - Buffer.prototype.swap32 = function swap32() { // For Buffer.length < 192, it's generally faster to // do the swap in javascript. For larger buffers, @@ -1644,7 +1581,6 @@ Buffer.prototype.swap32 = function swap32() { return _swap32(this); }; - Buffer.prototype.swap64 = function swap64() { // For Buffer.length < 192, it's generally faster to // do the swap in javascript. For larger buffers,