From 9cee8b1b621f2803bbdd7209aea74c918081eaad Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 17 Aug 2016 10:56:24 -0700 Subject: [PATCH] buffer: alias toLocaleString to toString Make Buffer.prototype.toLocaleString an alias of Buffer.prototype.toString so that the output is actually useful. Fixes: https://github.com/nodejs/node/issues/8147 PR-URL: https://github.com/nodejs/node/pull/8148 Reviewed-By: Anna Henningsen Reviewed-By: Trevor Norris --- lib/buffer.js | 2 ++ test/parallel/test-buffer-alloc.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index e40b81a693c9fd..84f63a57df42c9 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1332,3 +1332,5 @@ Buffer.prototype.swap64 = function swap64() { } return swap64n(this); }; + +Buffer.prototype.toLocaleString = Buffer.prototype.toString; diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 00b63848d4e2d4..57bc8715974032 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -1502,3 +1502,9 @@ assert.throws(() => Buffer.alloc({ valueOf: () => 1 }), /"size" argument must be a number/); assert.throws(() => Buffer.alloc({ valueOf: () => -1 }), /"size" argument must be a number/); + +assert.strictEqual(Buffer.prototype.toLocaleString, Buffer.prototype.toString); +{ + const buf = Buffer.from('test'); + assert.strictEqual(buf.toLocaleString(), buf.toString()); +}