From 3bd6d8d7f544164728ff4cfd2c37cff4877a8cb1 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 11 Apr 2018 20:58:43 -0700 Subject: doc: fix errors in sample code comments The errors thrown have changed in a few places. Update the comments to reflect the current errors. The `noAssert` option has been removed but it is still shown in sample code in a few places. Remove that sample code. PR-URL: https://github.com/nodejs/node/pull/19963 Reviewed-By: Trivikram Kamat Reviewed-By: Daniel Bevenius Reviewed-By: Vse Mozhet Byt Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum --- doc/api/buffer.md | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'doc/api/buffer.md') diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 10ad944b37..e0f2e812f3 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -1525,10 +1525,7 @@ console.log(buf.readDoubleBE(0)); console.log(buf.readDoubleLE(0)); // Prints: 5.447603722011605e-270 console.log(buf.readDoubleLE(1)); -// Throws an exception: RangeError: Index out of range -console.log(buf.readDoubleLE(1, true)); -// Warning: reads passed end of buffer! -// This will result in a segmentation fault! Don't do this! +// Throws ERR_OUT_OF_RANGE ``` ### buf.readFloatBE(offset) @@ -1558,10 +1555,7 @@ console.log(buf.readFloatBE(0)); console.log(buf.readFloatLE(0)); // Prints: 1.539989614439558e-36 console.log(buf.readFloatLE(1)); -// Throws an exception: RangeError: Index out of range -console.log(buf.readFloatLE(1, true)); -// Warning: reads passed end of buffer! -// This will result in a segmentation fault! Don't do this! +// Throws ERR_OUT_OF_RANGE ``` ### buf.readInt8(offset) @@ -1590,7 +1584,7 @@ console.log(buf.readInt8(0)); console.log(buf.readInt8(1)); // Prints: 5 console.log(buf.readInt8(2)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readInt16BE(offset) @@ -1622,7 +1616,7 @@ console.log(buf.readInt16BE(0)); console.log(buf.readInt16LE(0)); // Prints: 1280 console.log(buf.readInt16LE(1)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readInt32BE(offset) @@ -1654,7 +1648,7 @@ console.log(buf.readInt32BE(0)); console.log(buf.readInt32LE(0)); // Prints: 83886080 console.log(buf.readInt32LE(1)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readIntBE(offset, byteLength) @@ -1686,9 +1680,9 @@ console.log(buf.readIntLE(0, 6).toString(16)); console.log(buf.readIntBE(0, 6).toString(16)); // Prints: 1234567890ab console.log(buf.readIntBE(1, 6).toString(16)); -// Throws ERR_INDEX_OUT_OF_RANGE: +// Throws ERR_INDEX_OUT_OF_RANGE console.log(buf.readIntBE(1, 0).toString(16)); -// Throws ERR_OUT_OF_RANGE: +// Throws ERR_OUT_OF_RANGE ``` ### buf.readUInt8(offset) @@ -1715,7 +1709,7 @@ console.log(buf.readUInt8(0)); console.log(buf.readUInt8(1)); // Prints: 254 console.log(buf.readUInt8(2)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readUInt16BE(offset) @@ -1749,7 +1743,7 @@ console.log(buf.readUInt16BE(1).toString(16)); console.log(buf.readUInt16LE(1).toString(16)); // Prints: 5634 console.log(buf.readUInt16LE(2).toString(16)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readUInt32BE(offset) @@ -1779,7 +1773,7 @@ console.log(buf.readUInt32BE(0).toString(16)); console.log(buf.readUInt32LE(0).toString(16)); // Prints: 78563412 console.log(buf.readUInt32LE(1).toString(16)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.readUIntBE(offset, byteLength) @@ -1811,7 +1805,7 @@ console.log(buf.readUIntBE(0, 6).toString(16)); console.log(buf.readUIntLE(0, 6).toString(16)); // Prints: ab9078563412 console.log(buf.readUIntBE(1, 6).toString(16)); -// Throws an exception: RangeError: Index out of range +// Throws ERR_OUT_OF_RANGE ``` ### buf.slice([start[, end]]) @@ -1907,7 +1901,7 @@ console.log(buf1); const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap16(); -// Throws an exception: RangeError: Buffer size must be a multiple of 16-bits +// Throws ERR_INVALID_BUFFER_SIZE ``` ### buf.swap32() @@ -1934,7 +1928,7 @@ console.log(buf1); const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap32(); -// Throws an exception: RangeError: Buffer size must be a multiple of 32-bits +// Throws ERR_INVALID_BUFFER_SIZE ``` ### buf.swap64() @@ -1961,7 +1955,7 @@ console.log(buf1); const buf2 = Buffer.from([0x1, 0x2, 0x3]); buf2.swap64(); -// Throws an exception: RangeError: Buffer size must be a multiple of 64-bits +// Throws ERR_INVALID_BUFFER_SIZE ``` Note that JavaScript cannot encode 64-bit integers. This method is intended -- cgit v1.2.3