Skip to content

Commit

Permalink
Editorial: simplify the example on default toJSON()
Browse files Browse the repository at this point in the history
This example was adapted from a previous one in
whatwg#433, but things are much simpler
now and the example makes it seem more complicated than it really is.
Interface mixins aren't special, so make the same point without them.

Fixes whatwg#979.
  • Loading branch information
foolip committed Apr 23, 2021
1 parent ecfa7fb commit 184b465
Showing 1 changed file with 12 additions and 50 deletions.
62 changes: 12 additions & 50 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -12088,29 +12088,17 @@ A [=regular operation=] that does not [=have default method steps=] must not be
1. Return |stack|.
</div>

<div class=example id=example-tojson-default-inheritance-and-mixins>
<div class=example id=example-tojson-default-inheritance>

The following [=IDL fragment=] defines a number of [=interfaces=],
which are [=inherited interfaces=] of <code class="idl">A</code>,
and [=interface mixins=], which are [=included=] by <code class="idl">A</code> or
by <code class="idl">A</code>'s [=inherited interfaces=],
as show in the below inheritance tree.

<pre>
C* - M4
|
B - M3
|
M1 - A - M2*
</pre>

[=Interfaces=] and [=interface mixins=] marked with an asterisk ("*")
declare a <code>toJSON</code> [=operation=]
with a [{{Default}}] [=extended attribute=].
Only [=regular attributes=] of [=interfaces=] declare a <code>toJSON</code> [=operation=]
with a [{{Default}}] [=extended attribute=] are included, even if an
[=inherited interfaces=] declares such a <code>toJSON</code> [=operation=]. For example,
consider the following [=IDL fragment=]:

<pre class=webidl>
[Exposed=Window]
interface A : B {
[Default] object toJSON();
attribute DOMString a;
};

Expand All @@ -12124,50 +12112,24 @@ A [=regular operation=] that does not [=have default method steps=] must not be
[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;
};

A includes M1;
A includes M2;
B includes M3;
C includes M4;
</pre>

Calling the <code>toJSON()</code> method of an object
implementing interface <code class="idl">A</code> defined above
would return the following JSON object:
Calling the <code>toJSON()</code> method of an object implementing interface
<code class="idl">A</code> defined above would return the following JSON object:

<pre highlight=json>
{
"a": "...",
"m1": "...",
"m2": "...",
"c": "...",
"m4": "..."
"c": "..."
}
</pre>

An object implementing interface <code class="idl">B</code> would return:
Calling the <code>toJSON()</code> method of an object implementing interface
<code class="idl">B</code> (or <code class="idl">C</code>) defined above would return:

<pre highlight=json>
{
"c": "...",
"m4": "..."
"c": "..."
}
</pre>
</div>
Expand Down

0 comments on commit 184b465

Please sign in to comment.