-
-
Notifications
You must be signed in to change notification settings - Fork 419
WebIDL Guide
To specify an interface using WebIDL, you define a <pre class="idl"> block.
<pre class="idl">
interface Request {
readonly attribute ByteString method;
readonly attribute USVString url;
};
</pre>The recommended pattern is a <section data-dfn-for="InterfaceName"> that groups the IDL block with prose definitions for each member:
<section data-dfn-for="Fetch">
<h2>The <code>Fetch</code> interface</h2>
<pre class="idl">
[Exposed=Window]
interface Fetch {
constructor(USVString url);
readonly attribute USVString url;
undefined send();
};
</pre>
<section>
<h2>Constructors</h2>
<p>The <dfn constructor for="Fetch">constructor(url)</dfn> steps are:</p>
<ol class="algorithm">
<li>Set [=this=]'s {{Fetch/url}} to |url|.</li>
</ol>
</section>
<section>
<h2>Attributes</h2>
<p>The <dfn attribute>url</dfn> attribute steps are to return [=this=]'s url.</p>
</section>
<section>
<h2>Methods</h2>
<p>The <dfn method>send()</dfn> method steps are:</p>
<ol class="algorithm">
<li>...</li>
</ol>
</section>
</section>data-dfn-for on a <section> sets the default interface context for all <dfn> elements within it. This saves repeating the interface name on every definition:
<section data-dfn-for="Request">
<p>The <dfn>url</dfn> attribute of {{Request}}.</p>
<p>The <dfn>clone()</dfn> method.</p>
<!-- Both dfns are automatically "for Request" -->
</section>Without data-dfn-for, use explicit for= attributes on individual <dfn> elements.
Define constructors with <dfn constructor for="InterfaceName">:
<p>The <dfn constructor for="Widget">constructor(name, options)</dfn> steps are:</p>
<ol class="algorithm">
<li>Let |w:Widget| be a new {{Widget}} object.</li>
<li>Set |w|'s {{Widget/name}} to |name|.</li>
<li>Return |w|.</li>
</ol>Link to the constructor from prose: {{Widget/constructor(name, options)}}.
Enum values defined in the IDL block are automatically linked. To add prose descriptions, define them explicitly using data-dfn-type="enum-value" and data-dfn-for:
<pre class="idl">
enum RequestMode { "navigate", "cors", "no-cors", "same-origin" };
</pre>
<p>The <dfn data-dfn-type="enum-value" data-dfn-for="RequestMode">"cors"</dfn>
mode means cross-origin requests are sent with CORS headers.</p>
<p>The <dfn data-dfn-type="enum-value" data-dfn-for="RequestMode">"navigate"</dfn>
mode is used for top-level navigation.</p>Link to enum values in prose: {{RequestMode/"cors"}}.
Dictionary members defined in IDL are automatically linked. Reference them in prose as {{DictionaryName/memberName}}:
<pre class="idl">
dictionary RequestInit {
ByteString method = "GET";
boolean keepalive = false;
};
</pre>
<p>If |init|'s {{RequestInit/method}} is not a [=method=], throw a {{TypeError}}.</p>If two interfaces share attribute or method names, use data-dfn-for to distinguish them:
<section data-dfn-for="Request">
<p>The <dfn>url</dfn> attribute of {{Request}}.</p>
</section>
<section data-dfn-for="Response">
<p>The <dfn>url</dfn> attribute of {{Response}}.</p>
</section>When defining IDL members as prose <dfn> elements, you can omit data-dfn-type when data-dfn-for is set on the containing section — ReSpec infers the type from the IDL. For explicit control:
| Pattern | Type inferred |
|---|---|
<dfn attribute>url</dfn> |
attribute |
<dfn method>send()</dfn> |
method |
<dfn constructor for="Foo">constructor()</dfn> |
constructor |
<dfn data-dfn-type="dict-member">method</dfn> |
dict-member |
- The
<pre class="idl">block is syntax-highlighted and validated by ReSpec - IDL terms are automatically added to the terms index and IDL index
- Use
class="exclude"on a<pre class="idl">to keep it out of the IDL index:<pre class="idl exclude"> - See data-dfn-type for the full list of definition types
💖 Support ReSpec by becoming a sponsor via Open Collective. 💖
✨ View rendered version of this documentation at https://respec.org/docs/ ✨
- Getting Started
- How Do I…
- Spec Editor's Guide
- Writing Algorithms
- WebIDL Guide
- Configuring ReSpec
- Developers Guide
- Shorthands
- addSectionLinks
- authors
- caniuse
- edDraftURI
- editors
- format (markdown)
- formerEditors
- github
- highlightVars
- isPreview
- license
- lint
- localBiblio
- logos
- maxTocLevel
- mdn
- modificationDate
- monetization
- noTOC
- otherLinks
- pluralize
- postProcess
- preProcess
- previousDiffURI
- previousMaturity
- previousPublishDate
- prevRecShortname
- prevRecURI
-
processVersion(Removed) - publishDate
- shortName
- specStatus
- subjectPrefix
- subtitle
- testSuiteURI
- xref
- additionalCopyrightHolders
-
addPatentNote(Removed) - alternateFormats
- canonicalURI
- charterDisclosureURI
- copyrightStart
- crEnd
- dark mode
- doJsonLd
- errata
- group
- implementationReportURI
- level
- noRecTrack
- prevED
- prEnd
- submissionCommentNumber
-
wg(Deprecated — usegroup) -
wgId(Deprecated — usegroup) -
wgPatentURI(Deprecated — usegroup) -
wgPublicList(Deprecated — usegroup) -
wgURI(Deprecated — usegroup)
a11ycheck-charsetcheck-internal-slotscheck-punctuationinformative-dfnlocal-refs-existno-captionless-tablesno-headingless-sectionsno-http-propsno-link-warningsno-unused-dfnsno-unused-varsprivsec-sectionwpt-tests-exist
Handled by ReSpec for you.
- conformance
- idl-index
- index
- issue-summary
- references
- tof (Table of Figures)
- data-abbr
- data-cite
- data-dfn-for
- data-dfn-type
- data-export
- data-format
- data-include
- data-include-format
- data-include-replace
- data-link-for
- data-link-type
- data-local-lt
- data-lt
- data-lt-no-plural
- data-lt-noDefault
- data-max-toc
- data-number
- data-oninclude
- data-sort
- data-tests
-
data-transform(Deprecated) - data-type
- dir
- lang