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

Fix collection serialization and support collection types found in the wild #1340

Merged
merged 4 commits into from
Nov 5, 2018
Merged

Fix collection serialization and support collection types found in the wild #1340

merged 4 commits into from
Nov 5, 2018

Conversation

andreastt
Copy link
Member

WebDriver’s JSON serialisation algorithm doesn’t handle all the collection types handled by implementations found in the wild. These are:

  • Arguments
  • FileList
  • HTMLAllCollection
  • HTMLFormControlsCollection
  • HTMLOptionsCollection

Whilst adding these I also discovered that the algorithm didn’t really inspect the interior of array-like collections at all, so the PR also fixes that. This is effectively mirroring how geckodriver handles JSON currently. See each commit message for more detailed information, since I also fixed a few other minor bugs along the way.

Tests for this can be found in https://github.com/web-platform-tests/wpt/blob/master/webdriver/tests/execute_script/collections.py.

This was discovered whilst reviewing web-platform-tests/wpt#13880.

The way the internal JSON clone algorithm is written it will not
be possible for an implementation to hit all variants.  For example,
we return if the value is an instance of an Object before we check
if it has a callable toJSON property.

Another change in this patch is that every JS object can be serialised
and returned, so it does not make sense to return an error at the
end, since everything in JS is an object.
Previously collections such as Array, HTMLCollection, and NodeList
were copied similarly to Objects.  This would cause them to never
be expanded into arrays.

This changes it so that we look at each of the items on their
iterable object and serialise each of the items.
…ollections

WebDriver previously only handled serialisation of Array, NodeList,
and HTMLCollection.  Implementations in the wild handle further
types, such as Arguments, FileList, HTMLAllCollection,
HTMLFormControlsCollection, and HTMLOptionsCollection.
@AutomatedTester AutomatedTester merged commit cf9002e into w3c:master Nov 5, 2018
@gsnedders
Copy link
Member

This seems a bit nonsensical?

We now have "A collection is an Object that implements the Iterable interface, and whose: […] type is HTMLAllCollection".

HTMLAllCollection isn't an interface with an iterable declaration, so instances are still not collections.

(I haven't gone through all the types listed, so there might be others which similarly don't have iterable declarations.)

@gsnedders
Copy link
Member

Also: what's a "type"?

@andreastt
Copy link
Member Author

Yes, thanks for pointing those things out. There are some rough edges here. 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”.

@jugglinmike
Copy link
Contributor

That's useful context, @ato, because it explains why the new text references the Iterable interface. This pull request was merged, so I'll share some thoughts on this in a new issue: #1347

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

Successfully merging this pull request may close these issues.

4 participants