From f33a06adc7b0286e83039be2056cfd225bdab281 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 19 Jul 2024 10:29:24 +0900 Subject: [PATCH] Stop assuming "transfer" is same-agent cluster The previous text assumed that the AllocateArrayBuffer step would never throw, since it was basically spec fiction for retargeting a pointer. However, if we transfer across agent clusters, memory allocation will be needed. And even then, we shouldn't be normatively asserting that implementations use the pointer-retargeting strategy. Instead, we can explain it in a note. --- index.bs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/index.bs b/index.bs index a3b7cdac..2aaaa217 100644 --- a/index.bs +++ b/index.bs @@ -9036,9 +9036,10 @@ a reference to the same object that the IDL value represents. |arrayBuffer| to a JavaScript value. 1. Perform [=?=] [$DetachArrayBuffer$](|jsArrayBuffer|). -

This will throw an exception if |jsArrayBuffer| has an \[[ArrayBufferDetachKey]] - that is not undefined, such as is the case with the value of {{Memory|WebAssembly.Memory}}'s - {{Memory/buffer}} attribute. [[WASM-JS-API-1]] +

This will throw an exception if + |jsArrayBuffer| has an \[[ArrayBufferDetachKey]] that is not undefined, such as is the case + with the value of {{Memory|WebAssembly.Memory}}'s {{Memory/buffer}} attribute. + [[WASM-JS-API-1]]

Detaching a buffer that is already [=BufferSource/detached=] is a no-op. @@ -9081,16 +9082,26 @@ a reference to the same object that the IDL value represents. 1. Let |arrayBufferByteLength| be |jsArrayBuffer|.\[[ArrayBufferByteLength]]. 1. Perform [=?=] [$DetachArrayBuffer$](|jsArrayBuffer|). 1. If |targetRealm| is not given, let |targetRealm| be the [=current realm=]. - 1. Let |jsTransferred| be [=!=] + 1. Let |jsTransferred| be [=?=] [$AllocateArrayBuffer$](|targetRealm|.\[[Intrinsics]].[[{{%ArrayBuffer%}}]], 0). 1. Set |jsTransferred|.\[[ArrayBufferData]] to |arrayBufferData|. 1. Set |jsTransferred|.\[[ArrayBufferByteLength]] to |arrayBufferByteLength|. 1. Return the result of [=converted to an IDL value|converting=] |jsTransferred| to an IDL value of type {{ArrayBuffer}}. -

This will throw an exception under the same circumstances as - [=ArrayBuffer/detaching=], and also for {{ArrayBuffer}}s that are already - [=BufferSource/detached=]. +

+ This will throw an exception under any of the following circumstances: + + * |arrayBuffer| cannot be [=BufferSource/detached=], for the reasons + explained in that algorithm's + definition; + * |arrayBuffer| is already [=BufferSource/detached=]; + * Sufficient memory cannot be allocated in |realm|. Generally this will only be the case + if |realm| is in a different [=agent cluster=] than the one in which |arrayBuffer| was + allocated. If they are in the same [=agent cluster=], then implementations will just + change the backing pointers to get the same observable results with better performance + and no allocations. +

Frozen arrays — FrozenArray<|T|>