Skip to content

Commit f805d0b

Browse files
author
Aviv Keller
authored
buffer: correctly apply prototype to cloned File / Blob
PR-URL: #55138 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e7d2732 commit f805d0b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/internal/blob.js

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ class Blob {
386386
}
387387

388388
function TransferableBlob(handle, length, type = '') {
389+
ObjectSetPrototypeOf(this, Blob.prototype);
389390
markTransferMode(this, true, false);
390391
this[kHandle] = handle;
391392
this[kType] = type;

lib/internal/file.js

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class File extends Blob {
130130

131131
function TransferableFile(handle, length, type = '') {
132132
FunctionPrototypeApply(TransferableBlob, this, [handle, length, type]);
133+
ObjectSetPrototypeOf(this, File.prototype);
133134
}
134135

135136
ObjectSetPrototypeOf(TransferableFile.prototype, File.prototype);

test/parallel/test-structuredClone-global.js

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ for (const StreamClass of [ReadableStream, WritableStream, TransformStream]) {
3030
assert.ok(extendedTransfer instanceof StreamClass);
3131
}
3232

33+
for (const Transferrable of [File, Blob]) {
34+
const a2 = Transferrable === File ? '' : {};
35+
const original = new Transferrable([], a2);
36+
const transfer = structuredClone(original);
37+
assert.strictEqual(Object.getPrototypeOf(transfer), Transferrable.prototype);
38+
assert.ok(transfer instanceof Transferrable);
39+
40+
const extendedOriginal = new (class extends Transferrable {})([], a2);
41+
const extendedTransfer = structuredClone(extendedOriginal);
42+
assert.strictEqual(Object.getPrototypeOf(extendedTransfer), Transferrable.prototype);
43+
assert.ok(extendedTransfer instanceof Transferrable);
44+
}
45+
3346
{
3447
// See: https://github.com/nodejs/node/issues/49940
3548
const cloned = structuredClone({}, {

0 commit comments

Comments
 (0)