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

Are string types and sequence types distinguishable? #266

Closed
TimothyGu opened this issue Jan 15, 2017 · 3 comments
Closed

Are string types and sequence types distinguishable? #266

TimothyGu opened this issue Jan 15, 2017 · 3 comments

Comments

@TimothyGu
Copy link
Member

TimothyGu commented Jan 15, 2017

As discussed in whatwg/url#204, there is some confusion about the distinguishability between string types and sequences. Although currently, the spec maintains that they are distinguishable, @domenic and @annevk have express doubts over that.

What I have found is that:

  1. ES string primitives are NOT valid sequences, and are therefore distinguishable. Even though string primitives have a @@iterator, they fail the typeof === 'object' check in conversion to a sequence.
  2. ES string wrapper objects ARE valid sequences. They pass the aforementioned test, and they likewise have a valid iterator interface.

This is exemplified in Firefox, which implements iterable-to-sequence conversion:

>>  new Headers([ 'ab' ]).get('a')
**  "TypeError: Element of member of HeadersOrByteStringSequenceSequenceOrByteStringMozMap can't be converted to a sequence."
>>  new Headers([ new String('ab') ]).get('a')
<-  "b"

How can we resolve this situation?

@bzbarsky
Copy link
Collaborator

  1. String types and sequences are distinguishble.
  2. They are very explicitly and purposefully distinguishable, and there are APIs that use (DOMString or sequence<DOMString>). We purposefully allowed that.
  3. ES String objects are in fact valid sequences. They're also valid dictionaries (something else that is distinguishable from strings), valid callback interfaces, etc. The fact is, the current design of IDL was more or less predicated on "people don't use explicit String objects and expect any good to come of it".

I don't think there's anything to resolve here; the spec as written is written as intended and reflects reality.

@annevk
Copy link
Member

annevk commented Jan 16, 2017

I think you misunderstood my comment @TimothyGu. I tried to say that they are distinguishable (plus link to prove it), but that I think your proposal is not the way to go.

@TimothyGu
Copy link
Member Author

@annevk, yeah, does seem like I misunderstood. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants