Re: [heycam/webidl] Conversion from specification values to IDL values to ECMAScript values (#674)

> ECMAScript and IDL values are 1:1

This is not quite true.  You could have two different IDL values that end up producing the same ES value (most simply two different numeric types, though you can also get this with a dictionary and a record, say).  And conversely, you could obviously have quite different ES values that produce the same IDL value given an IDL type to convert to.

What _is_ true (or should be) is that once you know what IDL type you are dealing with then (1) the set of IDL values for that type is well-defined, (2) how to convert those values to ES values is well-defined, and (3) how to convert ES values to IDL values for that type is well-defined.

As far as spec prose goes, does that help at all?  That is, can we define conversions as needed from infra values to IDL values as long as the desired type is known?  We already have that for the `sequence<T>` IDL type.  https://heycam.github.io/webidl/#idl-sequence last sentence says:

> Any list can be implicitly treated as a sequence<T>, as long as it contains only items that are of type T.

That won't help if your IDL type is a union and your infra value could conceivably map to several different types in the union, though.  Back to @annevk's example, if you have a byte sequence and the IDL type is `(ByteString or Uint8Array)` then nothing clearly defines how that should get handled...

-- 
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/674#issuecomment-469864564

Received on Tuesday, 5 March 2019 21:29:42 UTC