Skip to content

Commit bb0c918

Browse files
cjihrigtargos
authored andcommitted
buffer: add @@toStringTag to Blob
This commit adds the toStringTag to the Blob class to match the behavior of Chrome and Firefox. PR-URL: nodejs#37336 Fixes: nodejs#37337 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 71ccdf3 commit bb0c918

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/internal/blob.js

+7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
const {
44
ArrayFrom,
5+
ObjectDefineProperty,
56
ObjectSetPrototypeOf,
67
PromiseResolve,
78
RegExpPrototypeTest,
89
StringPrototypeToLowerCase,
910
Symbol,
1011
SymbolIterator,
12+
SymbolToStringTag,
1113
Uint8Array,
1214
} = primordials;
1315

@@ -219,6 +221,11 @@ class Blob extends JSTransferable {
219221
}
220222
}
221223

224+
ObjectDefineProperty(Blob.prototype, SymbolToStringTag, {
225+
configurable: true,
226+
value: 'Blob',
227+
});
228+
222229
InternalBlob.prototype.constructor = Blob;
223230
ObjectSetPrototypeOf(
224231
InternalBlob.prototype,

test/parallel/test-blob.js

+11
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,14 @@ assert.throws(() => new Blob(['test', 1]), {
185185
const b = new Blob(['hello'], { type: '\x01' });
186186
assert.strictEqual(b.type, '');
187187
}
188+
189+
{
190+
const descriptor =
191+
Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag);
192+
assert.deepStrictEqual(descriptor, {
193+
configurable: true,
194+
enumerable: false,
195+
value: 'Blob',
196+
writable: false
197+
});
198+
}

0 commit comments

Comments
 (0)