web-platform-tests / wpt

Test suites for Web platform specs — including WHATWG, W3C, and others
https://web-platform-tests.org/
Other
4.82k stars 3.01k forks source link

idlharness.js: test dictionary types (conversion to/from ES values) #9106

Open foolip opened 6 years ago

foolip commented 6 years ago

idlharness.js doesn't test anything about dictionaries, but could.

Given a method that takes a single value and passes that along to some context that expects a dictionary of a certain type, one could test which properties are accessed, and if TypeError is thrown when required members are omitted.

Also, just like we test instances of interfaces, we could test "instances" of dictionaries, to test that required members are present, and that optional members that are present have the right type.

@alvestrand wanted something like this to test https://w3c.github.io/webrtc-stats/

alvestrand commented 6 years ago

The current hand-generated alternative by @soareschen is seen in https://github.com/w3c/web-platform-tests/blob/master/webrtc/RTCStats-helper.js - I think we can make this more maintainable by using IDL parsers.

foolip commented 6 years ago

@Orphis has found a clever way to do this using Proxy, which makes it possible to get a list of all the property values that are read from a JS object when converting to IDL dictionaries.

That would also detect dictionary members that are non-standard. @mdittmer FYI, this could perhaps be used to inform the support status of dictionary members on MDN.