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

"Record & Tuple" proposal HTML serialization support #6958

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 221 additions & 2 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,20 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://tc39.es/proposal-json-modules/#sec-synthetic-module-records">Synthetic Module Record</dfn> specification type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-json-modules/#sec-parse-json-module">ParseJSONModule</dfn> abstract operation</li>
</ul>

<p>User agents that support JavaScript must also implement the <cite>Record & Tuple</cite>
proposal. The following terms are defined there, and used in this specification: <ref
spec=JSRECORDTUPLE></p>

<ul class="brief">
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-record-type">Record</dfn> type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-tuple-type">Tuple</dfn> type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-box-type">Box</dfn> type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-record-object">Record</dfn> object type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-tuple-object">Tuple</dfn> object type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-box-object">Box</dfn> object type</li>
<li>The <dfn data-x-href="https://tc39.es/proposal-record-tuple/#sec-createrecord">CreateRecord</dfn> abstract operation</li>
</ul>
</dd>

<dt>WebAssembly</dt>
Expand Down Expand Up @@ -8847,6 +8861,58 @@ interface <dfn interface>DOMStringList</dfn> {
<li><p>If <span data-x="js-Type">Type</span>(<var>value</var>) is Symbol, then throw a
<span>"<code>DataCloneError</code>"</span> <code>DOMException</code>.</p></li>

<li>
<p>If <span data-x="js-Type">Type</span>(<var>value</var>) is Record, then:</p>

<ol>
<li><p>Let <var>copiedFields</var> be a new empty <span data-x="js-List">List</span>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <span>Record</span> { [[Key]], [[Value]] }
<var>entry</var> of <var>value</var>.[[Fields]]:</p>

<ol>
<li><p>Let <var>copiedValue</var> be ?
<span>StructuredSerializeInternal</span>(<var>value</var>.[[Value]], <var>forStorage</var>,
<var>memory</var>).</p></li>

<li><p>Let <var>copiedEntry</var> be a new <span>Record</span> { [[Key]]:
<var>entry</var>.[[Key]], [[Value]]: <var>copiedValue</var> }.</p></li>

<li><p><span data-x="list append">Append</span> <var>copiedEntry</var> to
<var>copiedFields</var>.</p></li>
</ol>
</li>

<li><p>Return { [[Type]]: "record", [[Fields]]: <var>copiedFields</var> }.</p></li>
</ol>
</li>

<li>
<p>If <span data-x="js-Type">Type</span>(<var>value</var>) is Tuple, then:</p>

<ol>
<li><p>Let <var>copiedElements</var> be a new empty
<span data-x="js-List">List</span>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>element</var> of
<var>value</var>.[[Sequence]]:</p>

<ol>
<li><p>Let <var>copiedElement</var> be ?
<span>StructuredSerializeInternal</span>(<var>element</var>, <var>forStorage</var>,
<var>memory</var>).</p></li>

<li><p><span data-x="list append">Append</span> <var>copiedElement</var> to
<var>copiedElements</var>.</p></li>
</ol>
</li>

<li><p>Return { [[Type]]: "tuple", [[Sequence]]: <var>copiedElements</var> }.</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.

"a empty"

</ol>
</li>

<li><p>Let <var>serialized</var> be an uninitialized value.</p></li>

<li><p>If <var>value</var> has a [[BooleanData]] internal slot, then set <var>serialized</var> to
Expand All @@ -8864,6 +8930,26 @@ interface <dfn interface>DOMStringList</dfn> {
<var>serialized</var> to { [[Type]]: "String", [[StringData]]: <var>value</var>.[[StringData]]
}.</p></li>

<li>
<p>Otherwise, if <var>value</var> has a [[RecordData]] internal slot, then:

<ol>
<li><p>Set <var>serialized</var> to { [[Type]]: "Record", [[RecordData]]: empty }.</p></li>

<li><p>Set <var>deep</var> to true.</p></li>
</ol>
</li>

<li>
<p>Otherwise, if <var>value</var> has a [[TupleData]] internal slot, then:

<ol>
<li><p>Set <var>serialized</var> to { [[Type]]: "Tuple", [[TupleData]]: empty }.</p></li>

<li><p>Set <var>deep</var> to true.</p></li>
</ol>
</li>

<li><p>Otherwise, if <var>value</var> has a [[DateValue]] internal slot, then set
<var>serialized</var> to { [[Type]]: "Date", [[DateValue]]: <var>value</var>.[[DateValue]]
}.</p></li>
Expand Down Expand Up @@ -9098,7 +9184,35 @@ interface <dfn interface>DOMStringList</dfn> {

<ol>
<li>
<p>If <var>value</var> has a [[MapData]] internal slot, then:
<p>If <var>value</var> has a [[RecordData]] internal slot, then:</p>

<ol>
<li><p>Let <var>data</var> be ?
<span>StructuredSerializeInternal</span>(<var>value</var>.[[RecordData]],
<var>forStorage</var>, <var>memory</var>).</p></li>

<li><p>Assert: <var>data</var>.[[Type]] is "record".</p></li>

<li><p>Set <var>serialized</var>.[[RecordData]] to <var>data</var>.</p></li>
</ol>
</li>

<li>
<p>Otherwise, if <var>value</var> has a [[TupleData]] internal slot, then:</p>

<ol>
<li><p>Let <var>data</var> be ?
<span>StructuredSerializeInternal</span>(<var>value</var>.[[TupleData]],
<var>forStorage</var>, <var>memory</var>).</p></li>

<li><p>Assert: <var>data</var>.[[Type]] is "tuple".</p></li>

<li><p>Set <var>serialized</var>.[[TupleData]] to <var>data</var>.</p></li>
</ol>
</li>

<li>
<p>Otherwise, if <var>value</var> has a [[MapData]] internal slot, then:

<ol>
<li><p>Let <var>copiedList</var> be a new empty <span data-x="js-List">List</span>.
Expand Down Expand Up @@ -9278,6 +9392,55 @@ o.myself = o;</code></pre>
<li><p>If <var>serialized</var>.[[Type]] is "primitive", then set <var>value</var> to
<var>serialized</var>.[[Value]].</p>

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

<ol>
<li><p>Let <var>entries</var> be a new empty <span data-x="js-List">List</span>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <span>Record</span> { [[Key]], [[Value]] }
<var>entry</var> of <var>serialized</var>.[[Fields]]:</p>

<ol>
<li><p>Let <var>fieldValue</var> be ?
<span>StructuredDeserialize</span>(<var>entry</var>.[[Value]], <var>targetRealm</var>,
<var>memory</var>).</p></li>

<li><p><span data-x="list append">Append</span> { [[Key]]: <var>entry</var>.[[Key]],
[[Value]]: <var>fieldValue</var> } to <var>entries</var>.</p></li>
</ol>
</li>

<li><p>Set <var>value</var> to ! <span>CreateRecord</span>(<var>entries</var>).</p></li>
</ol>
</li>

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

<ol>
<li><p>Let <var>elements</var> be a new empty <span data-x="js-List">List.</span></p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>element</var> of
<var>serialized</var>.[[Sequence]]:</p>

<ol>
<li><p>Let <var>deserializedElement</var> be ?
<span>StructuredDeserialize</span>(<var>element</var>, <var>targetRealm</var>,
<var>memory</var>).</p></li>

<li><p><span data-x="list append">Append</span> <var>deserializedElement</var> to
<var>elements</var>.</p></li>
</ol>
</li>

<li><p>Set <var>value</var> to a new Tuple value whose [[Sequence]] is
<var>elements</var>.</p></li>
</ol>
</li>

<li><p>Otherwise, if <var>serialized</var>.[[Type]] is "Boolean", then set <var>value</var> to a
new Boolean object in <var>targetRealm</var> whose [[BooleanData]] internal slot value is
<var>serialized</var>.[[BooleanData]].</p></li>
Expand All @@ -9294,6 +9457,28 @@ o.myself = o;</code></pre>
new String object in <var>targetRealm</var> whose [[StringData]] internal slot value is
<var>serialized</var>.[[StringData]].</p></li>

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

<ol>
<li><p>Set <var>value</var> to a new Record object in <var>targetRealm</var> whose
[[RecordData]] internal slot is empty.</p></li>

<li><p>Set <var>deep</var> to true.</p></li>
</ol>
</li>

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

<ol>
<li><p>Set <var>value</var> to a new Tuple object in <var>targetRealm</var> whose
[[TupleData]] internal slot is empty.</p></li>

<li><p>Set <var>deep</var> to true.</p></li>
</ol>
</li>

<li><p>Otherwise, if <var>serialized</var>.[[Type]] is "Date", then set <var>value</var> to a new
Date object in <var>targetRealm</var> whose [[DateValue]] internal slot value is
<var>serialized</var>.[[DateValue]].</p></li>
Expand Down Expand Up @@ -9469,7 +9654,37 @@ o.myself = o;</code></pre>

<ol>
<li>
<p>If <var>serialized</var>.[[Type]] is "Map", then:</p>
<p>If <var>serialized</var>.[[Type]] is "Record", then:</p>

<ol>
<li><p>Let <var>deserializedRecord</var> be ?
<span>StructuredDeserialize</span>(<var>serialized</var>.[[RecordData]],
<var>targetRealm</var>, <var>memory</var>).</p></li>

<li><p>Assert: <span data-x="js-Type">Type</span>(<var>deserializedRecord</var>) is
Record.</p></li>

<li><p>Set <var>value</var>.[[RecordData]] to <var>deserializedRecord</var>.</p></li>
</ol>
</li>

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

<ol>
<li><p>Let <var>deserializedTuple</var> be ?
<span>StructuredDeserialize</span>(<var>serialized</var>.[[TupleData]],
<var>targetRealm</var>, <var>memory</var>).</p></li>

<li><p>Assert: <span data-x="js-Type">Type</span>(<var>deserializedTuple</var>) is
Tuple.</p></li>

<li><p>Set <var>value</var>.[[TupleData]] to <var>deserializedTuple</var>.</p></li>
</ol>
</li>

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

<ol>
<li>
Expand Down Expand Up @@ -127625,6 +127840,9 @@ INSERT INTERFACES HERE
<dt id="refsJSJSONMODULES">[JSJSONMODULES]</dt>
<dd><cite><a href="https://tc39.es/proposal-json-modules/">JSON Modules</a></cite>. Ecma International.</dd>

<dt id="refsJSRECORDTUPLE">[JSRECORDTUPLE]</dt>
<dd><cite><a href="https://tc39.es/proposal-record-tuple/">Record & Tuple</a></cite>. Ecma International.</dd>

<dt id="refsJSINTL">[JSINTL]</dt>
<dd><cite><a href="https://tc39.es/ecma402/">ECMAScript Internationalization API Specification</a></cite>. Ecma International.</dd>

Expand Down Expand Up @@ -128726,6 +128944,7 @@ INSERT INTERFACES HERE
Nickolay Ponomarev,
Nicolas Gallagher,
Nicolas Pena Moreno,
Nicolò Ribaudo,
Nikki Bee,
Niklas Gögge,
Nina Satragno,
Expand Down