Skip to content

Commit 01cf452

Browse files
committed
Add serialization support for NodeList and HTMLCollection
These should serialize like Arrays, in particular for the `document.querySelectorAll` use case where you want to directly get the list of elements back.
1 parent 864cf12 commit 01cf452

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

index.bs

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ To <dfn>set internal ids if needed</dfn> given |serialization internal map|,
15701570
[=remote end definition=] and [=local end definition=]
15711571

15721572
<pre class="cddl remote-cddl local-cddl">
1573-
RemoteValue = {
1573+
RemoteValue = (
15741574
PrimitiveProtocolValue //
15751575
SymbolRemoteValue //
15761576
ArrayRemoteValue //
@@ -1589,9 +1589,11 @@ RemoteValue = {
15891589
PromiseRemoteValue //
15901590
TypedArrayRemoteValue //
15911591
ArrayBufferRemoteValue //
1592+
NodeListRemoteValue //
1593+
HTMLCollectionRemoteValue //
15921594
NodeRemoteValue //
15931595
WindowProxyRemoteValue //
1594-
}
1596+
)
15951597

15961598
InternalId = js-uint;
15971599

@@ -1705,6 +1707,20 @@ ArrayBufferRemoteValue = {
17051707
?internalId: InternalId,
17061708
}
17071709

1710+
NodeListRemoteValue = {
1711+
type: "nodelist",
1712+
?handle: Handle,
1713+
?internalId: InternalId,
1714+
?value: ListRemoteValue,
1715+
}
1716+
1717+
HTMLCollectionRemoteValue = {
1718+
type: "htmlcollection",
1719+
?handle: Handle,
1720+
?internalId: InternalId,
1721+
?value: ListRemoteValue,
1722+
}
1723+
17081724
NodeRemoteValue = {
17091725
type: "node",
17101726
?handle: Handle,
@@ -1772,26 +1788,9 @@ an |ownership type|, a |serialization internal map| and a |realm|:
17721788
property set to |handle id| if it's not null, or omitted otherwise.
17731789

17741790
<dt>[=IsArray=](|value|)
1775-
<dd>
1776-
1777-
1. Let |remote value| be a map matching the <code>ArrayRemoteValue</code>
1778-
production in the [=local end definition=], with the <code>handle</code>
1779-
property set to |handle id| if it's not null, or omitted otherwise.
1780-
1781-
1. [=Set internal ids if needed=] given |serialization internal map|,
1782-
|remote value| and |value|.
1783-
1784-
1. Let |serialized| be null.
1785-
1786-
1. If |known object| is <code>false</code>, and |max depth| is not 0, run
1787-
the following steps:
1788-
1789-
1. Let |serialized| be the result of [=serialize as a list=] given
1790-
[=CreateArrayIterator=](|value|, value), |max depth|, |child ownership|,
1791-
|serialization internal map| and |realm|.
1792-
1793-
1. If |serialized| is not null, set field <code>value</code> of |remote value| to
1794-
|serialized|.
1791+
<dd>Let |remote value| be [=serialize an Array-like=] with
1792+
<code>ArrayRemoteValue</code>, |handle id|, |value|, |max depth|,
1793+
|ownership type|, |known object|, |serialization internal map|, and |realm|.
17951794

17961795
<dt>[=IsRegExp=](|value|)
17971796
<dd>
@@ -1894,6 +1893,17 @@ an |ownership type|, a |serialization internal map| and a |realm|:
18941893
production in the [=local end definition=], with the <code>handle</code>
18951894
property set to |handle id| if it's not null, or omitted otherwise.
18961895

1896+
<dt>|value| is a [=platform object=] that implements {{NodeList}}
1897+
<dd>Let |remote value| be [=serialize an Array-like=] with
1898+
<code>NodeListRemoteValue</code>,|handle id|, |value|, |max depth|,
1899+
|ownership type|, |known object|, |serialization internal map|, and |realm|.
1900+
1901+
<dt>|value| is a [=platform object=] that implements {{HTMLCollection}}
1902+
<dd>Let |remote value| be [=serialize an Array-like=] with
1903+
<code>HTMLCollectionRemoteValue</code>, |value|, |handle id|, |value|, |max
1904+
depth|, |ownership type|, |known object|, |serialization internal map|, and
1905+
|realm|.
1906+
18971907
<dt>|value| is a [=platform object=] that implements [=Node=]
18981908
<dd>
18991909
1. Let |remote value| be a map matching the <code>NodeRemoteValue</code>
@@ -2032,6 +2042,30 @@ remove optional flag from the field.
20322042

20332043
</div>
20342044

2045+
<div algorithm>
2046+
To <dfn>serialize an Array-like</dfn> given |production|, |handle id|, |value|,
2047+
|max depth|, |ownership type|, |known object|, |serialization internal map|, and |realm|:
2048+
2049+
1. Let |remote value| be a map matching |production|, with the
2050+
<code>handle</code> property set to |handle id| if it's not null, or omitted
2051+
otherwise.
2052+
2053+
1. [=Set internal ids if needed=] given |serialization internal map|,
2054+
|remote value| and |value|.
2055+
2056+
1. If |known object| is <code>false</code>, and |max depth| is not 0:
2057+
2058+
1. Let |serialized| be the result of [=serialize as a list=] given
2059+
[=CreateArrayIterator=](|value|, value), |max depth|, |ownership type|,
2060+
|serialization internal map| and |realm|.
2061+
2062+
1. If |serialized| is not null, set field <code>value</code> of |remote value| to
2063+
|serialized|.
2064+
2065+
1. Return |remote value|
2066+
2067+
</div>
2068+
20352069
<div algorithm>
20362070
To <dfn>serialize as a list</dfn> given |iterable|, |max depth|, |ownership type|,
20372071
|serialization internal map| and |realm|:

0 commit comments

Comments
 (0)