Skip to content

Commit 60a2cbf

Browse files
sygdomenic
authored andcommitted
Integrate with the resizable buffers proposal
This commit adds the [AllowResizable] extended attribute, which allow BufferSources to take resizable buffers. It composes with [AllowShared] in the obvious way. The default behavior is unchanged, with only fixed-length buffers allowed. Proposal link: https://github.com/tc39/proposal-resizablearraybuffer
1 parent 76cbc96 commit 60a2cbf

File tree

1 file changed

+98
-16
lines changed

1 file changed

+98
-16
lines changed

index.bs

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
243243
text: ResolvedBinding Record; url: resolvedbinding-record
244244
text: running execution context; url: running-execution-context
245245
text: element size; url: table-the-typedarray-constructors
246+
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: RESIZABLE-BUFFERS-PROPOSAL
247+
type: abstract-op
248+
text: IsResizableArrayBuffer; url: sec-isresizablearraybuffer
246249
</pre>
247250

248251
<style>
@@ -6610,6 +6613,7 @@ annotate are called <dfn export for="annotated types" lt="inner type">inner type
66106613
</div>
66116614

66126615
The following extended attributes are <dfn for="extended attributes">applicable to types</dfn>:
6616+
[{{AllowResizable}}],
66136617
[{{AllowShared}}],
66146618
[{{Clamp}}],
66156619
[{{EnforceRange}}], and
@@ -8856,10 +8860,34 @@ that correspond to the union’s [=member types=].
88568860
<h4 id="es-buffer-source-types">Buffer source types</h4>
88578861

88588862
Values of the IDL [=buffer source types=]
8859-
are represented by objects of the corresponding ECMAScript class, with the additional restriction
8860-
that unless the type is [=extended attributes associated with|associated with=] the
8861-
[{{AllowShared}}] extended attribute, they can only be backed by ECMAScript
8862-
{{ECMAScript/ArrayBuffer}} objects, and not {{ECMAScript/SharedArrayBuffer}} objects.
8863+
are represented by objects of the corresponding ECMAScript class, with the following additional restrictions on those objects.
8864+
8865+
<ul>
8866+
<li>
8867+
If the type is not [=extended attributes associated with|associated with=] either the
8868+
[{{AllowResizable}}] or [{{AllowShared}}] [=extended attribute=], they can only be backed by
8869+
ECMAScript {{ECMAScript/ArrayBuffer}} objects |V| for which <a
8870+
abstract-op>IsResizableArrayBuffer</a>(|V|) is false.
8871+
</li>
8872+
<li>
8873+
If the type is [=extended attributes associated with|associated with=] the
8874+
[{{AllowResizable}}] [=extended attribute=] but not with the [{{AllowShared}}] [=extended
8875+
attribute=], they can only be backed by ECMAScript {{ECMAScript/ArrayBuffer}} objects.
8876+
</li>
8877+
<li>
8878+
If the type is [=extended attributes associated with|associated with=] the [{{AllowShared}}]
8879+
[=extended attribute=] but not with the [{{AllowResizable}}] [=extended attribute=], they
8880+
can only be backed by ECMAScript {{ECMAScript/ArrayBuffer}} and ECMAScript
8881+
{{ECMAScript/SharedArrayBuffer}} objects |V| for which <a
8882+
abstract-op>IsResizableArrayBuffer</a>(|V|) is false.
8883+
</li>
8884+
<li>
8885+
If the type is [=extended attributes associated with|associated with=] both the
8886+
[{{AllowResizable}}] and the [{{AllowShared}}] [=extended attribute|extended attributes=],
8887+
they can be backed by any ECMAScript {{ECMAScript/ArrayBuffer}} or
8888+
{{ECMAScript/SharedArrayBuffer}} object.
8889+
</li>
8890+
</ul>
88638891

88648892
<div id="es-to-buffer-source" algorithm="convert an ECMAScript value to IDL ArrayBuffer">
88658893

@@ -8873,6 +8901,10 @@ that unless the type is [=extended attributes associated with|associated with=]
88738901
[=extended attributes associated with|associated with=] the [{{AllowShared}}]
88748902
[=extended attribute=], and <a abstract-op>IsSharedArrayBuffer</a>(|V|) is true, then [=ECMAScript/throw=]
88758903
a {{ECMAScript/TypeError}}.
8904+
1. If the conversion is not to an IDL type
8905+
[=extended attributes associated with|associated with=] the [{{AllowResizable}}]
8906+
[=extended attribute=], and <a abstract-op>IsResizableArrayBuffer</a>(|V|) is true,
8907+
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
88768908
1. Return the IDL {{ArrayBuffer}} value that is a reference
88778909
to the same object as |V|.
88788910
</div>
@@ -8889,6 +8921,10 @@ that unless the type is [=extended attributes associated with|associated with=]
88898921
[=extended attributes associated with|associated with=] the [{{AllowShared}}]
88908922
[=extended attribute=], and <a abstract-op>IsSharedArrayBuffer</a>(|V|.\[[ViewedArrayBuffer]]) is true,
88918923
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
8924+
1. If the conversion is not to an IDL type
8925+
[=extended attributes associated with|associated with=] the [{{AllowResizable}}]
8926+
[=extended attribute=], and <a abstract-op>IsResizableArrayBuffer</a>(|V|.\[[ViewedArrayBuffer]]) is true,
8927+
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
88928928
1. Return the IDL {{DataView}} value that is a reference
88938929
to the same object as |V|.
88948930
</div>
@@ -8921,6 +8957,10 @@ that unless the type is [=extended attributes associated with|associated with=]
89218957
[=extended attributes associated with|associated with=] the [{{AllowShared}}]
89228958
[=extended attribute=], and <a abstract-op>IsSharedArrayBuffer</a>(|V|.\[[ViewedArrayBuffer]]) is true,
89238959
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
8960+
1. If the conversion is not to an IDL type
8961+
[=extended attributes associated with|associated with=] the [{{AllowResizable}}]
8962+
[=extended attribute=], and <a abstract-op>IsResizableArrayBuffer</a>(|V|.\[[ViewedArrayBuffer]]) is true,
8963+
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
89248964
1. Return the IDL value of type |T| that is a reference to the same object as |V|.
89258965
</div>
89268966

@@ -9181,6 +9221,27 @@ This section defines a number of
91819221
whose presence affects the ECMAScript binding.
91829222

91839223

9224+
<h4 id="AllowResizable" extended-attribute lt="AllowResizable">[AllowResizable]</h4>
9225+
9226+
If the [{{AllowResizable}}] [=extended attribute=] appears on one of the [=buffer source types=] without the presence of the [{{AllowShared}}] [=extended attribute=], it
9227+
creates a new IDL type that allows the buffer source type to be backed by an ECMAScript
9228+
{{ECMAScript/ArrayBuffer}} that is resizable, instead of only by a fixed-length {{ECMAScript/ArrayBuffer}}.
9229+
9230+
If the [{{AllowResizable}}] [=extended attribute=] and the [{{AllowShared}}] [=extended attribute=] both appear on one of the [=buffer source types=], it
9231+
creates a new IDL type that allows the buffer source type to be additionally backed by an ECMAScript
9232+
{{ECMAScript/SharedArrayBuffer}} that is growable.
9233+
9234+
The [{{AllowResizable}}] extended attribute must [=takes no arguments|take no arguments=].
9235+
9236+
A type that is not a [=buffer source type=] must not be
9237+
[=extended attributes associated with|associated with=] the [{{AllowResizable}}] extended attribute.
9238+
9239+
See the rules for converting ECMAScript values to IDL [=buffer source types=] in
9240+
[[#es-buffer-source-types]] for the specific requirements that the use of [{{AllowResizable}}] entails.
9241+
9242+
See the <a href="#example-allowresizable-allowshared">example</a> in [[#AllowShared]] for example usage of both [{{AllowResizable}}] and [{{AllowShared}}].
9243+
9244+
91849245
<h4 id="AllowShared" extended-attribute lt="AllowShared">[AllowShared]</h4>
91859246

91869247
If the [{{AllowShared}}] [=extended attribute=] appears on one of the [=buffer source types=], it
@@ -9195,22 +9256,43 @@ A type that is not a [=buffer source type=] must not be
91959256
See the rules for converting ECMAScript values to IDL [=buffer source types=] in
91969257
[[#es-buffer-source-types]] for the specific requirements that the use of [{{AllowShared}}] entails.
91979258

9198-
<div class="example">
9199-
In the following [=IDL fragment=], one operation's argument uses the [{{AllowShared}}] extended
9259+
<div class="example" id="example-allowresizable-allowshared">
9260+
In the following [=IDL fragment=], one operation's argument uses the [{{AllowResizable}}] extended
92009261
attribute, while the other does not:
92019262

92029263
<pre highlight="webidl">
92039264
[Exposed=Window]
9204-
interface RenderingContext {
9205-
undefined readPixels(long width, long height, BufferSource pixels);
9206-
undefined readPixelsShared(long width, long height, [AllowShared] BufferSource pixels);
9207-
};
9208-
</pre>
9209-
9210-
With this definition, a call to <code>readPixels</code> with an {{ECMAScript/SharedArrayBuffer}}
9211-
instance, or any typed array or {{ECMAScript/DataView}} backed by one, will throw a
9212-
{{ECMAScript/TypeError}} exception. In contrast, a call to <code>readPixelsShared</code> will allow such
9213-
objects as input.
9265+
interface ExampleBufferFeature {
9266+
undefined writeInto(BufferSource dest);
9267+
undefined writeIntoResizable([AllowResizable] BufferSource dest);
9268+
undefined writeIntoShared([AllowShared] BufferSource dest);
9269+
undefined writeIntoSharedResizable([AllowResizable, AllowShared] BufferSource dest);
9270+
};
9271+
</pre>
9272+
9273+
With this definition,
9274+
<ul>
9275+
<li>
9276+
A call to <code>writeInto</code> with a resizable {{ECMAScript/ArrayBuffer}} instance, a
9277+
{{ECMAScript/SharedArrayBuffer}} instance, or any typed array or {{ECMAScript/DataView}}
9278+
backed by either, will throw a {{ECMAScript/TypeError}} exception.
9279+
</li>
9280+
<li>
9281+
A call to <code>writeIntoResizable</code> with a {{ECMAScript/SharedArrayBuffer}}
9282+
instance, or any typed array or {{ECMAScript/DataView}} backed by one, will throw a
9283+
{{ECMAScript/TypeError}} exception.
9284+
</li>
9285+
<li>
9286+
A call to <code>writeIntoShared</code> with a resizable {{ECMAScript/ArrayBuffer}}
9287+
instance, a growable {{ECMAScript/SharedArrayBuffer}} instance, or any typed array or
9288+
{{ECMAScript/DataView}} backed by one, will throw a {{ECMAScript/TypeError}} exception.
9289+
</li>
9290+
<li>
9291+
A call to <code>writeIntoSharedResizable</code> will accept an
9292+
{{ECMAScript/ArrayBuffer}} instance, a {{ECMAScript/SharedArrayBuffer}} instance, or any
9293+
typed array or {{ECMAScript/DataView}} backed by either.
9294+
</li>
9295+
</ul>
92149296
</div>
92159297

92169298

0 commit comments

Comments
 (0)