- From: Jeffrey Yasskin <notifications@github.com>
- Date: Fri, 14 Oct 2016 13:08:08 -0700
- To: heycam/webidl <webidl@noreply.github.com>
- Message-ID: <heycam/webidl/pull/180/review/4334793@github.com>
jyasskin commented on this pull request. Thanks! > +<h4 id="es-record">Records — record<|K|, |V|></h4> + +IDL {{record}}<|K|, |V|> values are represented by +ECMAScript <emu-val>Object</emu-val> values. + +<p id="es-to-record"> + An ECMAScript value |O| is [=converted to an IDL value|converted=] to an IDL <code>{{record}}<|K|, |V|></code> value as follows: +</p> + +<ol class="algorithm"> + 1. Let |result| be a new empty instance of <code>{{record}}<|K|, |V|></code>. + 1. If [=Type=](|O|) is <emu-val>Undefined</emu-val> or <emu-val>Null</emu-val>, + return |result|. + 1. If [=Type=](|O|) is not <emu-val>Object</emu-val>, + <a lt="es throw">throw a <emu-val>TypeError</emu-val></a>. + 1. Let |keys| be [=?=] |O|.[=[[OwnPropertyKeys]]=](). Done. > + 1. If [=Type=](|O|) is <emu-val>Undefined</emu-val> or <emu-val>Null</emu-val>, + return |result|. + 1. If [=Type=](|O|) is not <emu-val>Object</emu-val>, + <a lt="es throw">throw a <emu-val>TypeError</emu-val></a>. + 1. Let |keys| be [=?=] |O|.[=[[OwnPropertyKeys]]=](). + 1. Repeat, for each element |key| of |keys| in [=List=] order: + 1. Let |desc| be [=?=] |O|.[=[[GetOwnProperty]]=](|key|). + 1. If |desc| is not <emu-val>undefined</emu-val> + and |desc|.[=[[Enumerable]]=] is <emu-val>true</emu-val>: + 1. Let |typedKey| be |key| [=converted to an IDL value=] of type |K|. + 1. Let |value| be [=?=] [=Get=](|O|, |key|). + 1. Let |typedValue| be |value| [=converted to an IDL value=] of type |V|. + 1. If |typedKey| is already a key in |result|, set its value to |typedValue|. + + Note: This can happen when |O| is a proxy object. + 1. Otherwise, append to |result| a mapping from |typedKey| to |typedValue|. Done. > + An IDL <code>{{record}}<…></code> value |D| is [=converted to an + ECMAScript value|converted=] to an ECMAScript value as follows: +</p> + +<ol class="algorithm"> + 1. Let |result| be [=!=] [=ObjectCreate=]([=%ObjectPrototype%=]). + 1. Repeat, for each [=record/mapping=] (|key|, |value|) in |D|: + 1. Let |esKey| be |key| [=converted to an ECMAScript value=]. + 1. Let |esValue| be |value| [=converted to an ECMAScript value=]. + 1. Let |created| be [=!=] [=CreateDataProperty=](|result|, |esKey|, |esValue|). + 1. Assert: |created| is <emu-val>true</emu-val>. + 1. Return |result|. +</ol> + +<div class="example" id="example-es-record"> + Passing the ECMAScript value <code>{b: 3, a: 4}</code> to a Done. > +</p> + +<ol class="algorithm"> + 1. Let |result| be [=!=] [=ObjectCreate=]([=%ObjectPrototype%=]). + 1. Repeat, for each [=record/mapping=] (|key|, |value|) in |D|: + 1. Let |esKey| be |key| [=converted to an ECMAScript value=]. + 1. Let |esValue| be |value| [=converted to an ECMAScript value=]. + 1. Let |created| be [=!=] [=CreateDataProperty=](|result|, |esKey|, |esValue|). + 1. Assert: |created| is <emu-val>true</emu-val>. + 1. Return |result|. +</ol> + +<div class="example" id="example-es-record"> + Passing the ECMAScript value <code>{b: 3, a: 4}</code> to a + <code>{{record}}<DOMString, double></code> argument + would result in the IDL value <code>[ ("b", 3), ("a", 4) ]</code>. I think > There is no way to represent a constant record value in IDL. means that we don't have syntax for it in the WebIDL grammar. The phrase, > a record containing the two mappings ("b", 3) and ("a", 4), in that order. would still "represent a constant record value", but I'd like to have a more concise way to do it. > @@ -7695,6 +7837,9 @@ represented by ECMAScript values that correspond to the union’s 1. If |types| includes a [=dictionary type=], then return the result of [=converted to an IDL value|converting=] |V| to that dictionary type. + 1. If |types| includes a [=record type=], then return the + result of [=converted to an IDL value|converting=] + |V| to that dictionary type. Whoops, done. -- 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/pull/180#pullrequestreview-4334793
Received on Friday, 14 October 2016 20:08:38 UTC