Skip to content

Are string types and sequence types distinguishable? #266

@TimothyGu

Description

@TimothyGu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions