Skip to content

Commit

Permalink
buffer: add @@toStringTag to Blob
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and targos committed Aug 8, 2021
1 parent 405f0f5 commit b2bcd51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

const {
ArrayFrom,
ObjectDefineProperty,
ObjectSetPrototypeOf,
PromiseResolve,
RegExpPrototypeTest,
StringPrototypeToLowerCase,
Symbol,
SymbolIterator,
SymbolToStringTag,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -219,6 +221,11 @@ class Blob extends JSTransferable {
}
}

ObjectDefineProperty(Blob.prototype, SymbolToStringTag, {
configurable: true,
value: 'Blob',
});

InternalBlob.prototype.constructor = Blob;
ObjectSetPrototypeOf(
InternalBlob.prototype,
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

0 comments on commit b2bcd51

Please sign in to comment.