Truly independent web browser
LibWeb: Do not serialize platform objects that are detached
Andreas Klinga43d84e870e3
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Libraries/LibWeb/HTML/StructuredSerialize.cppindex a59a25d6f07..769ba2a2690 100644--- a/Libraries/LibWeb/HTML/StructuredSerialize.cpp+++ b/Libraries/LibWeb/HTML/StructuredSerialize.cpp@@ -1572,7 +1572,10 @@ public:// 19. Otherwise, if value is a platform object that is a serializable object:else if (auto serializable = Bindings::serializable_from_object(*object); serializable.has_value()) {- // FIXME: 1. If value has a [[Detached]] internal slot whose value is true, then throw a "DataCloneError" DOMException.+ // 1. If value has a [[Detached]] internal slot whose value is true, then throw a "DataCloneError" DOMException.+ // NB: The platform objects that have a [[Detached]] internal slot are the transferable objects.+ if (auto transferable = Bindings::transferable_from_object(*object); transferable.has_value() && transferable->is_detached())+ return data_clone_error("Cannot serialize a detached platform object"_utf16);// 2. Let typeString be the identifier of the primary interface of value.// 3. Set serialized to { [[Type]]: typeString }.diff --git a/Tests/LibWeb/Text/expected/canvas/image-bitmap-in-rust.txt b/Tests/LibWeb/Text/expected/canvas/image-bitmap-in-rust.txtindex 063b4c0ebfc..bce7683c854 100644--- a/Tests/LibWeb/Text/expected/canvas/image-bitmap-in-rust.txt+++ b/Tests/LibWeb/Text/expected/canvas/image-bitmap-in-rust.txt@@ -1,8 +1,10 @@ImageBitmap: [object ImageBitmap], 2x1cloned ImageBitmap: 2x1, 255,0,0,255,0,255,0,128closed ImageBitmap: 0x0-clone of a closed ImageBitmap: 0x0+clone of a closed ImageBitmap: DataCloneErrortransfer of a closed ImageBitmap: DataCloneError+clone of an object with a closed ImageBitmap: DataCloneError+clone of a transferred ImageBitmap: DataCloneErrordrawImage of a closed ImageBitmap: InvalidStateErrorImageBitmap without bitmap data: 0x0createImageBitmap from it: InvalidStateErrordiff --git a/Tests/LibWeb/Text/input/canvas/image-bitmap-in-rust.html b/Tests/LibWeb/Text/input/canvas/image-bitmap-in-rust.htmlindex 435465860e4..566698a7779 100644--- a/Tests/LibWeb/Text/input/canvas/image-bitmap-in-rust.html+++ b/Tests/LibWeb/Text/input/canvas/image-bitmap-in-rust.html@@ -61,6 +61,10 @@println(`closed ImageBitmap: ${closed.width}x${closed.height}`);println(`clone of a closed ImageBitmap: ${outcome(() => { const c = structuredClone(closed); return `${c.width}x${c.height}`; })}`);println(`transfer of a closed ImageBitmap: ${outcome(() => structuredClone(closed, { transfer: [closed] }))}`);+ println(`clone of an object with a closed ImageBitmap: ${outcome(() => structuredClone({ bitmap: closed }))}`);+ const transferred = await createImageBitmap(original);+ structuredClone(transferred, { transfer: [transferred] });+ println(`clone of a transferred ImageBitmap: ${outcome(() => structuredClone(transferred))}`);println(`drawImage of a closed ImageBitmap: ${outcome(() => context.drawImage(closed, 0, 0))}`);// An ImageBitmap of an OffscreenCanvas without pixels has no bitmap data.