@@ -12090,84 +12090,73 @@ A [=regular operation=] that does not [=have default method steps=] must not be
12090
12090
12091
12091
<div class=example id=example-tojson-default-inheritance-and-mixins>
12092
12092
12093
- The following [=IDL fragment=] defines a number of [=interfaces=],
12094
- which are [=inherited interfaces=] of <code class="idl">A</code>,
12095
- and [=interface mixins=], which are [=included=] by <code class="idl">A</code> or
12096
- by <code class="idl">A</code>'s [=inherited interfaces=],
12097
- as show in the below inheritance tree.
12098
-
12099
- <pre>
12100
- C* - M4
12101
- |
12102
- B - M3
12103
- |
12104
- M1 - A - M2*
12105
- </pre>
12106
-
12107
- [=Interfaces=] and [=interface mixins=] marked with an asterisk ("*")
12108
- declare a <code>toJSON</code> [=operation=]
12109
- with a [{{Default}}] [=extended attribute=].
12093
+ Only [=regular attributes=] of [=interfaces=] that declare a <code>toJSON</code> operation with
12094
+ a [{{Default}}] [=extended attribute=] are included, even if an [=inherited interface=] declares
12095
+ such a <code>toJSON</code> operation. For example, consider the following [=IDL fragment=]:
12110
12096
12111
12097
<pre class=webidl>
12112
12098
[Exposed=Window]
12113
- interface A : B {
12099
+ interface A {
12100
+ [Default] object toJSON();
12114
12101
attribute DOMString a;
12115
12102
};
12116
12103
12117
12104
[Exposed=Window]
12118
- interface B : C {
12105
+ interface B : A {
12119
12106
attribute DOMString b;
12120
12107
};
12121
12108
12122
12109
[Exposed=Window]
12123
- interface C {
12110
+ interface C : B {
12124
12111
[Default] object toJSON();
12125
12112
attribute DOMString c;
12126
12113
};
12114
+ </pre>
12127
12115
12128
- interface mixin M1 {
12129
- attribute DOMString m1;
12130
- };
12131
-
12132
- interface mixin M2 {
12133
- [Default] object toJSON();
12134
- attribute DOMString m2;
12135
- };
12136
-
12137
- interface mixin M3 {
12138
- attribute DOMString m3;
12139
- };
12140
-
12141
- interface mixin M4 {
12142
- attribute DOMString m4;
12143
- };
12116
+ Calling the <code>toJSON()</code> method of an object implementing interface
12117
+ <code class="idl">C</code> defined above would return the following JSON object:
12144
12118
12145
- A includes M1;
12146
- A includes M2;
12147
- B includes M3;
12148
- C includes M4;
12119
+ <pre highlight=json>
12120
+ {
12121
+ "a": "...",
12122
+ "c": "..."
12123
+ }
12149
12124
</pre>
12150
12125
12151
- Calling the <code>toJSON()</code> method of an object
12152
- implementing interface <code class="idl">A</code> defined above
12153
- would return the following JSON object:
12126
+ Calling the <code>toJSON()</code> method of an object implementing interface
12127
+ <code class="idl">A</code> (or <code class="idl">B</code>) defined above would return:
12154
12128
12155
12129
<pre highlight=json>
12156
12130
{
12157
- "a": "...",
12158
- "m1": "...",
12159
- "m2": "...",
12160
- "c": "...",
12161
- "m4": "..."
12131
+ "a": "..."
12162
12132
}
12163
12133
</pre>
12164
12134
12165
- An object implementing interface <code class="idl">B</code> would return:
12135
+ A <code>toJSON</code> operation can also be declared on an [=interface mixin=] (or
12136
+ [=partial interface=]) and is equivalent to declaring it on the original [=interface=]. For
12137
+ example, consider the following [=IDL fragment=]:
12138
+
12139
+ <pre class=webidl>
12140
+ [Exposed=Window]
12141
+ interface D {
12142
+ attribute DOMString d;
12143
+ };
12144
+
12145
+ interface mixin M {
12146
+ [Default] object toJSON();
12147
+ attribute DOMString m;
12148
+ };
12149
+
12150
+ D includes M;
12151
+ </pre>
12152
+
12153
+ Calling the <code>toJSON()</code> method of an object implementing interface
12154
+ <code class="idl">D</code> defined above would return:
12166
12155
12167
12156
<pre highlight=json>
12168
12157
{
12169
- "c ": "...",
12170
- "m4 ": "..."
12158
+ "d ": "...",
12159
+ "m ": "..."
12171
12160
}
12172
12161
</pre>
12173
12162
</div>
0 commit comments