From 25f8d99b50d3cf4e75d2f393a3a6471428a35a99 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Sat, 20 Jan 2018 23:18:19 +0100 Subject: [PATCH] Custom implementation of toLocaleString() Make `toLocaleString()` to point to the same implementation as `toString()`. --- index.js | 2 ++ test/node/test-buffer-alloc.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a4c33f2..b30bb96 100644 --- a/index.js +++ b/index.js @@ -532,6 +532,8 @@ Buffer.prototype.toString = function toString () { return slowToString.apply(this, arguments) } +Buffer.prototype.toLocaleString = Buffer.prototype.toString + Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index 0eb4f01..32a9763 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -1005,13 +1005,13 @@ assert.throws(() => Buffer.alloc({ valueOf: () => 1 }), /"size" argument must be of type number/); assert.throws(() => Buffer.alloc({ valueOf: () => -1 }), /"size" argument must be of type number/); -/* + assert.strictEqual(Buffer.prototype.toLocaleString, Buffer.prototype.toString); { var buf = Buffer.from('test'); assert.strictEqual(buf.toLocaleString(), buf.toString()); } - +/* common.expectsError(() => { Buffer.alloc(0x1000, 'This is not correctly encoded', 'hex'); }, { -- 2.34.1