From 34fb380ed38ff324202b7779ae850edab133e577 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Tue, 25 Oct 2022 14:22:37 +0200 Subject: feat(ext/web): use ArrayBuffer.was_detached() (#16307) This PR adds a way to reliably check if an ArrayBuffer was detached --- cli/tests/unit/structured_clone_test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'cli/tests/unit/structured_clone_test.ts') diff --git a/cli/tests/unit/structured_clone_test.ts b/cli/tests/unit/structured_clone_test.ts index fdad0dba7..c60b38a8a 100644 --- a/cli/tests/unit/structured_clone_test.ts +++ b/cli/tests/unit/structured_clone_test.ts @@ -27,4 +27,27 @@ Deno.test("correct DataCloneError message", () => { DOMException, "Value not transferable", ); + + const ab = new ArrayBuffer(1); + // detach ArrayBuffer + structuredClone(ab, { transfer: [ab] }); + assertThrows( + () => { + structuredClone(ab, { transfer: [ab] }); + }, + DOMException, + "ArrayBuffer at index 0 is already detached", + ); + + const ab2 = new ArrayBuffer(0); + assertThrows( + () => { + structuredClone([ab2, ab], { transfer: [ab2, ab] }); + }, + DOMException, + "ArrayBuffer at index 1 is already detached", + ); + + // ab2 should not be detached after above failure + structuredClone(ab2, { transfer: [ab2] }); }); -- cgit v1.2.3