From 881e0a3d363b6a1590925ea3649bde30e6cbf279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= Date: Fri, 23 Apr 2021 22:40:18 +0200 Subject: [PATCH] Editorial: simplify the example on default toJSON() This example was adapted from a previous one in https://github.com/heycam/webidl/pull/433, but things are much simpler now and the example makes it seem more complicated than it really is. Make the points inheritance and mixins separately. This also fixes the order of attributes on the returned JSON object, which was wrong the original example. The attributes of the base interface should be included first. Reverse the inheritance order in the example to make this clearer, matching `interface B : A` in two other examples. Fixes https://github.com/heycam/webidl/issues/979. --- index.bs | 91 +++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 51 deletions(-) diff --git a/index.bs b/index.bs index 3e226f63..74c86308 100644 --- a/index.bs +++ b/index.bs @@ -12090,84 +12090,73 @@ A [=regular operation=] that does not [=have default method steps=] must not be
- The following [=IDL fragment=] defines a number of [=interfaces=], - which are [=inherited interfaces=] of A, - and [=interface mixins=], which are [=included=] by A or - by A's [=inherited interfaces=], - as show in the below inheritance tree. - -
-             C* - M4
-             |
-             B - M3
-             |
-        M1 - A - M2*
-    
- - [=Interfaces=] and [=interface mixins=] marked with an asterisk ("*") - declare a toJSON [=operation=] - with a [{{Default}}] [=extended attribute=]. + Only [=regular attributes=] of [=interfaces=] that declare a toJSON operation with + a [{{Default}}] [=extended attribute=] are included, even if an [=inherited interface=] declares + such a toJSON operation. For example, consider the following [=IDL fragment=]:
         [Exposed=Window]
-        interface A : B {
+        interface A {
+          [Default] object toJSON();
           attribute DOMString a;
         };
 
         [Exposed=Window]
-        interface B : C {
+        interface B : A {
           attribute DOMString b;
         };
 
         [Exposed=Window]
-        interface C {
+        interface C : B {
           [Default] object toJSON();
           attribute DOMString c;
         };
+    
- interface mixin M1 { - attribute DOMString m1; - }; - - interface mixin M2 { - [Default] object toJSON(); - attribute DOMString m2; - }; - - interface mixin M3 { - attribute DOMString m3; - }; - - interface mixin M4 { - attribute DOMString m4; - }; + Calling the toJSON() method of an object implementing interface + C defined above would return the following JSON object: - A includes M1; - A includes M2; - B includes M3; - C includes M4; +
+    {
+        "a": "...",
+        "c": "..."
+    }
     
- Calling the toJSON() method of an object - implementing interface A defined above - would return the following JSON object: + Calling the toJSON() method of an object implementing interface + A (or B) defined above would return:
     {
-        "a": "...",
-        "m1": "...",
-        "m2": "...",
-        "c": "...",
-        "m4": "..."
+        "a": "..."
     }
     
- An object implementing interface B would return: + A toJSON operation can also be declared on an [=interface mixin=] (or + [=partial interface=]) and is equivalent to declaring it on the original [=interface=]. For + example, consider the following [=IDL fragment=]: + +
+        [Exposed=Window]
+        interface D {
+          attribute DOMString d;
+        };
+
+        interface mixin M {
+          [Default] object toJSON();
+          attribute DOMString m;
+        };
+
+        D includes M;
+    
+ + Calling the toJSON() method of an object implementing interface + D defined above would return:
     {
-        "c": "...",
-        "m4": "..."
+        "d": "...",
+        "m": "..."
     }