Browse Source

buffer: fix indentation nits

Fix indentation issues that will be flagged by upcoming stricter
linting.

PR-URL: https://github.com/nodejs/node/pull/14224
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Rich Trott 8 years ago
parent
commit
e0340af455
  1. 70
      lib/buffer.js

70
lib/buffer.js

@ -143,8 +143,9 @@ function Buffer(arg, encodingOrOffset, length) {
// Common case. // Common case.
if (typeof arg === 'number') { if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') { if (typeof encodingOrOffset === 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'string', throw new errors.TypeError(
'string', arg); 'ERR_INVALID_ARG_TYPE', 'string', 'string', arg
);
} }
return Buffer.alloc(arg); return Buffer.alloc(arg);
} }
@ -172,13 +173,19 @@ Buffer.from = function(value, encodingOrOffset, length) {
if (isAnyArrayBuffer(value)) if (isAnyArrayBuffer(value))
return fromArrayBuffer(value, encodingOrOffset, length); return fromArrayBuffer(value, encodingOrOffset, length);
if (value == null) if (value == null) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument', throw new errors.TypeError(
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'], value); 'ERR_INVALID_ARG_TYPE',
'first argument',
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'],
value
);
}
if (typeof value === 'number') if (typeof value === 'number')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'value', 'not number', throw new errors.TypeError(
value); 'ERR_INVALID_ARG_TYPE', 'value', 'not number', value
);
const valueOf = value.valueOf && value.valueOf(); const valueOf = value.valueOf && value.valueOf();
if (valueOf != null && valueOf !== value) if (valueOf != null && valueOf !== value)
@ -194,8 +201,11 @@ Buffer.from = function(value, encodingOrOffset, length) {
length); length);
} }
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument', throw new errors.TypeError(
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object']); 'ERR_INVALID_ARG_TYPE',
'first argument',
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object']
);
}; };
Object.setPrototypeOf(Buffer, Uint8Array); Object.setPrototypeOf(Buffer, Uint8Array);
@ -397,8 +407,9 @@ Buffer.isBuffer = function isBuffer(b) {
Buffer.compare = function compare(a, b) { Buffer.compare = function compare(a, b) {
if (!isUint8Array(a) || !isUint8Array(b)) { if (!isUint8Array(a) || !isUint8Array(b)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], throw new errors.TypeError(
['buffer', 'uint8Array']); 'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['buffer', 'uint8Array']
);
} }
if (a === b) { if (a === b) {
@ -415,8 +426,9 @@ Buffer.isEncoding = function(encoding) {
}; };
Buffer[internalUtil.kIsEncodingSymbol] = Buffer.isEncoding; Buffer[internalUtil.kIsEncodingSymbol] = Buffer.isEncoding;
const kConcatErr = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'list', const kConcatErr = new errors.TypeError(
['array', 'buffer', 'uint8Array']); 'ERR_INVALID_ARG_TYPE', 'list', ['array', 'buffer', 'uint8Array']
);
Buffer.concat = function(list, length) { Buffer.concat = function(list, length) {
var i; var i;
@ -474,8 +486,9 @@ function byteLength(string, encoding) {
return string.byteLength; return string.byteLength;
} }
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'string', throw new errors.TypeError(
['string', 'buffer', 'arrayBuffer']); 'ERR_INVALID_ARG_TYPE', 'string', ['string', 'buffer', 'arrayBuffer']
);
} }
const len = string.length; const len = string.length;
@ -632,9 +645,11 @@ Buffer.prototype.toString = function(encoding, start, end) {
Buffer.prototype.equals = function equals(b) { Buffer.prototype.equals = function equals(b) {
if (!isUint8Array(b)) if (!isUint8Array(b)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'otherBuffer', throw new errors.TypeError(
['buffer', 'uint8Array']); 'ERR_INVALID_ARG_TYPE', 'otherBuffer', ['buffer', 'uint8Array']
);
}
if (this === b) if (this === b)
return true; return true;
@ -658,9 +673,11 @@ Buffer.prototype.compare = function compare(target,
end, end,
thisStart, thisStart,
thisEnd) { thisEnd) {
if (!isUint8Array(target)) if (!isUint8Array(target)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'target', throw new errors.TypeError(
['buffer', 'uint8Array']); 'ERR_INVALID_ARG_TYPE', 'target', ['buffer', 'uint8Array']
);
}
if (arguments.length === 1) if (arguments.length === 1)
return compare_(this, target); return compare_(this, target);
@ -739,8 +756,9 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
return binding.indexOfNumber(buffer, val, byteOffset, dir); return binding.indexOfNumber(buffer, val, byteOffset, dir);
} }
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'val', throw new errors.TypeError(
['string', 'buffer', 'uint8Array']); 'ERR_INVALID_ARG_TYPE', 'val', ['string', 'buffer', 'uint8Array']
);
} }
@ -878,8 +896,10 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
// if someone is still calling the obsolete form of write(), tell them. // if someone is still calling the obsolete form of write(), tell them.
// we don't want eg buf.write("foo", "utf8", 10) to silently turn into // we don't want eg buf.write("foo", "utf8", 10) to silently turn into
// buf.write("foo", "utf8"), so we can't ignore extra args // buf.write("foo", "utf8"), so we can't ignore extra args
throw new errors.Error('ERR_NO_LONGER_SUPPORTED', throw new errors.Error(
'Buffer.write(string, encoding, offset[, length])'); 'ERR_NO_LONGER_SUPPORTED',
'Buffer.write(string, encoding, offset[, length])'
);
} }
if (!encoding) return this.utf8Write(string, offset, length); if (!encoding) return this.utf8Write(string, offset, length);

Loading…
Cancel
Save