Skip to content

Commit

Permalink
Drop IDL extended attributes from data-type values (#2790)
Browse files Browse the repository at this point in the history
* Drop IDL extended attributes from data-type values

This is a fix for #2705, where the problem is that Bikeshed dies on argumentdef
tables when a spec defines an IDL interface attribute or a dictionary member
that comes with extended attributes, something like

```
dictionary test {
	required [EnforceRange] short member1;
}
```

To produce the ", of type foo" content that appears next to the term in the
table, Bikeshed relies on the `data-type` attribute set in the IDL block. The
value of that attribute comes from a `type` field returned by widlparser. The
code in Bikeshed expected that value to be a real IDL type (a simple type or
a union) but that construct in widlparser is a "type with extended attributes":
https://github.com/plinss/widlparser/blob/6c91beb68806fd6c206c57cecd15e455b0b6c1c1/widlparser/productions.py#L1294

As a result, the type Bikeshed sees is `[EnforceRange] short` in the above
example, which cannot be directly associated with a type in Web IDL.

This update gets back to actual IDL types in the `data-type` attribute, which
effectively solves the problem of the ", of type foo" content generation. A
new idl008 test was added to check extended attributes.

One side effect of that update is that `data-type` attribute values no longer
contain trailing spaces. That seems a good thing (spaces where already stripped
for attributes, but not for dictionary members), but required re-generating a
bunch of reference tests.

* Lint code
  • Loading branch information
tidoust authored Feb 9, 2024
1 parent 42fedad commit a347c59
Show file tree
Hide file tree
Showing 107 changed files with 4,063 additions and 2,476 deletions.
4 changes: 2 additions & 2 deletions bikeshed/idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ def markup_name(
readonly = "data-readonly"
else:
readonly = ""
extraParameters = '{} data-type="{}"'.format(readonly, str(rest.type).strip())
extraParameters = '{} data-type="{}"'.format(readonly, str(rest.type.type) + str(rest.type.suffix or ""))
elif idlType == "dict-member":
assert isinstance(construct, widlparser.DictionaryMember)
extraParameters = f'data-type="{construct.type}"'
extraParameters = 'data-type="{}"'.format(str(construct.type.type) + str(construct.type.suffix or ""))
if construct.default is not None:
value = str(construct.default).split("=", 1)[1].strip()
if value.startswith("["):
Expand Down
8 changes: 4 additions & 4 deletions tests/dict-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<h2 class="heading settled" data-level="1" id="test"><span class="secno">1. </span><span class="content">Test</span><a class="self-link" href="#test"></a></h2>
<pre class="idl highlight def"><c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-dictwithdefaults"><code><c- g>DictWithDefaults</c-></code></dfn> {
<a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#idl-sequence" id="ref-for-idl-sequence"><c- b>sequence</c-></a>&lt;<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-long" id="ref-for-idl-long"><c- b>long</c-></a>> <a class="idl-code" data-default="[]" data-link-type="dict-member" data-type="sequence<long> " href="#dom-dictwithdefaults-arraywithdefaultempty" id="ref-for-dom-dictwithdefaults-arraywithdefaultempty"><c- g>arrayWithDefaultEmpty</c-></a> = [];
<a data-link-type="idl-name" href="#dictdef-dictwithdefaults" id="ref-for-dictdef-dictwithdefaults"><c- n>DictWithDefaults</c-></a> <a class="idl-code" data-default="{}" data-link-type="dict-member" data-type="DictWithDefaults " href="#dom-dictwithdefaults-dictwithdefaultempty" id="ref-for-dom-dictwithdefaults-dictwithdefaultempty"><c- g>dictWithDefaultEmpty</c-></a> = {};
<a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#idl-sequence" id="ref-for-idl-sequence"><c- b>sequence</c-></a>&lt;<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-long" id="ref-for-idl-long"><c- b>long</c-></a>> <a class="idl-code" data-default="[]" data-link-type="dict-member" data-type="sequence<long>" href="#dom-dictwithdefaults-arraywithdefaultempty" id="ref-for-dom-dictwithdefaults-arraywithdefaultempty"><c- g>arrayWithDefaultEmpty</c-></a> = [];
<a data-link-type="idl-name" href="#dictdef-dictwithdefaults" id="ref-for-dictdef-dictwithdefaults"><c- n>DictWithDefaults</c-></a> <a class="idl-code" data-default="{}" data-link-type="dict-member" data-type="DictWithDefaults" href="#dom-dictwithdefaults-dictwithdefaultempty" id="ref-for-dom-dictwithdefaults-dictwithdefaultempty"><c- g>dictWithDefaultEmpty</c-></a> = {};
};
</pre>
<dl>
Expand Down Expand Up @@ -765,8 +765,8 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
</dl>
<h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
<pre class="idl highlight def"><c- b>dictionary</c-> <a href="#dictdef-dictwithdefaults"><code><c- g>DictWithDefaults</c-></code></a> {
<a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#idl-sequence"><c- b>sequence</c-></a>&lt;<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-long"><c- b>long</c-></a>> <a class="idl-code" data-default="[]" data-link-type="dict-member" data-type="sequence<long> " href="#dom-dictwithdefaults-arraywithdefaultempty"><c- g>arrayWithDefaultEmpty</c-></a> = [];
<a data-link-type="idl-name" href="#dictdef-dictwithdefaults"><c- n>DictWithDefaults</c-></a> <a class="idl-code" data-default="{}" data-link-type="dict-member" data-type="DictWithDefaults " href="#dom-dictwithdefaults-dictwithdefaultempty"><c- g>dictWithDefaultEmpty</c-></a> = {};
<a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#idl-sequence"><c- b>sequence</c-></a>&lt;<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-long"><c- b>long</c-></a>> <a class="idl-code" data-default="[]" data-link-type="dict-member" data-type="sequence<long>" href="#dom-dictwithdefaults-arraywithdefaultempty"><c- g>arrayWithDefaultEmpty</c-></a> = [];
<a data-link-type="idl-name" href="#dictdef-dictwithdefaults"><c- n>DictWithDefaults</c-></a> <a class="idl-code" data-default="{}" data-link-type="dict-member" data-type="DictWithDefaults" href="#dom-dictwithdefaults-dictwithdefaultempty"><c- g>dictWithDefaultEmpty</c-></a> = {};
};

</pre>
Expand Down
24 changes: 12 additions & 12 deletions tests/github/WICG/app-history/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,14 @@ <h2 class="heading settled" data-level="2" id="navigate-event"><span class="secn
};

<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-apphistorynavigateeventinit"><code><c- g>AppHistoryNavigateEventInit</c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit" id="ref-for-dictdef-eventinit"><c- n>EventInit</c-></a> {
<a data-link-type="idl-name" href="#enumdef-apphistorynavigationtype" id="ref-for-enumdef-apphistorynavigationtype①"><c- n>AppHistoryNavigationType</c-></a> <dfn class="dfn-paneled idl-code" data-default="&quot;push&quot;" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="AppHistoryNavigationType " id="dom-apphistorynavigateeventinit-navigationtype"><code><c- g>navigationType</c-></code></dfn> = "push";
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑤"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean " id="dom-apphistorynavigateeventinit-canrespond"><code><c- g>canRespond</c-></code></dfn> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑥"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean " id="dom-apphistorynavigateeventinit-userinitiated"><code><c- g>userInitiated</c-></code></dfn> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑦"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean " id="dom-apphistorynavigateeventinit-hashchange"><code><c- g>hashChange</c-></code></dfn> = <c- b>false</c->;
<a data-link-type="idl-name" href="#enumdef-apphistorynavigationtype" id="ref-for-enumdef-apphistorynavigationtype①"><c- n>AppHistoryNavigationType</c-></a> <dfn class="dfn-paneled idl-code" data-default="&quot;push&quot;" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="AppHistoryNavigationType" id="dom-apphistorynavigateeventinit-navigationtype"><code><c- g>navigationType</c-></code></dfn> = "push";
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑤"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean" id="dom-apphistorynavigateeventinit-canrespond"><code><c- g>canRespond</c-></code></dfn> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑥"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean" id="dom-apphistorynavigateeventinit-userinitiated"><code><c- g>userInitiated</c-></code></dfn> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean⑦"><c- b>boolean</c-></a> <dfn class="dfn-paneled idl-code" data-default="false" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="boolean" id="dom-apphistorynavigateeventinit-hashchange"><code><c- g>hashChange</c-></code></dfn> = <c- b>false</c->;
// required AppHistoryEntry destination;
// required AbortSignal signal;
<a data-link-type="idl-name" href="https://xhr.spec.whatwg.org/#formdata" id="ref-for-formdata①"><c- n>FormData</c-></a>? <dfn class="dfn-paneled idl-code" data-default="null" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="FormData? " id="dom-apphistorynavigateeventinit-formdata"><code><c- g>formData</c-></code></dfn> = <c- b>null</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-any" id="ref-for-idl-any①"><c- b>any</c-></a> <dfn class="dfn-paneled idl-code" data-default="null" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="any " id="dom-apphistorynavigateeventinit-info"><code><c- g>info</c-></code></dfn> = <c- b>null</c->;
<a data-link-type="idl-name" href="https://xhr.spec.whatwg.org/#formdata" id="ref-for-formdata①"><c- n>FormData</c-></a>? <dfn class="dfn-paneled idl-code" data-default="null" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="FormData?" id="dom-apphistorynavigateeventinit-formdata"><code><c- g>formData</c-></code></dfn> = <c- b>null</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-any" id="ref-for-idl-any①"><c- b>any</c-></a> <dfn class="dfn-paneled idl-code" data-default="null" data-dfn-for="AppHistoryNavigateEventInit" data-dfn-type="dict-member" data-export data-type="any" id="dom-apphistorynavigateeventinit-info"><code><c- g>info</c-></code></dfn> = <c- b>null</c->;
};

<c- b>enum</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="enum" data-export id="enumdef-apphistorynavigationtype"><code><c- g>AppHistoryNavigationType</c-></code></dfn> {
Expand Down Expand Up @@ -1852,14 +1852,14 @@ <h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">I
};

<c- b>dictionary</c-> <a href="#dictdef-apphistorynavigateeventinit"><code><c- g>AppHistoryNavigateEventInit</c-></code></a> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit"><c- n>EventInit</c-></a> {
<a data-link-type="idl-name" href="#enumdef-apphistorynavigationtype"><c- n>AppHistoryNavigationType</c-></a> <a data-default="&quot;push&quot;" data-type="AppHistoryNavigationType " href="#dom-apphistorynavigateeventinit-navigationtype"><code><c- g>navigationType</c-></code></a> = "push";
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean " href="#dom-apphistorynavigateeventinit-canrespond"><code><c- g>canRespond</c-></code></a> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean " href="#dom-apphistorynavigateeventinit-userinitiated"><code><c- g>userInitiated</c-></code></a> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean " href="#dom-apphistorynavigateeventinit-hashchange"><code><c- g>hashChange</c-></code></a> = <c- b>false</c->;
<a data-link-type="idl-name" href="#enumdef-apphistorynavigationtype"><c- n>AppHistoryNavigationType</c-></a> <a data-default="&quot;push&quot;" data-type="AppHistoryNavigationType" href="#dom-apphistorynavigateeventinit-navigationtype"><code><c- g>navigationType</c-></code></a> = "push";
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean" href="#dom-apphistorynavigateeventinit-canrespond"><code><c- g>canRespond</c-></code></a> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean" href="#dom-apphistorynavigateeventinit-userinitiated"><code><c- g>userInitiated</c-></code></a> = <c- b>false</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean"><c- b>boolean</c-></a> <a data-default="false" data-type="boolean" href="#dom-apphistorynavigateeventinit-hashchange"><code><c- g>hashChange</c-></code></a> = <c- b>false</c->;
// required AppHistoryEntry destination;
// required AbortSignal signal;
<a data-link-type="idl-name" href="https://xhr.spec.whatwg.org/#formdata"><c- n>FormData</c-></a>? <a data-default="null" data-type="FormData? " href="#dom-apphistorynavigateeventinit-formdata"><code><c- g>formData</c-></code></a> = <c- b>null</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-any"><c- b>any</c-></a> <a data-default="null" data-type="any " href="#dom-apphistorynavigateeventinit-info"><code><c- g>info</c-></code></a> = <c- b>null</c->;
<a data-link-type="idl-name" href="https://xhr.spec.whatwg.org/#formdata"><c- n>FormData</c-></a>? <a data-default="null" data-type="FormData?" href="#dom-apphistorynavigateeventinit-formdata"><code><c- g>formData</c-></code></a> = <c- b>null</c->;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-any"><c- b>any</c-></a> <a data-default="null" data-type="any" href="#dom-apphistorynavigateeventinit-info"><code><c- g>info</c-></code></a> = <c- b>null</c->;
};

<c- b>enum</c-> <a href="#enumdef-apphistorynavigationtype"><code><c- g>AppHistoryNavigationType</c-></code></a> {
Expand Down
Loading

0 comments on commit a347c59

Please sign in to comment.