? val
: new Buffer(val, encoding)
var len = bytes.length
+ if (len === 0) {
+ throw new TypeError('The value "' + val +
+ '" is invalid for argument "value"')
+ }
for (i = 0; i < end - start; ++i) {
this[i + start] = bytes[i % len]
}
var buf = Buffer.from('test');
assert.strictEqual(buf.toLocaleString(), buf.toString());
}
-/*
+
common.expectsError(() => {
Buffer.alloc(0x1000, 'This is not correctly encoded', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError
});
-
+/*
common.expectsError(() => {
Buffer.alloc(0x1000, 'c', 'hex');
}, {
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError
});
-
+*/
common.expectsError(() => {
Buffer.alloc(1, Buffer.alloc(0));
}, {
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError
});
-*/
+
'use strict';
var Buffer = require('../../').Buffer;
-
+const common = require('../common');
var assert = require('assert');
testBufs('61c8b462c8b563c8b6', 4, -1, 'hex');
testBufs('61c8b462c8b563c8b6', 4, 1, 'hex');
testBufs('61c8b462c8b563c8b6', 12, 1, 'hex');
-// Make sure this operation doesn't go on forever
-buf1.fill('yKJh', 'hex');
-assert.throws(() => buf1.fill('\u0222', 'hex'));
+common.expectsError(() => {
+ const buf = Buffer.allocUnsafe(SIZE);
+
+ buf.fill('yKJh', 'hex');
+}, {
+ code: 'ERR_INVALID_ARG_VALUE',
+ type: TypeError
+});
+
+common.expectsError(() => {
+ const buf = Buffer.allocUnsafe(SIZE);
+
+ buf.fill('\u0222', 'hex');
+}, {
+ code: 'ERR_INVALID_ARG_VALUE',
+ type: TypeError
+});
// BASE64
testBufs('YWJj', 'ucs2');