buffer: correctly apply prototype to cloned File / Blob

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Aviv Keller authored and GitHub committed 2024-09-28 22:05:58 +00:00
1 parent e7d27320c3
commit f805d0be95
3 files changed
+15

No files matched your search

+1
View File
@@ -386,6 +386,7 @@ class Blob {
}
function TransferableBlob(handle, length, type = '') {
ObjectSetPrototypeOf(this, Blob.prototype);
markTransferMode(this, true, false);
this[kHandle] = handle;
this[kType] = type;
+1
View File
@@ -130,6 +130,7 @@ class File extends Blob {
function TransferableFile(handle, length, type = '') {
FunctionPrototypeApply(TransferableBlob, this, [handle, length, type]);
ObjectSetPrototypeOf(this, File.prototype);
}
ObjectSetPrototypeOf(TransferableFile.prototype, File.prototype);
@@ -30,6 +30,19 @@ for (const StreamClass of [ReadableStream, WritableStream, TransformStream]) {
assert.ok(extendedTransfer instanceof StreamClass);
}
for (const Transferrable of [File, Blob]) {
const a2 = Transferrable === File ? '' : {};
const original = new Transferrable([], a2);
const transfer = structuredClone(original);
assert.strictEqual(Object.getPrototypeOf(transfer), Transferrable.prototype);
assert.ok(transfer instanceof Transferrable);
const extendedOriginal = new (class extends Transferrable {})([], a2);
const extendedTransfer = structuredClone(extendedOriginal);
assert.strictEqual(Object.getPrototypeOf(extendedTransfer), Transferrable.prototype);
assert.ok(extendedTransfer instanceof Transferrable);
}
{
// See: https://github.com/nodejs/node/issues/49940
const cloned = structuredClone({}, {