buffer: use a default offset

If none is provided, use zero as a default offset for all read/write
operations on the buffer.

PR-URL: https://github.com/nodejs/node/pull/19749
Refs: https://github.com/nodejs/node/pull/18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Ruben Bridgewater authored and James M Snell committed 2018-04-16 16:11:12 -07:00
1 parent 1964978fb8
commit cdacafc8bb
8 files changed
+134 -70

No files matched your search

+6 -1
View File
@@ -61,6 +61,11 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4)));
const small = Buffer.allocUnsafe(1);
['writeFloatLE', 'writeFloatBE'].forEach((fn) => {
// Verify that default offset works fine.
buffer[fn](23, undefined);
buffer[fn](23);
assert.throws(
() => small[fn](11.11, 0),
{
@@ -69,7 +74,7 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4)));
message: 'Attempt to write outside buffer bounds'
});
['', '0', null, undefined, {}, [], () => {}, true, false].forEach((off) => {
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
assert.throws(
() => small[fn](23, off),
{ code: 'ERR_INVALID_ARG_TYPE' }