- From: Ms2ger <notifications@github.com>
- Date: Wed, 07 Aug 2019 03:12:22 -0700
- To: heycam/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <heycam/webidl/issues/324/519034084@github.com>
Something like this could work for converting tuples; it'd just need to be added everywhere types are mentioned.
```md
<div id="es-to-tuple" algorithm="convert an ECMAScript value to tuple">
An ECMAScript value |V| is [=converted to an IDL value|converted=] to an IDL
<a lt="tuple type">tuple<<var ignore>T</var><sub>0</sub>, …, <var ignore>T</var><sub>|n| − 1</sub>></a>
value as follows:
1. If [$Type$](|V|) is not Object, [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1. Let |iter| be [=?=] [$GetIterator$](|V|, <emu-const>sync</emu-const>).
1. Let |i| be 0.
1. While |i| < |n|:
1. Let |next| be [=?=] [$IteratorStep$](|iter|).
1. If |next| is <emu-val>false</emu-val>, [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1. Let |nextItem| be [=?=] [$IteratorValue$](|next|).
1. Initialize |S|<sub>|i|</sub> to the result of [=converted to an IDL value|converting=]
|nextItem| to an IDL value of type |T|_|i|.
1. Set |i| to |i| + 1.
1. Return a tuple where the value of the element at index |j| is |S|<sub>|j|</sub>.
</div>
<div id="tuple-to-es" algorithm="convert a tuple to an ECMAScript value">
An IDL tuple value |tuple| of type
<a lt="tuple type">tuple<<var ignore>T</var><sub>0</sub>, …, <var ignore>T</var><sub>|n| − 1</sub>></a> is
[=converted to an ECMAScript value|converted=]
to an ECMAScript Array object as follows:
1. Let |A| be [=!=] [$ArrayCreate$](0).
1. Let |i| be 0.
1. While |i| < |n|:
1. Let |V| be the value in |S| at index |i|.
1. Let |E| be the result of [=converted to an ECMAScript value|converting=]
|V| to an ECMAScript value.
1. Let |P| be the result of calling [$ToString$](|i|).
1. Call [$CreateDataProperty$](|A|, |P|, |E|).
1. Set |i| to |i| + 1.
1. Return |A|.
</div>
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/324#issuecomment-519034084
Received on Wednesday, 7 August 2019 10:12:44 UTC