Re: [heycam/webidl] Replace serializers by toJSON and [Default] extended attribute (#323)

tobie commented on this pull request.



> +The [=corresponding default operation=] of the “toJSON” operation is the [=default toJSON operation=].
+
+<div algorithm>
+
+    To invoke the <dfn export>default toJSON operation</dfn> of [=interface=] |I|,
+    run the the following steps:
+
+    1.  Let |O| be the <emu-val>this</emu-val> value.
+    1.  Let |result| be [=!=] [=ObjectCreate=]([=%ObjectPrototype%=]).
+    1.  If there is an [=inherited interface=] of |I|
+        that declares a “toJSON” operation, then
+        1.  Let |super| be the “toJSON” operation  of
+            the closest [=inherited interface=] of |I|
+            that declares a “toJSON” operation.
+        1.  Set |result| to [=?=] [=Call=](|super|, |O|).
+    1.  If Type(|result|) is not Object, return |result|.

This behavior allows to set a [Default] extended attribute on a toJSON operation even it has ancestors that set a custom one.

If the custom toJSON operation defined on one of the ancestors returns an object, we just add the interface's attributes to it. Otherwise, we return whatever was returned by the ancestor's toJSON method.

Happy to hear comments as to why this is a bad idea.

-- 
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/pull/323#pullrequestreview-24121537

Received on Monday, 27 February 2017 23:17:38 UTC