Skip to content

Serialization of "collections" #1347

Open
@jugglinmike

Description

@jugglinmike

Serialization of "collections"

In this patch for WPT, we discovered an incongruity between the spec and the implementations. @ato dutifully followed up with a patch to resolve this, but that may be incomplete. A new issue seems like a more intuitive place to discuss than a merged pull request, so here it is!

@ato wrote:

The effect we want to achieve with this PR is that those things we define as
“collection types” should be expanded to an array of items, for which we
invoke the serialisation algorithm again on each item.

In Marionette we implement this in JS using [...collection] because it
works on all of the collection types, including HTMLAllCollection despite it
not carrying an iterable declaration. I would love some feedback on how you
define “expand all these things to arrays, as if calling [...collection] in
JS”.

HTML uses a narrower definition of what a collection is because it limits
them to things deriving from NodeList if I remember correctly. In particular
this excludes the Arguments object, but more importantly, there is not a
centralised list of collections in HTML or DOM, and this is an attempt an
enumerating those, plus adding Arguments into the mix.

“type” probably should be replace with “an instance of”.

That explains why the latest test references the "Iterable" interface. However, the text doesn't actually use that interface; it reads a length property and accesses additional string properties based on that. That's why prior to your explanation, I was planning to recommend we remove the requirement.

If we're targeting the behavior of [...collection], then we'll need to explicitly specify the use of the iterator protocol. That will ensure that all implementations do the right thing when (for instance) iterator.next throws an error. ECMAScript demonstrates how this is done in the runtime semantics for SpreadElement.

This is much more complicated (conceptually) than simple property access. If we're going to commit to it, I wonder if it's worthwhile to accept any iterable. This will be easier to specify, but more importantly, it will be an easier model for developers to internalize. @ato @gsnedders what do you think?

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