From d573bead367883ce7258861fafcc441ca8df964d Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 12 Feb 2021 17:27:06 -0500 Subject: [PATCH] buffer: add @@toStringTag to Blob This commit adds the toStringTag to the Blob class to match the behavior of Chrome and Firefox. PR-URL: https://github.com/nodejs/node/pull/37336 Backport-PR-URL: https://github.com/nodejs/node/pull/39704 Fixes: https://github.com/nodejs/node/issues/37337 Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell --- lib/internal/blob.js | 7 +++++++ test/parallel/test-blob.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index accfdf9539c1d2..9b60171e65aef0 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -2,12 +2,14 @@ const { ArrayFrom, + ObjectDefineProperty, ObjectSetPrototypeOf, PromiseResolve, RegExpPrototypeTest, StringPrototypeToLowerCase, Symbol, SymbolIterator, + SymbolToStringTag, Uint8Array, } = primordials; @@ -219,6 +221,11 @@ class Blob extends JSTransferable { } } +ObjectDefineProperty(Blob.prototype, SymbolToStringTag, { + configurable: true, + value: 'Blob', +}); + InternalBlob.prototype.constructor = Blob; ObjectSetPrototypeOf( InternalBlob.prototype, diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index b32cacdda723a9..eef9d3dbd1e1d4 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -185,3 +185,14 @@ assert.throws(() => new Blob(['test', 1]), { const b = new Blob(['hello'], { type: '\x01' }); assert.strictEqual(b.type, ''); } + +{ + const descriptor = + Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag); + assert.deepStrictEqual(descriptor, { + configurable: true, + enumerable: false, + value: 'Blob', + writable: false + }); +}