From 91f70c921ae537820b9742a5b57fc2709bb558df Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 29 Mar 2021 19:40:58 -0700 Subject: [PATCH 1/6] [js-api] Integrate with the ResizableArrayBuffer proposal --- document/js-api/index.bs | 109 ++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 13 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 1e4aa51d37..c7e5f33873 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -91,6 +91,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT text: IterableToList; url: sec-iterabletolist text: ToBigInt64; url: #sec-tobigint64 text: BigInt; url: #sec-ecmascript-language-types-bigint-type + text: SameValue; url: sec-samevalue type: abstract-op text: CreateMethodProperty; url: sec-createmethodproperty urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembly; type: dfn @@ -187,6 +188,13 @@ urlPrefix: https://webassembly.github.io/reference-types/core/; spec: WebAssembl urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL type: dfn text: create a namespace object; url: create-a-namespace-object +urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal + type: interface; for: ResizableArrayBuffer proposal + text: ResizableArrayBuffer; url: sec-resizablearraybuffer-objects + type: dfn + text: handled; url: sec-hostresizearraybuffer + text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer + text: HostResizeArrayBuffer; url: sec-hostresizearraybuffer @@ -634,10 +644,10 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each {{Memory}} object has the following internal slots: * \[[Memory]] : a [=memory address=] - * \[[BufferObject]] : an {{ArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address + * \[[BufferObject]] : an {{ArrayBuffer}} or {{ResizableArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address
- To create a memory buffer from a [=memory address=] |memaddr|, perform the following steps: + To create a fixed length memory buffer from a [=memory address=] |memaddr|, perform the following steps: 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. 1. Let |buffer| be a new {{ArrayBuffer}} whose \[[ArrayBufferData]] is |block| and \[[ArrayBufferByteLength]] is set to the length of |block|. @@ -645,11 +655,23 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Return |buffer|.
+
+ To create a resizable memory buffer from a [=memory address=] |memaddr| and a |maxsize|, perform the following steps: + + 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. + 1. Let |length| be the length of |block|. + 1. If |maxsize| > (65536 × 65536), + 1. Throw a {{RangeError}} exception. + 1. Let |buffer| be a new {{ResizableArrayBuffer}} whose \[[ArrayBufferData]] is |block|, \[[ArrayBufferByteLength]] is set to |length|, and \[[ArrayBufferMaxByteLength]] is |maxsize|. + 1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory". + 1. Return |buffer|. +
+
To initialize a memory object |memory| from a [=memory address=] |memaddr|, perform the following steps: 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. 1. Assert: |map|[|memaddr|] doesn't [=map/exist=]. - 1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|. + 1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. 1. Set |memory|.\[[Memory]] to |memaddr|. 1. Set |memory|.\[[BufferObject]] to |buffer|. 1. [=map/Set=] |map|[|memaddr|] to |memory|. @@ -679,28 +701,40 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
- To reset the Memory buffer of |memaddr|, perform the following steps: + To refresh the Memory buffer of |memaddr|, perform the following steps: 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. 1. Assert: |map|[|memaddr|] [=map/exists=]. 1. Let |memory| be |map|[|memaddr|]. - 1. Perform ! [=DetachArrayBuffer=](|memory|.\[[BufferObject]], "WebAssembly.Memory"). - 1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|. - 1. Set |memory|.\[[BufferObject]] to |buffer|. + 1. Let |buffer| be |memory|.\[[BufferObject]]. + 1. If [=IsResizableArrayBuffer=](|buffer|) is false, + 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. + 1. Set |memory|.\[[BufferObject]] to |buffer|. + 1. Otherwise, + 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. + 1. Set |buffer|.\[[ArrayBufferData]] to |block|. + 1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
-
- The grow(|delta|) method, when invoked, performs the following steps: +
+ To grow the memory buffer associated with a [=memory address=] |memaddr| by |delta|, perform the following steps: + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. - 1. Let |memaddr| be **this**.\[[Memory]]. 1. Let |ret| be the [=mem_size=](|store|, |memaddr|). 1. Let |store| be [=mem_grow=](|store|, |memaddr|, |delta|). 1. If |store| is [=error=], throw a {{RangeError}} exception. 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. - 1. [=Reset the memory buffer=] of |memaddr|. + 1. [=Refresh the memory buffer=] of |memaddr|. 1. Return |ret|.
+
+ The grow(|delta|) method, when invoked, performs the following steps: + 1. Let |memaddr| be **this**.\[[Memory]]. + 1. Return the result of [=grow the memory buffer|growing the memory buffer=] associated with |memaddr| by |delta|. +
+ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform the following steps:
@@ -708,7 +742,56 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. Let |frame| be the [=current frame=]. 1. Assert: due to validation, |frame|.[=frame/module=].[=moduleinst/memaddrs=][0] exists. 1. Let |memaddr| be the memory address |frame|.[=frame/module=].[=moduleinst/memaddrs=][0]. - 1. [=Reset the memory buffer=] of |memaddr|. + 1. [=Refresh the memory buffer=] of |memaddr|. +
+ +
+ The toFixedLengthBuffer() method, when invoked, performs the following steps: + 1. Let |buffer| be **this**.\[[BufferObject]]. + 1. If [=IsResizableArrayBuffer=](|buffer|) is false, return |buffer|. + 1. Let |memaddr| be **this**.\[[Memory]]. + 1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. + 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Set **this**.\[[BufferObject]] to |fixedBuffer|. + 1. Return |fixedBuffer|. +
+ +
+ The toResizableBuffer() method, when invoked, performs the following steps: + 1. Let |buffer| be **this**.\[[BufferObject]]. + 1. If [=IsResizableArrayBuffer=](|buffer|) is true, return |buffer|. + 1. Let |memaddr| be **this**.\[[Memory]]. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |memtype| be [=mem_type=](|store|, |memaddr|). + 1. If |memtype| has a max, + 1. Let |maxsize| be the max value in |memtype|. + 1. Otherwise, + 1. Let |maxsize| be an implementation-defined value ≥ |buffer|.\[[ArrayBufferByteLength]] and < (65536 × 65536). + + Note: The implementation-defined value above is the same across all invocations of this method. + + 1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|. + 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Set **this**.\[[BufferObject]] to |resizableBuffer|. + 1. Return |resizableBuffer|. +
+ +{{ResizableArrayBuffer}} objects returned by a {{Memory}} object must use the following definition of [=HostResizeArrayBuffer=]. + +
+ The abstract operation [=HostResizeArrayBuffer=] takes arguments |buffer| and |newLength|. It performs the following steps when called. + + 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. + 1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|. + 1. [=map/iterate|For each=] |memaddr| → |mem| in |map|, + 1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true, + 1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0. + 1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]]. + 1. If |lengthDelta| < 0 or |lengthDelta| modulo 65536 is not 0, + 1. Throw a {{RangeError}} exception. + 1. Let |delta| be |lengthDelta| ÷ 65536. + 1. [=grow the memory buffer|Grow the memory buffer=] associated with |memaddr| by |delta|. + 1. Return handled.
From fc72e6ee47e4964da796c8c1865963658abe772e Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Wed, 2 Jun 2021 17:39:37 -0700 Subject: [PATCH 2/6] Update for API redesign; address littledan review --- document/js-api/index.bs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index c7e5f33873..7ab65da4ea 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -189,8 +189,6 @@ urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL type: dfn text: create a namespace object; url: create-a-namespace-object urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal - type: interface; for: ResizableArrayBuffer proposal - text: ResizableArrayBuffer; url: sec-resizablearraybuffer-objects type: dfn text: handled; url: sec-hostresizearraybuffer text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer @@ -634,8 +632,8 @@ interface Memory { constructor(MemoryDescriptor descriptor); unsigned long grow([EnforceRange] unsigned long delta); ArrayBuffer toFixedLengthBuffer(); - ResizableArrayBuffer toResizableBuffer(); - readonly attribute (ArrayBuffer or ResizableArrayBuffer) buffer; + ArrayBuffer toResizableBuffer(); + readonly attribute ArrayBuffer buffer; }; @@ -644,13 +642,15 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each {{Memory}} object has the following internal slots: * \[[Memory]] : a [=memory address=] - * \[[BufferObject]] : an {{ArrayBuffer}} or {{ResizableArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address + * \[[BufferObject]] : an {{ArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address
To create a fixed length memory buffer from a [=memory address=] |memaddr|, perform the following steps: 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. - 1. Let |buffer| be a new {{ArrayBuffer}} whose \[[ArrayBufferData]] is |block| and \[[ArrayBufferByteLength]] is set to the length of |block|. + 1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferDetachKey]]. + 1. Set |buffer|.\[[ArrayBufferData]] to |block|. + 1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|. 1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory". 1. Return |buffer|.
@@ -662,7 +662,10 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |length| be the length of |block|. 1. If |maxsize| > (65536 × 65536), 1. Throw a {{RangeError}} exception. - 1. Let |buffer| be a new {{ResizableArrayBuffer}} whose \[[ArrayBufferData]] is |block|, \[[ArrayBufferByteLength]] is set to |length|, and \[[ArrayBufferMaxByteLength]] is |maxsize|. + 1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], \[[ArrayBufferMaxByteLength]], and \[[ArrayBufferDetachKey]]. + 1. Set |buffer|.\[[ArrayBufferData]] to |block|. + 1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|. + 1. Set |buffer|.\[[ArrayBufferMaxByteLength]] is |maxsize|. 1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory". 1. Return |buffer|.
@@ -766,17 +769,14 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. If |memtype| has a max, 1. Let |maxsize| be the max value in |memtype|. 1. Otherwise, - 1. Let |maxsize| be an implementation-defined value ≥ |buffer|.\[[ArrayBufferByteLength]] and < (65536 × 65536). - - Note: The implementation-defined value above is the same across all invocations of this method. - + 1. Let |maxsize| be 65536 × 65536. 1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|. 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). 1. Set **this**.\[[BufferObject]] to |resizableBuffer|. 1. Return |resizableBuffer|.
-{{ResizableArrayBuffer}} objects returned by a {{Memory}} object must use the following definition of [=HostResizeArrayBuffer=]. +{{ArrayBuffer}} objects returned by a {{Memory}} object must use the following definition of [=HostResizeArrayBuffer=].
The abstract operation [=HostResizeArrayBuffer=] takes arguments |buffer| and |newLength|. It performs the following steps when called. From 75a782e62425028fe2a9bff81b837c00cc01d0fd Mon Sep 17 00:00:00 2001 From: "Ioanna M. Dimitriou H" Date: Wed, 23 Aug 2023 19:27:39 +0200 Subject: [PATCH 3/6] [js-api] Change IsResizableArrayBuffer to !IsFixedLengthArrayBuffer Applies relevant normative change from https://github.com/tc39/ecma262/pull/3116 --- document/js-api/index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 4d4e1bdff9..0d02c3c061 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -150,7 +150,7 @@ urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal type: dfn text: handled; url: sec-hostresizearraybuffer - text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer + text: IsFixedLengthArrayBuffer; url: sec-isfixedarraybuffer text: HostResizeArrayBuffer; url: sec-hostresizearraybuffer @@ -678,7 +678,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Assert: |map|[|memaddr|] [=map/exists=]. 1. Let |memory| be |map|[|memaddr|]. 1. Let |buffer| be |memory|.\[[BufferObject]]. - 1. If [=IsResizableArrayBuffer=](|buffer|) is false, + 1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). 1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. 1. Set |memory|.\[[BufferObject]] to |buffer|. @@ -719,7 +719,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
The toFixedLengthBuffer() method, when invoked, performs the following steps: 1. Let |buffer| be **this**.\[[BufferObject]]. - 1. If [=IsResizableArrayBuffer=](|buffer|) is false, return |buffer|. + 1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, return |buffer|. 1. Let |memaddr| be **this**.\[[Memory]]. 1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). @@ -730,7 +730,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
The toResizableBuffer() method, when invoked, performs the following steps: 1. Let |buffer| be **this**.\[[BufferObject]]. - 1. If [=IsResizableArrayBuffer=](|buffer|) is true, return |buffer|. + 1. If [=IsFixedLengthArrayBuffer=](|buffer|) is false, return |buffer|. 1. Let |memaddr| be **this**.\[[Memory]]. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let |memtype| be [=mem_type=](|store|, |memaddr|). From d857651e39af4bd9767501a9a816cee4298db48f Mon Sep 17 00:00:00 2001 From: "Ioanna M. Dimitriou H" Date: Tue, 29 Aug 2023 02:21:25 +0200 Subject: [PATCH 4/6] Fix some build warnings --- document/js-api/index.bs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 0d02c3c061..26f6c14a31 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -160,6 +160,7 @@ spec:ecma-262; type:exception; for:ECMAScript; text:Error spec:ecmascript; type:exception; for:ECMAScript; text:TypeError spec:ecmascript; type:exception; for:ECMAScript; text:RangeError spec:ecmascript; type:interface; for:ECMAScript; text:ArrayBuffer +spec:ecmascript; type:dfn; text:agent spec:webidl; type:dfn; text:resolve @@ -618,7 +619,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|. 1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferDetachKey]]. 1. Set |buffer|.\[[ArrayBufferData]] to |block|. - 1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|. + 1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|. 1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory". 1. Return |buffer|.
@@ -679,7 +680,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each 1. Let |memory| be |map|[|memaddr|]. 1. Let |buffer| be |memory|.\[[BufferObject]]. 1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, - 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory"). 1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. 1. Set |memory|.\[[BufferObject]] to |buffer|. 1. Otherwise, @@ -722,7 +723,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, return |buffer|. 1. Let |memaddr| be **this**.\[[Memory]]. 1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|. - 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory"). 1. Set **this**.\[[BufferObject]] to |fixedBuffer|. 1. Return |fixedBuffer|.
@@ -739,7 +740,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. Otherwise, 1. Let |maxsize| be 65536 × 65536. 1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|. - 1. Perform ! [=DetachArrayBuffer=](|buffer|, "WebAssembly.Memory"). + 1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory"). 1. Set **this**.\[[BufferObject]] to |resizableBuffer|. 1. Return |resizableBuffer|.
From 31964d4e1a052729741126eae013b2058a569d0e Mon Sep 17 00:00:00 2001 From: "Ioanna M. Dimitriou H" Date: Thu, 31 Aug 2023 11:49:29 +0200 Subject: [PATCH 5/6] Addressing Ms2ger's review comment https://github.com/WebAssembly/spec/pull/1300#discussion_r1308436302 --- document/js-api/index.bs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 26f6c14a31..ba4529a85a 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -101,6 +101,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: memory address; url: exec/runtime.html#syntax-memaddr text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr + text: page size; url: exec/runtime.html#page-size url: syntax/types.html#syntax-numtype text: i32 text: i64 @@ -745,22 +746,24 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. Return |resizableBuffer|. -{{ArrayBuffer}} objects returned by a {{Memory}} object must use the following definition of [=HostResizeArrayBuffer=]. +{{ArrayBuffer}} objects returned by a {{Memory}} object must have size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [=HostResizeArrayBuffer=] is redefined as follows.
- The abstract operation [=HostResizeArrayBuffer=] takes arguments |buffer| and |newLength|. It performs the following steps when called. - - 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. - 1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|. - 1. [=map/iterate|For each=] |memaddr| → |mem| in |map|, - 1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true, - 1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0. - 1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]]. - 1. If |lengthDelta| < 0 or |lengthDelta| modulo 65536 is not 0, - 1. Throw a {{RangeError}} exception. - 1. Let |delta| be |lengthDelta| ÷ 65536. - 1. [=grow the memory buffer|Grow the memory buffer=] associated with |memaddr| by |delta|. - 1. Return handled. + The abstract operation [=HostResizeArrayBuffer=] takes arguments an {{ArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called. + + 1. If |buffer|.\[[ArrayBufferDetachKey]] is "WebAssembly.Memory", + 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. + 1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|. + 1. [=map/iterate|For each=] |memaddr| → |mem| in |map|, + 1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true, + 1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0. + 1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]]. + 1. If |lengthDelta| < 0 or |lengthDelta| modulo 65536 is not 0, + 1. Throw a {{RangeError}} exception. + 1. Let |delta| be |lengthDelta| ÷ 65536. + 1. [=grow the memory buffer|Grow the memory buffer=] associated with |memaddr| by |delta|. + 1. Return handled. + 1. Otherwise, return unhandled.
From 396f9d20a42be130ceb7817bdc62e56de9035444 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 3 Apr 2024 12:31:16 +0200 Subject: [PATCH 6/6] Apply suggestions from code review --- document/js-api/index.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index ba4529a85a..847223a35c 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -746,24 +746,24 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th 1. Return |resizableBuffer|.
-{{ArrayBuffer}} objects returned by a {{Memory}} object must have size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [=HostResizeArrayBuffer=] is redefined as follows. +{{ArrayBuffer}} objects returned by a {{Memory}} object must have a size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [=HostResizeArrayBuffer=] is redefined as follows.
- The abstract operation [=HostResizeArrayBuffer=] takes arguments an {{ArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called. + The abstract operation [=HostResizeArrayBuffer=] takes arguments |buffer| (an {{ArrayBuffer}}) and |newLength|. It performs the following steps when called. 1. If |buffer|.\[[ArrayBufferDetachKey]] is "WebAssembly.Memory", 1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=]. 1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|. 1. [=map/iterate|For each=] |memaddr| → |mem| in |map|, - 1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true, + 1. If [=SameValue=](|mem|.\[[BufferObject]], |buffer|) is true, 1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0. 1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]]. 1. If |lengthDelta| < 0 or |lengthDelta| modulo 65536 is not 0, 1. Throw a {{RangeError}} exception. 1. Let |delta| be |lengthDelta| ÷ 65536. - 1. [=grow the memory buffer|Grow the memory buffer=] associated with |memaddr| by |delta|. - 1. Return handled. - 1. Otherwise, return unhandled. + 1. [=Grow the memory buffer=] associated with |memaddr| by |delta|. + 1. Return handled. + 1. Otherwise, return unhandled.