summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2022-10-25 14:22:37 +0200
committerGitHub <noreply@github.com>2022-10-25 14:22:37 +0200
commit34fb380ed38ff324202b7779ae850edab133e577 (patch)
tree86548e0a099f6fc151e069b089a53b46ef396f3e /cli
parenta189c5393e1b106687736635fea0b8aeca283826 (diff)
feat(ext/web): use ArrayBuffer.was_detached() (#16307)
This PR adds a way to reliably check if an ArrayBuffer was detached
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/unit/structured_clone_test.ts23
1 files changed, 23 insertions, 0 deletions
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] });
});