Re: [heycam/webidl] Consider simplifying serializers (#188)

Fwiw, what Gecko implements at the moment is this syntax:

    jsonifier;

Which leads to a toJSON implementation which does the following:

1. Allocate an JS object.
2. Walk from the root of the interface tree to our position in it; for each interface we reach that has a `jsonifier` on it, stick the corresponding attributes on the JS object.  Note that this is sort of like calling your parent's toJSON method, except you've already got the object; this could be rewritten in terms of "find the nearest ancestor that has a `jsonifier` and call its default toJSON; if there is none allocate an object yourself" or something; the observable behavior is the same.
3. Return the JS object.

That is, you always do your own attributes, and your ancestor interfaces can opt in to do theirs too.  This has been sufficient for all the use cases we've actually encountered, I believe.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/188#issuecomment-253957300

Received on Saturday, 15 October 2016 02:30:21 UTC