Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add immutable array buffer awareness to structuredClone #11033

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
40 changes: 37 additions & 3 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-isconstructor">IsConstructor</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-isdatadescriptor">IsDataDescriptor</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-isdetachedbuffer">IsDetachedBuffer</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-isimmutablebuffer">IsImmutableBuffer</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-issharedarraybuffer">IsSharedArrayBuffer</dfn> abstract operation</li>
<li>The <dfn data-x="js-NewObjectEnvironment" data-x-href="https://tc39.es/ecma262/#sec-newobjectenvironment">NewObjectEnvironment</dfn> abstract operation</li>
<li>The <dfn data-x-href="https://tc39.es/ecma262/#sec-normalcompletion">NormalCompletion</dfn> abstract operation</li>
Expand Down Expand Up @@ -9744,6 +9745,23 @@ interface <dfn interface>DOMStringList</dfn> {
</ol>
</li>

<li>
<p>Otherwise, if <span>IsImmutableBuffer</span>(<var>value</var>) is true, then:</p>

<ol>
<li>
<p>Set <var>serialized</var> to { [[Type]]: "ImmutableArrayBuffer", [[ArrayBufferData]]:
<var>value</var>.[[ArrayBufferData]], [[ArrayBufferByteLength]]:
<var>value</var>.[[ArrayBufferByteLength]] }.</p>

<p class="note">To support deserialization by independent processes at arbitrary points in
the future, the <em>contents</em> of <var>value</var>.[[ArrayBufferData]] need to be
preserved when <var>forStorage</var> is true. But otherwise, a pointer <em>referencing</em>
<var>value</var>.[[ArrayBufferData]] is expected to suffice.</p>
</li>
</ol>
</li>

<li>
<p>Otherwise:</p>

Expand Down Expand Up @@ -9791,7 +9809,8 @@ interface <dfn interface>DOMStringList</dfn> {
<var>memory</var>).</p></li>

<li><p><span>Assert</span>: <var>bufferSerialized</var>.[[Type]] is "ArrayBuffer",
"ResizableArrayBuffer", "SharedArrayBuffer", or "GrowableSharedArrayBuffer".</p></li>
"ImmutableArrayBuffer", "ResizableArrayBuffer", "SharedArrayBuffer", or
"GrowableSharedArrayBuffer".</p></li>

<li><p>If <var>value</var> has a [[DataView]] internal slot, then set <var>serialized</var> to
{ [[Type]]: "ArrayBufferView", [[Constructor]]: "DataView", [[ArrayBufferSerialized]]:
Expand Down Expand Up @@ -10186,6 +10205,20 @@ o.myself = o;</code></pre>
</ol>
</li>

<li>
<p>Otherwise, if <var>serialized</var>.[[Type]] is "ImmutableArrayBuffer", then:</p>

<ol>
<li><p>Set <var>value</var> to a new ArrayBuffer object in <var>targetRealm</var> whose
[[ArrayBufferData]] internal slot value is <var>serialized</var>.[[ArrayBufferData]], whose
[[ArrayBufferByteLength]] internal slot value is
<var>serialized</var>.[[ArrayBufferByteLength]], and whose [[ArrayBufferIsImmutable]] internal
slot value is undefined.</p></li>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for a slot to not have a value in this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, but it's obviously not great and I see now that things are moving away from it. I've updated accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for the record, the document.all HTMLAllCollection seems to be another example—it has an [[IsHTMLDDA]] internal slot for which no value is ever specified AFAICT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in ECMAScript, Object Internal Methods and Internal Slots defines the initial value of an internal slot to be undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True although see also tc39/ecma262#3399

<li><p><span>Assert</span>: <span>IsImmutableBuffer</span>(<var>value</var>) is true.</p></li>
</ol>
</li>

<li>
<p>Otherwise, if <var>serialized</var>.[[Type]] is "ArrayBuffer", then set <var>value</var> to a
new ArrayBuffer object in <var>targetRealm</var> whose [[ArrayBufferData]] internal slot value
Expand Down Expand Up @@ -10462,8 +10495,9 @@ o.myself = o;</code></pre>
<span>[[Detached]]</span> internal slot, then throw a
<span>"<code>DataCloneError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>If <var>transferable</var> has an [[ArrayBufferData]] internal slot and
<span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true, then throw a
<li><p>If <var>transferable</var> has an [[ArrayBufferData]] internal slot and either
<span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true or
<span>IsImmutableBuffer</span>(<var>transferable</var>) is true, then throw a
<span>"<code>DataCloneError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>If <var>memory</var>[<var>transferable</var>] <span data-x="map exists">exists</span>,
Expand Down