Skip to content

Commit c04c7bd

Browse files
committed
Pull out new throws
1 parent ad5e145 commit c04c7bd

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

lib/buffer.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ function alignPool() {
4747

4848
function Buffer(arg, encodingOrOffset, length) {
4949
// Common case.
50-
if (typeof arg === 'number') {
51-
if (typeof encodingOrOffset === 'string') {
52-
throw new Error(
53-
'If encoding is specified then the first argument must be a string'
54-
);
55-
}
50+
if (typeof arg === 'number')
5651
return Buffer.allocUnsafe(arg);
57-
}
5852
return Buffer.from(arg, encodingOrOffset, length);
5953
}
6054

@@ -155,9 +149,6 @@ function fromString(string, encoding) {
155149
if (typeof encoding !== 'string' || encoding === '')
156150
encoding = 'utf8';
157151

158-
if (!Buffer.isEncoding(encoding))
159-
throw new TypeError('"encoding" must be a valid string encoding');
160-
161152
var length = byteLength(string, encoding);
162153
if (length >= (Buffer.poolSize >>> 1))
163154
return binding.createFromString(string, encoding);

0 commit comments

Comments
 (0)