You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13494 lines
817 KiB
13494 lines
817 KiB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<title>Web IDL</title>
|
|
<meta name="revision" content="$Id: Overview.html,v 1.4 2011/09/27 12:55:09 schepers Exp $" />
|
|
<link rel="stylesheet" href="WebIDL.css" type="text/css" />
|
|
<script src="section-links.js" type="application/ecmascript"></script>
|
|
<script src="dfn.js" type="application/ecmascript"></script>
|
|
|
|
|
|
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-WD" type="text/css" /></head>
|
|
|
|
<body>
|
|
<div class="head"><div><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" width="72" height="48" alt="W3C" /></a></div><h1>Web IDL</h1><h2>W3C Working Draft <em>27 September 2011</em></h2><dl><dt>This Version:</dt><dd><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110927/">http://www.w3.org/TR/2011/WD-WebIDL-20110927/</a></dd><dt>Latest Stable Version:</dt><dd><a href="http://www.w3.org/TR/WebIDL/">http://www.w3.org/TR/WebIDL/</a></dd><dt>Previous Version:</dt><dd><a href="http://www.w3.org/TR/2011/WD-WebIDL-20110712/">http://www.w3.org/TR/2011/WD-WebIDL-20110712/</a></dd><dt>Latest Editor’s Draft:</dt><dd><a href="http://dev.w3.org/2006/webapi/WebIDL/">http://dev.w3.org/2006/webapi/WebIDL/</a></dd><dt>Editor:</dt><dd><a href="http://mcc.id.au/">Cameron McCormack</a>, Mozilla Corporation <cam@mcc.id.au></dd></dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2011 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p></div><hr />
|
|
|
|
<div class="section">
|
|
<h2>Abstract</h2>
|
|
<p>
|
|
This document defines an interface definition language, Web IDL,
|
|
that can be used to describe interfaces that are intended to be
|
|
implemented in web browsers. Web IDL is an IDL variant with a
|
|
number of features that allow the behavior of common script objects in
|
|
the web platform to be specified more readily. How interfaces
|
|
described with Web IDL correspond to constructs within ECMAScript and
|
|
Java execution environments is also detailed in this document.
|
|
It is expected that this document acts
|
|
as a guide to implementors of already-published specifications,
|
|
and that newly published specifications reference this
|
|
document to ensure conforming implementations of interfaces
|
|
are interoperable.
|
|
</p>
|
|
|
|
<!-- XXX
|
|
Things to consider that aren't in ednotes:
|
|
* Consistent linking to term definitions.
|
|
* Consistent capitalisation and naming of algorithm variables.
|
|
|
|
Potential V2 features:
|
|
* Parameterized interface types, for BlahLists
|
|
http://www.w3.org/mid/op.vr2r6waf64w2qv@anne-van-kesterens-macbook-pro.local
|
|
-->
|
|
<!--
|
|
<?revision-note http://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=WebAppsWG&component=WebIDL&longdesc_type=allwordssubstr&longdesc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailtype1=substring&email1=&emailtype2=substring&email2=&bug_id_type=anyexact&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Importance&field0-0-0=noop&type0-0-0=noop&value0-0-0=?>
|
|
-->
|
|
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>Status of This Document</h2>
|
|
<p><em>
|
|
This section describes the status of this document at the time of
|
|
its publication. Other documents may supersede this document. A list
|
|
of current W3C publications and the latest revision of this technical
|
|
report can be found in the <a href="http://www.w3.org/TR/">W3C technical
|
|
reports index</a> at http://www.w3.org/TR/.
|
|
</em></p><p>
|
|
This document is the 27 September 2011 <b>Last Call Working Draft</b> of the
|
|
<cite>Web IDL</cite> specification.
|
|
|
|
Please send comments about this document to
|
|
<a href="mailto:public-script-coord@w3.org">public-script-coord@w3.org</a>
|
|
(<a href="http://lists.w3.org/Archives/Public/public-script-coord/">archived</a>).
|
|
</p>
|
|
<p>
|
|
Comments on this Last Call Working Draft are welcome. This Last Call ends on
|
|
18 October 2011. The Working Group intends to progress this document to
|
|
Candidate Recommendation, but in the event of non-editorial changes being
|
|
made in response to Last Call comments,
|
|
another Last Call Working Draft will be published before
|
|
doing so. Despite this, the Working Group believes the document is ready
|
|
for wider review at this point.
|
|
</p>
|
|
<p>
|
|
This document is produced by the
|
|
<a href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a>, part of the
|
|
<a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a>
|
|
in the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.
|
|
Changes made to this document can be found in the
|
|
<a href="http://dev.w3.org/cvsweb/2006/webapi/WebIDL/Overview.xml">W3C
|
|
public CVS server</a>.
|
|
</p>
|
|
<p>
|
|
In addition to the issues marked by editorial notes in this document,
|
|
there is a <a href="http://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=WebAppsWG&component=WebIDL&longdesc_type=allwordssubstr&longdesc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailtype1=substring&email1=&emailtype2=substring&email2=&bug_id_type=anyexact&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=">list of open bugs</a>
|
|
on the specification. Comments from the <a href="http://www.w3.org/TR/2011/WD-WebIDL-20110712/">12 July 2011 Last Call Working Draft</a> are tracked in the <a href="http://dev.w3.org/2006/webapi/WebIDL/lc1.txt">Web IDL LC#1 comment document</a>.
|
|
</p>
|
|
<p>
|
|
Publication as a Working Draft does not imply endorsement by the
|
|
W3C Membership. This is a draft document and may be updated, replaced
|
|
or obsoleted by other documents at any time. It is inappropriate to cite
|
|
this document as other than work in progress.
|
|
</p><p>
|
|
This document was produced by a group operating under the
|
|
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
|
|
2004 W3C Patent Policy</a>. W3C maintains a
|
|
<a href="http://www.w3.org/2004/01/pp-impl/42538/status">public list of
|
|
any patent disclosures</a> made in connection with the deliverables of
|
|
the group; that page also includes instructions for disclosing a patent.
|
|
An individual who has actual knowledge of a patent which the individual
|
|
believes contains
|
|
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
|
|
Claim(s)</a> must disclose the information in accordance with
|
|
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
|
|
6 of the W3C Patent Policy</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="toc">
|
|
<h2>Table of Contents</h2>
|
|
<div class="toc"><ul><li><a href="#introduction">1. Introduction</a><ul><li><a href="#conventions">1.1. Typographic conventions</a></li></ul></li><li><a href="#conformance">2. Conformance</a></li><li><a href="#idl">3. Interface definition language</a><ul><li><a href="#idl-names">3.1. Names</a></li><li><a href="#idl-modules">3.2. Modules</a></li><li><a href="#idl-interfaces">3.3. Interfaces</a><ul><li><a href="#idl-constants">3.3.1. Constants</a></li><li><a href="#idl-attributes">3.3.2. Attributes</a></li><li><a href="#idl-operations">3.3.3. Operations</a></li><li><a href="#idl-special-operations">3.3.4. Special operations</a><ul><li><a href="#idl-legacy-callers">3.3.4.1. Legacy callers</a></li><li><a href="#idl-stringifiers">3.3.4.2. Stringifiers</a></li><li><a href="#idl-indexed-properties">3.3.4.3. Indexed properties</a></li><li><a href="#idl-named-properties">3.3.4.4. Named properties</a></li></ul></li><li><a href="#idl-static-operations">3.3.5. Static operations</a></li><li><a href="#idl-overloading">3.3.6. Overloading</a></li></ul></li><li><a href="#idl-dictionaries">3.4. Dictionaries</a></li><li><a href="#idl-exceptions">3.5. Exceptions</a></li><li><a href="#idl-typedefs">3.6. Typedefs</a></li><li><a href="#idl-implements-statements">3.7. Implements statements</a></li><li><a href="#idl-objects">3.8. Objects implementing interfaces</a></li><li><a href="#idl-types">3.9. Types</a><ul><li><a href="#idl-any">3.9.1. any</a></li><li><a href="#idl-boolean">3.9.2. boolean</a></li><li><a href="#idl-byte">3.9.3. byte</a></li><li><a href="#idl-octet">3.9.4. octet</a></li><li><a href="#idl-short">3.9.5. short</a></li><li><a href="#idl-unsigned-short">3.9.6. unsigned short</a></li><li><a href="#idl-long">3.9.7. long</a></li><li><a href="#idl-unsigned-long">3.9.8. unsigned long</a></li><li><a href="#idl-long-long">3.9.9. long long</a></li><li><a href="#idl-unsigned-long-long">3.9.10. unsigned long long</a></li><li><a href="#idl-float">3.9.11. float</a></li><li><a href="#idl-double">3.9.12. double</a></li><li><a href="#idl-DOMString">3.9.13. DOMString</a></li><li><a href="#idl-object">3.9.14. object</a></li><li><a href="#idl-interface">3.9.15. Interface types</a></li><li><a href="#idl-dictionary">3.9.16. Dictionary types</a></li><li><a href="#idl-nullable-type">3.9.17. Nullable types — <var>T</var>?</a></li><li><a href="#idl-sequence">3.9.18. Sequences — sequence<<var>T</var>></a></li><li><a href="#idl-array">3.9.19. Arrays — <var>T</var>[]</a></li><li><a href="#idl-Date">3.9.20. Date</a></li></ul></li><li><a href="#idl-extended-attributes">3.10. Extended attributes</a><ul><li><a href="#Callback">3.10.1. [Callback]</a></li><li><a href="#Prefix">3.10.2. [Prefix]</a></li></ul></li></ul></li><li><a href="#ecmascript-binding">4. ECMAScript binding</a><ul><li><a href="#es-environment">4.1. ECMAScript environment</a></li><li><a href="#es-type-mapping">4.2. ECMAScript type mapping</a><ul><li><a href="#es-any">4.2.1. any</a></li><li><a href="#es-void">4.2.2. void</a></li><li><a href="#es-boolean">4.2.3. boolean</a></li><li><a href="#es-byte">4.2.4. byte</a></li><li><a href="#es-octet">4.2.5. octet</a></li><li><a href="#es-short">4.2.6. short</a></li><li><a href="#es-unsigned-short">4.2.7. unsigned short</a></li><li><a href="#es-long">4.2.8. long</a></li><li><a href="#es-unsigned-long">4.2.9. unsigned long</a></li><li><a href="#es-long-long">4.2.10. long long</a></li><li><a href="#es-unsigned-long-long">4.2.11. unsigned long long</a></li><li><a href="#es-float">4.2.12. float</a></li><li><a href="#es-double">4.2.13. double</a></li><li><a href="#es-DOMString">4.2.14. DOMString</a></li><li><a href="#es-object">4.2.15. object</a></li><li><a href="#es-interface">4.2.16. Interface types</a></li><li><a href="#es-dictionary">4.2.17. Dictionary types</a></li><li><a href="#es-nullable-type">4.2.18. Nullable types — <var>T</var>?</a></li><li><a href="#es-sequence">4.2.19. Sequences — sequence<<var>T</var>></a></li><li><a href="#es-array">4.2.20. Arrays — <var>T</var>[]</a><ul><li><a href="#platform-array-object-getownproperty">4.2.20.1. Platform array object [[GetOwnProperty]] method</a></li><li><a href="#platform-array-object-defineownproperty">4.2.20.2. Platform array object [[DefineOwnProperty]] method</a></li><li><a href="#platform-array-object-delete">4.2.20.3. Platform array object [[Delete]] method</a></li></ul></li><li><a href="#es-Date">4.2.21. Date</a></li></ul></li><li><a href="#es-extended-attributes">4.3. ECMAScript-specific extended attributes</a><ul><li><a href="#AllowAny">4.3.1. [AllowAny]</a></li><li><a href="#ArrayClass">4.3.2. [ArrayClass]</a></li><li><a href="#es-Callback">4.3.3. [Callback]</a></li><li><a href="#Clamp">4.3.4. [Clamp]</a></li><li><a href="#Constructor">4.3.5. [Constructor]</a></li><li><a href="#EnforceRange">4.3.6. [EnforceRange]</a></li><li><a href="#ImplicitThis">4.3.7. [ImplicitThis]</a></li><li><a href="#NamedConstructor">4.3.8. [NamedConstructor]</a></li><li><a href="#NamespaceObject">4.3.9. [NamespaceObject]</a></li><li><a href="#NoInterfaceObject">4.3.10. [NoInterfaceObject]</a></li><li><a href="#OverrideBuiltins">4.3.11. [OverrideBuiltins]</a></li><li><a href="#PutForwards">4.3.12. [PutForwards]</a></li><li><a href="#Replaceable">4.3.13. [Replaceable]</a></li><li><a href="#ReplaceableNamedProperties">4.3.14. [ReplaceableNamedProperties]</a></li><li><a href="#TreatNonCallableAsNull">4.3.15. [TreatNonCallableAsNull]</a></li><li><a href="#TreatNullAs">4.3.16. [TreatNullAs]</a></li><li><a href="#TreatUndefinedAs">4.3.17. [TreatUndefinedAs]</a></li><li><a href="#Unforgeable">4.3.18. [Unforgeable]</a></li></ul></li><li><a href="#es-modules">4.4. Modules</a></li><li><a href="#es-interfaces">4.5. Interfaces</a><ul><li><a href="#interface-object">4.5.1. Interface object</a><ul><li><a href="#es-interface-call">4.5.1.1. Interface object [[Call]] method</a></li></ul></li><li><a href="#named-constructors">4.5.2. Named constructors</a></li><li><a href="#interface-prototype-object">4.5.3. Interface prototype object</a></li><li><a href="#es-constants">4.5.4. Constants</a></li><li><a href="#es-attributes">4.5.5. Attributes</a></li><li><a href="#es-operations">4.5.6. Operations</a></li></ul></li><li><a href="#es-implements-statements">4.6. Implements statements</a></li><li><a href="#es-platform-objects">4.7. Platform objects implementing interfaces</a><ul><li><a href="#indexed-and-named-properties">4.7.1. Indexed and named properties</a></li><li><a href="#getownproperty">4.7.2. Platform object [[GetOwnProperty]] method</a></li><li><a href="#defineownproperty">4.7.3. Platform object [[DefineOwnProperty]] method</a></li><li><a href="#delete">4.7.4. Platform object [[Delete]] method</a></li><li><a href="#call">4.7.5. Platform object [[Call]] method</a></li><li><a href="#property-enumeration">4.7.6. Property enumeration</a></li></ul></li><li><a href="#es-user-objects">4.8. User objects implementing interfaces</a></li><li><a href="#es-exceptions">4.9. Exceptions</a><ul><li><a href="#es-exception-interface-object">4.9.1. Exception interface object</a><ul><li><a href="#es-exception-call">4.9.1.1. Exception interface object [[Call]] method</a></li></ul></li><li><a href="#es-exception-interface-prototype-object">4.9.2. Exception interface prototype object</a></li><li><a href="#es-exception-constants">4.9.3. Constants</a></li><li><a href="#es-exception-fields">4.9.4. Exception fields</a></li></ul></li><li><a href="#es-exception-objects">4.10. Exception objects</a></li><li><a href="#es-throwing-exceptions">4.11. Throwing exceptions</a></li><li><a href="#es-handling-exceptions">4.12. Handling exceptions</a></li></ul></li><li><a href="#java-binding">5. Java binding</a><ul><li><a href="#java-names">5.1. Names</a></li><li><a href="#java-type-mapping">5.2. Java type mapping</a><ul><li><a href="#java-any">5.2.1. any</a></li><li><a href="#java-void">5.2.2. void</a></li><li><a href="#java-boolean">5.2.3. boolean</a></li><li><a href="#java-byte">5.2.4. byte</a></li><li><a href="#java-octet">5.2.5. octet</a></li><li><a href="#java-short">5.2.6. short</a></li><li><a href="#java-unsigned-short">5.2.7. unsigned short</a></li><li><a href="#java-long">5.2.8. long</a></li><li><a href="#java-unsigned-long">5.2.9. unsigned long</a></li><li><a href="#java-long-long">5.2.10. long long</a></li><li><a href="#java-unsigned-long-long">5.2.11. unsigned long long</a></li><li><a href="#java-float">5.2.12. float</a></li><li><a href="#java-double">5.2.13. double</a></li><li><a href="#java-DOMString">5.2.14. DOMString</a></li><li><a href="#java-object">5.2.15. object</a></li><li><a href="#java-interface">5.2.16. Interface types</a></li><li><a href="#java-dictionary">5.2.17. Dictionary types</a></li><li><a href="#java-nullable-type">5.2.18. Nullable types — <var>T</var>?</a></li><li><a href="#java-sequence">5.2.19. Sequences — sequence<<var>T</var>></a></li><li><a href="#java-array">5.2.20. Arrays — <var>T</var>[]</a></li><li><a href="#java-Date">5.2.21. Date</a></li></ul></li><li><a href="#java-modules">5.3. Modules</a></li><li><a href="#java-interfaces">5.4. Interfaces</a><ul><li><a href="#java-constants">5.4.1. Constants</a></li><li><a href="#java-operations">5.4.2. Operations</a></li><li><a href="#java-attributes">5.4.3. Attributes</a></li></ul></li><li><a href="#java-platform-objects">5.5. Platform objects implementing interfaces</a></li><li><a href="#java-user-objects">5.6. User objects implementing interfaces</a></li><li><a href="#java-exceptions">5.7. Exceptions</a><ul><li><a href="#java-exception-constants">5.7.1. Constants</a></li><li><a href="#java-exception-fields">5.7.2. Exception fields</a></li></ul></li><li><a href="#java-exception-throwing">5.8. Throwing exceptions</a></li></ul></li><li><a href="#common">6. Common definitions</a><ul><li><a href="#common-DOMTimeStamp">6.1. DOMTimeStamp</a></li></ul></li><li><a href="#extensibility">7. Extensibility</a></li><li><a href="#referencing">8. Referencing this specification</a></li><li><a href="#acknowledgements">9. Acknowledgements</a></li></ul><ul><li><a href="#idl-grammar">A. IDL grammar</a></li><li><a href="#references">B. References</a><ul><li><a href="#normative-references">B.1. Normative references</a></li><li><a href="#informative-references">B.2. Informative references</a></li></ul></li><li><a href="#changes">C. Changes</a></li></ul></div>
|
|
</div>
|
|
|
|
<div id="sections">
|
|
<div id="introduction" class="section">
|
|
<h2>1. Introduction</h2>
|
|
|
|
<p class="norm">This section is informative.</p>
|
|
|
|
<p>
|
|
Technical reports published by the W3C that include programming
|
|
language interfaces have typically been described using the
|
|
Object Management Group’s Interface Definition Language (IDL)
|
|
<a href="#ref-OMGIDL">[OMGIDL]</a>. The IDL provides a means to
|
|
describe these interfaces in a language independent manner. Usually,
|
|
additional language binding appendices are included in such
|
|
documents which detail how the interfaces described with the IDL
|
|
correspond to constructs in the given language.
|
|
</p>
|
|
<p>
|
|
However, the bindings in these specifications for the language most
|
|
commonly used on the web, ECMAScript, are consistently specified with
|
|
low enough precision as to result in interoperability issues. In
|
|
addition, each specification must describe the same basic information,
|
|
such as DOM interfaces described in IDL corresponding to properties
|
|
on the ECMAScript global object, or the <a class="idltype" href="#idl-unsigned-long">unsigned
|
|
long</a> IDL type mapping to the <span class="estype">Number</span>
|
|
type in ECMAScript.
|
|
</p>
|
|
<p>
|
|
This specification defines an IDL language similar to OMG IDL
|
|
for use by specifications that define interfaces for Web APIs. A number of extensions are
|
|
given to the IDL to support common functionality that previously must
|
|
have been written in prose. In addition, precise language bindings
|
|
for ECMAScript 5th Edition and Java 5 are given.
|
|
</p>
|
|
|
|
<div id="conventions" class="section">
|
|
<h3>1.1. Typographic conventions</h3>
|
|
|
|
<p>
|
|
The following typographic conventions are used in this document:
|
|
</p>
|
|
<ul>
|
|
<li>Defining instances of terms: <dfn id="dfn-example-term">example term</dfn></li>
|
|
<li>Grammar symbols: <span class="sym">ExampleGrammarSymbol</span></li>
|
|
<li>IDL, ECMAScript and Java types: <span class="idltype">ExampleType</span></li>
|
|
<li>Code snippets: <code>a = b + obj.f()</code></li>
|
|
<li>Unicode characters: <span class="char">U+0030 DIGIT ZERO ("0")</span></li>
|
|
<li>Extended attributes: <span class="xattr">[ExampleExtendedAttribute]</span></li>
|
|
<li>Variable names in prose and algorithms: <var>exampleVariableName</var>.</li>
|
|
<li>IDL informal syntax examples:
|
|
<pre class="syntax">interface <i>identifier</i> {
|
|
<em>interface-members…</em>
|
|
};</pre>
|
|
(Red text is used to highlight specific parts of the syntax discussed in surrounding prose.)</li>
|
|
<li>IDL grammar snippets:
|
|
<table class="grammar">
|
|
<tr><td><span class="prod-number">[5]</span></td><td><span class="sym">ExampleGrammarSymbol</span></td><td class="prod-mid">→</td><td><span class="prod-lines">OtherSymbol "sometoken"<br /> | AnotherSymbol<br /> | ε <span class="comment">// nothing</span></span></td></tr>
|
|
</table>
|
|
(Each grammar rule is assigned a number for reference, shown on the left.)</li>
|
|
<li>Non-normative notes: <div class="note"><div class="noteHeader">Note</div><p>This is a note.</p></div></li>
|
|
<li>Non-normative examples: <div class="example"><div class="exampleHeader">Example</div><p>This is an example.</p></div></li>
|
|
<li>Code blocks: <div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code"><span class="comment">// This is an IDL code block.</span>
|
|
interface Example {
|
|
attribute long something;
|
|
};</code></pre></div></div>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// This is an ECMAScript code block.</span>
|
|
window.onload = function() { window.alert("loaded"); };</code></pre></div></div></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="conformance" class="section">
|
|
<h2>2. Conformance</h2>
|
|
|
|
<p>
|
|
Everything in this specification is normative except for diagrams,
|
|
examples, notes and sections marked as being informative.
|
|
</p>
|
|
<p>
|
|
The keywords “<span class="rfc2119">MUST</span>”,
|
|
“<span class="rfc2119">MUST NOT</span>”,
|
|
“<span class="rfc2119">REQUIRED</span>”,
|
|
“<span class="rfc2119">SHALL</span>”,
|
|
“<span class="rfc2119">SHALL NOT</span>”,
|
|
“<span class="rfc2119">SHOULD</span>”,
|
|
“<span class="rfc2119">SHOULD NOT</span>”,
|
|
“<span class="rfc2119">RECOMMENDED</span>”,
|
|
“<span class="rfc2119">MAY</span>” and
|
|
“<span class="rfc2119">OPTIONAL</span>” in this document are to be
|
|
interpreted as described in
|
|
<cite><a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to
|
|
Indicate Requirement Levels</a></cite>
|
|
<a href="#ref-RFC2119">[RFC2119]</a>.
|
|
</p>
|
|
<p>
|
|
The following conformance classes are defined by this specification:
|
|
</p>
|
|
<dl>
|
|
<dt><dfn id="dfn-conforming-idl-fragment">conforming IDL fragment</dfn></dt>
|
|
<dd>
|
|
<p>
|
|
An <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is considered
|
|
to be a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
|
|
IDL fragment</a> if it satisfies all of the
|
|
<span class="rfc2119">MUST</span>-,
|
|
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
|
|
criteria in this specification that apply to IDL fragments.
|
|
</p>
|
|
</dd>
|
|
<dt><dfn id="dfn-conforming-implementation">conforming implementation</dfn></dt>
|
|
<dd>
|
|
<p>
|
|
A user agent is considered to be a
|
|
<a class="dfnref" href="#dfn-conforming-implementation">conforming implementation</a>
|
|
relative to a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
|
|
IDL fragment</a> if it satisfies all of the <span class="rfc2119">MUST</span>-,
|
|
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
|
|
criteria in this specification that apply to implementations for all language
|
|
bindings that the user agent supports.
|
|
</p>
|
|
</dd>
|
|
<dt><dfn id="dfn-conforming-ecmascript-implementation">conforming ECMAScript implementation</dfn></dt>
|
|
<dd>
|
|
<p>
|
|
A user agent is considered to be a
|
|
<a class="dfnref" href="#dfn-conforming-ecmascript-implementation">conforming ECMAScript implementation</a>
|
|
relative to a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
|
|
IDL fragment</a> if it satisfies all of the <span class="rfc2119">MUST</span>-,
|
|
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
|
|
criteria in this specification that apply to implementations for the ECMAScript
|
|
language binding.
|
|
</p>
|
|
</dd>
|
|
<dt><dfn id="dfn-conforming-java-implementation">conforming Java implementation</dfn></dt>
|
|
<dd>
|
|
<p>
|
|
A user agent is considered to be a
|
|
<a class="dfnref" href="#dfn-conforming-java-implementation">conforming Java implementation</a>
|
|
relative to a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
|
|
IDL fragment</a> if it satisfies all of the <span class="rfc2119">MUST</span>-,
|
|
<span class="rfc2119">REQUIRED</span>- and <span class="rfc2119">SHALL</span>-level
|
|
criteria in this specification that apply to implementations for the Java
|
|
language binding.
|
|
</p>
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<div id="idl" class="section">
|
|
<h2>3. Interface definition language</h2>
|
|
|
|
<p>
|
|
This section describes a language, <em>Web IDL</em>, which can be used to define
|
|
interfaces for APIs in the Web platform. A specification that defines Web APIs
|
|
can include one or more <dfn id="dfn-idl-fragment">IDL fragments</dfn> that
|
|
describe the interfaces (the state and behavior that objects can exhibit)
|
|
for the APIs defined by that specification.
|
|
An <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is
|
|
a sequence of definitions that matches the <a class="sym" href="#prod-Definitions">Definitions</a> grammar symbol.
|
|
The set of <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a> that
|
|
an implementation supports is not ordered.
|
|
See <a href="#idl-grammar">Appendix A</a> for the complete grammar and an explanation of the notation used.
|
|
</p>
|
|
|
|
<p>
|
|
The different kinds of <dfn id="dfn-definition">definitions</dfn> that can appear in an
|
|
<a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> are:
|
|
<a class="dfnref" href="#dfn-module">modules</a>,
|
|
<a class="dfnref" href="#dfn-interface">interfaces</a>,
|
|
<a class="dfnref" href="#dfn-partial-interface">partial interface declarations</a>,
|
|
<a class="dfnref" href="#dfn-dictionary">dictionaries</a>,
|
|
<a class="dfnref" href="#dfn-exception">exceptions</a>,
|
|
<a class="dfnref" href="#dfn-typedef">typedefs</a> and
|
|
<a class="dfnref" href="#dfn-implements-statement">implements statements</a>.
|
|
These are all defined in the following sections.
|
|
</p>
|
|
|
|
<p>
|
|
Each <a class="dfnref" href="#dfn-definition">definition</a>
|
|
(matching <a class="sym" href="#prod-Definition">Definition</a>)
|
|
can be preceded by a list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
|
|
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
|
|
which can control how the definition will be handled in language bindings.
|
|
The extended attributes defined by this specification that are language binding
|
|
agnostic are discussed in <a href="#idl-extended-attributes">section 3.10</a>,
|
|
while those specific to the ECMAScript language binding are discussed
|
|
in <a href="#es-extended-attributes">section 4.3</a>.
|
|
</p>
|
|
|
|
<pre class="syntax">[<em>extended-attributes</em>]
|
|
interface <i>identifier</i> {
|
|
<i>interface-members…</i>
|
|
};</pre>
|
|
|
|
<p>
|
|
<a class="dfnref" href="#dfn-module">Modules</a>, described further in
|
|
<a href="#idl-modules">section 3.2</a> below,
|
|
are used to group related <a class="dfnref" href="#dfn-definition">definitions</a>
|
|
together in a single namespace. Definitions need not be placed in a module;
|
|
those that are not are said to be <dfn id="dfn-outermost-scope">declared at the outermost scope</dfn>.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-Definitions"><td><span class="prod-number">[1]</span></td><td><a class="sym" href="#prod-Definitions">Definitions</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Definition">Definition</a> <a class="sym" href="#prod-Definitions">Definitions</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-Definition"><td><span class="prod-number">[2]</span></td><td><a class="sym" href="#prod-Definition">Definition</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-NormalDefinition">NormalDefinition</a> <br /> |
|
|
<a class="sym" href="#prod-PartialInterface">PartialInterface</a></span></td></tr><tr id="proddef-NormalDefinition"><td><span class="prod-number">[3]</span></td><td><a class="sym" href="#prod-NormalDefinition">NormalDefinition</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Module">Module</a> <br /> |
|
|
<a class="sym" href="#prod-Interface">Interface</a> <br /> |
|
|
<a class="sym" href="#prod-Dictionary">Dictionary</a> <br /> |
|
|
<a class="sym" href="#prod-Exception">Exception</a> <br /> |
|
|
<a class="sym" href="#prod-Typedef">Typedef</a> <br /> |
|
|
<a class="sym" href="#prod-ImplementsStatement">ImplementsStatement</a></span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following is an example of an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">module gfx {
|
|
exception GraphicsException {
|
|
DOMString reason;
|
|
};
|
|
|
|
interface Paint { };
|
|
|
|
interface SolidColor : Paint {
|
|
attribute float red;
|
|
attribute float green;
|
|
attribute float blue;
|
|
};
|
|
|
|
interface Pattern : Paint {
|
|
attribute DOMString imageURL;
|
|
};
|
|
|
|
[Constructor]
|
|
interface GraphicalWindow {
|
|
readonly attribute unsigned long width;
|
|
readonly attribute unsigned long height;
|
|
|
|
attribute Paint currentPaint;
|
|
|
|
void drawRectangle(float x, float y, float width, float height)<!--
|
|
raises(GraphicsException)-->;
|
|
|
|
void drawText(float x, float y, DOMString text)<!--
|
|
raises(GraphicsException)-->;
|
|
};
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Here, four <a class="dfnref" href="#dfn-interface">interfaces</a> and one
|
|
<a class="dfnref" href="#dfn-exception">exception</a> are being defined.
|
|
The <span class="idltype">GraphicalWindow</span> interface has two
|
|
<a class="dfnref" href="#dfn-read-only">read only</a> <a class="dfnref" href="#dfn-attribute">attributes</a>,
|
|
one writable attribute, and two <a class="dfnref" href="#dfn-operation">operations</a>
|
|
defined on it. Objects that implement the <span class="idltype">GraphicalWindow</span> interface
|
|
will expose these attributes and operations in a manner appropriate to the
|
|
particular language being used.
|
|
</p>
|
|
<p>
|
|
Since the interfaces and the exception all appear inside a <a class="dfnref" href="#dfn-module">module</a>,
|
|
they are not <a class="dfnref" href="#dfn-outermost-scope">declared at the outermost scope</a>.
|
|
The module itself, however, is.
|
|
</p>
|
|
<p>
|
|
In ECMAScript, the attributes on the IDL interfaces will be exposed as accessor
|
|
properties and the operations as <span class="estype">Function</span>-valued
|
|
data properties on a prototype object for all <span class="idltype">GraphicalWindow</span>
|
|
objects; each ECMAScript object that implements <span class="idltype">GraphicalWindow</span>
|
|
will have that prototype object in its prototype chain.
|
|
</p>
|
|
<p>
|
|
In Java, there will exist a Java interface that corresponds to the IDL
|
|
<span class="idltype">GraphicalWindow</span> interface. This Java interface
|
|
will have methods that correspond to the operations, and getter and setter
|
|
methods that correspond to the attributes. Java objects that are considered
|
|
to implement the IDL <span class="idltype">GraphicalWindow</span> interface
|
|
will implement the corresponding Java interface.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Constructor">[Constructor]</a> that appears on <span class="idltype">GraphicalWindow</span>
|
|
is an <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
This extended attribute causes a constructor to exist in ECMAScript implementations,
|
|
so that calling <code>new GraphicalWindow()</code> would return a new object
|
|
that implemented the interface. The <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
extended attribute has no effect in the Java language binding, however.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-names" class="section">
|
|
<h3>3.1. Names</h3>
|
|
|
|
<p>
|
|
Every <a class="dfnref" href="#dfn-module">module</a>,
|
|
<a class="dfnref" href="#dfn-interface">interface</a>,
|
|
<a class="dfnref" href="#dfn-partial-interface">partial interface definition</a>,
|
|
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
|
|
<a class="dfnref" href="#dfn-exception">exception</a> and
|
|
<a class="dfnref" href="#dfn-typedef">typedef</a> (together called <dfn id="dfn-named-definition">named definitions</dfn>)
|
|
and every <a class="dfnref" href="#dfn-constant">constant</a>,
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
<a class="dfnref" href="#dfn-exception-field">exception field</a>
|
|
and <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> has an
|
|
<dfn id="dfn-identifier">identifier</dfn>, as do some
|
|
<a class="dfnref" href="#dfn-operation">operations</a>.
|
|
The identifier is determined by an
|
|
<a class="sym" href="#prod-identifier">identifier</a> token somewhere
|
|
in the declaration:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
For <a class="dfnref" href="#dfn-named-definition">named definitions</a>,
|
|
the <a class="sym" href="#prod-identifier">identifier</a> token that appears
|
|
directly after the <code>module</code>, <code>interface</code>,
|
|
<code>dictionary</code> or <code>exception</code> keyword
|
|
determines the identifier of that definition.
|
|
<pre class="syntax">module <em>module-identifier</em> { <i>definitions…</i> };
|
|
interface <em>interface-identifier</em> { <i>interface-members…</i> };
|
|
partial interface <em>interface-identifier</em> { <i>interface-members…</i> };
|
|
exception <em>exception-identifier</em> { <i>exception-members…</i> };
|
|
dictionary <em>dictionary-identifier</em> { <i>dictionary-members…</i> };</pre>
|
|
</li>
|
|
<li>
|
|
For <a class="dfnref" href="#dfn-constant">constants</a>, <a class="dfnref" href="#dfn-attribute">attributes</a>,
|
|
<a class="dfnref" href="#dfn-typedef">typedefs</a>, <a class="dfnref" href="#dfn-exception-field">exception fields</a>
|
|
and <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>,
|
|
the final <a class="sym" href="#prod-identifier">identifier</a> token before the
|
|
semicolon at the end of the declaration determines the identifier.
|
|
<pre class="syntax">interface <i>identifier</i> {
|
|
const <i>type</i> <em>constant-identifier</em> = <i>value</i>;
|
|
attribute <i>type</i> <em>attribute-identifier</em>;
|
|
};
|
|
|
|
typedef <i>type</i> <em>typedef-identifier</em>;
|
|
|
|
exception <i>identifier</i> {
|
|
<i>type</i> <em>exception-member-identifier</em>;
|
|
};
|
|
|
|
dictionary <i>identifier</i> {
|
|
<i>type</i> <em>dictionary-member-identifier</em>;
|
|
};</pre>
|
|
</li>
|
|
<li>
|
|
For <a class="dfnref" href="#dfn-operation">operations</a>, the
|
|
<a class="sym" href="#prod-identifier">identifier</a> token that appears
|
|
after the return type but before the opening parenthesis (that is,
|
|
one that is matched as part of the <a class="sym" href="#prod-OptionalIdentifier">OptionalIdentifier</a>
|
|
grammar symbol in an <a class="sym" href="#prod-Operation">Operation</a>) determines the identifier of the operation. If
|
|
there is no such <a class="sym" href="#prod-identifier">identifier</a> token,
|
|
then the operation does not have an identifier.
|
|
<pre class="syntax"><i>return-type</i> <em>operation-identifier</em>(<i>arguments…</i>);</pre>
|
|
</li>
|
|
</ul>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Operations can have no identifier when they are being used to declare a
|
|
<a href="#idl-special-operations">special kind of operation</a>, such as a getter or setter.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
For all of these constructs, the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
is the value of the <a class="sym" href="#prod-identifier">identifier</a> token with any single leading
|
|
<span class="char">U+005F LOW LINE ("_")</span> character (underscore) removed.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
A leading <span class="char">"_"</span> is used to escape an identifier from looking
|
|
like a reserved word so that, for example, an interface named “interface” can be
|
|
defined. The leading <span class="char">"_"</span> is dropped to unescape the
|
|
identifier.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-identifier">identifier</a> of any of the abovementioned
|
|
IDL constructs <a class="rfc2119">MUST NOT</a>
|
|
be one of the <a id="dfn-reserved-identifier" class="sym">reserved identifiers</a>
|
|
“prototype”, “constructor”, “toString”
|
|
or begin with a <span class="char">U+005F LOW LINE ("_")</span> character.
|
|
</p>
|
|
<p>
|
|
Every <a class="dfnref" href="#dfn-named-definition">named definition</a>
|
|
also has a <dfn id="dfn-qualified-name">qualified name</dfn>, determined as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the definition is
|
|
<a class="dfnref" href="#dfn-outermost-scope">declared at the outermost scope</a>,
|
|
then the qualified name
|
|
of the definition is two consecutive <span class="char">U+003A COLON (":")</span>
|
|
characters followed by the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of the definition. (Hereafter, two consecutive <span class="char">U+003A COLON (":")</span>
|
|
characters are referred to as a <dfn id="dfn-double-colon">double colon</dfn>.)
|
|
</li>
|
|
<li>
|
|
Otherwise, the definition is not declared at the outermost scope. The qualified name
|
|
of the definition is the qualified name
|
|
of the definition’s <a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>
|
|
followed by a <a class="dfnref" href="#dfn-double-colon">double colon</a>
|
|
followed by the identifier of the definition.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
Within the set of <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>
|
|
that a given implementation supports,
|
|
the <a class="dfnref" href="#dfn-qualified-name">qualified name</a> of every
|
|
<a class="dfnref" href="#dfn-module">module</a>,
|
|
<a class="dfnref" href="#dfn-interface">interface</a>,
|
|
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
|
|
<a class="dfnref" href="#dfn-exception">exception</a> and
|
|
<a class="dfnref" href="#dfn-typedef">typedef</a>
|
|
<span class="rfc2119">MUST NOT</span>
|
|
be the same as the qualified name of any other
|
|
<a class="dfnref" href="#dfn-interface">interface</a>,
|
|
<a class="dfnref" href="#dfn-dictionary">dictionary</a>,
|
|
<a class="dfnref" href="#dfn-exception">exception</a> or
|
|
<a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Multiple <a class="dfnref" href="#dfn-module">module</a> declarations can
|
|
have the same <a class="dfnref" href="#dfn-qualified-name">qualified name</a>.
|
|
When a subsequent module declaration for the same qualified name
|
|
is encountered, this effectively re-opens the module for definitions.
|
|
See <a href="#idl-modules">section 3.2</a> below
|
|
for details.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
A <dfn id="dfn-scoped-name">scoped name</dfn> (matching <a class="sym" href="#prod-ScopedName">ScopedName</a>)
|
|
is a string formed by concatenating a sequence of one or more identifiers with a
|
|
<a class="dfnref" href="#dfn-double-colon">double colon</a> between each pair of
|
|
adjacent identifiers, and is used in IDL to refer to definitions in other scopes.
|
|
A scoped name is an <dfn id="dfn-absolute-scoped-name">absolute scoped name</dfn>
|
|
if it begins with a <a class="dfnref" href="#dfn-double-colon">double colon</a>,
|
|
or a <dfn id="dfn-relative-scoped-name">relative scoped name</dfn> if it does not.
|
|
</p>
|
|
<p>
|
|
A scoped name can be <dfn id="dfn-resolve">resolved</dfn> (relative to a <a class="dfnref" href="#dfn-module">module</a>
|
|
or to the outermost scope) to a <a class="dfnref" href="#dfn-named-definition">named definition</a> as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the scoped name is a
|
|
<a class="dfnref" href="#dfn-relative-scoped-name">relative scoped name</a>, then
|
|
the following steps gives the definition it resolves to:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>name</var> be the <a class="dfnref" href="#dfn-qualified-name">qualified name</a>
|
|
of the <a class="dfnref" href="#dfn-module">module</a>, or the empty string if resolving
|
|
relative to the outermost scope.
|
|
</li>
|
|
<li>
|
|
Loop:
|
|
<ol>
|
|
<li>
|
|
If there is a <a class="dfnref" href="#dfn-definition">definition</a> whose
|
|
<a class="dfnref" href="#dfn-qualified-name">qualified name</a> is
|
|
equal to the concatenation of <var>name</var>, a
|
|
<a class="dfnref" href="#dfn-double-colon">double colon</a> and
|
|
the scoped name, then the scoped name resolves to that definition;
|
|
end these steps.
|
|
</li>
|
|
<li>
|
|
Remove the last name component from <var>name</var> (that is, from
|
|
the last <a class="dfnref" href="#dfn-double-colon">double colon</a>
|
|
to the end of the string, inclusive).
|
|
</li>
|
|
</ol>
|
|
until <var>name</var> is the empty string.
|
|
</li>
|
|
<li>
|
|
The scoped name does not resolve to a definition.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
Otherwise, the scoped name is an
|
|
<a href="#dfn-absolute-scoped-name">absolute scoped name</a>:
|
|
<ul>
|
|
<li>
|
|
If there exists a definition whose qualified name is
|
|
equal to the scoped name, then the scoped name resolves to that definition.
|
|
</li>
|
|
<li>
|
|
Otherwise, the scoped name does not resolve to a definition.
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
Unless otherwise stated, the <a class="dfnref" href="#dfn-module">module</a>
|
|
being used to <a class="dfnref" href="#dfn-resolve">resolve</a> a
|
|
<a class="dfnref" href="#dfn-scoped-name">scoped name</a> is the
|
|
<a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>
|
|
of the <a class="dfnref" href="#dfn-definition">definition</a>
|
|
on which the scoped name appears, or the outermost scope if it appears
|
|
on a definition <a class="dfnref" href="#dfn-outermost-scope">declared at the outermost scope</a>.
|
|
</p>
|
|
<p>
|
|
Within an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>, a reference
|
|
to a <a class="dfnref" href="#dfn-definition">definition</a> need not appear after
|
|
the declaration of the referenced definition. References can also be made
|
|
across <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>Therefore, the following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is valid:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface B : A {
|
|
void f(ArrayOfLongs x);
|
|
};
|
|
|
|
interface A {
|
|
};
|
|
|
|
typedef long[] ArrayOfLongs;</code></pre></div></div>
|
|
</div>
|
|
|
|
<table class="grammar"><tr id="proddef-ScopedName"><td><span class="prod-number">[58]</span></td><td><a class="sym" href="#prod-ScopedName">ScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AbsoluteScopedName">AbsoluteScopedName</a> <br /> |
|
|
<a class="sym" href="#prod-RelativeScopedName">RelativeScopedName</a></span></td></tr><tr id="proddef-AbsoluteScopedName"><td><span class="prod-number">[59]</span></td><td><a class="sym" href="#prod-AbsoluteScopedName">AbsoluteScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"::" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a></span></td></tr><tr id="proddef-RelativeScopedName"><td><span class="prod-number">[60]</span></td><td><a class="sym" href="#prod-RelativeScopedName">RelativeScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a></span></td></tr><tr id="proddef-ScopedNameParts"><td><span class="prod-number">[61]</span></td><td><a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"::" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a> <br /> |
|
|
ε</span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates how <a class="dfnref" href="#dfn-identifier">identifiers</a>
|
|
and <a class="dfnref" href="#dfn-qualified-name">qualified names</a> are given
|
|
to definitions, <a class="dfnref" href="#dfn-interface-member">interface members</a>
|
|
and <a class="dfnref" href="#dfn-exception-member">exception members</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code"><span class="comment">// Module identifier: "framework"</span>
|
|
<span class="comment">// Qualified name: "::framework"</span>
|
|
module framework {
|
|
|
|
<span class="comment">// Typedef identifier: "number"</span>
|
|
<span class="comment">// Qualified name: "::framework::number"</span>
|
|
typedef float number;
|
|
|
|
<span class="comment">// Exception identifier: "FrameworkException"</span>
|
|
<span class="comment">// Qualified name: "::framework::FrameworkException"</span>
|
|
exception FrameworkException {
|
|
|
|
<span class="comment">// Constant identifier: "ERR_NOT_FOUND"</span>
|
|
<span class="comment">// Qualified name: "::framework::FrameworkException::ERR_NOT_FOUND"</span>
|
|
const long ERR_NOT_FOUND = 1;
|
|
|
|
<span class="comment">// Exception field identifier: "code"</span>
|
|
long code;
|
|
};
|
|
|
|
<span class="comment">// Interface identifier: "System"</span>
|
|
<span class="comment">// Qualified name: "::framework::System"</span>
|
|
interface System {
|
|
|
|
<span class="comment">// Operation identifier: "createObject"</span>
|
|
<span class="comment">// Operation argument identifier: "interface"</span>
|
|
object createObject(DOMString _interface);
|
|
|
|
<span class="comment">// Operation has no identifier; it declares a getter.</span>
|
|
getter DOMString (DOMString keyName);
|
|
};
|
|
|
|
<span class="comment">// Module identifier: "gui"</span>
|
|
<span class="comment">// Qualified name: "::framework::gui"</span>
|
|
module gui {
|
|
|
|
<span class="comment">// Interface identifier: "TextField"</span>
|
|
<span class="comment">// Qualified name: "::framework::gui::TextField"</span>
|
|
interface TextField {
|
|
|
|
<span class="comment">// Attribute identifier: "const"</span>
|
|
attribute boolean _const;
|
|
|
|
<span class="comment">// Attribute identifier: "value"</span>
|
|
attribute DOMString? _value;
|
|
};
|
|
};
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Note that while the second <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
on the <span class="idltype">TextField</span> <a class="dfnref" href="#dfn-interface">interface</a>
|
|
need not have been escaped with an underscore (because “value” is
|
|
not a keyword in the IDL grammar), it is still unescaped
|
|
to obtain the attribute’s <a class="dfnref" href="#dfn-identifier">identifier</a>.
|
|
</p>
|
|
<p>
|
|
Also note that the <a class="dfnref" href="#dfn-exception-field">exception fields</a>,
|
|
<a class="dfnref" href="#dfn-operation">operations</a> and
|
|
<a class="dfnref" href="#dfn-attribute">attributes</a> above do not have
|
|
<a class="dfnref" href="#dfn-qualified-name">qualified names</a>, simply because
|
|
there is no need to be able to reference them from other scopes.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-modules" class="section">
|
|
<h3>3.2. Modules</h3>
|
|
|
|
<div class="ednote"><div class="ednoteHeader">Editorial note</div>
|
|
<p>Should W3C specs use modules at all? And if not, should we just remove them?
|
|
<a href="http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/0282.html">(Mail.)</a></p>
|
|
</div>
|
|
<p>
|
|
A <dfn id="dfn-module">module</dfn> is a <a class="dfnref" href="#dfn-definition">definition</a>
|
|
(matching <a class="sym" href="#prod-Module">Module</a>) that serves
|
|
as a container for grouping together related definitions in a single namespace.
|
|
</p>
|
|
<pre class="syntax">module <i>identifier</i> {
|
|
<i>definitions…</i>
|
|
};</pre>
|
|
<p>
|
|
Definitions have as their <dfn id="dfn-enclosing-module">enclosing module</dfn>
|
|
the module inside which they appear in the IDL.
|
|
If <a class="dfnref" href="#dfn-outermost-scope">declared at the outermost scope</a>,
|
|
a definition has no enclosing module.
|
|
</p>
|
|
<p>
|
|
The relevant language binding determines how modules affect the naming
|
|
of constructs that correspond to definitions in the language. If the language
|
|
supports some form of namespacing mechanism, then a module will correspond
|
|
to a namespace. The name of that namespace can be based on the module’s
|
|
<dfn id="dfn-prefixed-name">prefixed name</dfn>, which is defined as
|
|
follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the <a class="dfnref" href="#dfn-module">module</a> has a
|
|
<a class="xattr" href="#Prefix">[Prefix]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
whose argument starts with a <a class="dfnref" href="#dfn-double-colon">double colon</a>, then the
|
|
<a class="dfnref" href="#dfn-prefixed-name">prefixed name</a> of
|
|
the module is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
constructed by concatenating the <a class="xattr" href="#Prefix">[Prefix]</a>
|
|
argument, a <a class="dfnref" href="#dfn-double-colon">double colon</a>
|
|
and the module’s <a class="dfnref" href="#dfn-identifier">identifier</a>.
|
|
</li>
|
|
<li>
|
|
Otherwise, if the <a class="dfnref" href="#dfn-module">module</a> has a
|
|
<a class="xattr" href="#Prefix">[Prefix]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
whose argument does not start with a <a class="dfnref" href="#dfn-double-colon">double colon</a>, then the
|
|
<a class="dfnref" href="#dfn-prefixed-name">prefixed name</a> of
|
|
the module is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
constructed by concatenating:
|
|
<ol>
|
|
<li>the <a class="dfnref" href="#dfn-prefixed-name">prefixed name</a>
|
|
of the module’s <a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>
|
|
followed by a <a class="dfnref" href="#dfn-double-colon">double colon</a>, or
|
|
simply a <a class="dfnref" href="#dfn-double-colon">double colon</a> if there
|
|
is no enclosing module,</li>
|
|
<li>the <a class="xattr" href="#Prefix">[Prefix]</a> argument,</li>
|
|
<li>a <a class="dfnref" href="#dfn-double-colon">double colon</a>,</li>
|
|
<li>and the module’s <a class="dfnref" href="#dfn-identifier">identifier</a>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
Otherwise, if the <a class="dfnref" href="#dfn-qualified-name">qualified name</a>
|
|
of the <a class="dfnref" href="#dfn-module">module</a> is “::dom”, then
|
|
the <a class="dfnref" href="#dfn-prefixed-name">prefixed name</a> of the
|
|
module is the <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
“::org::w3c::dom”.
|
|
</li>
|
|
<li>
|
|
Otherwise, if the <a class="dfnref" href="#dfn-module">module</a> has
|
|
no <a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>,
|
|
then the <a class="dfnref" href="#dfn-prefixed-name">prefixed name</a> of the
|
|
module is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
constructed by concatenating the string “::org::w3c::dom::” and the
|
|
module’s <a class="dfnref" href="#dfn-identifier">identifier</a>.
|
|
</li>
|
|
<li>
|
|
Otherwise, the <a class="dfnref" href="#dfn-prefixed-name">prefixed name</a>
|
|
of the module is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
constructed by concatenating the prefixed name of the module’s
|
|
<a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>,
|
|
a <a class="dfnref" href="#dfn-double-colon">double colon</a>
|
|
and the module’s <a class="dfnref" href="#dfn-identifier">identifier</a>.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
In the Java language binding, the name of the Java package is
|
|
derived by taking the <a class="dfnref" href="#dfn-prefixed-name">prefixed name</a>
|
|
and replacing all <a class="dfnref" href="#dfn-double-colon">double colons</a>
|
|
with “.” (see <a href="#java-modules">section 5.3</a>).
|
|
It is expected that bindings for other languages that typically
|
|
use reversed domain names for namespacing will also use the prefixed
|
|
name of a module to determine namespace names.
|
|
</p>
|
|
<p>
|
|
The ECMAScript language binding allows a namespacing mechanism based
|
|
on the <a class="dfnref" href="#dfn-scoped-name">scoped name</a>
|
|
of a module by using the <a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
</p>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
are applicable to <a class="dfnref" href="#dfn-module">modules</a>:
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>,
|
|
<a class="xattr" href="#Prefix">[Prefix]</a>.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-Module"><td><span class="prod-number">[4]</span></td><td><a class="sym" href="#prod-Module">Module</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"module" <a class="sym" href="#prod-identifier">identifier</a> "{" <a class="sym" href="#prod-Definitions">Definitions</a> "}" ";"</span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
illustrates how related <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
can be grouped together in <a class="dfnref" href="#dfn-module">modules</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">module gfx {
|
|
|
|
module geom {
|
|
interface Shape { <span class="comment">/* ... */</span> };
|
|
interface Rectangle : Shape { <span class="comment">/* ... */</span> };
|
|
interface Path : Shape { <span class="comment">/* ... */</span> };
|
|
};
|
|
|
|
interface GraphicsContext {
|
|
void fillShape(geom::Shape s);
|
|
void strokeShape(geom::Shape s);
|
|
};
|
|
};
|
|
|
|
module gui {
|
|
|
|
interface Widget { <span class="comment">/* ... */</span> };
|
|
|
|
interface Window : Widget {
|
|
gfx::GraphicsContext getGraphicsContext();
|
|
};
|
|
|
|
interface Button : Widget { <span class="comment">/* ... */</span> };
|
|
};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-interfaces" class="section">
|
|
<h3>3.3. Interfaces</h3>
|
|
|
|
<p>
|
|
<a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a> are used to
|
|
describe object oriented systems. In such systems, objects are entities
|
|
that have identity and which are encapsulations of state and behavior.
|
|
An <dfn id="dfn-interface">interface</dfn> is a definition (matching
|
|
<a class="sym" href="#prod-Interface">Interface</a>) that declares some
|
|
state and behavior that an object implementing that interface will expose.
|
|
</p>
|
|
<pre class="syntax">interface <i>identifier</i> {
|
|
<i>interface-members…</i>
|
|
};</pre>
|
|
<p>
|
|
An interface is a specification of a set of
|
|
<dfn id="dfn-interface-member">interface members</dfn>
|
|
(matching <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a>),
|
|
which are the <a class="dfnref" href="#dfn-constant">constants</a>,
|
|
<a class="dfnref" href="#dfn-attribute">attributes</a> and
|
|
<a class="dfnref" href="#dfn-operation">operations</a>
|
|
that appear between the braces in the interface declaration.
|
|
Attributes describe the state that an object
|
|
implementing the interface will expose, and operations describe the
|
|
behaviors that can be invoked on the object. Constants declare
|
|
named constant values that are exposed as a convenience to users
|
|
of objects in the system.
|
|
</p>
|
|
<p>
|
|
Interfaces in Web IDL describe how objects that implement the
|
|
interface behave. In bindings for object oriented languages, it is
|
|
expected that an object that implements a particular IDL interface
|
|
provides ways to inspect and modify the object's state and to
|
|
invoke the behavior described by the interface.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In the Java language binding, for example, this is achieved by having the
|
|
object implement a Java interface that has methods for reading and
|
|
writing attribute values and to invoke an operation.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
An interface can be defined to <dfn id="dfn-inherit">inherit</dfn> from another interface.
|
|
If the identifier of the interface is followed by a
|
|
<span class="char">U+003A COLON (":")</span> character
|
|
and a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>,
|
|
then that scoped name identifies the inherited interface. The scoped name
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-resolve">resolve</a> to
|
|
a different interface. An object that implements an interface that inherits from another
|
|
also implements that inherited interface. The object therefore will also
|
|
have members that correspond to the interface members from the inherited interface.
|
|
</p>
|
|
<pre class="syntax">interface <i>identifier</i> : <em>scoped-name-of-inherited-interface</em> {
|
|
<i>interface-members…</i>
|
|
};</pre>
|
|
<p>
|
|
The order that members appear in has no significance.
|
|
</p>
|
|
<p>
|
|
Interfaces may specify an interface member that has the same name as
|
|
one from an inherited interface. Objects that implement the derived
|
|
interface will expose the member on the derived interface. It is
|
|
language binding specific whether the overridden member can be
|
|
accessed on the object.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
Consider the following two interfaces.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
void f();
|
|
void g();
|
|
};
|
|
|
|
interface B : A {
|
|
void f();
|
|
void g(DOMString x);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In the ECMAScript language binding, an instance of <span class="idltype">B</span>
|
|
will have a prototype chain that looks like the following:
|
|
</p>
|
|
<pre> [Object.prototype: the Object prototype object]
|
|
↑
|
|
[A.prototype: interface prototype object for A]
|
|
↑
|
|
[B.prototype: interface prototype object for B]
|
|
↑
|
|
[instanceOfB]</pre>
|
|
<p>
|
|
Calling <code>instanceOfB.f()</code> in ECMAScript will invoke the f defined
|
|
on <span class="idltype">B</span>. However, the f from <span class="idltype">A</span>
|
|
can still be invoked on an object that implements <span class="idltype">B</span> by
|
|
calling <code>A.prototype.f.call(instanceOfB)</code>.
|
|
</p>
|
|
<p>
|
|
In the Java language binding, the two IDL interfaces will correspond to
|
|
the following Java interfaces:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">public interface A {
|
|
void f();
|
|
void g();
|
|
}
|
|
|
|
public interface B extends A {
|
|
void f();
|
|
void g(String x);
|
|
}</code></pre></div></div>
|
|
<p>
|
|
Calling <code>instanceOfB.f()</code> in Java will invoke
|
|
the f defined on <span class="idltype">B</span>. Due to
|
|
the way method overriding is defined in Java, there is no
|
|
way to call the f defined on <span class="idltype">A</span>
|
|
on an object that implements <span class="idltype">B</span>.
|
|
Since the signature of g is different in <span class="idltype">A</span>
|
|
and <span class="idltype">B</span>, however, both can be called
|
|
with, for example, <code>instanceOfB.g()</code> and
|
|
<code>instanceOfB.g("")</code>.
|
|
</p>
|
|
<p>
|
|
In both languages, the f and g from the derived interface
|
|
<span class="idltype">B</span> are always accessible.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The <dfn id="dfn-inherited-interfaces">inherited interfaces</dfn> of
|
|
a given interface <var>A</var> is the set of all interfaces that <var>A</var>
|
|
inherits from, directly or indirectly. If <var>A</var> does not <a class="dfnref" href="#dfn-inherit">inherit</a>
|
|
from another interface, then the set is empty. Otherwise, the set
|
|
includes the interface <var>B</var> that <var>A</var> <a class="dfnref" href="#dfn-inherit-dictionary">inherits</a>
|
|
from and all of <var>B</var>’s <a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>.
|
|
</p>
|
|
<p>
|
|
An interface <span class="rfc2119">MUST NOT</span> be declared such that
|
|
its inheritance hierarchy has a cycle. That is, an interface
|
|
<var>A</var> cannot inherit from itself, nor can it inherit from another
|
|
interface <var>B</var> that inherits from <var>A</var>, and so on.
|
|
</p>
|
|
<p>
|
|
Note that general multiple inheritance of interfaces is not supported, and
|
|
objects also cannot implement arbitrary sets of interfaces.
|
|
Objects can be defined to implement a single given interface <var>A</var>,
|
|
which means that it also implements all of <var>A</var>’s
|
|
<a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>. In addition,
|
|
an <a href="#idl-implements-statements">implements statement</a> can be
|
|
used to define that objects implementing an interface will always
|
|
also implement another interface.
|
|
</p>
|
|
<p>
|
|
Each interface member can be preceded by a list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
|
|
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
|
|
which can control how the interface member will be handled in language bindings.
|
|
</p>
|
|
<pre class="syntax">interface <i>identifier</i> {
|
|
|
|
[<em>extended-attributes</em>]
|
|
const <i>type</i> <i>identifier</i> = <i>value</i>;
|
|
|
|
[<em>extended-attributes</em>]
|
|
attribute <i>type</i> <i>identifier</i>;
|
|
|
|
[<em>extended-attributes</em>]
|
|
<i>return-type</i> <i>identifier</i>(<i>arguments…</i>);
|
|
};</pre>
|
|
|
|
<p>
|
|
The IDL for interfaces can be split into multiple parts by using
|
|
<dfn id="dfn-partial-interface">partial interface</dfn> definitions
|
|
(matching <a class="sym" href="#prod-PartialInterface">PartialInterface</a>).
|
|
The <a class="dfnref" href="#dfn-identifier">identifier</a> of a partial
|
|
interface definition <span class="rfc2119">MUST</span> be the same
|
|
as the identifier of an interface definition in the same module. All of
|
|
the members that appear on each of the partial interfaces are considered to be
|
|
members of the interface itself.
|
|
</p>
|
|
<pre class="syntax">interface <em>SomeInterface</em> {
|
|
<i>interface-members…</i>
|
|
};
|
|
|
|
partial interface <em>SomeInterface</em> {
|
|
<i>interface-members…</i>
|
|
};</pre>
|
|
<p>
|
|
The order of apperance of an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
definition and any of its <a class="dfnref" href="#dfn-partial-interface">partial interface</a>
|
|
definitions within a single <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
does not matter.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>Partial interface definitions are intended for use as a specification
|
|
editorial aide, allowing the definition of an interface to be separated
|
|
over more than one section of the document, and sometimes multiple documents.</p>
|
|
</div>
|
|
<p>
|
|
The relevant language binding determines how interfaces correspond to constructs
|
|
in the language.
|
|
</p>
|
|
<!--
|
|
<p>
|
|
An <dfn id='dfn-interface-forward-declaration'>interface forward declaration</dfn>
|
|
is a definition that matches the <a class='sym' href='#prod-Interface'>Interface</a> non-terminal
|
|
whose <a class='sym' href='#prod-InterfaceBody'>InterfaceBody</a> is empty
|
|
(that is, <a class='sym' href='#prod-InterfaceBody'>InterfaceBody</a> ⇒ ε). A forward declaration
|
|
is used to introduce an interface name to allow for the definition of mutually
|
|
recursive interfaces, since scoped names
|
|
need to resolve to types that have been
|
|
<a class='dfnref' href='#dfn-declared-previously'>declared previously</a>.
|
|
</p>
|
|
-->
|
|
|
|
<p>
|
|
The following extended attributes are applicable to interfaces:
|
|
<a class="xattr" href="#ArrayClass">[ArrayClass]</a>,
|
|
<a class="xattr" href="#Callback">[Callback]</a>,
|
|
<a class="xattr" href="#Constructor">[Constructor]</a>,
|
|
<a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>,
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>,
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>,
|
|
<a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>,
|
|
<a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>.
|
|
</p>
|
|
|
|
<!--
|
|
<?productions grammar Interface PartialInterface Inheritance InterfaceMembers InterfaceMember ScopedNameList ScopedNames?>
|
|
-->
|
|
<table class="grammar"><tr id="proddef-Interface"><td><span class="prod-number">[5]</span></td><td><a class="sym" href="#prod-Interface">Interface</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"interface" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> "}" ";"</span></td></tr><tr id="proddef-PartialInterface"><td><span class="prod-number">[6]</span></td><td><a class="sym" href="#prod-PartialInterface">PartialInterface</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"partial" "interface" <a class="sym" href="#prod-identifier">identifier</a> "{" <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> "}" ";"</span></td></tr><tr id="proddef-Inheritance"><td><span class="prod-number">[7]</span></td><td><a class="sym" href="#prod-Inheritance">Inheritance</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">":" <a class="sym" href="#prod-ScopedName">ScopedName</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-InterfaceMembers"><td><span class="prod-number">[8]</span></td><td><a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-InterfaceMember">InterfaceMember</a> <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-InterfaceMember"><td><span class="prod-number">[9]</span></td><td><a class="sym" href="#prod-InterfaceMember">InterfaceMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Const">Const</a> <br /> |
|
|
<a class="sym" href="#prod-AttributeOrOperation">AttributeOrOperation</a></span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<!--
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a>
|
|
demonstrates the use of an
|
|
<a class='dfnref' href='#dfn-interface-forward-declaration'>interface forward declaration</a>
|
|
to allow the definition of mutually referential <a class='dfnref' href='#dfn-interface'>interfaces</a>.
|
|
Both <span class='idltype'>Human</span> and <span class='idltype'>Dog</span>
|
|
inherit from <span class='idltype'>Animal</span>. Objects that implement
|
|
either of those two interfaces will thus have a <code>name</code> attribute.
|
|
</p>
|
|
-->
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates the definition of two mutually referential <a class="dfnref" href="#dfn-interface">interfaces</a>.
|
|
Both <span class="idltype">Human</span> and <span class="idltype">Dog</span>
|
|
inherit from <span class="idltype">Animal</span>. Objects that implement
|
|
either of those two interfaces will thus have a <code>name</code> attribute.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Animal {
|
|
attribute DOMString name;
|
|
};
|
|
|
|
interface Human : Animal {
|
|
attribute Dog? pet;
|
|
};
|
|
|
|
interface Dog : Animal {
|
|
attribute Human? owner;
|
|
};</code></pre></div></div>
|
|
</div>
|
|
|
|
<div id="idl-constants" class="section">
|
|
<h4>3.3.1. Constants</h4>
|
|
|
|
<p>
|
|
A <dfn id="dfn-constant">constant</dfn> is a declaration (matching
|
|
<a class="sym" href="#prod-Const">Const</a>) used to bind a constant value to a name.
|
|
Constants can appear on <a class="dfnref" href="#dfn-interface">interfaces</a> and
|
|
<a class="dfnref" href="#dfn-exception">exceptions</a>.
|
|
</p>
|
|
<pre class="syntax">const <i>type</i> <i>identifier</i> = <i>value</i>;</pre>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-identifier">identifier</a> of a
|
|
<a class="dfnref" href="#dfn-constant">constant</a>
|
|
<span class="rfc2119">MUST NOT</span> be the same as the identifier
|
|
of another <a class="dfnref" href="#dfn-interface-member">interface member</a>
|
|
defined on the same interface
|
|
or another <a class="dfnref" href="#dfn-exception-member">exception member</a>
|
|
defined on the same exception.
|
|
</p>
|
|
<p>
|
|
The <a class="sym" href="#prod-ConstValue">ConstValue</a> part of a
|
|
constant declaration (or <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a>
|
|
declaration) gives the value of the constant (or the default value of the dictionary member), which can be
|
|
one of the two boolean literal tokens (<code>true</code>
|
|
and <code>false</code>),
|
|
the <code>null</code> token, an
|
|
<a class="sym" href="#prod-integer">integer</a> token, a
|
|
<a class="sym" href="#prod-float">float</a> token or a
|
|
<a class="sym" href="#prod-string">string</a> token.
|
|
</p>
|
|
<p>
|
|
The value of the boolean literal tokens <code>true</code> and
|
|
<code>false</code> are the IDL <a class="idltype" href="#idl-boolean">boolean</a> values
|
|
<span class="idlvalue">true</span> and <span class="idlvalue">false</span>.
|
|
</p>
|
|
<p>
|
|
The value of an <a class="sym" href="#prod-integer">integer</a> token is an integer
|
|
whose value is determined as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>S</var> be the sequence of characters matched by the <a class="sym" href="#prod-integer">integer</a> token.</li>
|
|
<li>Let <var>sign</var> be −1 if <var>S</var> begins with <span class="char">U+002D HYPHEN-MINUS ("-")</span>, and 1 otherwise.</li>
|
|
<li>Let <var>base</var> be the base of the number based on the characters that follow the optional leading <span class="char">U+002D HYPHEN-MINUS ("-")</span> character:
|
|
<dl class="switch">
|
|
<dt><span class="char">U+0030 DIGIT ZERO ("0")</span>, <span class="char">U+0058 LATIN CAPITAL LETTER X ("X")</span></dt>
|
|
<dt><span class="char">U+0030 DIGIT ZERO ("0")</span>, <span class="char">U+0078 LATIN SMALL LETTER X ("x")</span></dt>
|
|
<dd>The base is 16.</dd>
|
|
<dt><span class="char">U+0030 DIGIT ZERO ("0")</span></dt>
|
|
<dd>The base is 8.</dd>
|
|
<dt><span class="char">Otherwise</span></dt>
|
|
<dd>The base is 10.</dd>
|
|
</dl>
|
|
</li>
|
|
<li>Let <var>number</var> be the result of interpreting all remaining characters following the optional leading <span class="char">U+002D HYPHEN-MINUS ("-")</span>
|
|
character and any characters indicating the base as an integer specified in base <var>base</var>.</li>
|
|
<li>Return <var>sign</var> × <var>number</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The type of an <a class="sym" href="#prod-integer">integer</a> token is the same
|
|
as the type of the constant or dictionary member it is being used as the value of.
|
|
The value of the <a class="sym" href="#prod-integer">integer</a> token <span class="rfc2119">MUST NOT</span>
|
|
lie outside the valid range of values for its type, as given in
|
|
<a href="#idl-types">section 3.9</a> below.
|
|
</p>
|
|
<p id="float-token-value">
|
|
The value of a <a class="sym" href="#prod-float">float</a> token is
|
|
either an IEEE 754 single-precision floating point number or an IEEE 754
|
|
double-precision floating point number, depending on the type of the
|
|
constant or dictionary member it is being used as the value for, determined as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>S</var> be the sequence of characters matched by the <a class="sym" href="#prod-float">float</a> token.</li>
|
|
<li>Let <var>value</var> be the Mathematical Value that would be obtained if <var>S</var> were
|
|
parsed as an ECMAScript <em>NumericLiteral</em> (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 7.8.3).</li>
|
|
<li>
|
|
If the <a class="sym" href="#prod-float">float</a> token is being
|
|
used as the value for a <a class="idltype" href="#idl-float">float</a>, then
|
|
the value of the <a class="sym" href="#prod-float">float</a> token
|
|
is the IEEE 754 single-precision floating point number closest to
|
|
<var>result</var>. Otherwise, the <a class="sym" href="#prod-float">float</a> token is being
|
|
used as the value for a <a class="idltype" href="#idl-double">double</a>, and
|
|
the value of the <a class="sym" href="#prod-float">float</a> token
|
|
is the IEEE 754 double-precision floating point number closest to
|
|
<var>result</var>.
|
|
<a href="#ref-IEEE-754">[IEEE-754]</a>
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
It is not possible to specify an infinite or Not-a-Number
|
|
<a class="idltype" href="#idl-float">float</a> constant or dictionary member default value.
|
|
</p>
|
|
<p>
|
|
The type of a <a class="sym" href="#prod-float">float</a> token is the same
|
|
as the type of the constant or dictionary member it is being used as the value of. The value of the
|
|
<a class="sym" href="#prod-float">float</a> token <span class="rfc2119">MUST NOT</span>
|
|
lie outside the valid range of values for its type, as given in
|
|
<a href="#idl-types">section 3.9</a> below.
|
|
</p>
|
|
<p>
|
|
The value of a <a class="sym" href="#prod-string">string</a> token
|
|
is a <a class="idltype" href="#idl-DOMString">DOMString</a>, determined as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>S</var> be the sequest of characters matched by the <a class="sym" href="#prod-string">string</a>
|
|
token with its leading and trailing <span class="char">U+0022 QUOTATION MARK ('"')</span>
|
|
characters removed.</li>
|
|
<li>The value of the <a class="sym" href="#prod-string">string</a> token is the
|
|
sequence of 16 bit unsigned integer code units (hereafter referred to just as
|
|
<dfn id="dfn-code-unit">code units</dfn>) corresponding to the UTF-16 encoding
|
|
of <var>S</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The value of the <code>null</code> token is the special
|
|
<span class="idlvalue">null</span> value that is a member of the
|
|
<a class="dfnref" href="#dfn-nullable-type">nullable types</a>. The type of
|
|
the <code>null</code> token is the same as the
|
|
type of the constant or dictionary member it is being used as the value of.
|
|
</p>
|
|
<p>
|
|
If <var>VT</var> is the type of the value assigned to a constant, and <var>DT</var>
|
|
is the type of the constant or dictionary member itself, then these types <span class="rfc2119">MUST</span>
|
|
be compatible, which is the case if <var>DT</var> and <var>VT</var> are identical,
|
|
or <var>DT</var> is a <a class="dfnref" href="#dfn-nullable-type">nullable type</a>
|
|
whose <a class="dfnref" href="#dfn-inner-type">inner type</a> is <var>VT</var>.
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-constant">Constants</a> are not associated with
|
|
particular instances of the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which they appear. It is language binding specific whether
|
|
<a class="dfnref" href="#dfn-constant">constants</a> are exposed on instances.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Both the ECMAScript and the Java language binding do however
|
|
allow <a class="dfnref" href="#dfn-constant">constants</a> to be accessed
|
|
through objects implementing the IDL <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
on which the <a class="dfnref" href="#dfn-constant">constants</a> are declared.
|
|
For example, with the following IDL:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
const DOMString greeting = "hi";
|
|
};</code></pre></div></div>
|
|
<p>
|
|
the constant value can be accessed in ECMAScript and in Java either as
|
|
<code>A.greeting</code> or <code>instanceOfA.greeting</code>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
No <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification are applicable to constants.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-Const"><td><span class="prod-number">[18]</span></td><td><a class="sym" href="#prod-Const">Const</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"const" <a class="sym" href="#prod-ConstType">ConstType</a> <a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-ConstValue">ConstValue</a> ";"</span></td></tr><tr id="proddef-ConstValue"><td><span class="prod-number">[19]</span></td><td><a class="sym" href="#prod-ConstValue">ConstValue</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-BooleanLiteral">BooleanLiteral</a> <br /> |
|
|
<a class="sym" href="#prod-integer">integer</a> <br /> |
|
|
<a class="sym" href="#prod-float">float</a> <br /> |
|
|
<a class="sym" href="#prod-string">string</a> <br /> |
|
|
"null"</span></td></tr><tr id="proddef-BooleanLiteral"><td><span class="prod-number">[20]</span></td><td><a class="sym" href="#prod-BooleanLiteral">BooleanLiteral</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"true" <br /> |
|
|
"false"</span></td></tr></table>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates how <a class="dfnref" href="#dfn-constant">constants</a>
|
|
of the above types can be defined.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Util {
|
|
const boolean DEBUG = false;
|
|
const octet LF = 10;
|
|
const unsigned long BIT_MASK = 0x0000fc00;
|
|
const float AVOGADRO = 6.022e23;
|
|
};
|
|
|
|
exception Error {
|
|
const short ERR_UNKNOWN = 0;
|
|
const short ERR_OUT_OF_MEMORY = 1;
|
|
|
|
short errorCode;
|
|
};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-attributes" class="section">
|
|
<h4>3.3.2. Attributes</h4>
|
|
|
|
<p>
|
|
An <dfn id="dfn-attribute">attribute</dfn> is an <a class="dfnref" href="#dfn-interface-member">interface member</a>
|
|
(matching <span class="sym">"stringifier"</span> <a class="sym" href="#prod-Attribute">Attribute</a> or <a class="sym" href="#prod-Attribute">Attribute</a>)
|
|
that is used to declare that objects implementing the <a class="dfnref" href="#dfn-interface">interface</a> will have a member with the given
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> whose value can
|
|
be retrieved and (in some cases) changed.
|
|
</p>
|
|
<pre class="syntax">attribute <i>type</i> <i>identifier</i>;</pre>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-identifier">identifier</a> of an
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
<span class="rfc2119">MUST NOT</span> be the same as the identifier
|
|
of another <a class="dfnref" href="#dfn-interface-member">interface member</a>
|
|
defined on the same <a class="dfnref" href="#dfn-interface">interface</a>.
|
|
</p>
|
|
<p>
|
|
The type of the attribute is given by the type (matching <a class="sym" href="#prod-AttributeType">AttributeType</a>)
|
|
that appears after the <code>attribute</code> keyword. This allows for
|
|
any type except <a href="#idl-sequence">sequence types</a>.
|
|
If the <a class="sym" href="#prod-AttributeType">AttributeType</a> is a
|
|
<a class="dfnref" href="#dfn-scoped-name">scoped name</a>, then it <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-resolve">resolve</a> to an interface or <a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
</p>
|
|
<p>
|
|
The attribute is <dfn id="dfn-read-only">read only</dfn> if the
|
|
<code>readonly</code> keyword is used before the <code>attribute</code> keyword.
|
|
An object that implements the interface on which a read only attribute
|
|
is defined will not allow assignment to that attribute. It is language
|
|
binding specific whether assignment is simply disallowed by the language,
|
|
ignored or an exception is thrown.
|
|
</p>
|
|
<pre class="syntax">readonly attribute <i>type</i> <i>identifier</i>;</pre>
|
|
<p>
|
|
An attribute that is not <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
can be declared to <dfn id="dfn-inherit-getter">inherit its getter</dfn>
|
|
from an ancestor interface. This can be used to make a read only attribute
|
|
in an ancestor interface be writable on a derived interface. An attribute
|
|
<a class="dfnref" href="#dfn-inherit-getter">inherits its getter</a> if
|
|
its declaration includes <code>inherit</code> in the declaration.
|
|
The read only attribute from which the attribute inherits its getter
|
|
is the attribute with the same identifier on the closest ancestor interface
|
|
of the one on which the inheriting attribute is defined. The attribute
|
|
whose getter is being inherited <span class="rfc2119">MUST</span> be
|
|
of the same type as the inheriting attribute, and <code>inherit</code>
|
|
<span class="rfc2119">MUST NOT</span> appear on a read only attribute.
|
|
</p>
|
|
<pre class="syntax">interface <i>Ancestor</i> {
|
|
readonly attribute <i>TheType</i> <i>theIdentifier</i>;
|
|
};
|
|
|
|
interface <i>Derived</i> : <i>Ancestor</i> {
|
|
inherit attribute <i>TheType</i> <i>theIdentifier</i>;
|
|
};</pre>
|
|
<!--
|
|
<p>
|
|
The <a class='sym' href='#prod-GetRaises'>GetRaises</a> and
|
|
<a class='sym' href='#prod-SetRaises'>SetRaises</a> clauses are used
|
|
to declare the possible exceptions that can be thrown when retrieving
|
|
the value of and assigning a value to the attribute, respectively.
|
|
Each scoped name in the
|
|
<a class='sym' href='#prod-GetRaises'>GetRaises</a> and
|
|
<a class='sym' href='#prod-SetRaises'>SetRaises</a> clauses
|
|
<span class='rfc2119'>MUST</span> resolve to an <a class='dfnref' href='#dfn-exception'>exception</a>.
|
|
</p>
|
|
<pre class='syntax'>attribute <i>type</i> <i>identifier</i> getraises(<i>scoped-name</i>, <i>…</i>);
|
|
attribute <i>type</i> <i>identifier</i> setraises(<i>scoped-name</i>, <i>…</i>);
|
|
attribute <i>type</i> <i>identifier</i> getraises(<i>scoped-name</i>, <i>…</i>) setraises(<i>scoped-name</i>, <i>…</i>);
|
|
attribute <i>type</i> <i>identifier</i> inherits getter setraises(<i>scoped-name</i>, <i>…</i>);</pre>
|
|
-->
|
|
<p>
|
|
When the <code>stringifier</code> keyword is used
|
|
in an attribute declaration, it indicates that objects implementing the
|
|
interface will be stringified to the value of the attribute. See
|
|
<a href="#idl-stringifiers">section 3.3.4.2</a>
|
|
below for details.
|
|
</p>
|
|
<pre class="syntax">stringifier attribute DOMString <i>identifier</i>;</pre>
|
|
<p id="callback-attribute-exceptions">
|
|
If an implementation attempts to get or set the value of an
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> on a
|
|
<a class="dfnref" href="#dfn-user-object">user object</a>
|
|
(for example, when a callback object has been supplied to the implementation),
|
|
and that attempt results in an exception being thrown, then, unless otherwise specified, that
|
|
exception will be propagated to the user code that caused the
|
|
implementation to access the attribute. Similarly, if a value
|
|
returned from getting the attribute cannot be converted to
|
|
an IDL type, then any exception resulting from this will also
|
|
be propagated to the user code that resulted in the implementation
|
|
attempting to get the value of the attribute.
|
|
</p>
|
|
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
are applicable to attributes:
|
|
<a class="xattr" href="#Clamp">[Clamp]</a>,
|
|
<a class="xattr" href="#EnforceRange">[EnforceRange]</a>,
|
|
<a class="xattr" href="#PutForwards">[PutForwards]</a>,
|
|
<a class="xattr" href="#Replaceable">[Replaceable]</a>,
|
|
<a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>,
|
|
<a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>,
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>,
|
|
<a class="xattr" href="#Unforgeable">[Unforgeable]</a>.
|
|
</p>
|
|
|
|
<!--
|
|
<?productions grammar AttributeOrOperation StringifierAttributeOrOperation Attribute ReadOnly Get GetRaises SetRaises ExceptionList?>
|
|
-->
|
|
<table class="grammar"><tr id="proddef-AttributeOrOperation"><td><span class="prod-number">[21]</span></td><td><a class="sym" href="#prod-AttributeOrOperation">AttributeOrOperation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"stringifier" <a class="sym" href="#prod-StringifierAttributeOrOperation">StringifierAttributeOrOperation</a> <br /> |
|
|
<a class="sym" href="#prod-Attribute">Attribute</a> <br /> |
|
|
<a class="sym" href="#prod-Operation">Operation</a></span></td></tr><tr id="proddef-StringifierAttributeOrOperation"><td><span class="prod-number">[22]</span></td><td><a class="sym" href="#prod-StringifierAttributeOrOperation">StringifierAttributeOrOperation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Attribute">Attribute</a> <br /> |
|
|
<a class="sym" href="#prod-OperationRest">OperationRest</a> <br /> |
|
|
";"</span></td></tr><tr id="proddef-Attribute"><td><span class="prod-number">[23]</span></td><td><a class="sym" href="#prod-Attribute">Attribute</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Inherit">Inherit</a> <a class="sym" href="#prod-ReadOnly">ReadOnly</a> "attribute" <a class="sym" href="#prod-AttributeType">AttributeType</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr><tr id="proddef-ReadOnly"><td><span class="prod-number">[24]</span></td><td><a class="sym" href="#prod-ReadOnly">ReadOnly</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"readonly" <br /> |
|
|
ε</span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates how <a class="dfnref" href="#dfn-attribute">attributes</a>
|
|
can be declared on an <a class="dfnref" href="#dfn-interface">interface</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code"><!--exception InvalidName {
|
|
DOMString reason;
|
|
};
|
|
|
|
exception NoSuchPet { };
|
|
-->interface Animal {
|
|
|
|
<span class="comment">// A simple attribute that can be set to any string value.</span>
|
|
readonly attribute DOMString name;
|
|
|
|
<span class="comment">// An attribute whose value can be assigned to.</span>
|
|
attribute unsigned short age;
|
|
};
|
|
|
|
interface Person : Animal {
|
|
|
|
<span class="comment">// An attribute whose getter behavior is inherited from Animal, and need not be</span>
|
|
<span class="comment">// specified in the description of Person.</span>
|
|
inherit attribute DOMString name<!-- setraises (InvalidName)-->;
|
|
<!--
|
|
<span class='comment'>// An attribute whose value cannot be assigned to, and which can raise an</span>
|
|
<span class='comment'>// exception in some circumstances.</span>
|
|
readonly attribute DOMString petName getraises (NoSuchPet);
|
|
-->};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-operations" class="section">
|
|
<h4>3.3.3. Operations</h4>
|
|
|
|
<p>
|
|
An <dfn id="dfn-operation">operation</dfn> is an <a class="dfnref" href="#dfn-interface-member">interface member</a>
|
|
(matching <span class="sym">"stringifier"</span> <a class="sym" href="#prod-OperationRest">OperationRest</a> or <a class="sym" href="#prod-Operation">Operation</a>)
|
|
that defines a behavior that can be invoked on objects implementing the interface.
|
|
There are three kinds of operation:
|
|
</p>
|
|
<ol>
|
|
<li><a class="dfnref" href="#dfn-regular-operation">regular operations</a>, which
|
|
are those used to declare that objects implementing the
|
|
<a class="dfnref" href="#dfn-interface">interface</a> will have a method with
|
|
the given <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<pre class="syntax"><i>return-type</i> <i>identifier</i>(<i>arguments…</i>);</pre></li>
|
|
<li><a class="dfnref" href="#dfn-special-operation">special operations</a>,
|
|
which are used to declare special behavior on objects
|
|
implementing the interface, such as object indexing and stringification
|
|
<pre class="syntax"><i>special-keywords…</i> <i>return-type</i> <i>identifier</i>(<i>arguments…</i>);
|
|
<i>special-keywords…</i> <i>return-type</i> (<i>arguments…</i>);</pre></li>
|
|
<li><a class="dfnref" href="#dfn-static-operation">static operations</a>,
|
|
which are used to declare operations that are not associated with
|
|
a particular object implementing the interface
|
|
<pre class="syntax">static <i>return-type</i> <i>identifier</i>(<i>arguments…</i>);</pre></li>
|
|
</ol>
|
|
<p>
|
|
If an operation has an identifier but no <span class="sym">static</span>
|
|
keyword, then it declares a <dfn id="dfn-regular-operation">regular operation</dfn>.
|
|
If the operation has one or more
|
|
<a class="dfnref" href="#dfn-special-keyword">special keywords</a>
|
|
used in its declaration (that is, any keyword matching
|
|
<a class="sym" href="#prod-Special">Special</a>, or
|
|
the <code>stringifier</code> keyword),
|
|
then it declares a special operation. A single operation can declare
|
|
both a regular operation and a special operation; see
|
|
<a href="#idl-special-operations">section 3.3.4</a> below
|
|
for details on special operations.
|
|
</p>
|
|
<p>
|
|
If an operation has no identifier,
|
|
then it <span class="rfc2119">MUST</span>
|
|
be declared to be a special operation using one of the
|
|
special keywords.
|
|
</p>
|
|
<p>
|
|
The identifier of a
|
|
<a class="dfnref" href="#dfn-regular-operation">regular operation</a>
|
|
or <a class="dfnref" href="#dfn-static-operation">static operation</a>
|
|
<span class="rfc2119">MUST NOT</span> be the same as the identifier
|
|
of a <a class="dfnref" href="#dfn-constant">constant</a> or
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
defined on the same <a class="dfnref" href="#dfn-interface">interface</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
The identifier can be the same as that of another operation on the
|
|
interface, however. This is how operation overloading is specified.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The <dfn id="dfn-return-type">return type</dfn> of the operation is given
|
|
by the type (matching <a class="sym" href="#prod-ReturnType">ReturnType</a>)
|
|
that appears before the operation’s optional <a class="dfnref" href="#dfn-identifier">identifier</a>.
|
|
A return type of <code id="idl-void">void</code> indicates that the operation returns no value.
|
|
If the return type is a
|
|
<a class="dfnref" href="#dfn-scoped-name">scoped name</a>, then it <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-resolve">resolve</a> to an interface, dictionary or <a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
</p>
|
|
<p>
|
|
An operation’s arguments (matching <a class="sym" href="#prod-ArgumentList">ArgumentList</a>)
|
|
are given between the parentheses in the declaration. Each individual argument is specified
|
|
as a type (matching <a class="sym" href="#prod-Type">Type</a>) followed by an <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
(given by an <a class="sym" href="#prod-identifier">identifier</a> token).
|
|
If the <a class="sym" href="#prod-Type">Type</a> is a scoped name,
|
|
then it <span class="rfc2119">MUST</span> resolve to an interface, <a class="dfnref" href="#dfn-dictionary">dictionary</a>
|
|
or <a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
</p>
|
|
<pre class="syntax"><i>return-type</i> <i>identifier</i>(<i>type</i> <i>identifier</i>, <i>type</i> <i>identifier</i>, …);</pre>
|
|
<p>
|
|
Each argument can be preceded by a list of
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
|
|
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
|
|
which can control how a value passed as the argument will be handled in
|
|
language bindings.
|
|
</p>
|
|
<pre class="syntax"><i>return-type</i> <i>identifier</i>([<em>extended-attributes</em>] <i>type</i> <i>identifier</i>, [<em>extended-attributes</em>] <i>type</i> <i>identifier</i>, …);</pre>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates how <a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
can be declared on an <a class="dfnref" href="#dfn-interface">interface</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dimensions {
|
|
attribute unsigned long width;
|
|
attribute unsigned long height;
|
|
};
|
|
|
|
exception NoPointerDevice { };
|
|
|
|
interface Button {
|
|
|
|
<span class="comment">// An operation that takes no arguments and returns a boolean<!--, and could possibly</span>
|
|
<span class='comment'>// raise an exception-->.</span>
|
|
boolean isMouseOver()<!-- raises (NoPointerDevice)-->;
|
|
|
|
<span class="comment">// Overloaded operations.</span>
|
|
void setDimensions(Dimensions size);
|
|
void setDimensions(unsigned long width, unsigned long height);
|
|
};</code></pre></div></div>
|
|
</div>
|
|
|
|
<p>
|
|
An operation is considered to be a <dfn id="dfn-variadic-operation">variadic operation</dfn>
|
|
if the final argument uses the <code>...</code> token just
|
|
after the argument type. Declaring an operation to be variadic indicates that
|
|
the operation can be invoked with any number of arguments after that final argument.
|
|
Those extra implied formal arguments are of the same type as the final explicit
|
|
argument in the operation declaration. The final argument can also be omitted
|
|
when invoking the operation. An argument <span class="rfc2119">MUST NOT</span>
|
|
be declared with the <code>...</code> token unless it
|
|
is the final argument in the operation’s argument list.
|
|
</p>
|
|
<pre class="syntax"><i>return-type</i> <i>identifier</i>(<i>type</i><em>...</em> <i>identifier</i>);
|
|
<i>return-type</i> <i>identifier</i>(<i>type</i> <i>identifier</i>, <i>type</i><em>...</em> <i>identifier</i>);</pre>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface that has
|
|
two variadic operations:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface IntegerSet {
|
|
readonly attribute unsigned long cardinality;
|
|
|
|
void union(long... ints);
|
|
void intersection(long... ints);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In the ECMAScript binding, variadic operations are implemented by
|
|
functions that can accept the subsequent arguments:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var s = getIntegerSet(); <span class="comment">// Obtain an instance of IntegerSet.</span>
|
|
|
|
s.union(); <span class="comment">// Passing no arguments corresponding to 'ints'.</span>
|
|
s.union(1, 4, 7); <span class="comment">// Passing three arguments corresponding to 'ints'.</span></code></pre></div></div>
|
|
<p>
|
|
A binding for a language that does not support variadic functions
|
|
might specify that an explicit array or list of integers be passed
|
|
to such an operation.
|
|
</p>
|
|
</div>
|
|
|
|
<p>
|
|
An argument is considered to be an <dfn id="dfn-optional-argument">optional argument</dfn>
|
|
if it is declared with the <code>optional</code> keyword.
|
|
The final argument of a <a class="dfnref" href="#dfn-variadic-operation">variadic operation</a>
|
|
is also considered to be an optional argument. Declaring an argument
|
|
to be optional indicates that the argument value can be omitted
|
|
when the operation is invoked. An argument <span class="rfc2119">MUST NOT</span>
|
|
be declared to be optional unless all subsequent arguments to the
|
|
operation are also optional.
|
|
</p>
|
|
<pre class="syntax"><i>return-type</i> <i>identifier</i>(<i>type</i> <i>identifier</i>, optional <i>type</i> <i>identifier</i>);</pre>
|
|
|
|
<p>
|
|
Web IDL operations do not support being called with omitted optional arguments
|
|
unless all subsequent optional arguments are also omitted. Bindings for
|
|
languages that do support function calling in this way will fail such
|
|
calls in a language binding specific manner.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
ECMAScript and Java, the two language for which bindings are specified
|
|
in this document, do not support function calling like this.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with a single <a class="dfnref" href="#dfn-operation">operation</a>
|
|
that can be invoked with two different argument list lengths:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface ColorCreator {
|
|
object createColor(float v1, float v2, float v3, optional float alpha);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
It is equivalent to an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
that has two <a class="dfnref" href="#dfn-overloaded">overloaded</a>
|
|
<a class="dfnref" href="#dfn-operation">operations</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface ColorCreator {
|
|
|
|
object createColor(float v1, float v2, float v3);
|
|
object createColor(float v1, float v2, float v3, float alpha);
|
|
};</code></pre></div></div>
|
|
</div>
|
|
<!--
|
|
<p>
|
|
A <code>raises</code> clause (matching <a class='sym' href='#prod-Raises'>Raises</a>) is used
|
|
to declare the possible <a class='dfnref' href='#dfn-exception'>exceptions</a>
|
|
that can be thrown when invoking the operation.
|
|
Each scoped name in the <code>Raises</code> clause
|
|
<span class='rfc2119'>MUST</span> resolve to an exception.
|
|
</p>
|
|
<pre class='syntax'><i>return-type</i> <i>identifier</i>(<i>arguments</i>…) raises(<i>scoped-name</i>, …);</pre>
|
|
-->
|
|
|
|
<p id="callback-operation-exceptions">
|
|
If an implementation attempts to invoke an
|
|
<a class="dfnref" href="#dfn-operation">operation</a> on a
|
|
<a class="dfnref" href="#dfn-user-object">user object</a> (for example, when a callback object
|
|
has been supplied to the implementation), and that attempt results in an
|
|
exception being thrown, then, unless otherwise specified, that
|
|
exception will be propagated to the user code that caused the
|
|
implementation to invoke the operation. Similarly, if a value
|
|
returned from invoking the operation cannot be converted to
|
|
an IDL type, then any exception resulting from this will also
|
|
be propagated to the user code that resulted in the implementation
|
|
attempting to invoke the operation.
|
|
</p>
|
|
|
|
<p>
|
|
The following extended attributes
|
|
are applicable to operations:
|
|
<a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>,
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>.
|
|
</p>
|
|
<p>
|
|
The following extended attributes are applicable to operation arguments:
|
|
<a class="xattr" href="#AllowAny">[AllowAny]</a>,
|
|
<a class="xattr" href="#Clamp">[Clamp]</a>,
|
|
<a class="xattr" href="#EnforceRange">[EnforceRange]</a>,
|
|
<a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>,
|
|
<a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>,
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>.
|
|
</p>
|
|
|
|
<!--
|
|
<?productions grammar Operation OperationRest Qualifiers Specials Special ReturnType OptionalIdentifier ArgumentList Arguments Argument In Optional Ellipsis Raises?>
|
|
-->
|
|
<table class="grammar"><tr id="proddef-Operation"><td><span class="prod-number">[26]</span></td><td><a class="sym" href="#prod-Operation">Operation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Qualifiers">Qualifiers</a> <a class="sym" href="#prod-OperationRest">OperationRest</a></span></td></tr><tr id="proddef-Qualifiers"><td><span class="prod-number">[27]</span></td><td><a class="sym" href="#prod-Qualifiers">Qualifiers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"static" <br /> |
|
|
<a class="sym" href="#prod-Specials">Specials</a></span></td></tr><tr id="proddef-Specials"><td><span class="prod-number">[28]</span></td><td><a class="sym" href="#prod-Specials">Specials</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Special">Special</a> <a class="sym" href="#prod-Specials">Specials</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-Special"><td><span class="prod-number">[29]</span></td><td><a class="sym" href="#prod-Special">Special</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"getter" <br /> |
|
|
"setter" <br /> |
|
|
"creator" <br /> |
|
|
"deleter" <br /> |
|
|
"legacycaller"</span></td></tr><tr id="proddef-OperationRest"><td><span class="prod-number">[30]</span></td><td><a class="sym" href="#prod-OperationRest">OperationRest</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ReturnType">ReturnType</a> <a class="sym" href="#prod-OptionalIdentifier">OptionalIdentifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")" ";"</span></td></tr><tr id="proddef-OptionalIdentifier"><td><span class="prod-number">[31]</span></td><td><a class="sym" href="#prod-OptionalIdentifier">OptionalIdentifier</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-ArgumentList"><td><span class="prod-number">[32]</span></td><td><a class="sym" href="#prod-ArgumentList">ArgumentList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Argument">Argument</a> <a class="sym" href="#prod-Arguments">Arguments</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-Arguments"><td><span class="prod-number">[33]</span></td><td><a class="sym" href="#prod-Arguments">Arguments</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"," <a class="sym" href="#prod-Argument">Argument</a> <a class="sym" href="#prod-Arguments">Arguments</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-Argument"><td><span class="prod-number">[34]</span></td><td><a class="sym" href="#prod-Argument">Argument</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-Optional">Optional</a> <a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-Ellipsis">Ellipsis</a> <a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="proddef-Optional"><td><span class="prod-number">[35]</span></td><td><a class="sym" href="#prod-Optional">Optional</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"optional" <br /> |
|
|
ε</span></td></tr><tr id="proddef-Ellipsis"><td><span class="prod-number">[36]</span></td><td><a class="sym" href="#prod-Ellipsis">Ellipsis</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"..." <br /> |
|
|
ε</span></td></tr><tr id="proddef-ReturnType"><td><span class="prod-number">[57]</span></td><td><a class="sym" href="#prod-ReturnType">ReturnType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Type">Type</a> <br /> |
|
|
"void"</span></td></tr></table>
|
|
</div>
|
|
|
|
<div id="idl-special-operations" class="section">
|
|
<h4>3.3.4. Special operations</h4>
|
|
|
|
<p>
|
|
A <dfn id="dfn-special-operation">special operation</dfn> is a
|
|
declaration of a certain kind of special behavior on objects implementing
|
|
the interface on which the special operation declarations appear.
|
|
Special operations are declared by using one or more
|
|
<dfn id="dfn-special-keyword">special keywords</dfn>
|
|
in an operation declaration.
|
|
</p>
|
|
<p>
|
|
There are six kinds of special operations. The table below indicates
|
|
for a given kind of special operation what special keyword
|
|
is used to declare it and what the purpose of the special operation is:
|
|
</p>
|
|
<table class="vert">
|
|
<tr>
|
|
<th>Special operation</th>
|
|
<th>Keyword</th>
|
|
<th>Purpose</th>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-getter">Getters</dfn></td>
|
|
<td><code>getter</code></td>
|
|
<td>Defines behavior for when an object is indexed for property retrieval.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-setter">Setters</dfn></td>
|
|
<td><code>setter</code></td>
|
|
<td>Defines behavior for when an object is indexed for property assignment.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-creator">Creators</dfn></td>
|
|
<td><code>creator</code></td>
|
|
<td>Defines behavior for when an object is indexed for property creation.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-deleter">Deleters</dfn></td>
|
|
<td><code>deleter</code></td>
|
|
<td>Defines behavior for when an object is indexed for property deletion.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-legacy-caller">Legacy callers</dfn></td>
|
|
<td><code>legacycaller</code></td>
|
|
<td>Defines behavior for when an object is called as if it were a function.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><dfn id="dfn-stringifier">Stringifiers</dfn></td>
|
|
<td><code>stringifier</code></td>
|
|
<td>Defines how an object is converted into a <a class="idltype" href="#idl-DOMString">DOMString</a>.</td>
|
|
</tr>
|
|
</table>
|
|
<p>
|
|
Not all language bindings support all of the six kinds of special
|
|
object behavior. When special operations are declared using
|
|
operations with no identifier, then in language bindings that do
|
|
not support the particular kind of special operations there simply
|
|
will not be such functionality.
|
|
</p>
|
|
<p>
|
|
Some language bindings, such as ECMAScript, do not distinguish
|
|
assignment to an existing indexed or named property and the creation
|
|
of a new one. Regardless, it is the creator that is invoked when
|
|
an attempt is made to create a new indexed or named property, and
|
|
the setter when the property already exists.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>The following IDL fragment defines an interface with a getter and a setter:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dictionary {
|
|
readonly attribute unsigned long propertyCount;
|
|
|
|
getter float (DOMString propertyName);
|
|
setter void (DOMString propertyName, float propertyValue);
|
|
};</code></pre></div></div>
|
|
<p>In language bindings that do not support property getters and setters,
|
|
objects implementing <span class="idltype">Dictionary</span> will not
|
|
have that special behavior. For example, in the Java language binding,
|
|
the corresponding Java interface will have only a single method,
|
|
<code>long getPropertyCount()</code>.</p>
|
|
</div>
|
|
<!--
|
|
<p>
|
|
<a class='dfnref' href='#dfn-special-operation'>Special operations</a>
|
|
can be declared using an <a class='dfnref' href='#dfn-operation'>operation</a>
|
|
that has an <a class='dfnref' href='#dfn-identifier'>identifier</a>
|
|
and the <code>omittable</code> keyword to indicate that
|
|
in language bindings that do not support that kind of special operation,
|
|
the <a class='dfnref' href='#dfn-regular-operation'>regular operation</a>
|
|
is to be available on the object for use instead. Such operations are
|
|
known as <dfn id='dfn-omittable'>omittable</dfn>.
|
|
</p>
|
|
<div class='example'>
|
|
<p>The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a>
|
|
declares <a class='dfnref' href='#dfn-special-operation'>special operations</a>
|
|
with <a class='dfnref' href='#dfn-identifier'>identifiers</a>
|
|
and using the <code>omittable</code> keyword:</p>
|
|
<x:codeblock language='idl'>interface Dictionary {
|
|
readonly attribute unsigned long propertyCount;
|
|
|
|
omittable getter float getProperty(DOMString propertyName);
|
|
omittable setter void setProperty(DOMString propertyName, float propertyValue);
|
|
};</x:codeblock>
|
|
<p>In language bindings that do not support property getters and setters,
|
|
such as Java,
|
|
objects implementing <span class='idltype'>Dictionary</span> will have
|
|
<span class='idlident'>getProperty</span> and <span class='idlident'>setProperty</span>
|
|
operations available. The corresponding Java interface would be:</p>
|
|
<x:codeblock language='java'>public interface Dictionary {
|
|
|
|
long getPropertyCount();
|
|
float getProperty(String propertyName);
|
|
void setProperty(String propertyName, float propertyValue);
|
|
}</x:codeblock>
|
|
<p>
|
|
These operations will be omitted in language
|
|
bindings that do support property getters and setters, such as
|
|
ECMAScript, however.
|
|
</p>
|
|
<x:codeblock language='es'>var dictionary = getDictionary(); <span class='comment'>// Get an instance of Dictionary.</span>
|
|
|
|
dictionary.getProperty; <span class='comment'>// Actually invokes the property getter with property name "getProperty".</span>
|
|
dictionary.x = 1; <span class='comment'>// Invokes the property setter with property name "x" and value 1.</span></x:codeblock>
|
|
</div>
|
|
-->
|
|
<p>
|
|
Defining a special operation <!--without using the <code>omittable</code> keyword
|
|
on an operation but giving the operation an--> with an <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
is equivalent to separating the special operation out into its own
|
|
declaration without an identifier. This approach is allowed to
|
|
simplify prose descriptions of an interface’s operations.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>The following two interfaces are equivalent:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dictionary {
|
|
readonly attribute unsigned long propertyCount;
|
|
|
|
getter float getProperty(DOMString propertyName);
|
|
setter void setProperty(DOMString propertyName, float propertyValue);
|
|
};</code></pre></div></div>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dictionary {
|
|
readonly attribute unsigned long propertyCount;
|
|
|
|
float getProperty(DOMString propertyName);
|
|
void setProperty(DOMString propertyName, float propertyValue);
|
|
|
|
getter float (DOMString propertyName);
|
|
setter void (DOMString propertyName, float propertyValue);
|
|
};</code></pre></div></div>
|
|
</div>
|
|
<!--
|
|
<p>
|
|
The <code>omittable</code> keyword <span class='rfc2119'>MUST NOT</span>
|
|
appear on an operation that has no identifier.
|
|
</p>
|
|
-->
|
|
<p>
|
|
A given <a class="dfnref" href="#dfn-special-keyword">special keyword</a> <span class="rfc2119">MUST NOT</span>
|
|
appear twice on an operation.
|
|
</p>
|
|
<p>
|
|
Getters, setters, creators and deleters come in two varieties: ones that
|
|
take a <a class="idltype" href="#idl-DOMString">DOMString</a> as a property name,
|
|
known as
|
|
<dfn id="dfn-named-property-getter">named property getters</dfn>,
|
|
<dfn id="dfn-named-property-setter">named property setters</dfn>,
|
|
<dfn id="dfn-named-property-creator">named property creators</dfn> and
|
|
<dfn id="dfn-named-property-deleter">named property deleters</dfn>,
|
|
and ones that take an <a class="idltype" href="#idl-unsigned-long">unsigned long</a>
|
|
as a property index, known as
|
|
<dfn id="dfn-indexed-property-getter">indexed property getters</dfn>,
|
|
<dfn id="dfn-indexed-property-setter">indexed property setters</dfn>,
|
|
<dfn id="dfn-indexed-property-creator">indexed property creators</dfn> and
|
|
<dfn id="dfn-indexed-property-deleter">indexed property deleters</dfn>.
|
|
See <a href="#idl-indexed-properties">section 3.3.4.3</a>
|
|
and <a href="#idl-named-properties">section 3.3.4.4</a>
|
|
for details.
|
|
</p>
|
|
<p>
|
|
On a given <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
there <span class="rfc2119">MUST</span> exist at most one
|
|
stringifier and at most one of each variety of getter, setter,
|
|
creator and deleter. Multiple legacy callers can exist on an interface
|
|
to specify overloaded calling behavior.
|
|
</p>
|
|
<p>
|
|
Special operations declared using operations <span class="rfc2119">MUST NOT</span>
|
|
be <a class="dfnref" href="#dfn-variadic-operation">variadic</a> nor have any
|
|
<a class="dfnref" href="#dfn-optional-argument">optional arguments</a>.
|
|
</p>
|
|
<p>
|
|
If an object implements more than one <a class="dfnref" href="#dfn-interface">interface</a>
|
|
that defines a given special operation, then it is undefined which (if any)
|
|
special operation is invoked for that operation.
|
|
</p>
|
|
|
|
<div id="idl-legacy-callers" class="section">
|
|
<h5>3.3.4.1. Legacy callers</h5>
|
|
|
|
<p>
|
|
When an <a class="dfnref" href="#dfn-interface">interface</a> has one or more
|
|
<a class="dfnref" href="#dfn-legacy-caller">legacy callers</a>, it indicates that objects that implement
|
|
the interface can be called as if they were functions. As mentioned above,
|
|
legacy callers can be specified using an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
declared with the <code>legacycaller</code> keyword.
|
|
</p>
|
|
<pre class="syntax">legacycaller <i>return-type</i> <i>identifier</i>(<i>arguments…</i>);
|
|
legacycaller <i>return-type</i> (<i>arguments…</i>);<!--
|
|
omittable legacycaller <i>return-type</i> <i>identifier</i>(<i>arguments…</i>);--></pre>
|
|
<p>
|
|
If multiple legacy callers are specified on an interface, overload resolution
|
|
is used to determine which legacy caller is invoked when the object is called
|
|
as if it were a function.
|
|
</p>
|
|
<p>
|
|
Specifications <span class="rfc2119">SHOULD NOT</span> use legacy callers unless
|
|
required to specify the behavior of legacy APIs.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with a <a class="dfnref" href="#dfn-legacy-caller">legacy caller</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface NumberQuadrupler {
|
|
<span class="comment">// This operation simply returns four times the given number x.</span>
|
|
legacycaller float compute(float x);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation supporting this interface would
|
|
allow a <a class="dfnref" href="#dfn-platform-object">platform object</a>
|
|
that implements <span class="idltype">NumberQuadrupler</span>
|
|
to be called as a function:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var f = getNumberQuadrupler(); <span class="comment">// Obtain an instance of NumberQuadrupler.</span>
|
|
|
|
f.compute(3); <span class="comment">// This evaluates to 12.</span>
|
|
f(3); <span class="comment">// This also evaluates to 12.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-stringifiers" class="section">
|
|
<h5>3.3.4.2. Stringifiers</h5>
|
|
|
|
<p>
|
|
When an <a class="dfnref" href="#dfn-interface">interface</a> has a
|
|
<a class="dfnref" href="#dfn-stringifier">stringifier</a>, it indicates that objects that implement
|
|
the interface have a non-default conversion to a string. As mentioned above,
|
|
stringifiers can be specified using an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
declared with the <code>stringifier</code> keyword.
|
|
</p>
|
|
<pre class="syntax">stringifier DOMString <i>identifier</i>();
|
|
stringifier DOMString ();<!--
|
|
omittable stringifier DOMString <i>identifier</i>();--></pre>
|
|
<p>
|
|
If an operation used to declare a stringifier does not have an
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>, then prose
|
|
accompanying the interface <span class="rfc2119">MUST</span> define
|
|
the <dfn id="dfn-stringification-behavior">stringification behavior</dfn>
|
|
of the interface. If the operation does have an identifier,
|
|
then the object is converted to a string by invoking the
|
|
operation to obtain the string.
|
|
</p>
|
|
<p>
|
|
Stringifiers declared with operations <span class="rfc2119">MUST</span>
|
|
be declared to take zero arguments and return a <a class="idltype" href="#idl-DOMString">DOMString</a>.
|
|
</p>
|
|
<p>
|
|
As a shorthand, if the <code>stringifier</code> keyword
|
|
is declared using an operation with no identifier, then the
|
|
operation’s <a class="dfnref" href="#dfn-return-type">return type</a> and
|
|
argument list can be omitted.
|
|
</p>
|
|
<pre class="syntax">stringifier;</pre>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>The following two interfaces are equivalent:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
stringifier DOMString ();
|
|
};</code></pre></div></div>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
stringifier;
|
|
};</code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
The <code>stringifier</code> keyword
|
|
can also be placed on an <a class="dfnref" href="#dfn-attribute">attribute</a>.
|
|
In this case, the string to convert the object to is the
|
|
value of the attribute. The <code>stringifier</code> keyword
|
|
<span class="rfc2119">MUST NOT</span> be placed on an attribute unless
|
|
it is declared to be of type <a class="idltype" href="#idl-DOMString">DOMString</a>.
|
|
</p>
|
|
<pre class="syntax">stringifier attribute DOMString <i>identifier</i>;</pre>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines an interface that will stringify to the value of its
|
|
<a class="idlattr">name</a> attribute:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Constructor]
|
|
interface Student {
|
|
attribute unsigned long id;
|
|
stringifier attribute DOMString name;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In the ECMAScript binding, using a <span class="idltype">Student</span>
|
|
object in a context where a string is expected will result in the
|
|
value of the object’s “name” property being
|
|
used:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var s = new Student();
|
|
s.id = 12345678;
|
|
s.name = '周杰倫';
|
|
|
|
var greeting = 'Hello, ' + s + '!'; <span class="comment">// Now greeting == 'Hello, 周杰倫!'.</span></code></pre></div></div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines an interface that has custom stringification behavior that is
|
|
not specified in the IDL itself.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Constructor]
|
|
interface Student {
|
|
attribute unsigned long id;
|
|
attribute DOMString? familyName;
|
|
attribute DOMString givenName;
|
|
|
|
stringifier DOMString ();
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Thus, prose is required to explain the stringification behavior, such
|
|
as the following paragraph:
|
|
</p>
|
|
<blockquote>
|
|
<p>
|
|
Objects that implement the <span class="idltype">Student</span>
|
|
interface must stringify as follows. If the value of the
|
|
<span class="idlattr">familyName</span> attribute is
|
|
<span class="idlvalue">null</span>, the stringification of the
|
|
object is the value of the <span class="idlattr">givenName</span>
|
|
attribute. Otherwise, if the value of the
|
|
<span class="idlattr">familyName</span> attribute is not <span class="idlvalue">null</span>,
|
|
the stringification of the object is the concatenation of the
|
|
value of the <span class="idlattr">givenName</span> attribute,
|
|
a single space character, and the value of
|
|
the <span class="idlattr">familyName</span> attribute.
|
|
</p>
|
|
</blockquote>
|
|
<p>
|
|
An ECMAScript implementation of the IDL would behave as follows:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var s = new Student();
|
|
s.id = 12345679;
|
|
s.familyName = 'Smithee';
|
|
s.givenName = 'Alan';
|
|
|
|
var greeting = 'Hi ' + s; <span class="comment">// Now greeting == 'Hi Alan Smithee'.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-indexed-properties" class="section">
|
|
<h5>3.3.4.3. Indexed properties</h5>
|
|
|
|
<p>
|
|
An <a class="dfnref" href="#dfn-interface">interface</a> that defines
|
|
an <a class="dfnref" href="#dfn-indexed-property-getter">indexed property getter</a>,
|
|
<a class="dfnref" href="#dfn-indexed-property-setter">indexed property setter</a>,
|
|
<a class="dfnref" href="#dfn-indexed-property-creator">indexed property creator</a>
|
|
and/or an <a class="dfnref" href="#dfn-indexed-property-deleter">indexed property deleter</a>
|
|
is said to <dfn id="dfn-support-indexed-properties">support indexed properties</dfn>.
|
|
</p>
|
|
<p>
|
|
If an interface <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed properties</a>,
|
|
then the interface definition <span class="rfc2119">MUST</span> be accompanied by
|
|
a description of what indices the object can be indexed with at
|
|
any given time. These indices are called the <dfn id="dfn-supported-property-indices">supported property indices</dfn>.
|
|
</p>
|
|
<p>
|
|
Indexed property getters and deleters <span class="rfc2119">MUST</span>
|
|
be declared to take a single <a class="idltype" href="#idl-unsigned-long">unsigned long</a> argument.
|
|
Indexed property setters and creators <span class="rfc2119">MUST</span>
|
|
be declared to take two arguments, where the first is an <a class="idltype" href="#idl-unsigned-long">unsigned long</a>.
|
|
</p>
|
|
<pre class="syntax">getter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>);
|
|
setter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
creator <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
deleter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>);
|
|
|
|
getter <i>type</i> (unsigned long <i>identifier</i>);
|
|
setter <i>type</i> (unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
creator <i>type</i> (unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
deleter <i>type</i> (unsigned long <i>identifier</i>);<!--
|
|
|
|
omittable getter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>);
|
|
omittable setter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
omittable creator <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
omittable deleter <i>type</i> <i>identifier</i>(unsigned long <i>identifier</i>);--></pre>
|
|
<p>
|
|
The following requirements apply to the definitions of indexed property getters, setters, creators and deleters:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If an <a class="dfnref" href="#dfn-indexed-property-getter">indexed property getter</a> was specified using an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
with an <a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
then the value returned when indexing the object with a given index
|
|
is the value that would be returned by invoking the operation, passing
|
|
the index as its only argument. If the operation used to declare the indexed property getter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-determine-the-value-of-an-indexed-property">determine the value of an indexed property</dfn>
|
|
for a given index.
|
|
</li>
|
|
<li>
|
|
If an <a class="dfnref" href="#dfn-indexed-property-setter">indexed property setter</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property assignment with a given property index and value
|
|
is the same as if the operation is invoked, passing
|
|
the index as the first argument and the value as the second argument. If the operation used to declare the indexed property setter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-set-the-value-of-an-existing-indexed-property">set the value of an existing indexed property</dfn>
|
|
for a given property index and value.
|
|
</li>
|
|
<li>
|
|
If an <a class="dfnref" href="#dfn-indexed-property-creator">indexed property creator</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property creation with a given property index and value
|
|
is the same as if the operation is invoked, passing
|
|
the index as the first argument and the value as the second argument. If the operation used to declare the indexed property creator
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-set-the-value-of-a-new-indexed-property">set the value of a new indexed property</dfn>
|
|
for a given property index and value.
|
|
</li>
|
|
<li>
|
|
If an <a class="dfnref" href="#dfn-indexed-property-deleter">indexed property deleter</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property deletion with a given property index
|
|
is the same as if the operation is invoked, passing
|
|
the index as the only argument. If the operation used to declare the indexed property deleter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-delete-an-existing-indexed-property">delete an existing indexed property</dfn>
|
|
for a given property index.
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface
|
|
<span class="idltype">OrderedMap</span> which allows
|
|
retrieving and setting values by name or by index number:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface OrderedMap {
|
|
readonly attribute unsigned long size;
|
|
|
|
getter any getByIndex(unsigned long index);
|
|
setter void setByIndex(unsigned long index, any value);
|
|
deleter void removeByIndex(unsigned long index);
|
|
|
|
getter any get(DOMString name);
|
|
setter creator void set(DOMString name, any value);
|
|
deleter void remove(DOMString name);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Since all of the special operations are declared using
|
|
operations with identifiers, the only additional prose
|
|
that is necessary is that which describes what keys those sets
|
|
have. Assuming that the <code>get()</code> operation is
|
|
defined to return <span class="idlvalue">null</span> if an
|
|
attempt is made to look up a non-existing entry in the
|
|
<span class="idltype">OrderedMap</span>, then the following
|
|
two sentences would suffice:
|
|
</p>
|
|
<blockquote>
|
|
<p>
|
|
An object <var>map</var> implementing <span class="idltype">OrderedMap</span>
|
|
supports indexed properties with indices in the range
|
|
0 ≤ <var>index</var> < <code>map.size</code>.
|
|
</p>
|
|
<p>
|
|
Such objects also support a named property for every name that,
|
|
if passed to <code>get()</code>, would return a non-null value.
|
|
</p>
|
|
</blockquote>
|
|
<p>
|
|
As described in <a href="#es-platform-objects">section 4.7</a>,
|
|
an ECMAScript implementation would create
|
|
properties on a <a class="dfnref" href="#dfn-platform-object">platform object</a> implementing
|
|
<span class="idltype">OrderedMap</span> that correspond to
|
|
entries in both the named and indexed property sets.
|
|
These properties can then be used to interact
|
|
with the object in the same way as invoking the object’s
|
|
methods, as demonstrated below:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// Assume map is a platform object implementing the OrderedMap interface.</span>
|
|
var map = getOrderedMap();
|
|
var x, y;
|
|
|
|
x = map[0]; <span class="comment">// If map.length > 0, then this is equivalent to:
|
|
//
|
|
// x = map.getByIndex(0)
|
|
//
|
|
// since a property named "0" will have been placed on map.
|
|
// Otherwise, x will be set to undefined, since there will be
|
|
// no property named "0" on map.</span>
|
|
|
|
map[1] = false; <span class="comment">// If map.length > 1, then this will set the property named
|
|
// "1" on map to false, and then will do the equivalent of:
|
|
//
|
|
// map.setByIndex(1, false)
|
|
//
|
|
// Otherwise, if map.length ≤ 1, then it will set the
|
|
// property but have no other effect (since an indexed property creator
|
|
// was not specified).</span>
|
|
|
|
y = map.apple; <span class="comment">// If there exists a named property named "apple", then this
|
|
// will be equivalent to:
|
|
//
|
|
// y = map.get('apple')
|
|
//
|
|
// since a property named "apple" will have been placed on
|
|
// map. Otherwise, y will be set to undefined, since there
|
|
// will be no property named "apple" on map.</span>
|
|
|
|
map.berry = 123; <span class="comment">// Regardless of whether there exists a named property named
|
|
// "berry", this will set the "berry" property to 123, and
|
|
// then do the equivalent of:
|
|
//
|
|
// map.set('berry', 123)</span>
|
|
|
|
delete map.cake; <span class="comment">// If a named property named "cake" exists, then the "cake"
|
|
// property will be deleted, and then the equivalent to the
|
|
// following will be performed:
|
|
//
|
|
// map.remove("cake")</span>
|
|
</code></pre></div></div></div>
|
|
</div>
|
|
|
|
<div id="idl-named-properties" class="section">
|
|
<h5>3.3.4.4. Named properties</h5>
|
|
|
|
<p>
|
|
An <a class="dfnref" href="#dfn-interface">interface</a> that defines
|
|
a <a class="dfnref" href="#dfn-named-property-getter">named property getter</a>,
|
|
<a class="dfnref" href="#dfn-named-property-setter">named property setter</a>,
|
|
<a class="dfnref" href="#dfn-named-property-creator">named property creator</a>
|
|
and/or a <a class="dfnref" href="#dfn-named-property-deleter">named property deleter</a>
|
|
is said to <dfn id="dfn-support-named-properties">support named properties</dfn>.
|
|
</p>
|
|
<p>
|
|
If an interface <a class="dfnref" href="#dfn-support-named-properties">supports named properties</a>,
|
|
then the interface definition <span class="rfc2119">MUST</span> be accompanied by
|
|
a description of the ordered set of names that can be used to index the object
|
|
at any given time. These names are called the
|
|
<dfn id="dfn-supported-property-names">supported property names</dfn>.
|
|
</p>
|
|
<p>
|
|
Named property getters and deleters <span class="rfc2119">MUST</span>
|
|
be declared to take a single <a class="idltype" href="#idl-DOMString">DOMString</a> argument.
|
|
Named property setters and creators <span class="rfc2119">MUST</span>
|
|
be declared to take two arguments, where the first is a <a class="idltype" href="#idl-DOMString">DOMString</a>.
|
|
</p>
|
|
<pre class="syntax">getter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>);
|
|
setter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
creator <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
deleter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>);
|
|
|
|
getter <i>type</i> (DOMString <i>identifier</i>);
|
|
setter <i>type</i> (DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
creator <i>type</i> (DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
deleter <i>type</i> (DOMString <i>identifier</i>);<!--
|
|
|
|
omittable getter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>);
|
|
omittable setter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
omittable creator <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>, <i>type</i> <i>identifier</i>);
|
|
omittable deleter <i>type</i> <i>identifier</i>(DOMString <i>identifier</i>);--></pre>
|
|
<p>
|
|
The following requirements apply to the definitions of named property getters, setters, creators and deleters:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If a <a class="dfnref" href="#dfn-named-property-getter">named property getter</a> was specified using an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
with an <a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
then the value returned when indexing the object with a given name
|
|
is the value that would be returned by invoking the operation, passing
|
|
the name as its only argument. If the operation used to declare the named property getter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-determine-the-value-of-a-named-property">determine the value of a named property</dfn>
|
|
for a given property name.
|
|
</li>
|
|
<li>
|
|
If a <a class="dfnref" href="#dfn-named-property-setter">named property setter</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property assignment with a given property name and value
|
|
is the same as if the operation is invoked, passing
|
|
the name as the first argument and the value as the second argument. If the operation used to declare the named property setter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-set-the-value-of-an-existing-named-property">set the value of an existing named property</dfn>
|
|
for a given property name and value.
|
|
</li>
|
|
<li>
|
|
If a <a class="dfnref" href="#dfn-named-property-creator">named property creator</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property creation with a given property name and value
|
|
is the same as if the operation is invoked, passing
|
|
the name as the first argument and the value as the second argument. If the operation used to declare the named property creator
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-set-the-value-of-a-new-named-property">set the value of a new named property</dfn>
|
|
for a given property name and value.
|
|
</li>
|
|
<li>
|
|
If a <a class="dfnref" href="#dfn-named-property-deleter">named property deleter</a> was specified using an operation
|
|
with an identifier,
|
|
then the behavior that occurs when indexing the object for property deletion with a given property name
|
|
is the same as if the operation is invoked, passing
|
|
the name as the only argument. If the operation used to declare the named property deleter
|
|
did not have an identifier, then the interface definition must be accompanied
|
|
by a description of how to <dfn id="dfn-delete-an-existing-named-property">delete an existing named property</dfn>
|
|
for a given property name.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-static-operations" class="section">
|
|
<h4>3.3.5. Static operations</h4>
|
|
|
|
<p>
|
|
A <dfn id="dfn-static-operation">static operation</dfn> is one that is
|
|
not called on a particular instance of the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which it is declared, and is instead associated with the interface
|
|
itself. Static operations are declared by using the
|
|
<code>static</code> keyword in an operation
|
|
declaration.
|
|
</p>
|
|
<p>
|
|
It is language binding specific whether it is possible to invoke
|
|
a static operation through a reference to an instance of the
|
|
interface.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface
|
|
<span class="idltype">Circle</span> that has a static
|
|
operation declared on it:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Point { /* ... */ };
|
|
|
|
interface Circle {
|
|
attribute float cx;
|
|
attribute float cy;
|
|
attribute float radius;
|
|
|
|
static Point triangulate(Circle c1, Circle c2, Circle c3);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In the ECMAScript language binding, the <span class="estype">Function</span> object for
|
|
<code>triangulate</code> will exist on the <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
for <span class="idltype">Circle</span>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var circles = getCircles(); <span class="comment">// an Array of Circle objects</span>
|
|
|
|
typeof Circle.triangulate; <span class="comment">// Evaluates to "function"</span>
|
|
Circle.prototype.triangulate; <span class="comment">// Evaluates to undefined</span>
|
|
circles[0].triangulate; <span class="comment">// Also evaluates to undefined</span>
|
|
|
|
<span class="comment">// Call the static operation</span>
|
|
var triangulationPoint = Circle.triangulate(circles[0], circles[1], circles[2]);</code></pre></div></div>
|
|
<p>
|
|
In the Java language binding, however, the <code>triangulate</code> method
|
|
will exist on an abstract class:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">Circle[] circles = getCircles(); <span class="comment">// an array of Circle objects</span>
|
|
|
|
<span class="comment">// Call the static operation</span>
|
|
Point triangulationPoint = CircleUtils.triangulate(circles[0], circles[1], circles[2]);</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-overloading" class="section">
|
|
<h4>3.3.6. Overloading</h4>
|
|
|
|
<p>
|
|
If a <a class="dfnref" href="#dfn-regular-operation">regular operation</a>
|
|
or <a class="dfnref" href="#dfn-static-operation">static operation</a>
|
|
defined on an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
has an <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
that is the same as the identifier of another operation on that
|
|
interface of the same kind (regular or static), then the operation is said to be
|
|
<dfn id="dfn-overloaded">overloaded</dfn>. When the identifier
|
|
of an overloaded operation is used to invoke one of the
|
|
operations on an object that implements the interface, the
|
|
number and types of the arguments passed to the operation
|
|
determine which of the overloaded operations is actually
|
|
invoked. If an interface has multiple
|
|
<a class="dfnref" href="#dfn-legacy-caller">legacy callers</a> defined on it,
|
|
then those legacy callers are also said to be overloaded.
|
|
In the ECMAScript language binding, <a href="#Constructor">constructors</a>
|
|
can be overloaded too. There are some restrictions on the arguments
|
|
that overloaded operations, legacy callers and constructors can be
|
|
specified to take, and in order to describe these restrictions,
|
|
the notion of an <em>effective overload set</em> is used.
|
|
</p>
|
|
<p>
|
|
An <dfn id="dfn-effective-overload-set">effective overload set</dfn>
|
|
for a given
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
argument count,
|
|
<a class="dfnref" href="#dfn-interface">interface</a> and
|
|
target language binding represents
|
|
the allowable invocations in that language binding
|
|
of operations or constructors
|
|
(specified with <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
and <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>)
|
|
that have the specified identifier on that interface. The
|
|
set is used to determine whether there are ambiguities in the
|
|
overloaded operations or constructors specified on the interface.
|
|
The effective overload set is stated to be
|
|
“for regular operations”, “for static operations”, “for constructors” or “for legacy callers”,
|
|
to distinguish between these four uses. Effective overload sets for
|
|
legacy callers do not use an identifier; only an argument count,
|
|
interface and target language binding are needed.
|
|
</p>
|
|
<p>
|
|
The elements of an effective overload set are triples of the form
|
|
<<var>f</var>, <var>types</var>, <var>any</var>>. If the effective overload
|
|
set is for regular operations, static operations or legacy callers, then <var>f</var> is an operation,
|
|
and if it is for constructors, then <var>f</var> is an
|
|
extended attribute. In either case, <var>types</var> is a list
|
|
of IDL types and <var>any</var> is a list of boolean values.
|
|
Each triple represents an allowable invocation of the operation,
|
|
constructor or legacy caller with an argument value list of the given types.
|
|
<var>any</var> specifies whether a particular argument has been
|
|
annotated with the <a class="xattr" href="#AllowAny">[AllowAny]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
Due to the use of <a class="dfnref" href="#dfn-optional-argument">optional arguments</a>
|
|
and <a class="dfnref" href="#dfn-variadic-operation">variadic operations</a>
|
|
and constructors, there may
|
|
be multiple entries in an effective overload set identifying
|
|
the same operation or constructor.
|
|
</p>
|
|
<p>
|
|
The effective overload set for identifier <var>A</var>,
|
|
argument count <var>N</var>,
|
|
interface <var>I</var> and a given target language binding
|
|
is derived as follows. Whenever an argument of an extended
|
|
attribute is mentioned, it is referring to an argument of the
|
|
extended attribute’s <a class="dfnref" href="#dfn-xattr-named-argument-list">named argument list</a>.
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>S</var> to ∅.</li>
|
|
<li>Let <var>F</var> be a set with elements as follows, according to the kind of effective overload set:
|
|
<dl class="switch">
|
|
<dt>For regular operations</dt>
|
|
<dd>
|
|
The elements of <var>F</var> are the <a class="dfnref" href="#dfn-regular-operation">regular operations</a> with
|
|
identifier <var>A</var> defined on interface <var>I</var>.
|
|
</dd>
|
|
<dt>For static operations</dt>
|
|
<dd>
|
|
The elements of <var>F</var> are the <a class="dfnref" href="#dfn-static-operation">static operations</a> with
|
|
identifier <var>A</var> defined on interface <var>I</var>.
|
|
</dd>
|
|
<dt>For constructors</dt>
|
|
<dd>
|
|
The elements of <var>F</var> are the
|
|
<a class="sym" href="#NamedConstructor">[NamedConstructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> on interface <var>I</var> whose
|
|
<a class="dfnref" href="#dfn-xattr-named-argument-list">named argument lists’</a>
|
|
identifiers are <var>A</var>. If <var>A</var> is the same as the identifier of
|
|
interface <var>I</var>, then <var>F</var> also includes the
|
|
<a class="sym" href="#Constructor">[Constructor]</a> extended
|
|
attributes on <var>I</var>.
|
|
</dd>
|
|
<dt>For legacy callers</dt>
|
|
<dd>
|
|
The elements of <var>F</var> are the <a class="dfnref" href="#dfn-legacy-caller">callers</a>
|
|
defined on interface <var>I</var>.
|
|
</dd>
|
|
</dl>
|
|
</li>
|
|
<!--
|
|
<li>If the effective overload set is for regular operations, then:
|
|
<ol>
|
|
<li>
|
|
If the target language binding supports object indexing,
|
|
then remove from <var>F</var> any operation that is declared
|
|
to be an <a class='dfnref' href='#dfn-omittable'>omittable</a>
|
|
<a class='dfnref' href='#dfn-getter'>getter</a>,
|
|
<a class='dfnref' href='#dfn-setter'>setter</a>,
|
|
<a class='dfnref' href='#dfn-creator'>creator</a> or
|
|
<a class='dfnref' href='#dfn-deleter'>deleter</a>.
|
|
</li>
|
|
<li>
|
|
If the target language binding supports object calling,
|
|
then remove from <var>F</var> any operation that is declared
|
|
to be an omittable <a class='dfnref' href='#dfn-legacy-caller'>caller</a>.
|
|
</li>
|
|
<li>
|
|
If the target language binding supports object stringification,
|
|
then remove from <var>F</var> any operation that is declared
|
|
to be an omittable <a class='dfnref' href='#dfn-stringifier'>stringifier</a>.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
-->
|
|
<li>Let <var>maxarg</var> be the maximum number of arguments the operations or constructor extended attributes in <var>F</var> are declared to take.</li>
|
|
<li>Let <var>m</var> be the maximum of <var>maxarg</var> and <var>N</var>.</li>
|
|
<li>For each operation or extended attribute <var>X</var> in <var>F</var>:
|
|
<ol class="algorithm">
|
|
<li>Let <var>n</var> be the number of arguments <var>X</var> is declared to take.</li>
|
|
<li>Let <var>t</var><sub>0..<var>n</var>−1</sub> be the types of the arguments <var>X</var> is defined to take.</li>
|
|
<li>Let <var>a</var><sub>0..<var>n</var>−1</sub> be boolean values indicating whether each argument <var>X</var> is defined to take is declared with the <a class="xattr" href="#AllowAny">[AllowAny]</a> extended attribute.</li>
|
|
<li>Add to <var>S</var> the triple <<var>X</var>, <var>t</var><sub>0..<var>n</var>−1</sub>, <var>a</var><sub>0..<var>n</var>−1</sub>>.</li>
|
|
<li>If <var>n</var> > 0 and <var>X</var> is declared to be <a class="dfnref" href="#dfn-variadic-operation">variadic</a>, then:
|
|
<ol class="algorithm">
|
|
<li>Add to <var>S</var> the triple <<var>X</var>, <var>t</var><sub>0..<var>n</var>−2</sub>, <var>a</var><sub>0..<var>n</var>−2</sub>>.</li>
|
|
<li>For every integer <var>i</var>, such that <var>n</var> ≤ <var>i</var> ≤ <var>m</var>−1:
|
|
<ol class="algorithm">
|
|
<li>Let <var>u</var><sub>0..<var>i</var></sub> be a list of types, where <var>u</var><sub>j</sub> = <var>t</var><sub>j</sub> (for <var>j</var> < <var>n</var>) and <var>u</var><sub>j</sub> = <var>t</var><sub><var>n</var>−1</sub> (for <var>j</var> ≥ <var>n</var>).</li>
|
|
<li>Let <var>b</var><sub>0..<var>i</var></sub> be a list of booleans, where <var>b</var><sub>j</sub> = <var>a</var><sub>j</sub> (for <var>j</var> < <var>n</var>) and <var>b</var><sub>j</sub> = <var>a</var><sub><var>n</var>−1</sub> (for <var>j</var> ≥ <var>n</var>).</li>
|
|
<li>Add to <var>S</var> the triple <<var>X</var>, <var>u</var><sub>0..<var>i</var></sub>, <var>b</var><sub>0..<var>i</var></sub>>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>For every integer <var>i</var>, such that 0 < <var>i</var> < <var>n</var>:
|
|
<ol class="algorithm">
|
|
<li>If argument <var>i</var> of <var>X</var> is <a class="dfnref" href="#dfn-optional-argument">optional</a>, then add to <var>S</var> the triple <<var>X</var>, <var>t</var><sub>0..<var>i−1</var></sub>, <var>a</var><sub>0..<var>i−1</var></sub>>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>n</var> > 0 and the first argument of <var>X</var> is optional, then add to <var>S</var> the triple <<var>X</var>, (), ()> (where “()” represents the empty list).</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
The effective overload set for identifier <var>A</var> and interface <var>X</var> is <var>S</var>.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
For each pair of entries in an
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
at least one of the following <span class="rfc2119">MUST</span> be true:
|
|
</p>
|
|
<ul>
|
|
<li>the type list lengths of the two entries are different, or</li>
|
|
<li>there is an index <var>i</var> such that the types in the two type lists at index <var>i</var> are <a class="dfnref" href="#dfn-distinguishable">distinguishable</a>.</li>
|
|
</ul>
|
|
<p>
|
|
Two types are
|
|
<dfn id="dfn-distinguishable">distinguishable</dfn> if there is
|
|
a “●” mark in the corresponding entry in the following table:
|
|
</p>
|
|
<table id="distinguishable-table" class="matrix">
|
|
<tr>
|
|
<th class="corner"></th>
|
|
<th>primitive</th>
|
|
<th>primitive?</th>
|
|
<th>DOMString</th>
|
|
<th>DOMString?</th>
|
|
<th>interface</th>
|
|
<th>interface?</th>
|
|
<th>object</th>
|
|
<th>object?</th>
|
|
<th>dictionary</th>
|
|
<th>dictionary?</th>
|
|
<th>sequence<<var>T</var>></th>
|
|
<th>sequence<<var>T</var>>?</th>
|
|
<th><var>T</var>[]</th>
|
|
<th><var>T</var>[]?</th>
|
|
<th>Date</th>
|
|
<th>Date?</th>
|
|
</tr>
|
|
<tr>
|
|
<th>primitive</th>
|
|
<td></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
</tr>
|
|
<tr>
|
|
<th>primitive?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>DOMString</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
</tr>
|
|
<tr>
|
|
<th>DOMString?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>interface</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td>● <a class="note-link" href="#distinguishable-interface-note">[1]</a></td>
|
|
<td>● <a class="note-link" href="#distinguishable-interface-note">[1]</a></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
<td>●</td>
|
|
</tr>
|
|
<tr>
|
|
<th>interface?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td>● <a class="note-link" href="#distinguishable-interface-note">[1]</a></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
<td>●</td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>object</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>object?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>dictionary</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>dictionary?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>sequence<<var>T</var>></th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>sequence<<var>T</var>>?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th><var>T</var>[]</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th><var>T</var>[]?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Date</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Date?</th>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td class="belowdiagonal"></td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
<ul class="notes">
|
|
<li id="distinguishable-interface-note"><a class="note-link">[1]</a> Two <a href="#idl-interface">interface types</a> are distinguishable only if two different <a class="dfnref" href="#dfn-interface">interfaces</a> are identified.</li>
|
|
</ul>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
These restrictions on argument types reduce
|
|
the possibility of resolution ambiguity in
|
|
<a class="dfnref" href="#dfn-overloaded">overloaded</a> operations
|
|
and constructors, but do not completely
|
|
eliminate it. In the ECMAScript language binding, the
|
|
restrictions still can result in overloaded operation and constructor invocations
|
|
that cannot be distinguished solely based on the values passed to
|
|
the corresponding function. For example, with the following
|
|
<a class="dfnref" href="#dfn-interface">interfaces</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
|
|
interface B {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
|
|
interface C {
|
|
void f(A? x);
|
|
void f(B? x);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
it is possible to pass an object that implements both <span class="idltype">A</span>
|
|
and <span class="idltype">B</span> to <code>f</code>. Similarly,
|
|
passing <span class="esvalue">null</span> to <code>f</code>
|
|
would also be ambiguous. Since the ECMAScript
|
|
language binding provides no way to disambiguate such calls,
|
|
the interface description will need to
|
|
describe which operation is invoked in these cases. (It is
|
|
acceptable not to describe this if there is no observable
|
|
difference in behavior for a particular choice of operation
|
|
or constructor to disambiguate the call, or if no object will
|
|
actually implement the two interfaces, for example.)
|
|
</p>
|
|
</div>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
For the following interface:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
/* f1 */ void f(DOMString a);
|
|
/* f2 */ void f([AllowAny] DOMString a, DOMString b, float... c);
|
|
/* f3 */ void f();
|
|
/* f4 */ void f(long a, DOMString b, optional DOMString c, float... d);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
the <a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for identifier <code>f</code> with argument count 4 (for the
|
|
ECMAScript language binding) is:
|
|
</p>
|
|
<div class="set">
|
|
{ <f1, (DOMString), (false)>,<br />
|
|
<f2, (DOMString, DOMString), (true, false)>,<br />
|
|
<f2, (DOMString, DOMString, float), (true, false, false)>,<br />
|
|
<f2, (DOMString, DOMString, float, float), (true, false, false, false)>,<br />
|
|
<f3, (), ()>,<br />
|
|
<f4, (long, DOMString), (false, false)>,<br />
|
|
<f4, (long, DOMString, DOMString), (false, false)>,<br />
|
|
<f4, (long, DOMString, DOMString, float), (false, false, false, false)> }
|
|
</div>
|
|
<p>
|
|
There are thus no overloaded operation resolution ambiguities
|
|
for the interface.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-dictionaries" class="section">
|
|
<h3>3.4. Dictionaries</h3>
|
|
|
|
<p>
|
|
A <dfn id="dfn-dictionary">dictionary</dfn> is a definition (matching
|
|
<a class="sym" href="#prod-Dictionary">Dictionary</a>)
|
|
used to define an associative array data type with a fixed, ordered set of key–value pairs,
|
|
termed <dfn id="dfn-dictionary-member">dictionary members</dfn>,
|
|
where keys are strings and values are of a particular type specified in the definition.
|
|
</p>
|
|
<pre class="syntax">dictionary <i>identifier</i> {
|
|
<i>dictionary-members…</i>
|
|
};</pre>
|
|
<p>
|
|
A dictionary can be defined to <dfn id="dfn-inherit-dictionary">inherit</dfn> from another dictionary.
|
|
If the identifier of the dictionary is followed by a colon and a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>,
|
|
then that scoped name identifies the inherited dictionary. The scoped name
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-resolve">resolve</a> to
|
|
a dictionary.
|
|
</p>
|
|
<p>
|
|
A dictionary <span class="rfc2119">MUST NOT</span> be declared such that
|
|
its inheritance hierarchy has a cycle. That is, an interface
|
|
<var>A</var> cannot inherit from itself, nor can it inherit from another
|
|
interface <var>B</var> that inherits from <var>A</var>, and so on.
|
|
</p>
|
|
<pre class="syntax">dictionary <em>Base</em> {
|
|
<i>dictionary-members…</i>
|
|
};
|
|
|
|
dictionary <i>Derived</i> : <em>Base</em> {
|
|
<i>dictionary-members…</i>
|
|
};</pre>
|
|
<p>
|
|
The <dfn id="dfn-inherited-dictionaries">inherited dictionaries</dfn> of
|
|
a given dictionary <var>D</var> is the set of all dictionaries that <var>D</var>
|
|
inherits from, directly or indirectly. If <var>D</var> does not <a class="dfnref" href="#dfn-inherit-dictionary">inherit</a>
|
|
from another dictionary, then the set is empty. Otherwise, the set
|
|
includes the dictionary <var>E</var> that <var>D</var> <a class="dfnref" href="#dfn-inherit-dictionary">inherits</a>
|
|
from and all of <var>E</var>’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>.
|
|
</p>
|
|
<p>
|
|
A dictionary value of type <var>D</var> can have key–value pairs corresponding
|
|
to the dictionary members defined on <var>D</var> and on any of <var>D</var>’s
|
|
<a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>.
|
|
On a given dictionary value, the presence of each dictionary member is optional.
|
|
When specified in the dictionary value, a dictionary member is said to be
|
|
<dfn id="dfn-present">present</dfn>, otherwise it is <a class="dfnref" href="#dfn-present">not present</a>.
|
|
Dictionary members can also optionally have a <dfn id="dfn-default-value">default value</dfn>, which is
|
|
the value the dictionary member is to be considered to have when not present.
|
|
</p>
|
|
<p>
|
|
Each <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> (matching
|
|
<a class="sym" href="#prod-DictionaryMember">DictionaryMember</a>) is specified
|
|
as a type (matching <a class="sym" href="#prod-Type">Type</a>) followed by an
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
(given by an <a class="sym" href="#prod-identifier">identifier</a> token following
|
|
the type). The identifier is the key name of the key–value pair.
|
|
If the <a class="sym" href="#prod-Type">Type</a>
|
|
is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>, then it
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-resolve">resolve</a> to an
|
|
interface, dictionary or <a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
</p>
|
|
<pre class="syntax">dictionary <i>identifier</i> {
|
|
<i>type</i> <i>identifier</i>;
|
|
};</pre>
|
|
<p>
|
|
If the identifier is followed by a <span class="char">U+003D EQUALS SIGN ("=")</span>
|
|
and a value (matching <a class="sym" href="#prod-ConstValue">ConstValue</a>),
|
|
then that gives the dictionary member its <a class="dfnref" href="#dfn-default-value">default value</a>,
|
|
in the same way that a <a class="dfnref" href="#dfn-constant">constant</a> is
|
|
given its value.
|
|
</p>
|
|
<pre class="syntax">dictionary <i>identifier</i> {
|
|
<i>type</i> <i>identifier</i> = <i>value</i>;
|
|
};</pre>
|
|
<p>
|
|
The order of the <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>
|
|
on a given dictionary is the order in which they appear in the dictionary
|
|
<a class="dfnref" href="#dfn-definition">definition</a>, and
|
|
with inherited dictionary members ordered before non-inherited members.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>For example, with the following definitions:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">dictionary B : A {
|
|
long a;
|
|
long b;
|
|
};
|
|
|
|
dictionary A {
|
|
long c;
|
|
long d;
|
|
};
|
|
|
|
dictionary C : B {
|
|
long e;
|
|
long f;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
the order of the <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>
|
|
of a dictionary value of type <span class="idltype">C</span> is
|
|
c, d, a, b, e, f.
|
|
</p>
|
|
<p>
|
|
Dictionaries are required to have their members ordered because
|
|
in some language bindings the behavior observed when passing
|
|
a dictionary value to a platform object depends on the order
|
|
the dictionary members are fetched. For example, consider the
|
|
following additional interface:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Something {
|
|
void f(A a);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
and this ECMAScript code:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var something = getSomething(); <span class="comment">// Get an instance of Something.</span>
|
|
var x = 0;
|
|
|
|
var dict = { };
|
|
Object.defineProperty(dict, "d", { get: function() { return ++x; } });
|
|
Object.defineProperty(dict, "c", { get: function() { return ++x; } });
|
|
|
|
something.f(dict);</code></pre></div></div>
|
|
<p>
|
|
The order that the dictionary members are fetched in determines
|
|
what values they will be taken to have. Since the order for
|
|
<span class="idltype">A</span> is defined to be c then d,
|
|
the value for c will be 1 and the value for d will be 2.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The identifier of a dictionary member <span class="rfc2119">MUST NOT</span> be
|
|
the same as that of another dictionary member defined on the dictionary or
|
|
on that dictionary’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>.
|
|
</p>
|
|
<p>
|
|
Dictionaries <span class="rfc2119">MUST NOT</span> be used as the type of an
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
<a class="dfnref" href="#dfn-constant">constant</a> or
|
|
<a class="dfnref" href="#dfn-exception-field">exception field</a>.
|
|
</p>
|
|
<p>
|
|
No <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification are applicable to dictionaries.
|
|
</p>
|
|
<p>
|
|
The following extended attributes are applicable to dictionary members:
|
|
<a class="xattr" href="#Clamp">[Clamp]</a>,
|
|
<a class="xattr" href="#EnforceRange">[EnforceRange]</a>.
|
|
</p>
|
|
<table class="grammar"><tr id="proddef-Dictionary"><td><span class="prod-number">[10]</span></td><td><a class="sym" href="#prod-Dictionary">Dictionary</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"dictionary" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-DictionaryMembers">DictionaryMembers</a> "}" ";"</span></td></tr><tr id="proddef-DictionaryMembers"><td><span class="prod-number">[11]</span></td><td><a class="sym" href="#prod-DictionaryMembers">DictionaryMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-DictionaryMember">DictionaryMember</a> <a class="sym" href="#prod-DictionaryMembers">DictionaryMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-DictionaryMember"><td><span class="prod-number">[12]</span></td><td><a class="sym" href="#prod-DictionaryMember">DictionaryMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-DefaultValue">DefaultValue</a> ";"</span></td></tr><tr id="proddef-DefaultValue"><td><span class="prod-number">[13]</span></td><td><a class="sym" href="#prod-DefaultValue">DefaultValue</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"=" <a class="sym" href="#prod-ConstValue">ConstValue</a> <br /> |
|
|
ε</span></td></tr></table>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
One use of dictionary types is to allow a number of optional arguments to
|
|
an <a class="dfnref" href="#dfn-operation">operation</a> without being
|
|
constrained as to the order they are specified at the call site. For example,
|
|
consider the following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Constructor]
|
|
interface Point {
|
|
attribute float x;
|
|
attribute float y;
|
|
};
|
|
|
|
dictionary PaintOptions {
|
|
DOMString? fillPattern = "black";
|
|
DOMString? strokePattern = null;
|
|
Point position;
|
|
};
|
|
|
|
interface GraphicsContext {
|
|
void drawRectangle(float width, float height, optional PaintOptions options);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the IDL, an <span class="estype">Object</span>
|
|
can be passed in for the optional <span class="idltype">PaintOptions</span> dictionary:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// Get an instance of GraphicsContext.</span>
|
|
var ctx = getGraphicsContext();
|
|
|
|
<span class="comment">// Draw a rectangle.</span>
|
|
ctx.drawRectangle(300, 200, { fillPattern: "red", position: new Point(10, 10) });</code></pre></div></div>
|
|
<p>
|
|
Both fillPattern and strokePattern are given <a class="dfnref" href="#dfn-default-value">default values</a>,
|
|
so if they are omitted, the definition of drawRectangle can assume that they
|
|
have the given default values and not include explicit wording to handle
|
|
their non-presence.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-exceptions" class="section">
|
|
<h3>3.5. Exceptions</h3>
|
|
|
|
<p>
|
|
An <dfn id="dfn-exception">exception</dfn> is a definition (matching
|
|
<a class="sym" href="#prod-Exception">Exception</a>) used
|
|
to declare a class of exceptions that can be thrown by implementations.
|
|
</p>
|
|
<pre class="syntax">exception <i>identifier</i> {
|
|
<i>exception-members…</i>
|
|
};</pre>
|
|
<p>
|
|
Exceptions are different from <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
in that they can have only <a class="dfnref" href="#dfn-constant">constants</a>
|
|
and <a class="dfnref" href="#dfn-exception-field">exception fields</a>
|
|
declared on them (together known as <dfn id="dfn-exception-member">exception members</dfn>),
|
|
rather than the three types of <a class="dfnref" href="#dfn-interface-member">interface members</a>.
|
|
</p>
|
|
<p>
|
|
An exception can be defined to <dfn id="dfn-inherit-exception">inherit</dfn> from another exception.
|
|
If the identifier of the exception is followed by a <span class="char">U+003A COLON (":")</span>
|
|
character and a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>,
|
|
then that scoped name identifies the inherited exception. The scoped name
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-resolve">resolve</a> to
|
|
an exception.
|
|
</p>
|
|
<p>
|
|
An exception <span class="rfc2119">MUST NOT</span> be declared such that
|
|
its inheritance hierarchy has a cycle. That is, an interface
|
|
<var>A</var> cannot inherit from itself, nor can it inherit from another
|
|
interface <var>B</var> that inherits from <var>A</var>, and so on.
|
|
</p>
|
|
<p>
|
|
An object that implements an exception that inherits from another
|
|
also implements that inherited exception. The object therefore will also
|
|
have members that correspond to the
|
|
exception members from the inherited exception.
|
|
</p>
|
|
<pre class="syntax">exception <em>Base</em> {
|
|
<i>exception-members…</i>
|
|
};
|
|
|
|
exception <i>Derived</i> : <em>Base</em> {
|
|
<i>exception-members…</i>
|
|
};</pre>
|
|
<p>
|
|
Exceptions have an associated <dfn id="dfn-exception-message">message</dfn>, a
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a>, which is
|
|
exposed on an exception object in a language binding-specific manner.
|
|
</p>
|
|
<p>
|
|
Exceptions also have an associated <dfn id="dfn-exception-type">type</dfn>, also
|
|
a <a class="idltype" href="#idl-DOMString">DOMString</a>, which is
|
|
exposed on an exception object in a language binding-specific manner.
|
|
The <a class="dfnref" href="#dfn-exception-type">type</a> of an exception
|
|
is intended to be used to distinguish between the different kinds of
|
|
exceptions that can be represented by the given IDL exception.
|
|
</p>
|
|
<p>
|
|
Exceptions can be <dfn id="dfn-throw">thrown</dfn>, optionally with a specific
|
|
<a class="dfnref" href="#dfn-exception-message">message</a> and
|
|
<a class="dfnref" href="#dfn-exception-type">type</a>,
|
|
the behavior of which again is language binding-specific.
|
|
</p>
|
|
<p>
|
|
Each <dfn id="dfn-exception-field">exception field</dfn> (matching
|
|
<a class="sym" href="#prod-ExceptionField">ExceptionField</a>) is specified
|
|
as a type (matching <a class="sym" href="#prod-Type">Type</a>) followed by an
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
(given by an <a class="sym" href="#prod-identifier">identifier</a> token following
|
|
the type). If the <a class="sym" href="#prod-Type">Type</a>
|
|
is a <a class="dfnref" href="#dfn-scoped-name">scoped name</a>, then it
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-resolve">resolve</a> to an
|
|
interface or <a class="dfnref" href="#dfn-typedef">typedef</a>.
|
|
Exception fields are
|
|
similar to <a class="dfnref" href="#dfn-attribute">attributes</a> in that they
|
|
will correspond to attributes of the same name and type on exception objects
|
|
that are thrown by implementations.
|
|
</p>
|
|
<pre class="syntax">exception <i>identifier</i> {
|
|
<i>type</i> <i>identifier</i>;
|
|
};</pre>
|
|
<p>
|
|
The identifier of an exception field <span class="rfc2119">MUST NOT</span> be
|
|
the same as that of another <a class="dfnref" href="#dfn-exception-member">exception member</a>,
|
|
and it <span class="rfc2119">MUST NOT</span> be “name” or “message”.
|
|
</p>
|
|
<p>
|
|
Each exception member can be preceded by a list of <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> (matching
|
|
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>),
|
|
which can control how the exception member will be handled in language bindings.
|
|
</p>
|
|
<pre class="syntax">exception <i>identifier</i> {
|
|
|
|
[<em>extended-attributes</em>]
|
|
const <i>type</i> <i>identifier</i> = <i>value</i>;
|
|
|
|
[<em>extended-attributes</em>]
|
|
<i>type</i> <i>identifier</i>;
|
|
};</pre>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
It is recommended that future Web platform specifications not
|
|
mint new IDL <a class="dfnref" href="#dfn-exception">exceptions</a> but instead just use <span class="estype">DOMException</span>
|
|
and distinguish different kinds of exceptions by their
|
|
<a class="dfnref" href="#dfn-exception-type">type</a> and
|
|
not by an integer code. The type will be exposed in ECMAScript using a “name” property on the
|
|
exception object. (It may however be useful to mint new IDL exceptions
|
|
if additional <a class="dfnref" href="#dfn-exception-field">exception fields</a>
|
|
are required.)
|
|
</p>
|
|
<p>
|
|
It is recommended that exception names be chosen that use a similar
|
|
naming scheme as the built-in ECMAScript error objects. For example,
|
|
“HierarchyRequestError” or “NotFoundError”, if names are being given
|
|
to the DOM Core exceptions. Any new IDL exceptions should also be named similarly.
|
|
</p>
|
|
<p>
|
|
There is no IDL syntax for declaring exception types. In prose, an
|
|
exception of a particular type can be thrown by using wording like the
|
|
following:
|
|
</p>
|
|
<blockquote>Throw a <span class="estype">DOMException</span> of type
|
|
<a class="dfnref" href="#dfn-exception-type">type</a>
|
|
HierarchyRequestError with <a class="dfnref" href="#dfn-exception-message">message</a>
|
|
“Cannot append that Node here”.</blockquote>
|
|
</div>
|
|
<p>
|
|
The following extended attributes are applicable to exceptions:
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>.
|
|
</p>
|
|
<p>
|
|
No <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification are applicable to exception fields.
|
|
</p>
|
|
<table class="grammar"><tr id="proddef-Exception"><td><span class="prod-number">[14]</span></td><td><a class="sym" href="#prod-Exception">Exception</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"exception" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-ExceptionMembers">ExceptionMembers</a> "}" ";"</span></td></tr><tr id="proddef-ExceptionMembers"><td><span class="prod-number">[15]</span></td><td><a class="sym" href="#prod-ExceptionMembers">ExceptionMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-ExceptionMember">ExceptionMember</a> <a class="sym" href="#prod-ExceptionMembers">ExceptionMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-ExceptionMember"><td><span class="prod-number">[37]</span></td><td><a class="sym" href="#prod-ExceptionMember">ExceptionMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Const">Const</a> <br /> |
|
|
<a class="sym" href="#prod-ExceptionField">ExceptionField</a></span></td></tr><tr id="proddef-ExceptionField"><td><span class="prod-number">[38]</span></td><td><a class="sym" href="#prod-ExceptionField">ExceptionField</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AttributeType">AttributeType</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr></table>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following example demonstrates how a reduced version of DOM Core’s
|
|
<span class="idltype">DOMException</span> might be defined for three
|
|
of the existing exception types and one new type. Exception types
|
|
have historically been distinguished only by an integer code. The new
|
|
exception type here is not.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">exception DOMException {
|
|
const unsigned short INDEX_SIZE_ERR = 1;
|
|
const unsigned short DOMSTRING_SIZE_ERR = 2;
|
|
const unsigned short HIERARCHY_REQUEST_ERR = 3;
|
|
|
|
unsigned short code;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Assume that the specification defines that throwing a <span class="estype">DOMException</span>
|
|
of a particular type uses a corresponding value for the
|
|
code field, as follows:
|
|
</p>
|
|
<table>
|
|
<tr><th>Type</th><th>Value of code</th></tr>
|
|
<tr><td>IndexSizeError</td><td>INDEX_SIZE_ERR</td></tr>
|
|
<tr><td>DOMStringSizeError</td><td>DOMSTRING_SIZE_ERR</td></tr>
|
|
<tr><td>HierarchyRequestError</td><td>HIERARCHY_REQUEST_ERR</td></tr>
|
|
<tr><td>InsufficientBlingError</td><td>0</td></tr>
|
|
</table>
|
|
<p>
|
|
In an ECMAScript implementation, the types of <span class="idltype">DOMException</span>s
|
|
could be distinguished by code, and the existing ones and the new ones could
|
|
be distinguished by type:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">try {
|
|
document.appendChild(document);
|
|
} catch (e) {
|
|
<span class="comment">// The traditional way, by looking at the code.</span>
|
|
if (e.code == DOMException.HIERARCHY_REQUEST_ERR) {
|
|
...
|
|
}
|
|
|
|
<span class="comment">// By looking at the name.</span>
|
|
if (e.name == "HierarchyRequestError") {
|
|
...
|
|
}
|
|
if (e.name == "InsufficientBlingError") {
|
|
e.code; <span class="comment">// This would evaluate to 0.</span>
|
|
...
|
|
}
|
|
}</code></pre></div></div>
|
|
<!--
|
|
<p>
|
|
The advantage of looking at the name rather than code is that exception
|
|
names are much less likely to conflict across specifications. Exception
|
|
codes do conflict already. For example, if a
|
|
<span class='idltype'>DOMException</span> or an <span class='idltype'>SVGException</span>
|
|
could be thrown inside the one <code>try</code> block, authors would
|
|
need to check both the code and the interface of the exception object
|
|
to be sure of what kind of exception was thrown.
|
|
</p>
|
|
-->
|
|
<p>
|
|
Note that using <code>e instanceof <var>ExceptionClass</var></code>
|
|
can return <code>false</code> if the exception object comes from a
|
|
different document than the global scope of the running script, even if
|
|
the exception is an instance of the <var>ExceptionClass</var> in
|
|
its own document. For this reason, authors are suggested not to use
|
|
<code>instanceof</code> to perform exception type testing.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-typedefs" class="section">
|
|
<h3>3.6. Typedefs</h3>
|
|
|
|
<p>
|
|
A <dfn id="dfn-typedef">typedef</dfn> is a definition (matching
|
|
<a class="sym" href="#prod-Typedef">Typedef</a>)
|
|
used to declare a new name for a type. This new name is not exposed
|
|
by language bindings; it is purely used as a shorthand for referencing
|
|
the type in the IDL.
|
|
</p>
|
|
<pre class="syntax">typedef <i>type</i> <i>identifier</i>;</pre>
|
|
<p>
|
|
The type being given a new name is specified after the <code>typedef</code>
|
|
keyword (matching <a class="sym" href="#prod-Type">Type</a>), and the
|
|
<a class="sym" href="#prod-identifier">identifier</a> token following the
|
|
type gives the name.
|
|
</p>
|
|
<p>
|
|
The <a class="sym" href="#prod-Type">Type</a> <span class="rfc2119">MUST NOT</span>
|
|
be a <a class="dfnref" href="#dfn-scoped-name">scoped name</a> that
|
|
<a class="dfnref" href="#dfn-resolve">resolves</a> to an
|
|
<a class="dfnref" href="#dfn-interface">interface</a> or
|
|
<a class="dfnref" href="#dfn-dictionary">dictionary</a>.
|
|
</p>
|
|
<p>
|
|
No <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification are applicable to <a class="dfnref" href="#dfn-typedef">typedefs</a>.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-Typedef"><td><span class="prod-number">[16]</span></td><td><a class="sym" href="#prod-Typedef">Typedef</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"typedef" <a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
demonstrates the use of <a class="dfnref" href="#dfn-typedef">typedefs</a>
|
|
to allow the use of a short
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> instead of a long
|
|
<a class="dfnref" href="#dfn-scoped-name">scoped name</a> or
|
|
<a href="#idl-sequence">sequence type</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">module gfx {
|
|
module geom {
|
|
module geom2d {
|
|
|
|
interface Point {
|
|
attribute float x;
|
|
attribute float y;
|
|
};
|
|
|
|
typedef sequence<Point> PointSequence;
|
|
|
|
interface Rect {
|
|
attribute Point topleft;
|
|
attribute Point bottomright;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
module gui {
|
|
|
|
typedef gfx::geom::geom2d::Point Point;
|
|
typedef gfx::geom::geom2d::PointSequence PointSequence;
|
|
typedef gfx::geom::geom2d::Rect Rect;
|
|
|
|
interface Widget {
|
|
|
|
readonly attribute Rect bounds;
|
|
|
|
boolean pointWithinBounds(Point p);
|
|
boolean allPointsWithinBounds(PointSequence ps);
|
|
};
|
|
};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-implements-statements" class="section">
|
|
<h3>3.7. Implements statements</h3>
|
|
|
|
<p>
|
|
An <dfn id="dfn-implements-statement">implements statement</dfn> is a definition
|
|
(matching <a class="sym" href="#prod-ImplementsStatement">ImplementsStatement</a>)
|
|
used to declare that all objects implementing an interface <var>A</var>
|
|
(identified by the first <a class="dfnref" href="#dfn-scoped-name">scoped name</a>)
|
|
<span class="rfc2119">MUST</span> additionally implement interface <var>B</var>
|
|
(identified by the second scoped name), including all other interfaces that
|
|
<var>B</var> inherits from.
|
|
</p>
|
|
<pre class="syntax"><i>scoped-name-A</i> implements <i>scoped-name-B</i>;</pre>
|
|
<p>
|
|
Transitively, if objects implementing <var>B</var>
|
|
are declared with an <a class="dfnref" href="#dfn-implements-statement">implements statement</a>
|
|
to additionally implement interface <var>C</var>, then all objects implementing
|
|
<var>A</var> do additionally implement interface <var>C</var>.
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-implements-statement">Implements statements</a>
|
|
can appear in a <a class="dfnref" href="#dfn-module">module</a>
|
|
or at the <a class="dfnref" href="#dfn-outermost-scope">outermost scope</a>.
|
|
</p>
|
|
<p>
|
|
The two <a class="dfnref" href="#dfn-scoped-name">scoped names</a> <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-resolve">resolve</a> to two different interfaces.
|
|
</p>
|
|
<p>
|
|
The interface identified on the left-hand side of an implements statement
|
|
<span class="rfc2119">MUST NOT</span> <a class="dfnref" href="#dfn-inherit">inherit</a>
|
|
from the interface identifier on the right-hand side, and vice versa.
|
|
</p>
|
|
<p>
|
|
If each <a class="dfnref" href="#dfn-implements-statement">implements statement</a> is
|
|
considered to be an edge in a directed graph, from a node representing the interface
|
|
on the left-hand side of the statement to a node representing the interface on the
|
|
right-hand side, then this graph <span class="rfc2119">MUST NOT</span> have any cycles.
|
|
</p>
|
|
<p>
|
|
Interfaces that a given object implements are partitioned into those that are considered
|
|
<dfn id="dfn-supplemental-interface">supplemental interfaces</dfn> and those that are not.
|
|
An interface <var>A</var> is considered to be a
|
|
<a class="dfnref" href="#dfn-supplemental-interface">supplemental interface</a> of an object
|
|
<var>O</var> if:
|
|
</p>
|
|
<ul>
|
|
<li><var>O</var> implements a different interface <var>B</var>, and the IDL states that
|
|
<code>B implements A</code>; or</li>
|
|
<li><var>O</var> implements a different <a class="dfnref" href="#dfn-supplemental-interface">supplemental interface</a>
|
|
<var>C</var>, and <var>C</var> <a class="dfnref" href="#dfn-inherit">inherits</a> from <var>A</var>.</li>
|
|
</ul>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Specification authors are discouraged from writing <a class="dfnref" href="#dfn-implements-statement">implements statements</a>
|
|
where the <a class="dfnref" href="#dfn-interface">interface</a> on the left-hand side
|
|
is a <a class="dfnref" href="#dfn-supplemental-interface">supplemental interface</a>.
|
|
For example, if author 1 writes:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Window { ... };
|
|
interface SomeFunctionality { ... };
|
|
Window implements SomeFunctionality;</code></pre></div></div>
|
|
<p>
|
|
and author 2 later writes:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Gizmo { ... };
|
|
interface MoreFunctionality { ... };
|
|
SomeFunctionality implements MoreFunctionality;
|
|
Gizmo implements SomeFunctionality;</code></pre></div></div>
|
|
<p>
|
|
then it might be the case that author 2 is unaware of exactly which
|
|
interfaces already are used on the left-hand side of an
|
|
<code>implements SomeFunctionality</code> statement, and so has
|
|
required more object implement <span class="idltype">MoreFunctionality</span>
|
|
than he or she expected.
|
|
</p>
|
|
<p>
|
|
Better in this case would be for author 2 to write:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Gizmo { ... };
|
|
interface MoreFunctionality { ... };
|
|
Gizmo implements SomeFunctionality;
|
|
Gizmo implements MoreFunctionality;</code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
The <dfn id="dfn-consequential-interfaces">consequential interfaces</dfn> of an interface
|
|
<var>A</var> are:
|
|
</p>
|
|
<ul>
|
|
<li>each interface <var>B</var> where the IDL states <code>A implements B</code>;</li>
|
|
<li>each interface that a consequential interface of <var>A</var> inherits from; and</li>
|
|
<li>each interface <var>D</var> where the IDL states that <code>C implements D</code>,
|
|
where <var>C</var> is a consequential interface of <var>A</var>.</li>
|
|
</ul>
|
|
<p>
|
|
For a given interface, there <span class="rfc2119">MUST NOT</span>
|
|
be any member defined on any of its consequential interfaces
|
|
whose identifier is the same as any other member defined on any
|
|
of those consequential interfaces or on the original interface itself.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>For example, that precludes the following:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A { attribute long x; };
|
|
interface B { attribute long x; };
|
|
A implements B; <span class="comment">// B::x would clash with A::x</span>
|
|
|
|
interface C { attribute long y; };
|
|
interface D { attribute long y; };
|
|
interface E : D { };
|
|
C implements E; <span class="comment">// D::y would clash with C::y</span>
|
|
|
|
interface F { };
|
|
interface H { attribute long z; };
|
|
interface I { attribute long z; };
|
|
F implements H;
|
|
F implements I; <span class="comment">// H::z and I::z would clash when mixed in to F</span></code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
No <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification are applicable to
|
|
<a class="dfnref" href="#dfn-implements-statement">implements statements</a>.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-ImplementsStatement"><td><span class="prod-number">[17]</span></td><td><a class="sym" href="#prod-ImplementsStatement">ImplementsStatement</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ScopedName">ScopedName</a> "implements" <a class="sym" href="#prod-ScopedName">ScopedName</a> ";"</span></td></tr></table>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines two <a class="dfnref" href="#dfn-interface">interfaces</a>, stating
|
|
that one interface is always implemented on objects implementing the other.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">module dom {
|
|
interface Node {
|
|
readonly attribute unsigned short nodeType;
|
|
<span class="comment">// ...</span>
|
|
};
|
|
};
|
|
|
|
module events {
|
|
|
|
interface EventTarget {
|
|
void addEventListener(DOMString type,
|
|
EventListener listener,
|
|
boolean useCapture);
|
|
<span class="comment">// ...</span>
|
|
};
|
|
|
|
dom::Node implements EventTarget;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation would thus have an “addEventListener”
|
|
property in the prototype chain of every <span class="idltype">Node</span>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var n = getNode(); <span class="comment">// Obtain an instance of Node.</span>
|
|
typeof n.addEventListener; <span class="comment">// Evaluates to "function".</span></code></pre></div></div>
|
|
<p>
|
|
Similarly, in Java, any <span class="javatype">Node</span>
|
|
object could be cast to <span class="javatype">EventTarget</span>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">Node n = getNode(); <span class="comment">// Obtain an instance of Node.</span>
|
|
EventTarget et = (EventTarget) n; <span class="comment">// This should never throw ClassCastException.</span></code></pre></div></div>
|
|
<p>
|
|
Note that it is not the case that all <span class="idltype">EventTarget</span>
|
|
objects implement <span class="idltype">Node</span>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-objects" class="section">
|
|
<h3>3.8. Objects implementing interfaces</h3>
|
|
|
|
<p>
|
|
In systems described by <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>,
|
|
each object that implements one or more <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
is considered to be either a <dfn id="dfn-platform-object">platform object</dfn> or a
|
|
<dfn id="dfn-user-object">user object</dfn>. Platform objects are those which are
|
|
created and supplied by an implementation of those IDL fragments. In a browser, for example,
|
|
the browser-implemented DOM objects (implementing interfaces such as <span class="idltype">Node</span> and
|
|
<span class="idltype">Document</span>) that provide access to a web page’s contents
|
|
to ECMAScript running in the page would be platform objects. An ECMAScript library
|
|
that adds support for some Web API that is not natively supported by a browser
|
|
would also be considered to expose platform objects. Exception objects too are
|
|
considered to be platform objects.
|
|
</p>
|
|
<p>
|
|
On the other hand, user objects are those that authors would create, implementing
|
|
particular interfaces that the Web APIs use to be able to invoke author-defined
|
|
operations or to send and receive values to the author’s program through
|
|
manipulating the object’s attributes. In a web page, an ECMAScript object
|
|
that implements the <span class="idltype">EventListener</span> interface, which is
|
|
used to register a callback that the DOM Events implementation invokes, would be considered
|
|
to be a user object. There is no way for a user object to represent an exception.
|
|
</p>
|
|
<p>
|
|
In IDL, the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
is used to annotate <a class="dfnref" href="#dfn-interface">interfaces</a> that
|
|
can be implemented as user objects. These interfaces may or may not also be
|
|
implemented as platform objects.
|
|
</p>
|
|
<p>
|
|
Only interfaces with all of the following characteristics can be implemented
|
|
as user objects:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
The interface has a
|
|
<a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
on it.
|
|
</li>
|
|
<li>
|
|
The interface does not <a class="dfnref" href="#dfn-inherit">inherit</a>
|
|
from any non-<a class="xattr" href="#Callback">[Callback]</a>-annotated interface.
|
|
</li>
|
|
<li>
|
|
The interface and all of its <a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>
|
|
do not have any <a class="dfnref" href="#dfn-consequential-interfaces">consequential interfaces</a>.
|
|
</li>
|
|
<li>
|
|
The interface does not have a
|
|
<a class="xattr" href="#Constructor">[Constructor]</a> or
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attribute on it.
|
|
</li>
|
|
<li>
|
|
The interface has no <a class="dfnref" href="#dfn-special-operation">special operations</a>.
|
|
</li>
|
|
<li>
|
|
No <a class="dfnref" href="#dfn-attribute">attribute</a> on the interface has a
|
|
<a class="xattr" href="#PutForwards">[PutForwards]</a>,
|
|
<a class="xattr" href="#Replaceable">[Replaceable]</a>,
|
|
<a class="xattr" href="#TreatNullAs">[TreatNullAs]</a> or
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
extended attribute on it.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
When a user object is passed to a platform object expecting an object of a
|
|
particular interface, be it as an argument value in an operation invocation,
|
|
by assignment to an attribute, or through a dictionary member, and that
|
|
interface was not declared using the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>, then
|
|
the object will not be considered to be one that implements that interface.
|
|
Language bindings define when this check is made and what happens
|
|
in response in such a case (such as throwing an exception).
|
|
</p>
|
|
</div>
|
|
|
|
<!--
|
|
<div id='idl-valuetypes' class='section'>
|
|
<h3>Valuetypes</h3>
|
|
|
|
<p>
|
|
Valuetypes in OMG IDL are used to define types similar to structs in C.
|
|
That is, they define composite types that can have zero or more
|
|
member variables that are passed by value. OMG IDL valuetypes have the
|
|
additional feature of allowing <span class='idlvalue'>null</span> to
|
|
be passed in place of an object with those member variables. An
|
|
OMG IDL boxed valuetype is a special case, where the valuetype has
|
|
a single member.
|
|
</p>
|
|
<p>
|
|
The IDL defined in this specification supports only
|
|
<dfn id='dfn-boxed-valuetype'>boxed valuetypes</dfn>, which are definitions
|
|
that match the <a class='sym' href='#prod-Valuetype'>Valuetype</a> non-terminal.
|
|
The <a class='dfnref' href='#dfn-identifier'>identifier</a> of the valuetype
|
|
is given by the <a class='sym' href='#prod-identifier'>identifier</a> terminal,
|
|
and the type being boxed is given by the
|
|
<a class='sym' href='#prod-BoxedType'>BoxedType</a> non-terminal. If the
|
|
<a class='sym' href='#prod-BoxedType'>BoxedType</a> is a
|
|
<a class='sym' href='#prod-ScopedName'>ScopedName</a>, then it
|
|
<span class='rfc2119'>MUST</span> refer to a type that does not allow
|
|
<span class='idlvalue'>null</span> as a value (i.e.,
|
|
<a class='idltype' href='#idl-boolean'>boolean</a>,
|
|
<a class='idltype' href='#idl-octet'>octet</a>,
|
|
<a class='idltype' href='#idl-short'>short</a>,
|
|
<a class='idltype' href='#idl-unsigned-short'>unsigned short</a>,
|
|
<a class='idltype' href='#idl-unsigned-long'>unsigned long</a>,
|
|
<a class='idltype' href='#idl-long-long'>long long</a>,
|
|
<a class='idltype' href='#idl-unsigned-long-long'>unsigned long long</a>,
|
|
<a class='idltype' href='#idl-float'>float</a>,
|
|
<a class='idltype' href='#idl-double'>double</a> or
|
|
<a class='idltype' href='#idl-sequence'>sequence<<var>T</var>></a>.
|
|
</p>
|
|
<p>
|
|
Boxed valuetypes are essentially used just for allowing a <span class='idlvalue'>null</span>
|
|
value to be used where normally a non-null value could only be used.
|
|
</p>
|
|
|
|
<div class='example'>
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a>
|
|
demonstrates the use of <a class='dfnref' href='#dfn-boxed-valuetype'>boxed valuetypes</a>:
|
|
</p>
|
|
<x:codeblock language='idl'>valuetype OptionalFloat float;
|
|
|
|
interface Person {
|
|
|
|
<span class='comment'>// This attribute can be a float or null. In this case, null might be used</span>
|
|
<span class='comment'>// to represent the case where the height of the person is unknown.</span>
|
|
readonly attribute OptionalFloat height;
|
|
};</x:codeblock>
|
|
</div>
|
|
|
|
<?productions grammar Valuetype ValuetypeRest?>
|
|
</div>
|
|
-->
|
|
|
|
<div id="idl-types" class="section">
|
|
<h3>3.9. Types</h3>
|
|
|
|
<p>
|
|
This section lists the types supported by Web IDL, the set of values
|
|
corresponding to each type, and how <a class="dfnref" href="#dfn-constant">constants</a>
|
|
of that type are represented.
|
|
</p>
|
|
<p>
|
|
The following types are known as <dfn id="dfn-integer-type">integer types</dfn>:
|
|
<a class="idltype" href="#idl-byte">byte</a>,
|
|
<a class="idltype" href="#idl-octet">octet</a>,
|
|
<a class="idltype" href="#idl-short">short</a>,
|
|
<a class="idltype" href="#idl-unsigned-short">unsigned short</a>,
|
|
<a class="idltype" href="#idl-long">long</a>,
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a>,
|
|
<a class="idltype" href="#idl-long-long">long long</a> and
|
|
<a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a>.
|
|
</p>
|
|
<p>
|
|
The following types are known as <dfn id="dfn-primitive-type">primitive types</dfn>:
|
|
<a class="idltype" href="#idl-boolean">boolean</a>,
|
|
the <a class="dfnref" href="#dfn-integer-type">integer types</a>,
|
|
<a class="idltype" href="#idl-float">float</a> and
|
|
<a class="idltype" href="#idl-float">double</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="idltype" href="#idl-object">object</a> type and
|
|
all <a class="dfnref" href="#idl-interface">interface types</a>
|
|
are known as <dfn id="dfn-object-type">object types</dfn>.
|
|
</p>
|
|
<p>
|
|
Every type has a <dfn id="dfn-type-name">type name</dfn>, which
|
|
is a string, not necessarily unique, that identifies the type.
|
|
Each sub-section below defines what the type name is for each
|
|
type.
|
|
</p>
|
|
<p id="type-conversion-exceptions">
|
|
When conversions are made from language binding specific types to
|
|
IDL types in order to invoke an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
or assign a value to an <a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
all conversions necessary will be performed before the
|
|
specified functionality of the operation or attribute assignment
|
|
is carried out. If the conversion cannot
|
|
be performed, then the operation will not run or
|
|
the attribute will not be updated. In some language bindings,
|
|
type conversions could result in an exception being thrown.
|
|
In such cases, these exceptions will be propagated to the
|
|
code that made the attempt to invoke the operation or
|
|
assign to the attribute.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-Type"><td><span class="prod-number">[46]</span></td><td><a class="sym" href="#prod-Type">Type</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AttributeType">AttributeType</a> <br /> |
|
|
<a class="sym" href="#prod-SequenceType">SequenceType</a></span></td></tr><tr id="proddef-SequenceType"><td><span class="prod-number">[47]</span></td><td><a class="sym" href="#prod-SequenceType">SequenceType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"sequence" "<" <a class="sym" href="#prod-Type">Type</a> ">" <a class="sym" href="#prod-Null">Null</a></span></td></tr><tr id="proddef-AttributeType"><td><span class="prod-number">[48]</span></td><td><a class="sym" href="#prod-AttributeType">AttributeType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-PrimitiveOrStringType">PrimitiveOrStringType</a> <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
<a class="sym" href="#prod-ScopedName">ScopedName</a> <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"object" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"Date" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"any" <a class="sym" href="#prod-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a></span></td></tr><tr id="proddef-ConstType"><td><span class="prod-number">[49]</span></td><td><a class="sym" href="#prod-ConstType">ConstType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-PrimitiveOrStringType">PrimitiveOrStringType</a> <a class="sym" href="#prod-Null">Null</a></span></td></tr><tr id="proddef-PrimitiveOrStringType"><td><span class="prod-number">[50]</span></td><td><a class="sym" href="#prod-PrimitiveOrStringType">PrimitiveOrStringType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-UnsignedIntegerType">UnsignedIntegerType</a> <br /> |
|
|
"boolean" <br /> |
|
|
"byte" <br /> |
|
|
"octet" <br /> |
|
|
"float" <br /> |
|
|
"double" <br /> |
|
|
"DOMString"</span></td></tr><tr id="proddef-UnsignedIntegerType"><td><span class="prod-number">[51]</span></td><td><a class="sym" href="#prod-UnsignedIntegerType">UnsignedIntegerType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"unsigned" <a class="sym" href="#prod-IntegerType">IntegerType</a> <br /> |
|
|
<a class="sym" href="#prod-IntegerType">IntegerType</a></span></td></tr><tr id="proddef-IntegerType"><td><span class="prod-number">[52]</span></td><td><a class="sym" href="#prod-IntegerType">IntegerType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"short" <br /> |
|
|
"long" <a class="sym" href="#prod-OptionalLong">OptionalLong</a></span></td></tr><tr id="proddef-OptionalLong"><td><span class="prod-number">[53]</span></td><td><a class="sym" href="#prod-OptionalLong">OptionalLong</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"long" <br /> |
|
|
ε</span></td></tr><tr id="proddef-TypeSuffix"><td><span class="prod-number">[54]</span></td><td><a class="sym" href="#prod-TypeSuffix">TypeSuffix</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" "]" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"?" <a class="sym" href="#prod-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-TypeSuffixStartingWithArray"><td><span class="prod-number">[55]</span></td><td><a class="sym" href="#prod-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" "]" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-Null"><td><span class="prod-number">[56]</span></td><td><a class="sym" href="#prod-Null">Null</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"?" <br /> |
|
|
ε</span></td></tr></table>
|
|
|
|
<div id="idl-any" class="section">
|
|
<h4>3.9.1. any</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-any">any</a> type is the union of all other possible types.
|
|
Its <a class="dfnref" href="#dfn-type-name">type name</a> is “Any”.
|
|
</p>
|
|
<p>
|
|
The <a class="idltype" href="#idl-any">any</a> type is like
|
|
a discriminated union type, in that each of its values has a
|
|
specific non-<a class="idltype" href="#idl-any">any</a> type
|
|
associated with it. For example, one value of the
|
|
<a class="idltype" href="#idl-any">any</a> type is the
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a>
|
|
150, while another is the <a class="idltype" href="#idl-long">long</a> 150.
|
|
These are distinct values.
|
|
</p>
|
|
<p>
|
|
The particular type of an <a class="idltype" href="#idl-any">any</a>
|
|
value is known as its <dfn id="dfn-specific-type">specific type</dfn>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-boolean" class="section">
|
|
<h4>3.9.2. boolean</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-boolean">boolean</a> type has two values:
|
|
<span class="idlvalue">true</span> and <span class="idlvalue">false</span>.
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-boolean">boolean</a> constant values in IDL are
|
|
represented with the <code>true</code> and
|
|
<code>false</code> tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-boolean">boolean</a> type is “Boolean”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-byte" class="section">
|
|
<h4>3.9.3. byte</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-byte">byte</a> type is a signed integer
|
|
type that has values in the range [−128, 127].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-byte">byte</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-byte">byte</a> type is “Byte”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-octet" class="section">
|
|
<h4>3.9.4. octet</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-octet">octet</a> type is an unsigned integer
|
|
type that has values in the range [0, 255].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-octet">octet</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-octet">octet</a> type is “Octet”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-short" class="section">
|
|
<h4>3.9.5. short</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-short">short</a> type is a signed integer
|
|
type that has values in the range [−32768, 32767].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-short">short</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-short">short</a> type is “Short”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-unsigned-short" class="section">
|
|
<h4>3.9.6. unsigned short</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-unsigned-short">unsigned short</a> type is an unsigned integer
|
|
type that has values in the range [0, 65535].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-unsigned-short">unsigned short</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-unsigned-short">unsigned short</a> type is “UnsignedShort”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-long" class="section">
|
|
<h4>3.9.7. long</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-long">long</a> type is a signed integer
|
|
type that has values in the range [−2147483648, 2147483647].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-long">long</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-long">long</a> type is “Long”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-unsigned-long" class="section">
|
|
<h4>3.9.8. unsigned long</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-unsigned-long">unsigned long</a> type is an unsigned integer
|
|
type that has values in the range [0, 4294967295].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a> type is “UnsignedLong”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-long-long" class="section">
|
|
<h4>3.9.9. long long</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-long-long">long long</a> type is a signed integer
|
|
type that has values in the range [−9223372036854775808, 9223372036854775807].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-long-long">long long</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-long-long">long long</a> type is “LongLong”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-unsigned-long-long" class="section">
|
|
<h4>3.9.10. unsigned long long</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> type is an unsigned integer
|
|
type that has values in the range [0, 18446744073709551615].
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-integer">integer</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> type is “UnsignedLongLong”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-float" class="section">
|
|
<h4>3.9.11. float</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-float">float</a> type is a floating point numeric
|
|
type that corresponds to the set of possible single-precision 32 bit
|
|
IEEE 754 floating point numbers. <a href="#ref-IEEE-754">[IEEE-754]</a>
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-float">float</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-float">float</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-float">float</a> type is “Float”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-double" class="section">
|
|
<h4>3.9.12. double</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-double">double</a> type is a floating point numeric
|
|
type that corresponds to the set of possible double-precision 64 bit
|
|
IEEE 754 floating point numbers. <a href="#ref-IEEE-754">[IEEE-754]</a>
|
|
</p>
|
|
<p>
|
|
<a class="idltype" href="#idl-double">double</a> constant values in IDL are
|
|
represented with <a class="sym" href="#prod-float">float</a>
|
|
tokens.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-double">double</a> type is “Double”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-DOMString" class="section">
|
|
<h4>3.9.13. DOMString</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-DOMString">DOMString</a> type
|
|
corresponds to the set of all possible sequences of
|
|
16 bit unsigned integer <a class="dfnref" href="#dfn-code-unit">code units</a>.
|
|
Such sequences are commonly interpreted as UTF-16 encoded strings <a href="#ref-RFC2781">[RFC2781]</a>
|
|
although this is not required.
|
|
While <a class="idltype" href="#idl-DOMString">DOMString</a> is defined to be an OMG IDL boxed
|
|
<a class="idltype" href="#idl-sequence">sequence<unsigned short></a>
|
|
valuetype in <cite><a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-C74D1578">DOM Level 3 Core</a></cite>
|
|
(<a href="#ref-DOM3CORE">[DOM3CORE]</a>, section 1.2.1),
|
|
this document defines <a class="idltype" href="#idl-DOMString">DOMString</a> to be an intrinsic type so as to avoid
|
|
special casing that sequence type in various situations where a
|
|
string is required.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Note also that <span class="idlvalue">null</span>
|
|
is not a value of type <a class="idltype" href="#idl-DOMString">DOMString</a>.
|
|
To allow <span class="idlvalue">null</span>, a
|
|
<a href="#idl-nullable-type">nullable</a> <a class="idltype" href="#idl-DOMString">DOMString</a>,
|
|
written as <code>DOMString?</code> in IDL, needs to be used.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
Nothing in this specification requires a <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
value to be a valid UTF-16 string. For example, a <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
value might include unmatched surrogate pair characters. However, authors
|
|
of specifications using Web IDL might want to obtain a sequence of
|
|
Unicode characters given a particular sequence of <a class="dfnref" href="#dfn-code-unit">code units</a>.
|
|
The following algorithm defines a way to
|
|
<dfn id="dfn-obtain-unicode">convert a DOMString to a sequence of Unicode characters</dfn>:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>S</var> be the <a class="idltype" href="#idl-DOMString">DOMString</a> value.</li>
|
|
<li>Let <var>n</var> be the length of <var>S</var>.</li>
|
|
<li>Initialize <var>i</var> to 0.</li>
|
|
<li>Initialize <var>U</var> to be an empty sequence of Unicode characters.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>c</var> be the <a class="dfnref" href="#dfn-code-unit">code unit</a> in <var>S</var> at index <var>i</var>.</li>
|
|
<li>Depending on the value of <var>c</var>:
|
|
<dl class="switch">
|
|
<dt><var>c</var> < 0xD800 or <var>c</var> > 0xDFFF</dt>
|
|
<dd>Append to <var>U</var> the Unicode character with code point <var>c</var>. </dd>
|
|
|
|
<dt>0xDC00 ≤ <var>c</var> ≤ 0xDFFF</dt>
|
|
<dd>Append to <var>U</var> a <span class="char">U+FFFD REPLACEMENT CHARACTER</span>.</dd>
|
|
|
|
<dt>0xD800 ≤ <var>c</var> ≤ 0xDBFF</dt>
|
|
<dd>
|
|
<ol class="only">
|
|
<li>If <var>i</var> = <var>n</var>−1, then append to <var>U</var> a <span class="char">U+FFFD REPLACEMENT CHARACTER</span>.</li>
|
|
<li>Otherwise, <var>i</var> < <var>n</var>−1:
|
|
<ol>
|
|
<li>Let <var>d</var> be the code unit in <var>S</var> at index
|
|
<var>i</var>+1.</li>
|
|
<li>If 0xDC00 ≤ <var>d</var> ≤ 0xDFFF, then:
|
|
<ol>
|
|
<li>Let <var>a</var> be <var>c</var> & 0x3FF.</li>
|
|
<li>Let <var>b</var> be <var>d</var> & 0x3FF.</li>
|
|
<li>Append to <var>U</var> the Unicode character with
|
|
code point 2<sup>16</sup>+2<sup>10</sup><var>a</var>+<var>b</var>.</li>
|
|
<li>Set <var>i</var> to <var>i</var>+1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, <var>d</var> < 0xDC00 or <var>d</var> > 0xDFFF.
|
|
Append to <var>U</var> a <span class="char">U+FFFD REPLACEMENT CHARACTER</span>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</dd>
|
|
</dl>
|
|
</li>
|
|
<li>Set <var>i</var> to <var>i</var>+1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>U</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> type is “String”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-object" class="section">
|
|
<h4>3.9.14. object</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-object">object</a> type corresponds to the set of
|
|
all possible non-null object references.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant <a class="idltype" href="#idl-object">object</a>
|
|
value in IDL.
|
|
</p>
|
|
<p>
|
|
To denote a type that includes all possible object references plus the
|
|
<span class="idlvalue">null</span> value, use the <a href="#dfn-nullable-type">nullable type</a>
|
|
<span class="idltype">object?</span>.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-object">object</a> type is “Object”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-interface" class="section">
|
|
<h4>3.9.15. Interface types</h4>
|
|
|
|
<p>
|
|
A <a class="dfnref" href="#dfn-scoped-name">scoped name</a> that
|
|
<a class="dfnref" href="#dfn-resolve">resolves</a> to an
|
|
<a class="dfnref" href="#dfn-interface">interface</a> is used to refer to
|
|
a type that corresponds to the set of all possible non-null references to objects that
|
|
implement that interface.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant object reference value for
|
|
a particular interface type in IDL.
|
|
</p>
|
|
<p>
|
|
To denote a type that includes all possible references to objects implementing
|
|
the given interface plus the <span class="idlvalue">null</span> value,
|
|
use a <a href="#dfn-nullable-type">nullable type</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of an interface type
|
|
is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the interface.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-dictionary" class="section">
|
|
<h4>3.9.16. Dictionary types</h4>
|
|
|
|
<p>
|
|
A <a class="dfnref" href="#dfn-scoped-name">scoped name</a> that
|
|
<a class="dfnref" href="#dfn-resolve">resolves</a> to a
|
|
<a class="dfnref" href="#dfn-dictionary">dictionary</a> is used to refer to
|
|
a type that corresponds to the set of all dictionaries that adhere to
|
|
the dictionary definition.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant dictionary value in IDL.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of a dictionary type
|
|
is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the dictionary.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-nullable-type" class="section">
|
|
<h4>3.9.17. Nullable types — <var>T</var>?</h4>
|
|
|
|
<p>
|
|
A <dfn id="dfn-nullable-type">nullable type</dfn> is an IDL type constructed
|
|
from an existing type (called the <dfn id="dfn-inner-type">inner type</dfn>),
|
|
which just allows the additional value <span class="idlvalue">null</span>
|
|
to be a member of its set of values. <a class="dfnref" href="#dfn-nullable-type">Nullable types</a>
|
|
are represented in IDL by placing a <span class="char">U+003F QUESTION MARK ("?")</span>
|
|
character after an existing type. The inner type <span class="rfc2119">MUST NOT</span>
|
|
be <a class="idltype" href="#idl-any">any</a> or another nullable type, as they already
|
|
allow the <span class="idlvalue">null</span> value.
|
|
</p>
|
|
<p>
|
|
Nullable type constant values in IDL are represented in the same way that
|
|
constant values of their <a class="dfnref" href="#dfn-inner-type">inner type</a>
|
|
would be represented, or with the <code>null</code> token.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of a nullable type
|
|
is the concatenation of the type name of the inner type <var>T</var> and
|
|
the string “OrNull”.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
For example, a type that allows the values <span class="idlvalue">true</span>,
|
|
<span class="idlvalue">false</span> and <span class="idlvalue">null</span>
|
|
is written as <span class="idltype">boolean?</span>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface MyConstants {
|
|
const boolean? ARE_WE_THERE_YET = false;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-interface">interface</a> has two
|
|
<a class="dfnref" href="#dfn-attribute">attributes</a>: one whose value can
|
|
be a <a class="idltype" href="#idl-DOMString">DOMString</a> or the <span class="idlvalue">null</span>
|
|
value, and another whose value can be a reference to a <span class="idltype">Node</span>
|
|
object or the <span class="idlvalue">null</span> value:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Node {
|
|
readonly attribute DOMString? namespaceURI;
|
|
readonly attribute Node? parentNode;
|
|
<span class="comment">// ...</span>
|
|
};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-sequence" class="section">
|
|
<h4>3.9.18. Sequences — sequence<<var>T</var>></h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a>
|
|
type is a parameterized type whose values are (possibly zero-length) sequences of
|
|
values of type <var>T</var>. Sequences are always passed by value. In
|
|
language bindings where a sequence is represented by an object of
|
|
some kind, passing a sequence to a user agent implemented object
|
|
will not result in a reference to the sequence being kept by that object.
|
|
Similarly, any sequence returned from a user agent implemented object
|
|
will be a copy and modifications made to it will not be visible to the object.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant sequence value in IDL.
|
|
</p>
|
|
<p>
|
|
Sequences <span class="rfc2119">MUST NOT</span> be used as the
|
|
type of an <a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
<a class="dfnref" href="#dfn-constant">constant</a>
|
|
or <a class="dfnref" href="#dfn-exception-field">exception field</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
This restriction exists so that it is clear to specification writers
|
|
and API users that <a href="#idl-sequence">sequences</a>
|
|
are copied rather than having references
|
|
to them passed around. Instead of a writable <a class="dfnref" href="#dfn-attribute">attribute</a> of a sequence
|
|
type, it is suggested that a pair of <a class="dfnref" href="#dfn-operation">operations</a> to get and set the
|
|
sequence is used. Another option is to use an <a href="#idl-array">array type</a>,
|
|
which can be used as the type of an attribute.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of a sequence type
|
|
is the concatenation of the type name for <var>T</var> and
|
|
the string “Sequence”.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="idl-array" class="section">
|
|
<h4>3.9.19. Arrays — <var>T</var>[]</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-array"><var>T</var>[]</a> type
|
|
is a parameterized type whose values are non-null references to (possibly zero-length) arrays
|
|
of values of type <var>T</var>.
|
|
Unlike <a class="dfnref" href="#idl-sequence">sequences</a>,
|
|
arrays are passed by reference. Passing an array to a <a class="dfnref" href="#dfn-platform-object">platform object</a>
|
|
could result in that array being modified by the object.
|
|
An array returned from a platform object might also be modified by the object,
|
|
and any modifications to the array performed by user code might be acted upon by the
|
|
platform object.
|
|
</p>
|
|
<p>
|
|
The element type of an array <span class="rfc2119">MUST NOT</span> be
|
|
a <a href="#idl-sequence">sequence</a> or <a href="#idl-dictionary">dictionary</a> type.
|
|
</p>
|
|
<p>
|
|
Arrays can either be <dfn id="dfn-fixed-length">fixed length</dfn> or
|
|
<dfn id="dfn-variable-length">variable length</dfn>. Fixed length
|
|
arrays cannot have their length changed by user code after they have been
|
|
created, while variable length arrays can. Unless otherwise
|
|
specified, arrays are fixed length.
|
|
</p>
|
|
<p>
|
|
Arrays can also be designated as being <dfn id="dfn-read-only-array">read only</dfn>.
|
|
User code cannot modify the values of read only array elements.
|
|
If an array is read only, then it is also implicitly <a class="dfnref" href="#dfn-fixed-length">fixed length</a>.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant array value in IDL.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of an array type
|
|
is the concatenation of the type name for <var>T</var> and
|
|
the string “Array”.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>See <a href="#es-array">section 4.2.20</a> for an example using array types.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-Date" class="section">
|
|
<h4>3.9.20. Date</h4>
|
|
|
|
<p>
|
|
The <a class="idltype" href="#idl-Date">Date</a> type is a type that
|
|
represents an instant in time with millisecond accuracy. The instants
|
|
in time that this type can represent are the same that can be represented
|
|
with ECMAScript <span class="estype">Date</span> objects (<a href="#ref-ECMA-262">[ECMA-262]</a>,
|
|
section 15.9.1.1) – namely, every millisecond in the 200,000,000 days centered
|
|
around midnight of 1 January, 1970 UTC, except for any millisecond that is part
|
|
of an inserted leap second, because they cannot be represented by this type.
|
|
</p>
|
|
<p>
|
|
An additional value that this type can represent is one that indicates
|
|
an indeterminate or undefined time, which we write as
|
|
<span class="idlvalue">undefined</span>.
|
|
</p>
|
|
<p>
|
|
There is no way to represent a constant <a class="idltype" href="#idl-Date">Date</a>
|
|
value in IDL.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a class="idltype" href="#idl-Date">Date</a> type is “Date”.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="idl-extended-attributes" class="section">
|
|
<h3>3.10. Extended attributes</h3>
|
|
|
|
<p>
|
|
An <dfn id="dfn-extended-attribute">extended attribute</dfn> is an annotation
|
|
that can appear on
|
|
<!--a class='dfnref' href='#dfn-definition'-->definitions<!--/a-->,
|
|
<a class="dfnref" href="#dfn-interface-member">interface members</a>,
|
|
<a class="dfnref" href="#dfn-exception-member">exception members</a>,
|
|
<a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>,
|
|
and <a class="dfnref" href="#dfn-operation">operation</a> arguments, and
|
|
is used to control how language bindings will handle those constructs.
|
|
Extended attributes are specified with an
|
|
<a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a>,
|
|
which is a square bracket enclosed, comma separated list of
|
|
<a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a>s.
|
|
</p>
|
|
<p>
|
|
The <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a>
|
|
grammar symbol matches nearly any sequence of tokens, however the
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this document only accept a more restricted syntax.
|
|
Any extended attribute encountered in an
|
|
<a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> is
|
|
matched against the following five grammar symbols to determine
|
|
which form (or forms) it is in:
|
|
</p>
|
|
<table class="vert">
|
|
<tr>
|
|
<th>Grammar symbol</th>
|
|
<th>Form</th>
|
|
<th>Example</th>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<a class="sym" href="#prod-ExtendedAttributeNoArgs">ExtendedAttributeNoArgs</a>
|
|
</td>
|
|
<td>
|
|
<dfn id="dfn-xattr-no-arguments">takes no arguments</dfn>
|
|
</td>
|
|
<td>
|
|
<code>[Replaceable]</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<a class="sym" href="#prod-ExtendedAttributeArgList">ExtendedAttributeArgList</a>
|
|
</td>
|
|
<td>
|
|
<dfn id="dfn-xattr-argument-list">takes an argument list</dfn>
|
|
</td>
|
|
<td>
|
|
<code>[Constructor(float x, float y)]</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<a class="sym" href="#prod-ExtendedAttributeNamedArgList">ExtendedAttributeNamedArgList</a>
|
|
</td>
|
|
<td>
|
|
<dfn id="dfn-xattr-named-argument-list">takes a named argument list</dfn>
|
|
</td>
|
|
<td>
|
|
<code>[NamedConstructor=Image(DOMString src)]</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<a class="sym" href="#prod-ExtendedAttributeIdent">ExtendedAttributeIdent</a>
|
|
</td>
|
|
<td>
|
|
<dfn id="dfn-xattr-identifier">takes an identifier</dfn>
|
|
</td>
|
|
<td>
|
|
<code>[PutForwards=name]</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<a class="sym" href="#prod-ExtendedAttributeScopedName">ExtendedAttributeScopedName</a>
|
|
</td>
|
|
<td>
|
|
<dfn id="dfn-xattr-scoped-name">takes a scoped name</dfn>
|
|
</td>
|
|
<td>
|
|
<code>[Prefix=org::example]</code>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>
|
|
This specification defines a number of extended attributes that
|
|
are applicable to all language bindings, which are described in the
|
|
sub-sections below. In addition, ECMAScript language binding
|
|
specific extended attributes are defined in
|
|
<a href="#es-extended-attributes">section 4.3</a>.
|
|
Each extended attribute definition will state which of the above
|
|
five forms are allowed. Although
|
|
<a class="sym" href="#prod-ExtendedAttributeIdent">ExtendedAttributeIdent</a> and
|
|
<a class="sym" href="#prod-ExtendedAttributeScopedName">ExtendedAttributeScopedName</a>
|
|
are ambiguous, no extended attribute defined in this document
|
|
takes both of those forms.
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="proddef-ExtendedAttributeList"><td><span class="prod-number">[39]</span></td><td><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <a class="sym" href="#prod-ExtendedAttributes">ExtendedAttributes</a> "]" <br /> |
|
|
ε</span></td></tr><tr id="proddef-ExtendedAttributes"><td><span class="prod-number">[40]</span></td><td><a class="sym" href="#prod-ExtendedAttributes">ExtendedAttributes</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"," <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <a class="sym" href="#prod-ExtendedAttributes">ExtendedAttributes</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-ExtendedAttribute"><td><span class="prod-number">[41]</span></td><td><a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
"(" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> ")" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
"[" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "]" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
"{" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "}" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
<a class="sym" href="#prod-Other">Other</a> <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
</span></td></tr><tr id="proddef-ExtendedAttributeRest"><td><span class="prod-number">[42]</span></td><td><a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <br /> |
|
|
ε</span></td></tr><tr id="proddef-ExtendedAttributeInner"><td><span class="prod-number">[43]</span></td><td><a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
"(" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> ")" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
"[" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "]" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
"{" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "}" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
<a class="sym" href="#prod-OtherOrComma">OtherOrComma</a> <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
ε
|
|
</span></td></tr><tr id="proddef-Other"><td><span class="prod-number">[44]</span></td><td><a class="sym" href="#prod-Other">Other</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
<a class="sym" href="#prod-integer">integer</a> <br /> |
|
|
<a class="sym" href="#prod-float">float</a> <br /> |
|
|
<a class="sym" href="#prod-identifier">identifier</a> <br /> |
|
|
<a class="sym" href="#prod-string">string</a> <br /> |
|
|
<a class="sym" href="#prod-other">other</a>
|
|
<br /> |
|
|
"..." <br /> |
|
|
":" <br /> |
|
|
"::" <br /> |
|
|
";" <br /> |
|
|
"<" <br /> |
|
|
"=" <br /> |
|
|
">" <br /> |
|
|
"?"
|
|
<br /> |
|
|
"Date" <br /> |
|
|
"DOMString" <br /> |
|
|
"any" <br /> |
|
|
"attribute" <br /> |
|
|
"boolean" <br /> |
|
|
"byte"
|
|
<br /> |
|
|
"legacycaller" <br /> |
|
|
"const" <br /> |
|
|
"creator" <br /> |
|
|
"deleter" <br /> |
|
|
"double"
|
|
<br /> |
|
|
"exception" <br /> |
|
|
"false" <br /> |
|
|
"float" <br /> |
|
|
"getter" <br /> |
|
|
"implements"
|
|
<br /> |
|
|
"inherit" <br /> |
|
|
"interface" <br /> |
|
|
"long" <br /> |
|
|
"module" <br /> |
|
|
"null" <br /> |
|
|
"object" <br /> |
|
|
"octet"
|
|
<br /> |
|
|
"optional" <br /> |
|
|
"sequence"
|
|
<br /> |
|
|
"setter" <br /> |
|
|
"short" <br /> |
|
|
"static" <br /> |
|
|
"stringifier" <br /> |
|
|
"true" <br /> |
|
|
"typedef"
|
|
<br /> |
|
|
"unsigned" <br /> |
|
|
"void"
|
|
</span></td></tr><tr id="proddef-OtherOrComma"><td><span class="prod-number">[45]</span></td><td><a class="sym" href="#prod-OtherOrComma">OtherOrComma</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Other">Other</a> <br /> |
|
|
","</span></td></tr><tr id="proddef-ExtendedAttributeNoArgs"><td><span class="prod-number">[62]</span></td><td><a class="sym" href="#prod-ExtendedAttributeNoArgs">ExtendedAttributeNoArgs</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="proddef-ExtendedAttributeArgList"><td><span class="prod-number">[63]</span></td><td><a class="sym" href="#prod-ExtendedAttributeArgList">ExtendedAttributeArgList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")"</span></td></tr><tr id="proddef-ExtendedAttributeIdent"><td><span class="prod-number">[64]</span></td><td><a class="sym" href="#prod-ExtendedAttributeIdent">ExtendedAttributeIdent</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="proddef-ExtendedAttributeScopedName"><td><span class="prod-number">[65]</span></td><td><a class="sym" href="#prod-ExtendedAttributeScopedName">ExtendedAttributeScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-ScopedName">ScopedName</a></span></td></tr><tr id="proddef-ExtendedAttributeNamedArgList"><td><span class="prod-number">[66]</span></td><td><a class="sym" href="#prod-ExtendedAttributeNamedArgList">ExtendedAttributeNamedArgList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-identifier">identifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")"</span></td></tr></table>
|
|
|
|
<!--
|
|
<div id='ExceptionConsts' class='section'>
|
|
<h4>[ExceptionConsts]</h4>
|
|
|
|
<p>
|
|
If the <a class='xattr' href='#ExceptionConsts'>[ExceptionConsts]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>
|
|
appears on a <a class='dfnref' href='#dfn-module'>module</a>, it indicates that any
|
|
<a class='dfnref' href='#dfn-constant'>constants</a> declared on that module are intended to
|
|
exist on the language construct that corresponds to the <a class='dfnref' href='#dfn-exception'>exception</a>
|
|
given by the extended attribute’s argument (for languages that
|
|
support constants on exceptions). Exactly how these constants
|
|
are exposed is language binding specific.
|
|
</p>
|
|
<p>
|
|
The <a class='xattr' href='#ExceptionConsts'>[ExceptionConsts]</a> extended attribute
|
|
<span class='rfc2119'>MUST</span> <a class='dfnref' href='#dfn-xattr-identifier'>take an identifier</a>
|
|
that is the <a class='dfnref' href='#dfn-identifier'>identifier</a>
|
|
of an exception defined in that module, on which the constants declared at the
|
|
module scope should live.
|
|
</p>
|
|
<div class='example'>
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a> declares an exception and a number of constants
|
|
at the module scope:
|
|
</p>
|
|
<x:codeblock language='idl'>[ExceptionConsts=FileIOException]
|
|
module fileio {
|
|
|
|
exception FileIOException {
|
|
unsigned short code;
|
|
};
|
|
|
|
const unsigned short FILE_NOT_FOUND = 1;
|
|
const unsigned short READ_ERROR = 2;
|
|
const unsigned short WRITE_ERROR = 3;
|
|
};</x:codeblock>
|
|
<p>
|
|
In the ECMAScript binding, this will result in properties on the
|
|
<a class='dfnref' href='#dfn-exception-interface-object'>exception interface object</a> for each of the constants:
|
|
</p>
|
|
<x:codeblock language='es'>typeof FileIOException; <span class='comment'>// evaluates to "object"</span>
|
|
FileIOException.FILE_NOT_FOUND; <span class='comment'>// evaluates to 1</x:codeblock></span>
|
|
</div>
|
|
</div>
|
|
-->
|
|
|
|
<!--
|
|
<div id='NoNull' class='section'>
|
|
<h4>[NoNull]</h4>
|
|
|
|
<p>
|
|
If the <a class='xattr' href='#NoNull'>[NoNull]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>
|
|
appears on an <a class='dfnref' href='#dfn-attribute'>attribute</a>,
|
|
an <a class='dfnref' href='#dfn-operation'>operation</a> or an operation
|
|
argument, whose type is a
|
|
<a class='dfnref' href='#dfn-boxed-valuetype'>boxed valuetype</a>,
|
|
it indicates that a <span class='idlvalue'>null</span> value is not
|
|
expected and will never be returned. How
|
|
implementations treat the assignment of a <span class='idlvalue'>null</span>
|
|
value to an attribute with the <a class='xattr' href='#NoNull'>[NoNull]</a>
|
|
extended attribute, or passing a <span class='idlvalue'>null</span> value as a
|
|
<a class='xattr' href='#NoNull'>[NoNull]</a> operation argument,
|
|
is specific to the language binding.
|
|
</p>
|
|
<p>
|
|
The <a class='xattr' href='#NoNull'>[NoNull]</a>
|
|
extended attribute <span class='rfc2119'>MUST</span> take no argument.
|
|
</p>
|
|
<div class='example'>
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a> defines an interface that has one
|
|
attribute with the <a class='xattr' href='#NoNull'>[NoNull]</a>
|
|
extended attribute, and one operation with an argument that has
|
|
the extended attribute:
|
|
</p>
|
|
<x:codeblock language='idl'>interface Dog {
|
|
[NoNull] attribute DOMString name;
|
|
attribute DOMString shortName;
|
|
|
|
boolean isMemberOfBreed([NoNull] DOMString breedName);
|
|
};</x:codeblock>
|
|
<p>
|
|
An ECMAScript implementation implementing the <span class='idltype'>Dog</span>
|
|
interface would not allow the <span class='esvalue'>null</span> value to
|
|
be assigned to the <span class='prop'>name</span> property or passed as the
|
|
argument to the <span class='prop'>isMemberOfBreed</span> function:
|
|
</p>
|
|
<x:codeblock language='es'>var d = getDog(); <span class='comment'>// Assume d is a platform object implementing the Dog interface.</span>
|
|
|
|
d.name = null; <span class='comment'>// This assigns the string "null" to the .name property.</span>
|
|
d.isMemberOfBreed(null); <span class='comment'>// This passes the string "null" to the isMemberOfBreed function.</x:codeblock></span>
|
|
</div>
|
|
</div>
|
|
-->
|
|
|
|
<!--
|
|
<div id='Overloads' class='section'>
|
|
<h4>[Overloads]</h4>
|
|
|
|
<p>
|
|
If the <a class='xattr' href='#Overloads'>[Overloads]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>
|
|
appears on an <a class='dfnref' href='#dfn-operation'>operation</a>, it indicates that
|
|
the operation is to be considered to overload the operation
|
|
with the <a class='sym' href='#prod-identifier'>identifier</a>
|
|
given as the extended attribute argument.
|
|
The extent to which a language supports method overloading
|
|
determines whether an object implementing an interface with
|
|
overloaded operations must implement the operation using the
|
|
overloaded name or the original name, and is specific to the
|
|
language binding.
|
|
</p>
|
|
<p>
|
|
The <a class='xattr' href='#Overloads'>[Overloads]</a>
|
|
extended attribute <span class='rfc2119'>MUST</span> take a single argument,
|
|
an <a class='sym' href='#prod-identifier'>identifier</a>,
|
|
which <span class='rfc2119'>MUST</span> be the <a class='sym' href='#prod-identifier'>identifier</a>
|
|
of another operation defined on the <a class='dfnref' href='#dfn-interface'>interface</a>,
|
|
which this operation overloads. The
|
|
<a class='sym' href='#prod-identifier'>identifier</a> <span class='rfc2119'>MUST NOT</span>
|
|
identify an operation that itself is declared with an
|
|
<a class='xattr' href='#Overloads'>[Overloads]</a> extended
|
|
attribute.
|
|
</p>
|
|
<div class='example'>
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a> defines an interface with
|
|
overloaded operations:
|
|
</p>
|
|
<x:codeblock language='idl'>interface Person;
|
|
|
|
interface PersonFactory {
|
|
Person createPerson();
|
|
[Overloads=createPerson] Person createPersonWithAge(short age);
|
|
};</x:codeblock>
|
|
<p>
|
|
Since the ECMAScript binding allows overloading, a platform object
|
|
implementing the <span class='idltype'>PersonFactory</span>
|
|
interface will have a single property <span class='prop'>createPerson</span>:
|
|
</p>
|
|
<x:codeblock language='es'>var f = getFactory(); <span class='comment'>// Assume f is a platform object implementing the PersonFactory interface.</span>
|
|
|
|
typeof f.createPerson; <span class='comment'>// Evaluates to "function".</span>
|
|
typeof f.createPersonWithAge; <span class='comment'>// Evaluates to "undefined".</span>
|
|
|
|
var p1 = f.createPerson(); <span class='comment'>// Corresponds to the createPerson operation.</span>
|
|
var p2 = f.createPerson(26); <span class='comment'>// Corresponds to the createPersonWithAge operation.</x:codeblock></span>
|
|
<p>
|
|
However, a hypothetical C language binding would not, since
|
|
C does not support overloading. Separate functions would likely
|
|
be used for the two operations:
|
|
</p>
|
|
<x:codeblock language='c'>PersonFactory* f = getFactory();
|
|
|
|
Person* p1 = PersonFactory_createPerson(f); <span class='comment'>// Corresponds to the createPerson operation.</span>
|
|
Person* p2 = PersonFactory_createPersonWithAge(f, 26); <span class='comment'>// Corresponds to the createPersonWithAge operation.</x:codeblock></span>
|
|
</div>
|
|
</div>
|
|
-->
|
|
|
|
<div id="Callback" class="section">
|
|
<h4>3.10.1. [Callback]</h4>
|
|
|
|
<div class="ednote"><div class="ednoteHeader">Editorial note</div>
|
|
<p>
|
|
Since the <a class="xattr" href="#Callback">[Callback]</a> extended attribute
|
|
is now important at the IDL level to indicate whether user objects can
|
|
implement a given interface, does it make sense to hoist it up into
|
|
proper syntax (i.e., not be an extended attribute)?
|
|
</p>
|
|
<p>
|
|
It may be that <a class="xattr" href="#Callback">[Callback]</a>
|
|
is not the best name for the extended attribute anyway, although
|
|
it does capture many uses of interfaces that user objects can
|
|
implement. Maybe <span class="xattr">[UserObject]</span> is better.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
If the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
it indicates that <a class="dfnref" href="#dfn-user-object">user objects</a>
|
|
can implement the interface. As described in <a href="#idl-objects">section 3.8 above</a>,
|
|
user objects will only be considered to implement a given interface if
|
|
the interface is annotated with <a class="xattr" href="#Callback">[Callback]</a>.
|
|
User objects implementing an interface are most often
|
|
used to provide callback methods to a <a class="dfnref" href="#dfn-platform-object">platform object</a>,
|
|
hence the name of this extended attribute.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Callback">[Callback]</a> extended attribute
|
|
<span class="rfc2119">MUST</span> either <a class="dfnref" href="#dfn-xattr-identifier">take an identifier</a>
|
|
or <a class="dfnref" href="#dfn-xattr-no-arguments">no argument</a>.
|
|
The identifier, if present, is used only by the ECMAScript language binding,
|
|
to control exactly which kinds of objects can be considered to
|
|
implement a <a class="xattr" href="#Callback">[Callback]</a>-annotated
|
|
interface. See <a href="#es-Callback">section 4.3.3 below</a> for
|
|
details and an example of this.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Callback">[Callback]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> be used on an interface that
|
|
does not meet the criteria for an interface that can implemented by
|
|
user objects, as described in <a href="#idl-objects">section 3.8 above</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Specification authors wanting to APIs that take ECMAScript objects
|
|
as “property bag” like function arguments are suggested to use
|
|
<a href="#idl-dictionaries">dictionary types</a> rather than
|
|
<a class="dfnref" href="#dfn-interface">interfaces</a> annotated
|
|
with <code>[Callback,NoInterfaceObject]</code>.
|
|
</p>
|
|
<p>
|
|
For example, instead of this:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Callback,NoInterfaceObject]
|
|
interface Options {
|
|
attribute DOMString? option1;
|
|
attribute DOMString? option2;
|
|
attribute long? option3;
|
|
};
|
|
|
|
interface A {
|
|
void doTask(DOMString type, Options options);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
to be used like this:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var a = getA(); <span class="comment">// Get an instance of A.</span>
|
|
|
|
a.doTask("something", { option1: "banana", option3: 100 });</code></pre></div></div>
|
|
<p>
|
|
instead write the following:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">dictionary Options {
|
|
DOMString? option1;
|
|
DOMString? option2;
|
|
long? option3;
|
|
};
|
|
|
|
interface A {
|
|
void doTask(DOMString type, Options options);
|
|
};</code></pre></div></div>
|
|
</div>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines
|
|
simplified versions of a few DOM <a class="dfnref" href="#dfn-interface">interfaces</a>, one of which
|
|
is annotated with the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Node {
|
|
readonly attribute DOMString nodeName;
|
|
readonly attribute Node? parentNode;
|
|
Node appendChild(Node newChild);
|
|
void addEventListener(DOMString type, EventListener listener);
|
|
};
|
|
|
|
[Callback]
|
|
interface EventListener {
|
|
void handleEvent(Event event);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Since the <span class="idltype">EventListener</span> interface is annotated
|
|
with <a class="xattr" href="#Callback">[Callback]</a>, <a class="dfnref" href="#dfn-user-object">user objects</a>
|
|
can implement it:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var node = getNode(); <span class="comment">// Obtain an instance of Node.</span>
|
|
|
|
var listener = {
|
|
handleEvent: function(event) {
|
|
...
|
|
}
|
|
};
|
|
node.addEventListener("click", listener);</code></pre></div></div>
|
|
<p>
|
|
It is not possible for a user object to implement <span class="idltype">Node</span>, however:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var node = getNode(); <span class="comment">// Obtain an instance of Node.</span>
|
|
|
|
var newNode = {
|
|
nodeName: "span",
|
|
parentNode: null,
|
|
appendChild: function(newchild) {
|
|
...
|
|
},
|
|
addEventListener: function(type, listener) {
|
|
...
|
|
}
|
|
};
|
|
node.appendChild(newNode); <span class="comment">// This will throw a TypeError exception.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="Prefix" class="section">
|
|
<h4>3.10.2. [Prefix]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#Prefix">[Prefix]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on a <a class="dfnref" href="#dfn-module">module</a>,
|
|
it affects the name of the language binding specific namespacing
|
|
construct the module will correspond to. See the definition of a module’s
|
|
<a class="dfnref" href="#dfn-prefixed-name">prefixed name</a> for
|
|
details.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Prefix">[Prefix]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-scoped-name">take a scoped name</a>.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
See <a href="#java-modules">section 5.3</a> for an
|
|
example of the use of <a class="xattr" href="#Prefix">[Prefix]</a>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="ecmascript-binding" class="section">
|
|
<h2>4. ECMAScript binding</h2>
|
|
|
|
<p>
|
|
This section describes how definitions written with the IDL defined in
|
|
<a href="#idl">section 3</a> correspond to particular constructs
|
|
in ECMAScript, as defined by the <cite>ECMAScript Language Specification, 5th edition</cite>
|
|
<a href="#ref-ECMA-262">[ECMA-262]</a>.
|
|
</p>
|
|
<p>
|
|
Objects defined in this section have internal properties as described in
|
|
ECMA-262 sections 8.12 and 13.2 unless otherwise specified, in which case one or
|
|
more of the following are redefined in accordance with the rules for host objects:
|
|
<span class="prop">[[Call]]</span>,
|
|
<span class="prop">[[DefineOwnProperty]]</span>,
|
|
<span class="prop">[[GetOwnProperty]]</span> and
|
|
<span class="prop">[[Delete]]</span><!-- and
|
|
<span class="prop">[[HasInstance]]</span>-->.
|
|
</p>
|
|
<p>
|
|
If a value for the internal property
|
|
<span class="prop">[[Class]]</span> is not given for a particular
|
|
object, its value is implementation specific.
|
|
</p>
|
|
<p>
|
|
Unless otherwise specified, the <span class="prop">[[Extensible]]</span> internal property
|
|
of objects defined in this section has the value <span class="esvalue">true</span>.
|
|
</p>
|
|
<p>
|
|
Unless otherwise specified, the <span class="prop">[[Prototype]]</span> internal property
|
|
of objects defined in this section is the <span class="esvalue">Object</span> prototype object.
|
|
</p>
|
|
<p>
|
|
If an object is defined to be a <dfn id="dfn-function-object">function object</dfn>, then
|
|
it has characteristics as follows:
|
|
</p>
|
|
<ul>
|
|
<li>Its <span class="prop">[[Prototype]]</span> internal property is the <span class="esvalue">Function</span> prototype object.</li>
|
|
<li>Its <span class="prop">[[Get]]</span> internal property is set as described in ECMA-262 section 15.3.5.4.</li>
|
|
<li>Its <span class="prop">[[Construct]]</span> internal property is set as described in ECMA-262 section 13.2.2.</li>
|
|
<li>Its <span class="prop">[[HasInstance]]</span> internal property is set as described in ECMA-262 section 15.3.5.3, unless otherwise specified.</li>
|
|
<li>Its <span class="prop">[[Class]]</span> internal property is “Function”, unless otherwise specified.</li>
|
|
</ul>
|
|
<p>
|
|
Algorithms in this section use the conventions described in ECMA-262
|
|
section 5.2, such as the use of steps and substeps, the use of mathematical
|
|
operations, and so on. The ToBoolean, ToNumber, ToUint16, ToInt32, ToUint32, ToString,
|
|
ToObject, IsAccessorDescriptor and IsDataDescriptor abstract operations and the
|
|
Type(<var>x</var>) notation referenced in this section are defined in ECMA-262 sections 8 and 9.
|
|
</p>
|
|
|
|
<div id="es-environment" class="section">
|
|
<h3>4.1. ECMAScript environment</h3>
|
|
<p>
|
|
In an ECMAScript implementation of a given set of
|
|
<a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>,
|
|
there will exist a number of ECMAScript objects that correspond to
|
|
definitions in those <a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>.
|
|
These objects are termed the <dfn id="dfn-initial-object">initial objects</dfn>,
|
|
and comprise the following:
|
|
</p>
|
|
<ul>
|
|
<li><a class="dfnref" href="#dfn-namespace-object">namespace objects</a></li>
|
|
<li><a class="dfnref" href="#dfn-interface-object">interface objects</a></li>
|
|
<li><a class="dfnref" href="#dfn-named-constructor">named constructors</a></li>
|
|
<li><a class="dfnref" href="#dfn-interface-prototype-object">interface prototype objects</a></li>
|
|
<!--
|
|
<li><a class='dfnref' href='#dfn-mixin-prototype-object'>mixin prototype objects</a></li>
|
|
-->
|
|
<li><a class="dfnref" href="#dfn-attribute-getter">attribute getters</a></li>
|
|
<li><a class="dfnref" href="#dfn-attribute-setter">attribute setters</a></li>
|
|
<li><a href="#es-operations">the <span class="estype">Function</span> objects that correspond to operations</a></li>
|
|
<li><a href="#es-stringifier">the <span class="estype">Function</span> objects that correspond to stringifiers</a></li>
|
|
<li><a class="dfnref" href="#dfn-exception-interface-object">exception interface objects</a></li>
|
|
<li><a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype objects</a></li>
|
|
<li><a class="dfnref" href="#dfn-exception-field-getter">exception field getters</a></li>
|
|
</ul>
|
|
<p>
|
|
Each ECMAScript global environment (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 10.2.3)
|
|
<span class="rfc2119">MUST</span> have its own unique set of each of
|
|
the <a class="dfnref" href="#dfn-initial-object">initial objects</a>, created
|
|
before control enters any ECMAScript execution context associated with the
|
|
environment, but after the global object for that environment is created. The <span class="prop">[[Prototype]]</span>s
|
|
of all initial objects in a given global environment <span class="rfc2119">MUST</span> come from the
|
|
that same global environment.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
In an HTML user agent, multiple global environments can exist when
|
|
multiple frames or windows are created. Each frame or window will have
|
|
its own set of <a class="dfnref" href="#dfn-initial-object">initial objects</a>,
|
|
which the following HTML document demonstrates:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">HTML</span></div><div class="blockContent"><pre class="code"><code class="html-code"><!DOCTYPE html>
|
|
<title>Different global environments</title>
|
|
<iframe id=a></iframe>
|
|
<script>
|
|
var iframe = document.getElementById("a");
|
|
var w = iframe.contentWindow; <span class="comment">// The global object in the frame</span>
|
|
|
|
Object == w.Object; <span class="comment">// Evaluates to false, per ECMA-262</span>
|
|
Node == w.Node; <span class="comment">// Evaluates to false</span>
|
|
iframe instanceof w.Node; <span class="comment">// Evaluates to false</span>
|
|
iframe instanceof w.Object; <span class="comment">// Evaluates to false</span>
|
|
iframe.appendChild instanceof Function; <span class="comment">// Evaluates to true</span>
|
|
iframe.appendChild instanceof w.Function; <span class="comment">// Evaluates to false</span>
|
|
</script></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-type-mapping" class="section">
|
|
<h3>4.2. ECMAScript type mapping</h3>
|
|
|
|
<p>
|
|
This section describes how types in the IDL map to types in ECMAScript.
|
|
</p>
|
|
<p>
|
|
Each sub-section below describes how values of a given IDL type are represented
|
|
in ECMAScript. For each IDL type, it is described how ECMAScript values are
|
|
<dfn id="dfn-convert-ecmascript-to-idl-value">converted to an IDL value</dfn>
|
|
when passed to a <a class="dfnref" href="#dfn-platform-object">platform object</a> expecting that type, and how IDL values
|
|
of that type are <dfn id="dfn-convert-idl-to-ecmascript-value">converted to ECMAScript values</dfn>
|
|
when returned from a platform object.
|
|
</p>
|
|
|
|
<div id="es-any" class="section">
|
|
<h4>4.2.1. any</h4>
|
|
|
|
<p>
|
|
Since the IDL <a class="idltype" href="#idl-any">any</a> type
|
|
is the union of all other IDL types, it can correspond to any
|
|
ECMAScript value type.
|
|
</p>
|
|
<p>
|
|
How to <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">convert an ECMAScript value</a> to an IDL <a class="idltype" href="#idl-any">any</a> value depends on the type of the
|
|
ECMAScript value:
|
|
</p>
|
|
<dl class="switch">
|
|
<dt>The <span class="esvalue">undefined</span> value</dt>
|
|
<dd>
|
|
The IDL value is an
|
|
<a class="idltype" href="#idl-object">object</a> reference
|
|
to a special object that represents the ECMAScript
|
|
<span class="esvalue">undefined</span> value.
|
|
</dd>
|
|
<dt>The <span class="esvalue">null</span> value</dt>
|
|
<dd>
|
|
The IDL value is the <span class="idlvalue">null</span>
|
|
<a class="idltype" href="#idl-object">object?</a> reference.
|
|
</dd>
|
|
<dt>A <span class="estype">Boolean</span> value</dt>
|
|
<dd>
|
|
The IDL value is the
|
|
<a class="idltype" href="#idl-boolean">boolean</a>
|
|
value that represents the same truth value.
|
|
</dd>
|
|
<dt>A <span class="estype">Number</span> value</dt>
|
|
<dd>
|
|
The IDL value is that which is obtained
|
|
by following the rules for converting the
|
|
<span class="estype">Number</span> to an IDL
|
|
<a class="idltype" href="#idl-double">double</a> value,
|
|
as described in <a href="#es-double">section 4.2.13</a>,
|
|
below.
|
|
</dd>
|
|
<dt>A <span class="estype">String</span> value</dt>
|
|
<dd>
|
|
The IDL value is that which is obtained
|
|
by following the rules for converting the
|
|
<span class="estype">String</span> to an IDL
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> value,
|
|
as described in <a href="#es-DOMString">section 4.2.14</a>,
|
|
below.
|
|
</dd>
|
|
<dt>An <span class="estype">object</span> value</dt>
|
|
<dd>
|
|
The IDL value is an
|
|
<a class="idltype" href="#idl-object">object</a> value that
|
|
references the same object.
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
An IDL <a class="idltype" href="#idl-any">any</a> value is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted to an ECMAScript value</a>
|
|
as follows. If the value is an <a class="idltype" href="#idl-object">object</a>
|
|
reference to a special object that represents an ECMAScript <span class="esvalue">undefined</span>
|
|
value, then it is converted to the ECMAScript
|
|
<span class="esvalue">undefined</span> value. Otherwise,
|
|
the rules for converting the <a class="dfnref" href="#dfn-specific-type">specific type</a>
|
|
of the IDL <a class="idltype" href="#idl-any">any</a> value
|
|
as described in the remainder of this section are performed.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-void" class="section">
|
|
<h4>4.2.2. void</h4>
|
|
|
|
<p>
|
|
The only place that the <a class="idltype" href="#idl-void">void</a> type may appear
|
|
in IDL is as the <a class="dfnref" href="#dfn-return-type">return type</a> of an
|
|
<a class="dfnref" href="#dfn-operation">operation</a>. Functions on <a class="dfnref" href="#dfn-platform-object">platform objects</a>
|
|
that implement an operation whose IDL specifies a
|
|
<a class="idltype" href="#idl-void">void</a> return type <span class="rfc2119">MUST</span> return the
|
|
<span class="esvalue">undefined</span> value.
|
|
</p>
|
|
<p>
|
|
ECMAScript functions that implement an operation whose IDL
|
|
specifies a <a class="idltype" href="#idl-void">void</a> return type
|
|
<span class="rfc2119">MAY</span> return any value, which will be discarded.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-boolean" class="section">
|
|
<h4>4.2.3. boolean</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-boolean">boolean</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the result of computing ToBoolean(<var>V</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-boolean">boolean</a> value that is the one that represents the same truth value as the ECMAScript <span class="estype">Boolean</span> value <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The IDL <a class="idltype" href="#idl-boolean">boolean</a> value <span class="idlvalue">true</span>
|
|
is <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted</a> to
|
|
the ECMAScript <span class="esvalue">true</span> value and the IDL <a class="idltype" href="#idl-boolean">boolean</a>
|
|
value <span class="idlvalue">false</span> is converted to the ECMAScript
|
|
<span class="esvalue">false</span> value.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-byte" class="section">
|
|
<h4>4.2.4. byte</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-byte">byte</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < −2<sup>7</sup> or <var>x</var> > 2<sup>7</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-byte">byte</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, −2<sup>7</sup>), 2<sup>7</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-byte">byte</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +0, −0, +∞, or −∞, then return the IDL <a class="idltype" href="#idl-byte">byte</a> value that represents 0.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>Set <var>x</var> to <var>x</var> modulo 2<sup>8</sup>.</li>
|
|
<li>If <var>x</var> ≥ 2<sup>7</sup>, return the IDL <a class="idltype" href="#idl-byte">byte</a> value that represents the same numeric value as <var>x</var> − 2<sup>8</sup>.
|
|
Otherwise, return the IDL <a class="idltype" href="#idl-byte">byte</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-byte">byte</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that represents
|
|
the same numeric value as the IDL <a class="idltype" href="#idl-byte">byte</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [−128, 127].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-octet" class="section">
|
|
<h4>4.2.5. octet</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-octet">octet</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < 0 or <var>x</var> > 2<sup>8</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-octet">octet</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, 0), 2<sup>8</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-octet">octet</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +0, −0, +∞, or −∞, then return the IDL <a class="idltype" href="#idl-octet">octet</a> value that represents 0.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>Set <var>x</var> to <var>x</var> modulo 2<sup>8</sup>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-octet">octet</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-octet">octet</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that represents
|
|
the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-octet">octet</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [0, 255].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-short" class="section">
|
|
<h4>4.2.6. short</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-short">short</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < −2<sup>15</sup> or <var>x</var> > 2<sup>15</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-short">short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, −2<sup>15</sup>), 2<sup>15</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-short">short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +0, −0, +∞, or −∞, then return the IDL <a class="idltype" href="#idl-short">short</a> value that represents 0.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>Set <var>x</var> to <var>x</var> modulo 2<sup>16</sup>.</li>
|
|
<li>If <var>x</var> ≥ 2<sup>15</sup>, return the IDL <a class="idltype" href="#idl-short">short</a> value that represents the same numeric value as <var>x</var> − 2<sup>16</sup>.
|
|
Otherwise, return the IDL <a class="idltype" href="#idl-short">short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-short">short</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that represents the
|
|
same numeric value as the IDL
|
|
<a class="idltype" href="#idl-short">short</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [−32768, 32767].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-unsigned-short" class="section">
|
|
<h4>4.2.7. unsigned short</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < 0 or <var>x</var> > 2<sup>16</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, 0), 2<sup>16</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Set <var>x</var> to ToUint16(<var>x</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-unsigned-short">unsigned short</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [0, 65535].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-long" class="section">
|
|
<h4>4.2.8. long</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-long">long</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < −2<sup>31</sup> or <var>x</var> > 2<sup>31</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-long">long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, −2<sup>31</sup>), 2<sup>31</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-long">long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Set <var>x</var> to ToInt32(<var>x</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-long">long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-long">long</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-long">long</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [−2147483648, 2147483647].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-unsigned-long" class="section">
|
|
<h4>4.2.9. unsigned long</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < 0 or <var>x</var> > 2<sup>32</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, 0), 2<sup>32</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Set <var>x</var> to ToUint32(<var>x</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a> value.
|
|
The <span class="estype">Number</span> value will be an integer in the range [0, 4294967295].
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-long-long" class="section">
|
|
<h4>4.2.10. long long</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-long-long">long long</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < −2<sup>63</sup> or <var>x</var> > 2<sup>63</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-long-long">long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, −2<sup>63</sup>), 2<sup>63</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-long-long">long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +0, −0, +∞, or −∞, then return the IDL <a class="idltype" href="#idl-long-long">long long</a> value that represents 0.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>Set <var>x</var> to <var>x</var> modulo 2<sup>64</sup>.</li>
|
|
<li>If <var>x</var> is greater than or equal to 2<sup>63</sup>, return the IDL <a class="idltype" href="#idl-long-long">long long</a> value that represents the same numeric value as <var>x</var> − 2<sup>64</sup>.
|
|
Otherwise, return the IDL <a class="idltype" href="#idl-long-long">long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-long-long">long long</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> value that
|
|
represents the closest numeric value to the <a class="idltype" href="#idl-long-long">long long</a>,
|
|
choosing the numeric value with an <em>even significand</em> if there are
|
|
two equally close values (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.5).
|
|
If the <a class="idltype" href="#idl-long-long">long long</a> is in the range
|
|
(−(2<sup>53</sup> − 1), 2<sup>53</sup> − 1), then the <span class="estype">Number</span>
|
|
will be able to represent exactly the same value as the
|
|
<a class="idltype" href="#idl-long-long">long long</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-unsigned-long-long" class="section">
|
|
<h4>4.2.11. unsigned long long</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>x</var> to ToNumber(<var>V</var>).</li>
|
|
<li>If the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +∞, or −∞, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>If <var>x</var> < 0 or <var>x</var> > 2<sup>64</sup> − 1, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is not <span class="esvalue">NaN</span> and the conversion to an IDL value is being performed due to any of the following:
|
|
<ul>
|
|
<li><var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,</li>
|
|
<li><var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a> argument annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute, or</li>
|
|
<li><var>V</var> is being used as the value of <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> annotated with the <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute,</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>Round <var>x</var> to the nearest integer, choosing the even integer if it lies halfway between two.</li>
|
|
<li>Set <var>x</var> to min(max(<var>x</var>, 0), 2<sup>64</sup> − 1).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, +0, −0, +∞, or −∞, then return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value that represents 0.</li>
|
|
<li>Set <var>x</var> to sign(<var>x</var>) * floor(abs(<var>x</var>)).</li>
|
|
<li>Set <var>x</var> to <var>x</var> modulo 2<sup>64</sup>.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value that represents the same numeric value as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span> value that
|
|
represents the closest numeric value to the <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a>,
|
|
choosing the numeric value with an <em>even significand</em> if there are
|
|
two equally close values (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.5).
|
|
If the <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> is less than or equal to 2<sup>53</sup> − 1,
|
|
then the <span class="estype">Number</span> will be able to
|
|
represent exactly the same value as the
|
|
<a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-float" class="section">
|
|
<h4>4.2.12. float</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-float">float</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be ToNumber(<var>V</var>).</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, then return the IDL <a class="idltype" href="#idl-float">float</a> value that represents the IEEE 754 NaN value with the bit pattern 0x7fc00000 <a href="#ref-IEEE-754">[IEEE-754]</a>.</li>
|
|
<li>
|
|
Let <var>S</var> be the set of finite IEEE 754 single-precision floating
|
|
point values except −0, but with two special values added: 2<sup>128</sup> and
|
|
−2<sup>128</sup>.
|
|
</li>
|
|
<li>
|
|
Let <var>y</var> be the number in <var>S</var> that is closest
|
|
to <var>x</var>, selecting the number with an
|
|
<em>even significand</em> if there are two equally close values
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.5).
|
|
(The two special values 2<sup>128</sup> and −2<sup>128</sup>
|
|
are considered to have even significands for this purpose.)
|
|
</li>
|
|
<li>
|
|
If <var>y</var> is 2<sup>128</sup>, return +∞.
|
|
</li>
|
|
<li>
|
|
If <var>y</var> is −2<sup>128</sup>, return −∞.
|
|
</li>
|
|
<li>
|
|
If <var>y</var> is +0 and <var>x</var> is negative, return −0.
|
|
</li>
|
|
<li>
|
|
Return <var>y</var>.
|
|
</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Since there is only a single ECMAScript <span class="esvalue">NaN</span> value,
|
|
it must be canonicalized to a particular single precision IEEE 754 NaN value. The NaN value
|
|
mentioned above is chosen simply because it is the quiet NaN with the lowest
|
|
value when its bit pattern is interpreted as an unsigned 32 bit integer.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-float">float</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span>:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the IDL <a class="idltype" href="#idl-float">float</a> value is a NaN,
|
|
then the <span class="estype">Number</span> value is <span class="esvalue">NaN</span>.
|
|
</li>
|
|
<li>
|
|
Otherwise, the <span class="estype">Number</span> value is
|
|
the one that represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-float">float</a> value.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="es-double" class="section">
|
|
<h4>4.2.13. double</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-double">double</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be ToNumber(<var>V</var>).</li>
|
|
<li>If <var>x</var> is <span class="esvalue">NaN</span>, then return the IDL <a class="idltype" href="#idl-double">double</a> value that represents the IEEE 754 NaN value with the bit pattern 0x7ff8000000000000 <a href="#ref-IEEE-754">[IEEE-754]</a>.</li>
|
|
<li>
|
|
Return the IDL <a class="idltype" href="#idl-double">double</a> value
|
|
that has the same numeric value as <var>x</var>.
|
|
</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Since there is only a single ECMAScript <span class="esvalue">NaN</span> value,
|
|
it must be canonicalized to a particular double precision IEEE 754 NaN value. The NaN value
|
|
mentioned above is chosen simply because it is the quiet NaN with the lowest
|
|
value when its bit pattern is interpreted as an unsigned 64 bit integer.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-double">double</a> value to an ECMAScript
|
|
value is a <span class="estype">Number</span>:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the IDL <a class="idltype" href="#idl-double">double</a> value is a NaN,
|
|
then the <span class="estype">Number</span> value is <span class="esvalue">NaN</span>.
|
|
</li>
|
|
<li>
|
|
Otherwise, the <span class="estype">Number</span> value is
|
|
the one that represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-double">double</a> value.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="es-DOMString" class="section">
|
|
<h4>4.2.14. DOMString</h4>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-DOMString">DOMString</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>V</var> is <span class="esvalue">null</span>
|
|
and the conversion to an IDL value is being performed due
|
|
to any of the following:
|
|
<ul>
|
|
<li>
|
|
<var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
argument that is annotated with the <a class="xattr" href="#TreatNullAs">[TreatNullAs=EmptyString]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
annotated with <a class="xattr" href="#TreatNullAs">[TreatNullAs=EmptyString]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
operation annotated with <a class="xattr" href="#TreatNullAs">[TreatNullAs=EmptyString]</a>, or
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
attribute annotated with <a class="xattr" href="#TreatNullAs">[TreatNullAs=EmptyString]</a>,
|
|
</li>
|
|
</ul>
|
|
then return the <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
value that represents the empty string.
|
|
</li>
|
|
<li>If <var>V</var> is <span class="esvalue">undefined</span>
|
|
and the conversion to an IDL value is being performed due
|
|
to any of the following:
|
|
<ul>
|
|
<li>
|
|
<var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
argument that is annotated with the <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=EmptyString]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=EmptyString]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
operation annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=EmptyString]</a>, or
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
attribute annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=EmptyString]</a>,
|
|
</li>
|
|
</ul>
|
|
then return the <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
value that represents the empty string.
|
|
</li>
|
|
<li>Let <var>x</var> be ToString(<var>V</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-DOMString">DOMString</a> value that represents the same sequence of code units as the one the ECMAScript <span class="estype">String</span> value <var>x</var> represents.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-DOMString">DOMString</a> value to an ECMAScript
|
|
value is the <span class="estype">String</span>
|
|
value that represents the same sequence of <a class="dfnref" href="#dfn-code-unit">code units</a> that the
|
|
IDL <a class="idltype" href="#idl-DOMString">DOMString</a> represents.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-object" class="section">
|
|
<h4>4.2.15. object</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-object">object</a>
|
|
values are represented by ECMAScript <span class="estype">Object</span> values.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-object">object</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the result of calling ToObject(<var>V</var>).</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-object">object</a> value that is a reference to the same object as <var>x</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-object">object</a> value to an ECMAScript
|
|
value is the <span class="estype">Object</span> value that represents a reference to the same object that the
|
|
IDL <a class="idltype" href="#idl-object">object</a> represents.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-interface" class="section">
|
|
<h4>4.2.16. Interface types</h4>
|
|
|
|
<p>
|
|
IDL <a href="#idl-interface">interface type</a>
|
|
values are represented by ECMAScript <span class="estype">Object</span> values.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a href="#idl-interface">interface type</a> value
|
|
by running the following algorithm (where <var>I</var> is the <a class="dfnref" href="#dfn-interface">interface</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the result of calling ToObject(<var>V</var>).</li>
|
|
<li>If <var>x</var> is a <a class="dfnref" href="#dfn-platform-object">platform object</a> that implements <var>I</var>, then return the IDL <a href="#idl-interface">interface type</a> value that represents a reference to that platform object.</li>
|
|
<li>If <var>x</var> is a <a class="dfnref" href="#dfn-user-object">user object</a> that is considered to implement <var>I</var> according to the rules in <a href="#es-user-objects">section 4.8</a>, then return the IDL <a href="#idl-interface">interface type</a> value that represents a reference to that user object.</li>
|
|
<li>Throw a <span class="esvalue">TypeError</span>.</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a href="#idl-interface">interface type</a>
|
|
value to an ECMAScript value is the <span class="estype">Object</span>
|
|
value that represents a reference to the same object that the IDL
|
|
<a href="#idl-interface">interface type</a> value represents.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-dictionary" class="section">
|
|
<h4>4.2.17. Dictionary types</h4>
|
|
|
|
<p>
|
|
IDL <a href="#idl-dictionary">dictionary type</a> values are represented
|
|
by ECMAScript <span class="estype">Object</span> values. Properties on
|
|
the object (or its prototype chain) correspond to <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a>.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a href="#idl-dictionary">dictionary type</a> value
|
|
by running the following algorithm (where <var>D</var> is the <a class="dfnref" href="#dfn-dictionary">dictionary</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If Type(<var>V</var>) is not Object, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Let <var>dict</var> be an empty dictionary value of type <var>D</var>;
|
|
every <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a>
|
|
is initially considered to be <a class="dfnref" href="#dfn-present">not present</a>.</li>
|
|
<li>Let <var>dictionaries</var> be a list consisting of <var>D</var> and all of <var>D</var>’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>,
|
|
in order from least to most derived.</li>
|
|
<li>For each dictionary <var>dictionary</var> in <var>dictionaries</var>, in order:
|
|
<ol>
|
|
<li>For each dictionary member <var>member</var> declared on <var>D</var>, in order:
|
|
<ol>
|
|
<li>Let <var>key</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of <var>member</var>.</li>
|
|
<li>Let <var>present</var> be the result of calling the <span class="prop">[[HasProperty]]</span> internal method on <var>V</var> with property name <var>key</var>.</li>
|
|
<li>If <var>present</var> is true, then:
|
|
<ol>
|
|
<li>Let <var>value</var> be the result of calling the <span class="prop">[[Get]]</span> internal method on <var>V</var> with property name <var>key</var>.</li>
|
|
<li>Let <var>idlValue</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a> <var>value</var> to an IDL value whose type is the type <var>member</var> is declared to be of.</li>
|
|
<li>Set the dictionary member on <var>dict</var> with key name <var>key</var> to the value <var>idlValue</var>. This dictionary member is considered to be <a class="dfnref" href="#dfn-present">present</a>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>dict</var>.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
The order that <a class="dfnref" href="#dfn-dictionary-member">dictionary members</a> are looked
|
|
up on the ECMAScript object are not necessarily the same as the object’s property enumeration order.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
An IDL dictionary value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted</a>
|
|
to an ECMAScript <span class="estype">Object</span> value
|
|
by running the following algorithm (where <var>D</var> is the <a class="dfnref" href="#dfn-dictionary">dictionary</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be a new <span class="estype">Object</span> value created as if by the expression <code>({})</code>.</li>
|
|
<li>Let <var>dictionaries</var> be a list consisting of <var>D</var> and all of <var>D</var>’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>,
|
|
in order from least to most derived.</li>
|
|
<li>For each dictionary <var>dictionary</var> in <var>dictionaries</var>, in order:
|
|
<ol>
|
|
<li>For each dictionary member <var>member</var> declared on <var>dictionary</var>, in order:
|
|
<ol>
|
|
<li>Let <var>key</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of <var>member</var>.</li>
|
|
<li>If the dictionary member named <var>key</var> is <a class="dfnref" href="#dfn-present">present</a> on <var>V</var>, then:
|
|
<ol>
|
|
<li>Let <var>idlValue</var> be the value of <var>member</var> on <var>V</var>.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a> <var>idlValue</var> to an ECMAScript value.</li>
|
|
<li>Call the <span class="prop">[[DefineOwnProperty]]</span> internal method on <var>O</var> with property name <var>key</var>,
|
|
descriptor <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span>, [[Value]]: <var>value</var> }</span>
|
|
and Boolean flag <span class="esvalue">false</span>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>O</var>.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="es-nullable-type" class="section">
|
|
<h4>4.2.18. Nullable types — <var>T</var>?</h4>
|
|
|
|
<p>
|
|
IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a> values are represented
|
|
by values of either the ECMAScript type corresponding to the <a class="dfnref" href="#dfn-inner-type">inner IDL type</a>, or
|
|
the ECMAScript <span class="esvalue">null</span> value.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a> <span class="idltype"><var>T</var>?</span>
|
|
value (where <var>T</var> is the <a class="dfnref" href="#dfn-inner-type">inner type</a>) as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
If <var>V</var> is <span class="esvalue">undefined</span> and the
|
|
IDL type being converted to is <span class="idltype">DOMString?</span>, then:
|
|
<ol>
|
|
<li>
|
|
If the conversion to an IDL value is being performed due
|
|
to any of the following:
|
|
<ul>
|
|
<li>
|
|
<var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
argument that is annotated with the <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
operation annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>, or
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being returned from a <a class="dfnref" href="#dfn-user-object">user object</a> implementation of an
|
|
attribute annotated with <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>,
|
|
</li>
|
|
</ul>
|
|
then:
|
|
<ol>
|
|
<li>
|
|
If the argument given to <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
is <code>EmptyString</code>, then return the <span class="idltype">DOMString?</span>
|
|
value that represents the empty string.
|
|
</li>
|
|
<li>
|
|
Otherwise, the argument given to <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
is <code>Null</code>. Return the <span class="idlvalue">null</span>
|
|
<span class="idltype">DOMString?</span> value.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
Otherwise, if the result of calling IsCallable(<var>V</var>) is <span class="esvalue">true</span>, then:
|
|
<ol>
|
|
<li>
|
|
If the conversion to an IDL value is being performed due
|
|
to any of the following:
|
|
<ul>
|
|
<li>
|
|
<var>V</var> is being passed as an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
argument that is annotated with the <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>,
|
|
</li>
|
|
<li>
|
|
<var>V</var> is being assigned to an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
annotated with <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>,
|
|
</li>
|
|
</ul>
|
|
then return the IDL
|
|
<a class="dfnref" href="#dfn-nullable-type">nullable type</a> <span class="idltype"><var>T</var>?</span>
|
|
value <span class="idlvalue">null</span>.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
Otherwise, if <var>V</var> is <span class="esvalue">null</span> or <span class="esvalue">undefined</span>, then return the IDL
|
|
<a class="dfnref" href="#dfn-nullable-type">nullable type</a> <span class="idltype"><var>T</var>?</span>
|
|
value <span class="idlvalue">null</span>.
|
|
</li>
|
|
<li>
|
|
Otherwise, return the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a> <var>V</var>
|
|
to the <a class="dfnref" href="#dfn-inner-type">inner IDL type</a> <span class="idltype"><var>T</var></span>.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
an IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a> value to an ECMAScript value is:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a> <span class="idltype"><var>T</var>?</span>
|
|
value is <span class="idlvalue">null</span>,
|
|
then the ECMAScript value is <span class="esvalue">null</span>.
|
|
</li>
|
|
<li>
|
|
Otherwise, the IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a> value is the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
the ECMAScript value to the <a class="dfnref" href="#dfn-inner-type">inner IDL type</a> <span class="idltype"><var>T</var></span>.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="es-sequence" class="section">
|
|
<h4>4.2.19. Sequences — sequence<<var>T</var>></h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> values are represented by
|
|
ECMAScript <span class="estype">Array</span> values.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> value as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>V</var> is <span class="esvalue">null</span> or <span class="esvalue">undefined</span>,
|
|
then return a sequence of length zero.</li>
|
|
<li>Let <var>A</var> be the result of calling ToObject(<var>V</var>).</li>
|
|
<li>Let <var>length</var> be the result of calling <span class="prop">[[Get]]</span> on <var>A</var> with property name “length”.</li>
|
|
<li>Let <var>n</var> be the result of calling ToUint32(<var>length</var>).</li>
|
|
<li>Initialize <var>S</var><sub>0..<var>n</var>−1</sub> to be an IDL sequence with elements of type <var>T</var>, where each element is uninitialized.</li>
|
|
<li>Initialize <var>i</var> to be 0.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>P</var> be the result of calling ToString(<var>i</var>).</li>
|
|
<li>Let <var>E</var> be the result of calling <span class="prop">[[Get]]</span> on <var>A</var> with property name <var>P</var>.</li>
|
|
<li>Set <var>S</var><sub><var>i</var></sub> to the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>E</var> to an IDL value of type <var>T</var>.</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>S</var>.</li>
|
|
</ol>
|
|
<p>
|
|
An IDL sequence value <var>S</var><sub>0..<var>n</var>−1</sub> of type
|
|
<a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted</a>
|
|
to an ECMAScript <span class="estype">Array</span> object as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>A</var> be a new <span class="estype">Array</span> object created as if by the expression <code>[]</code>.</li>
|
|
<li>Initialize <var>i</var> to be 0.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>E</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>S</var><sub><var>i</var></sub> to an ECMAScript value.</li>
|
|
<li>Let <var>P</var> be the result of calling ToString(<var>i</var>).</li>
|
|
<li>Call the <span class="prop">[[DefineOwnProperty]]</span> internal method on <var>A</var> with property name <var>P</var>,
|
|
descriptor <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span>, [[Value]]: <var>E</var> }</span>
|
|
and Boolean flag <span class="esvalue">false</span>.</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>A</var>.</li>
|
|
</ol>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-interface">interface</a> defines
|
|
an <a class="dfnref" href="#dfn-attribute">attribute</a> of a sequence
|
|
type as well as an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
with an argument of a sequence type.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Canvas {
|
|
|
|
sequence<DOMString> getSupportedImageCodecs();
|
|
|
|
void drawPolygon(sequence<float> coordinates);
|
|
sequence<float> getLastDrawnPolygon();
|
|
|
|
<span class="comment">// ...</span>
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of this interface, an <span class="estype">Array</span>
|
|
object with elements of type <span class="estype">String</span> is used to
|
|
represent a <span class="idltype">sequence<DOMString></span>, while an
|
|
<span class="estype">Array</span> with elements of type <span class="estype">Number</span>
|
|
represents a <span class="idltype">sequence<float></span>. The
|
|
<span class="estype">Array</span> objects are effectively passed by
|
|
value; every time the <code>getSupportedImageCodecs()</code>
|
|
function is called a new <span class="estype">Array</span> is
|
|
returned, and whenever an <span class="estype">Array</span> is
|
|
passed to <code>drawPolygon</code> no reference
|
|
will be kept after the call completes.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">
|
|
<span class="comment">// Obtain an instance of Canvas. Assume that getSupportedImageCodecs()</span>
|
|
<span class="comment">// returns a sequence with two DOMString values: "image/png" and "image/svg+xml".</span>
|
|
var canvas = getCanvas();
|
|
|
|
<span class="comment">// An Array object of length 2.</span>
|
|
var supportedImageCodecs = canvas.getSupportedImageCodecs();
|
|
|
|
<span class="comment">// Evaluates to "image/png".</span>
|
|
supportedImageCodecs[0];
|
|
|
|
<span class="comment">// Each time canvas.getSupportedImageCodecs() is called, it returns a</span>
|
|
<span class="comment">// new Array object. Thus modifying the returned Array will not</span>
|
|
<span class="comment">// affect the value returned from a subsequent call to the function.</span>
|
|
supportedImageCodecs[0] = "image/jpeg";
|
|
|
|
<span class="comment">// Evaluates to "image/png".</span>
|
|
canvas.getSupportedImageCodecs()[0];
|
|
|
|
<span class="comment">// This evaluates to false.</span>
|
|
canvas.getSupportedImageCodecs() == canvas.getSupportedImageCodecs();
|
|
|
|
|
|
<span class="comment">// An Array of Numbers...</span>
|
|
var a = [0, 0, 100, 0, 50, 62.5];
|
|
|
|
<span class="comment">// ...can be passed to a platform object expecting a sequence<float>.</span>
|
|
canvas.drawPolygon(a);
|
|
|
|
<span class="comment">// Each element will be converted to a float by first calling ToNumber().</span>
|
|
<span class="comment">// So the following call is equivalent to the previous one, except that</span>
|
|
<span class="comment">// "hi" will be alerted before drawPolygon() returns.</span>
|
|
a = [false, '',
|
|
{ valueOf: function() { alert('hi'); return 100; } }, 0,
|
|
'50', new Number(62.5)];
|
|
canvas.drawPolygon(s);
|
|
|
|
<span class="comment">// Modifying an Array that was passed to drawPolygon() is guaranteed not to</span>
|
|
<span class="comment">// have an effect on the Canvas, since the Array is effectively passed by value.</span>
|
|
a[4] = 20;
|
|
var b = canvas.getLastDrawnPolygon();
|
|
alert(b[4]); <span class="comment">// This would alert "50".</span></code></pre></div></div>
|
|
</div>
|
|
<!--
|
|
<div class='ignore'>
|
|
<p>
|
|
IDL <a class='idltype' href='#idl-sequence'>sequence<<var>T</var>></a> values are represented by
|
|
ECMAScript <span class='estype'>Object</span> values with special properties.
|
|
</p>
|
|
<p>
|
|
Values <a class='dfnref' href='#dfn-pass-to-host-object'>passed to a host object</a> expecting a
|
|
<a class='idltype' href='#idl-sequence'>sequence<<var>T</var>></a>
|
|
<span class='rfc2119'>MUST</span> be objects with a <span class='prop'>length</span> property whose
|
|
value, after being converted to a <span class='estype'>Number</span> by the
|
|
ToUint32 operator, is a non-negative integer that specifies the number
|
|
of elements in the sequence. This number <span class='rfc2119'>MUST</span> also be equal
|
|
to the result of passing the original <span class='prop'>length</span> property value to the ToNumber algorithm.
|
|
Assigning to the <span class='prop'>length</span> property a non-negative
|
|
integer <span class='estype'>Number</span> <span class='rfc2119'>MUST</span> change the length of the sequence
|
|
to be the given number. If the sequence is lengthened, new elements <span class='rfc2119'>MUST</span> be given
|
|
the value that the <span class='esvalue'>undefined</span> value is converted to
|
|
when handling it according to the rules in this section for the type <var>T</var>.
|
|
If the sequence is shortened, the values beyond the new length of the sequence
|
|
are lost.
|
|
The object representing the sequence <span class='rfc2119'>MUST</span> return the element in
|
|
the sequence at position <var>n</var> when its
|
|
<span class='prop'>[[Get]]</span> internal method is invoked with
|
|
<var>n</var> as its argument.
|
|
</p>
|
|
<p>
|
|
Note that an ECMAScript <span class='estype'>Array</span>
|
|
is an object that matches this description. Implementations are free,
|
|
however, to use a host object to implement the sequence in the
|
|
interests of efficiency.
|
|
</p>
|
|
<p>
|
|
When the host object
|
|
gets an element of the sequence using the <span class='prop'>[[Get]]</span> method,
|
|
the returned value <span class='rfc2119'>MUST</span> first be handled according to
|
|
the rules in this section for the type <var>T</var>.
|
|
</p>
|
|
<p>
|
|
If a host object expecting a
|
|
<a class='idltype' href='#idl-sequence'>sequence<<var>T</var>></a>
|
|
is passed a value which is not an object that conforms to the above rules
|
|
(for example, it does not have a <span class='prop'>length</span> property), then
|
|
a <span class='estype'>TypeError</span> exception <span class='rfc2119'>MUST</span> be thrown.
|
|
</p>
|
|
<p>
|
|
While sequences are passed by reference (being objects), it is
|
|
of course up to the interface designer whether, for example,
|
|
after assigning a sequence to a property on a host object
|
|
that same seqence object is returned when getting the property.
|
|
The behavior of storing sequences in the host object in this
|
|
manner should be made clear in prose describing the interface.
|
|
</p>
|
|
<!- p>
|
|
Sequences are passed by reference. If a reference to a sequence
|
|
passed to a host object is kept (whether internally or as the
|
|
value of an attribute), and the passed sequence is not an ECMAScript
|
|
<span class='estype'>Array</span> object, the kept reference must
|
|
be a newly created ECMAScript <span class='estype'>Array</span> object
|
|
whose contents is the elements of the sequence.
|
|
</p>
|
|
<div class='ednote'>
|
|
<p>Change the above para according to comments in
|
|
<a href='http://www.w3.org/mid/op.tumn9hy664w2qv@annevk-t60.oslo.opera.com'>this thread</a>.</p>
|
|
</div ->
|
|
<div class='ednote'>
|
|
<p>
|
|
Should there be a way to declare a sequence whose length cannot be changed
|
|
from script?
|
|
</p>
|
|
</div>
|
|
</div>
|
|
-->
|
|
</div>
|
|
|
|
<div id="es-array" class="section">
|
|
<h4>4.2.20. Arrays — <var>T</var>[]</h4>
|
|
|
|
<p>
|
|
IDL array values are represented by references to objects known
|
|
as <dfn id="dfn-platform-array-object">platform array objects</dfn>, with particular
|
|
characteristics that allow them to behave similarly to native <span class="estype">Array</span>
|
|
objects. All <a class="dfnref" href="#dfn-platform-array-object">platform array objects</a>
|
|
are <a class="dfnref" href="#dfn-platform-object">platform objects</a>, and
|
|
thus each is associated with a particular global environment.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-platform-array-object">Platform array objects</a> differ
|
|
from <span class="estype">Array</span> objects in the following ways:
|
|
</p>
|
|
<ul>
|
|
<li>they are never sparse</li>
|
|
<li>their elements are always data properties</li>
|
|
<li>an ECMAScript-to-IDL value conversion is always performed when storing an element</li>
|
|
<li>their internal <span class="prop">[[Class]]</span> property value is different</li>
|
|
<li>their internal <span class="prop">[[Extensible]]</span> property value is always <span class="esvalue">true</span></li>
|
|
</ul>
|
|
</div>
|
|
<p>
|
|
The value of the internal <span class="prop">[[Prototype]]</span> property of a
|
|
<a class="dfnref" href="#dfn-platform-array-object">platform array object</a>
|
|
<span class="rfc2119">MUST</span> be the
|
|
<span class="estype">Array</span> prototype object
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4.4)
|
|
from its associated global environment.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Note that some of the functions from the <span class="estype">Array</span> prototype object
|
|
will not behave on a <a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
platform array object as they do on an <span class="estype">Array</span> object, since
|
|
attempting to assign to the “length” property will fail.
|
|
Similarly, some of the functions from the <span class="estype">Array</span>
|
|
prototype object will not perform any useful operation on
|
|
<a class="dfnref" href="#dfn-read-only-array">read only arrays</a>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
The value of the internal <span class="prop">[[Class]]</span> property of a
|
|
platform array object <span class="rfc2119">MUST</span> be
|
|
the <a class="dfnref" href="#dfn-type-name">type name</a> of the
|
|
<a href="#idl-array">array type</a>.
|
|
</p>
|
|
<!--
|
|
<p>
|
|
Platform array objects <span class='rfc2119'>MUST</span> have a property named “length”
|
|
whose value is a <span class='estype'>Number</span> that is the length
|
|
of the array. If the array is <a class='dfnref' href='#dfn-fixed-length'>fixed length</a>,
|
|
then this property has attributes <span class='descriptor'>{ [[Writable]]: <span class='esvalue'>false</span>, [[Enumerable]]: <span class='esvalue'>false</span>, [[Configurable]]: <span class='esvalue'>false</span> }</span>.
|
|
Otherwise, the array is <a class='dfnref' href='#dfn-variable-length'>variable length</a>,
|
|
and the property has attributes <span class='descriptor'>{ [[Writable]]: <span class='esvalue'>true</span>, [[Enumerable]]: <span class='esvalue'>false</span>, [[Configurable]]: <span class='esvalue'>false</span> }</span>.
|
|
</p>
|
|
<p>
|
|
Platform array objects <span class='rfc2119'>MUST</span> always have a property named
|
|
ToString(<var>i</var>) for every integer index 0 ≤ <var>i</var> < <var>n</var>,
|
|
where <var>n</var> is the length of the array. These properties have attributes
|
|
<span class='descriptor'>{ [[Writable]]: <span class='esvalue'>false</span>, [[Enumerable]]: <span class='esvalue'>true</span>, [[Configurable]]: <span class='esvalue'>false</span> }</span> if the array is
|
|
<a class='dfnref' href='#dfn-read-only-array'>read only</a> and
|
|
<span class='descriptor'>{ [[Writable]]: <span class='esvalue'>true</span>, [[Enumerable]]: <span class='esvalue'>true</span>, [[Configurable]]: <span class='esvalue'>false</span> }</span> otherwise. The values of these properties
|
|
<span class='rfc2119'>MUST</span> be the result of <a class='dfnref' href='#dfn-convert-idl-to-ecmascript-value'>converting</a>
|
|
the value of the array element at the corresponding index to an ECMAScript value.
|
|
</p>
|
|
-->
|
|
|
|
<p>
|
|
Platform array objects appear to have a “length” property and a property
|
|
for each element of the array. The values and behaviors of these properties are
|
|
implemented by the internal <span class="prop">[[GetOwnProperty]]</span>,
|
|
<span class="prop">[[DefineOwnProperty]]</span> and <span class="prop">[[Delete]]</span>
|
|
methods, which are also defined below.
|
|
</p>
|
|
|
|
<p>
|
|
Platform array objects cannot be fixed; if <code>Object.freeze</code>, <code>Object.seal</code>
|
|
or <code>Object.preventExtensions</code> is called on one, the function
|
|
<span class="rfc2119">MUST</span> throw a <span class="estype">TypeError</span>.
|
|
</p>
|
|
|
|
<p>
|
|
An ECMAScript value <var>V</var> is <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL array value of type <span class="idltype"><var>T</var>[]</span> as follows:
|
|
</p>
|
|
<ul>
|
|
<li>Let <var>O</var> be the result of calling ToObject(<var>V</var>).</li>
|
|
<li>If <var>O</var> is a <a class="dfnref" href="#dfn-platform-array-object">platform array object</a>,
|
|
then the IDL array value is the array value that the platform array object represents.</li>
|
|
<li>Otherwise, the IDL array value is determined as follows:
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>n</var> to be the result of calling <span class="prop">[[Get]]</span> on <var>V</var> with property name “length”.</li>
|
|
<li>Set <var>n</var> to ToUint32(<var>n</var>).</li>
|
|
<li>Initialize <var>values</var><sub>0..<var>n</var>−1</sub> to be a list of IDL values.</li>
|
|
<li>Initialize <var>i</var> to be 0.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>x</var> be the result of calling <span class="prop">[[Get]]</span> on <var>V</var> with
|
|
property name ToString(<var>i</var>).</li>
|
|
<li>Set <var>values</var><sub><var>i</var></sub> to be the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>x</var> to an IDL value of type <var>T</var>.</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>The IDL array value is a <a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
array of length <var>n</var> whose values are <var>values</var><sub>0..<var>n</var>−1</sub>.</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>
|
|
An IDL array value <var>V</var> of type <span class="idltype"><var>T</var>[]</span> is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted</a> to an
|
|
ECMAScript value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If <var>V</var> is already represented by a <a class="dfnref" href="#dfn-platform-array-object">platform array object</a>,
|
|
then the ECMAScript value is that platform array object.</li>
|
|
<li>Otherwise, the ECMAScript value is a newly created platform array object that represents <var>V</var>.</li>
|
|
</ul>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following IDL defines an interface that has an
|
|
<span class="idltype">unsigned short[]</span> attribute.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Constructor]
|
|
interface LotteryResults {
|
|
readonly attribute unsigned short[] numbers;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Assuming that the array has a <a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
of 6, the following ECMAScript code illustrates how the array
|
|
attribute in the above interface would behave:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var results = new LotteryResults(); <span class="comment">// results is a new platform object</span>
|
|
<span class="comment">// implementing the LotteryResults interface.</span>
|
|
|
|
var a = [4, 8, 15, 16, 23, 42]; <span class="comment">// Numbers will be assigned into the array.</span>
|
|
for (var i = 0; i < 6; i++) {
|
|
results.numbers[i] = a[i];
|
|
}
|
|
|
|
results.numbers = a; <span class="comment">// This has no effect, since numbers is</span>
|
|
<span class="comment">// read only.</span>
|
|
|
|
a[0] = 5; <span class="comment">// Change the array.</span>
|
|
results.numbers[0]; <span class="comment">// Evaluates to 4, since results.numbers is</span>
|
|
<span class="comment">// not a reference to 'a'.</span>
|
|
|
|
results.numbers[0] = 5; <span class="comment">// Modifies the array stored in the platform</span>
|
|
<span class="comment">// object.</span>
|
|
results.numbers[0]; <span class="comment">// Now evaluates to 5.</span>
|
|
|
|
results.numbers[0] = 6.25; <span class="comment">// Assigns 6 to the first element of the array</span>
|
|
<span class="comment">// since that is how 6.5 is converted to an</span>
|
|
<span class="comment">// unsigned short.</span>
|
|
|
|
results.numbers.length = 7; <span class="comment">// Has no effect, since numbers is</span>
|
|
<span class="comment">// fixed length.</span>
|
|
results.numbers[6]; <span class="comment">// Evaluates to undefined.</span>
|
|
|
|
results.numbers.slice(0, 2); <span class="comment">// Evaluates to an Array [6, 8].</span>
|
|
|
|
results.numbers.push(108); <span class="comment">// Has no effect, since the definition of</span>
|
|
<span class="comment">// push() relies on calling [[Put]] on a</span>
|
|
<span class="comment">// non-existent array index property</span>
|
|
<span class="comment">// and on "length", both of which will</span>
|
|
<span class="comment">// be silently ignored.</span>
|
|
|
|
delete results.numbers[3]; <span class="comment">// Has no effect and evaluates to false,</span>
|
|
<span class="comment">// since the array index properties are</span>
|
|
<span class="comment">// non-configurable.</span></code></pre></div></div>
|
|
<p>
|
|
If passing an <span class="estype">Array</span> object to a <a class="dfnref" href="#dfn-platform-object">platform object</a>
|
|
expecting an IDL array value, a new <a class="dfnref" href="#dfn-platform-array-object">platform array object</a>
|
|
will be created to represent an IDL array value determined from that <span class="estype">Array</span>.
|
|
If the <span class="idltype">LotteryResults</span> interface is instead defined as:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Constructor]
|
|
interface LotteryResults {
|
|
attribute unsigned short[] numbers;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
then an <span class="estype">Array</span> object can be assigned to the
|
|
“numbers” property. Unless the prose accompanying
|
|
the interface said otherwise, this would result in a
|
|
<a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
array of whatever length the <span class="estype">Array</span>
|
|
has being assigned to the IDL attribute.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var results = new LotteryResults();
|
|
|
|
results.numbers.length; <span class="comment">// Evaluates to 6.</span>
|
|
|
|
var a = [1, 3, 5];
|
|
|
|
results.numbers = a; <span class="comment">// Assigns a fixed length IDL array of length 3 to</span>
|
|
<span class="comment">// the numbers attribute.</span>
|
|
|
|
results.numbers; <span class="comment">// This now evaluates to a platform array object</span>
|
|
<span class="comment">// that represents the fixed length IDL array,</span>
|
|
<span class="comment">// not the Array object assigned in the previous</span>
|
|
<span class="comment">// statement.</span>
|
|
|
|
results.numbers == a; <span class="comment">// Evaluates to false.</span>
|
|
|
|
results.numbers.length; <span class="comment">// Evaluates to 3.</span>
|
|
|
|
results.numbers.push(7); <span class="comment">// Silently ignored in non-strict mode.</span>
|
|
results.numbers.length; <span class="comment">// So this still evaluates to 3.</span></code></pre></div></div>
|
|
</div>
|
|
|
|
<div id="platform-array-object-getownproperty" class="section">
|
|
<h5>4.2.20.1. Platform array object [[GetOwnProperty]] method</h5>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[GetOwnProperty]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-array-object">platform array object</a>
|
|
<var>A</var> with element type <var>T</var>
|
|
<span class="rfc2119">MUST</span> behave as follows when
|
|
called with property name <var>P</var>:
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>Let <var>length</var> be the length of the IDL array that <var>A</var> represents.</li>
|
|
<li>If <var>P</var> is “length”, then:
|
|
<ol>
|
|
<li>Let <var>desc</var> be a newly created property descriptor (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.10) with no fields.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Value]]</span> to the <span class="estype">Number</span> value for <var>length</var>.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Writable]]</span> to <span class="esvalue">false</span> if <var>A</var> represents a
|
|
<a class="dfnref" href="#dfn-read-only-array">read only</a> or <a class="dfnref" href="#dfn-fixed-length">fixed length</a> array, and <span class="esvalue">true</span> otherwise.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Enumerable]]</span> to <span class="esvalue">false</span>.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">false</span>.</li>
|
|
<li>Return <var>desc</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, if <var>P</var> is an array index (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4), then:
|
|
<ol>
|
|
<li>Let <var>index</var> be ToUint32(<var>P</var>).</li>
|
|
<li>If <var>index</var> ≥ <var>length</var>, then return <span class="esvalue">undefined</span>.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a> the <var>index</var>th element of
|
|
the IDL array that <var>A</var> represents to an IDL value of type <var>T</var>.</li>
|
|
<li>Let <var>desc</var> be a newly created property descriptor (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.10) with no fields.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Value]]</span> to <var>value</var>.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Writable]]</span> to <span class="esvalue">false</span> if <var>A</var> represents a <a class="dfnref" href="#dfn-read-only-array">read only array</a>,
|
|
and <span class="esvalue">true</span> otherwise.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Enumerable]]</span> and <var>desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">true</span>.</li>
|
|
<li>Return <var>desc</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return the result of calling the default <span class="prop">[[GetOwnProperty]]</span> internal method (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.12.1) on <var>A</var> passing <var>P</var> as the argument.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="platform-array-object-defineownproperty" class="section">
|
|
<h5>4.2.20.2. Platform array object [[DefineOwnProperty]] method</h5>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[DefineOwnProperty]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-array-object">platform array object</a>
|
|
<var>A</var> with element type <var>T</var>
|
|
<span class="rfc2119">MUST</span> behave as follows when passed
|
|
property name <var>P</var>, property descriptor <var>Desc</var> and
|
|
boolean flag <var>Throw</var>.
|
|
The term “Reject”
|
|
is used in the same sense as that defined in ECMA-262, namely, to mean “If <var>Throw</var> is
|
|
<span class="esvalue">true</span>, then throw a <span class="esvalue">TypeError</span> exception,
|
|
otherwise return <span class="esvalue">false</span>”.
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>oldLen</var> to be the length of the IDL array that <var>A</var> represents.</li>
|
|
|
|
<li>If <var>P</var> is “length”, then:
|
|
<ol>
|
|
<li>If the result of calling IsDataDescriptor(<var>Desc</var>) is <span class="esvalue">false</span>, then Reject.</li>
|
|
<li>Let <var>newLen</var> be ToUint32(<var>Desc</var>.<span class="prop">[[Value]]</span>).</li>
|
|
<li>If <var>newLen</var> is not equal to ToNumber(<var>Desc</var>.<span class="prop">[[Value]]</span>), then throw a <span class="estype">RangeError</span> exception.</li>
|
|
<li>If <var>A</var> represents a <a class="dfnref" href="#dfn-read-only-array">read only</a> or <a class="dfnref" href="#dfn-fixed-length">fixed length</a> IDL array, then Reject.</li>
|
|
|
|
<li>If <var>newLen</var> > <var>oldLen</var>:
|
|
<ol>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<span class="esvalue">undefined</span> to type <var>T</var>.</li>
|
|
<li>Update the IDL array that <var>A</var> represents to have a length of <var>newLen</var>, and set every
|
|
value of the IDL array at indices in the range [<var>oldLen</var>, <var>newLen</var>) to <var>value</var>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Otherwise, if <var>newLen</var> < <var>oldLen</var>, then update the IDL array that <var>A</var> represents to have a length of <var>newLen</var>, discarding elements
|
|
at indices in the range [<var>newLen</var>, <var>oldLen</var>).</li>
|
|
|
|
<li>Return <b>true</b>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Otherwise, if <var>P</var> is an array index (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4), then:
|
|
|
|
<ol>
|
|
<li>If the result of calling IsDataDescriptor(<var>Desc</var>) is <span class="esvalue">false</span>, then Reject.</li>
|
|
|
|
<li>Let <var>index</var> be ToUint32(<var>P</var>).</li>
|
|
<li>If <var>index</var> ≥ <var>oldLen</var>, then:
|
|
<ol>
|
|
<li>If <var>A</var> represents a <a class="dfnref" href="#dfn-read-only-array">read only</a> or <a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
IDL array, then Reject.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<span class="esvalue">undefined</span> to type <var>T</var>.</li>
|
|
<li>Update the IDL array that <var>A</var> represents to have a length of <var>index</var> + 1, and set every
|
|
value of the IDL array at indices in the range [<var>oldLen</var>, <var>index</var>) to <var>value</var>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>If <var>A</var> represents a <a class="dfnref" href="#dfn-read-only-array">read only</a> IDL array, then Reject.</li>
|
|
<li>Let <var>newValue</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>Desc</var>.<span class="prop">[[Value]]</span> to an IDL value of type <var>T</var>.</li>
|
|
<li>Set the <var>index</var>th element of the IDL array that <var>A</var> represents to <var>newValue</var>.</li>
|
|
|
|
<li>Return <b>true</b>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Set <var>Desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">true</span>.</li>
|
|
<li>Return the result of calling the default <span class="prop">[[DefineOwnProperty]]</span> internal method (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.12.9) on <var>A</var> passing <var>P</var>, <var>Desc</var>, and <var>Throw</var> as arguments.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="platform-array-object-delete" class="section">
|
|
<h5>4.2.20.3. Platform array object [[Delete]] method</h5>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[Delete]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-array-object">platform array object</a>
|
|
<var>A</var> with element type <var>T</var>
|
|
<span class="rfc2119">MUST</span> behave as follows when passed
|
|
property name <var>P</var> and boolean flag <var>Throw</var>.
|
|
The term “Reject” is used as defined in
|
|
<a href="#platform-array-object-defineownproperty">section 4.2.20.2</a> above.
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>If <var>P</var> is “length”, then Reject.</li>
|
|
<li>Let <var>length</var> be the length of the IDL array that <var>A</var> represents.</li>
|
|
<li>If <var>P</var> is an array index (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4), then:
|
|
<ol>
|
|
<li>Let <var>index</var> be ToUint32(<var>P</var>).</li>
|
|
<li>If <var>index</var> < <var>length</var>, then Reject.</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If <var>P</var> has an own property with name <var>P</var>, then remove it.</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="es-Date" class="section">
|
|
<h4>4.2.21. Date</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-Date">Date</a> values are represented by
|
|
ECMAScript <span class="estype">Date</span> objects.
|
|
</p>
|
|
<p>
|
|
An ECMAScript value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-Date">Date</a> value
|
|
by running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>D</var> be the result of calling ToObject(<var>V</var>).</li>
|
|
<li>If <var>D</var> is not an ECMAScript <span class="estype">Date</span> object, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>If the time value of <var>D</var> is <span class="esvalue">NaN</span>, then return the <span class="idlvalue">undefined</span> IDL <a class="idltype" href="#idl-Date">Date</a> value.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-Date">Date</a> value that represents the same time value as <var>D</var>.</li>
|
|
</ol>
|
|
<p>
|
|
An IDL <a class="idltype" href="#idl-Date">Date</a> value <var>V</var> is <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converted</a>
|
|
to an ECMAScript value by running the following the algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>V</var> is the <span class="idlvalue">undefined</span> <a class="idltype" href="#idl-Date">Date</a> value,
|
|
then return a newly constructed ECMAScript <span class="estype">Date</span> object whose time value is
|
|
<span class="esvalue">NaN</span>.</li>
|
|
<li>Otherwise, return a newly constructed ECMAScript <span class="estype">Date</span> object that represents
|
|
the same millisecond as <var>V</var>.</li>
|
|
</ol>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-platform-object">Platform objects</a> returning an ECMAScript <span class="estype">Date</span> object from <a class="dfnref" href="#dfn-attribute">attributes</a>,
|
|
<a class="dfnref" href="#dfn-operation">operations</a> or <a class="dfnref" href="#dfn-exception-field">exception field</a>
|
|
do not hold on to a reference to the <span class="estype">Date</span> object. A script that modifies a <span class="estype">Date</span> object
|
|
so retrieved cannot affect the platform object it was retrieved from.
|
|
</p>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="es-extended-attributes" class="section">
|
|
<h3>4.3. ECMAScript-specific extended attributes</h3>
|
|
|
|
<p>
|
|
This section defines a number of
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
whose presence affects only the ECMAScript binding.
|
|
</p>
|
|
|
|
<div id="AllowAny" class="section">
|
|
<h4>4.3.1. [AllowAny]</h4>
|
|
|
|
<div class="ednote"><div class="ednoteHeader">Editorial note</div>
|
|
<p>We perhaps should drop <span class="xattr">[AllowAny]</span>, and just make the overload resolution algorithm
|
|
treat <a class="idltype" href="#idl-DOMString">DOMString</a> like “all remaining types”.</p>
|
|
</div>
|
|
<p>
|
|
If the <a class="xattr" href="#AllowAny">[AllowAny]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-operation">operation argument</a>,
|
|
it indicates that any ECMAScript value will be accepted as that
|
|
argument’s value. Normally, as part of the <a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>,
|
|
a non-<a class="idltype" href="#idl-DOMString">DOMString</a> value will disqualify
|
|
a given overloaded operation that is declared to take a
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> for a given argument. When
|
|
the <a class="xattr" href="#AllowAny">[AllowAny]</a> extended
|
|
attribute is present on the argument, that disqualification is
|
|
not performed.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#AllowAny">[AllowAny]</a> extended attribute
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
See <a href="#idl-overloading">section 3.3.6</a> for the
|
|
specific requirements that the use of <a class="xattr" href="#AllowAny">[AllowAny]</a>
|
|
entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines two <a class="dfnref" href="#dfn-interface">interfaces</a>,
|
|
each with two overloaded <a class="dfnref" href="#dfn-operation">operations</a>.
|
|
One uses <a class="xattr" href="#AllowAny">[AllowAny]</a> and one does not.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
void f();
|
|
void f(A a);
|
|
void f(DOMString s);
|
|
};
|
|
|
|
interface B {
|
|
void g();
|
|
void g(B b);
|
|
void g([AllowAny] DOMString s);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the above two interfaces,
|
|
an <span class="idltype">A</span> object will not allow a
|
|
<span class="estype">float</span> value to be passed in as
|
|
an argument, while a <span class="idltype">B</span> object
|
|
will:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var a = getA(); <span class="comment">// Obtain an instance of A.</span>
|
|
var b = getB(); <span class="comment">// Obtain an instance of B.</span>
|
|
|
|
try {
|
|
a.f(1.23); <span class="comment">// Throws a TypeError.</span>
|
|
} catch (e) {
|
|
}
|
|
|
|
b.g(1.23); <span class="comment">// Equivalent to b.g("1.23").</span>
|
|
b.g(a); <span class="comment">// Equivalent to calling b.g with ToString(a).</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="ArrayClass" class="section">
|
|
<h4>4.3.2. [ArrayClass]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#ArrayClass">[ArrayClass]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
that is not defined to <a class="dfnref" href="#dfn-inherit">inherit</a>
|
|
from another, it indicates that the internal <span class="prop">[[Prototype]]</span>
|
|
property of its <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
will be the <span class="estype">Array</span> prototype object rather than
|
|
the <span class="estype">Object</span> prototype object. This allows
|
|
<span class="estype">Array</span> methods to be used more easily
|
|
with objects implementing the interface.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#ArrayClass">[ArrayClass]</a> extended attribute
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
It <span class="rfc2119">MUST NOT</span> be used on an interface that
|
|
has any <a class="dfnref" href="#dfn-inherited-interfaces">inherited interfaces</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
Interfaces using <a class="xattr" href="#ArrayClass">[ArrayClass]</a> will
|
|
need to define a “length” <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
of type <span class="estype">unsigned long</span> that exposes the length
|
|
of the array-like object, in order for the inherited <span class="estype">Array</span>
|
|
methods to operate correctly. Such interfaces would typically also
|
|
<a class="dfnref" href="#dfn-support-indexed-properties">support indexed properties</a>,
|
|
which would provide access to the array elements.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
See <a href="#interface-prototype-object">section 4.5.3</a> for the
|
|
specific requirements that the use of <a class="xattr" href="#ArrayClass">[ArrayClass]</a>
|
|
entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines two <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
that use <a class="xattr" href="#ArrayClass">[ArrayClass]</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[ArrayClass]
|
|
interface ItemList {
|
|
attribute unsigned long length;
|
|
getter object getItem(unsigned long index);
|
|
creator setter object setItem(unsigned long index, object item);
|
|
deleter void removeItem(unsigned long index);
|
|
};
|
|
|
|
[ArrayClass]
|
|
interface ImmutableItemList {
|
|
readonly attribute unsigned long length;
|
|
getter object getItem(unsigned long index);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the above two interfaces,
|
|
with appropriate definitions for getItem, setItem and removeItem,
|
|
<span class="estype">Array</span> methods to inspect and
|
|
modify the array-like object can be used.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var list = getItemList(); <span class="comment">// Obtain an instance of ItemList.</span>
|
|
|
|
list.concat(); <span class="comment">// Clone the ItemList into an Array.</span>
|
|
list.pop(); <span class="comment">// Remove an item from the ItemList.</span>
|
|
list.unshift({ }); <span class="comment">// Insert an item at index 0.</span></code></pre></div></div>
|
|
<p>
|
|
<span class="idltype">ImmutableItemList</span> has a read only
|
|
length <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
and no indexed property <a class="dfnref" href="#dfn-indexed-property-setter">setter</a>,
|
|
<a class="dfnref" href="#dfn-indexed-property-creator">creator</a> or
|
|
<a class="dfnref" href="#dfn-indexed-property-deleter">deleter</a>. The
|
|
mutating <span class="estype">Array</span> methods will generally not
|
|
succeed on objects implementing <span class="idltype">ImmutableItemList</span>.
|
|
The exact behavior depends on the definition of the <span class="estype">Array</span> methods
|
|
themselves (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4.4).
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-Callback" class="section">
|
|
<h4>4.3.3. [Callback]</h4>
|
|
|
|
<p>
|
|
As described in <a href="#Callback">section 3.10.1 above</a>,
|
|
the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> is used to
|
|
indicate that an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
can be implemented by a <a class="dfnref" href="#dfn-user-object">user object</a>.
|
|
In the ECMAScript language binding, the <a class="dfnref" href="#dfn-xattr-identifier">identifier argument</a>
|
|
of <a class="xattr" href="#Callback">[Callback]</a>, or the lack of one,
|
|
is used to control which kinds of ECMAScript objects can be used as user object implementations of
|
|
the interface, as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> was specified
|
|
as <code>[Callback]</code> (with no identifier argument) or as <code>[Callback=PropertyOnly]</code>,
|
|
then any native ECMAScript object is considered to be a <a class="dfnref" href="#dfn-user-object">user object</a>
|
|
implementation of the <a class="dfnref" href="#dfn-interface">interface</a>.</li>
|
|
<li>Otherwise, if it was specified as <code>[Callback=FunctionOnly]</code>, then only <span class="estype">Function</span>
|
|
objects are considered to be user object implementations of the interface.</li>
|
|
</ul>
|
|
<p>
|
|
<code>[Callback=FunctionOnly]</code> <span class="rfc2119">MUST NOT</span> be specified on
|
|
an <a class="dfnref" href="#dfn-interface">interface</a> that is not a
|
|
<dfn id="dfn-single-operation-interface">single operation interface</dfn>, which is an
|
|
interface that:
|
|
</p>
|
|
<ul>
|
|
<li>is not declared to <a class="dfnref" href="#dfn-inherit">inherit</a> from another interface,</li>
|
|
<li>has no <a class="dfnref" href="#dfn-consequential-interfaces">consequential interfaces</a>,</li>
|
|
<li>has no <a class="dfnref" href="#dfn-attribute">attributes</a>, and</li>
|
|
<li>has one or more <a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
that all have the same <a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
and no others.</li>
|
|
</ul>
|
|
<p>
|
|
<a href="#es-user-objects">Section 4.8 below</a> details how
|
|
native ECMAScript objects are used as <a class="dfnref" href="#dfn-user-object">user objects</a>
|
|
implementing an interface and exactly how <a class="xattr" href="#Callback">[Callback]</a>
|
|
influences this.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines a simple callback interface and an
|
|
interface for an object that expects an object that
|
|
implements that callback:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Callback]
|
|
interface Listener {
|
|
void eventOccurred();
|
|
};
|
|
|
|
interface Thing {
|
|
void addListener(Listener listener);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation of the above two interfaces
|
|
allows any native object to be passed to <code>addListener</code>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// Obtain an instance of Thing.</span>
|
|
var t = getThing();
|
|
|
|
<span class="comment">// The function is the implementation of the eventOccurred operation on the</span>
|
|
<span class="comment">// Listener interface. If Listener had been declared with</span>
|
|
<span class="comment">// [Callback=PropertyOnly] this addListener() call would still succeed, but</span>
|
|
<span class="comment">// a TypeError would be thrown when the user agent attempts to invoke the</span>
|
|
<span class="comment">// callback.</span>
|
|
t.addListener(function() { });
|
|
|
|
<span class="comment">// This also works, but it is the function with /* 1 */ in it that is the</span>
|
|
<span class="comment">// implementation of eventOccurred.</span>
|
|
var x = function() { <span class="comment">/* 1 */</span> };
|
|
x.eventOccurred = function() { <span class="comment">/* 2 */</span> };
|
|
t.addListener(x);
|
|
|
|
<span class="comment">// This works too, and the value of the eventOccurred property is the</span>
|
|
<span class="comment">// implementation of the operation. If Listener had been declared with</span>
|
|
<span class="comment">// [Callback=FunctionOnly] however, this would have thrown a TypeError.</span>
|
|
t.addListener({ eventOccurred: function() { } });</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="Clamp" class="section">
|
|
<h4>4.3.4. [Clamp]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#Clamp">[Clamp]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-operation">operation</a> argument,
|
|
writable <a class="dfnref" href="#dfn-attribute">attribute</a> or
|
|
<a class="dfnref" href="#dfn-dictionary-member">dictionary member</a>
|
|
whose type is one of the <a class="dfnref" href="#dfn-integer-type">integer types</a>,
|
|
it indicates that when an ECMAScript <span class="estype">Number</span> is
|
|
converted to the IDL type, out of range values will be clamped to the range
|
|
of valid values, rather than using the operators that use a modulo operation
|
|
(ToInt16, ToInt32, ToUint32, etc.).
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Clamp">[Clamp]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Clamp">[Clamp]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> appear on a <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
attribute, or an attribute, operation argument or dictionary member
|
|
that is not of an integer type. It also <span class="rfc2119">MUST NOT</span>
|
|
be used in conjunction with the <a class="xattr" href="#EnforceRange">[EnforceRange]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See the rules for converting ECMAScript values to the various IDL integer
|
|
types in <a href="#es-type-mapping">section 4.2</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#Clamp">[Clamp]</a> entails.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
In the following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>,
|
|
two <a class="dfnref" href="#dfn-operation">operations</a> are declared that
|
|
take three <a class="idltype" href="#idl-octet">octet</a> arguments; one uses
|
|
the <a class="xattr" href="#Clamp">[Clamp]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
on all three arguments, while the other does not:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface GraphicsContext {
|
|
void setColor(octet red, octet green, octet blue);
|
|
void setColorClamped([Clamp] octet red, [Clamp] octet green, [Clamp] octet blue);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the IDL, a call to setColorClamped with
|
|
<span class="estype">Number</span> values that are out of range for an
|
|
<a class="idltype" href="#idl-octet">octet</a> are clamped to the range [0, 255].
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">// Get an instance of GraphicsContext.
|
|
var context = getGraphicsContext();
|
|
|
|
// Calling the non-[Clamp] version uses ToUint8 to coerce the Numbers to octets.
|
|
// This is equivalent to calling setColor(255, 255, 1).
|
|
context.setColor(-1, 255, 257);
|
|
|
|
// Call setColorClamped with some out of range values.
|
|
// This is equivalent to calling setColorClamped(0, 255, 255).
|
|
context.setColorClamped(-1, 255, 257);</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="Constructor" class="section">
|
|
<h4>4.3.5. [Constructor]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>, it indicates that
|
|
the <a class="dfnref" href="#dfn-interface-object">interface object</a> for this interface
|
|
will have an <span class="prop">[[Construct]]</span> internal method,
|
|
allowing objects implementing the interface to be constructed.
|
|
Multiple <a class="xattr" href="#Constructor">[Constructor]</a> extended
|
|
attributes may appear on a given interface.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
extended attribute <span class="rfc2119">MUST</span> either
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a> or
|
|
<a class="dfnref" href="#dfn-xattr-argument-list">take an argument list</a>.
|
|
The bare form, <code>[Constructor]</code>, has the same meaning as
|
|
using an empty argument list, <code>[Constructor()]</code>. For each
|
|
<a class="xattr" href="#Constructor">[Constructor]</a> extended attribute
|
|
on the interface, there will be a way to construct an object that implements
|
|
the interface by passing the specified arguments.
|
|
</p>
|
|
<p>
|
|
If the <a class="xattr" href="#Constructor">[Constructor]</a> extended attribute
|
|
is specified on an interface, then the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> also be specified on that interface.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-interface-call">section 4.5.1.1</a>
|
|
below for details on how a constructor
|
|
is to be implemented.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following IDL defines two interfaces. The second has the
|
|
<a class="xattr" href="#Constructor">[Constructor]</a> extended
|
|
attribute, while the first does not.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface NodeList {
|
|
Node item(unsigned long index);
|
|
readonly attribute unsigned long length;
|
|
};
|
|
|
|
[Constructor,
|
|
Constructor(float radius)]
|
|
interface Circle {
|
|
attribute float r;
|
|
attribute float cx;
|
|
attribute float cy;
|
|
readonly attribute float circumference;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation supporting these interfaces would
|
|
have a <span class="prop">[[Construct]]</span> property on the
|
|
<span class="idltype">Circle</span> interface object which would
|
|
return a new object that implements the interface. It would take
|
|
either zero or one argument. The
|
|
<span class="idltype">NodeList</span> interface object would not
|
|
have a <span class="prop">[[Construct]]</span> property.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var x = new Circle(); <span class="comment">// The uses the zero-argument constructor to create a</span>
|
|
<span class="comment">// reference to a platform object that implements the</span>
|
|
<span class="comment">// Circle interface.</span>
|
|
|
|
var y = new Circle(1.25); <span class="comment">// This also creates a Circle object, this time using</span>
|
|
<span class="comment">// the one-argument constructor.</span>
|
|
|
|
var z = new NodeList(); <span class="comment">// This would throw a TypeError, since no</span>
|
|
<span class="comment">// [Constructor] is declared.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="EnforceRange" class="section">
|
|
<h4>4.3.6. [EnforceRange]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#EnforceRange">[EnforceRange]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-operation">operation</a> argument,
|
|
writable <a class="dfnref" href="#dfn-attribute">attribute</a> or
|
|
<a class="dfnref" href="#dfn-dictionary-member">dictionary member</a>
|
|
whose type is one of the <a class="dfnref" href="#dfn-integer-type">integer types</a>,
|
|
it indicates that when an ECMAScript <span class="estype">Number</span> is
|
|
converted to the IDL type, out of range values will cause an exception to
|
|
be thrown, rather than converted to being a valid value using the operators that use a modulo operation
|
|
(ToInt16, ToInt32, ToUint32, etc.). The <span class="estype">Number</span>
|
|
will be rounded towards zero before being checked against its range.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#EnforceRange">[EnforceRange]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#EnforceRange">[EnforceRange]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> appear on a <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
attribute, or an attribute, operation argument or dictionary member
|
|
that is not of an integer type. It also <span class="rfc2119">MUST NOT</span>
|
|
be used in conjunction with the <a class="xattr" href="#Clamp">[Clamp]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See the rules for converting ECMAScript values to the various IDL integer
|
|
types in <a href="#es-type-mapping">section 4.2</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#EnforceRange">[EnforceRange]</a> entails.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
In the following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>,
|
|
two <a class="dfnref" href="#dfn-operation">operations</a> are declared that
|
|
take three <a class="idltype" href="#idl-octet">octet</a> arguments; one uses
|
|
the <a class="xattr" href="#EnforceRange">[EnforceRange]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
on all three arguments, while the other does not:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface GraphicsContext {
|
|
void setColor(octet red, octet green, octet blue);
|
|
void setColorEnforcedRange([EnforceRange] octet red, [EnforceRange] octet green, [EnforceRange] octet blue);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the IDL, a call to setColorEnforcedRange with
|
|
<span class="estype">Number</span> values that are out of range for an
|
|
<a class="idltype" href="#idl-octet">octet</a> will result in an exception being
|
|
thrown.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">// Get an instance of GraphicsContext.
|
|
var context = getGraphicsContext();
|
|
|
|
// Calling the non-[EnforceRange] version uses ToUint8 to coerce the Numbers to octets.
|
|
// This is equivalent to calling setColor(255, 255, 1).
|
|
context.setColor(-1, 255, 257);
|
|
|
|
// When setColorEnforcedRange is called, Numbers are rounded towards zero.
|
|
// This is equivalent to calling setColor(0, 255, 255).
|
|
context.setColorEnforcedRange(-0.9, 255, 255.2);
|
|
|
|
// The following will cause a TypeError to be thrown, since even after
|
|
// rounding the first and third argument values are out of range.
|
|
context.setColorEnforcedRange(-1, 255, 256);</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="ImplicitThis" class="section">
|
|
<h4>4.3.7. [ImplicitThis]</h4>
|
|
<p>
|
|
If the <a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
it indicates that when a <span class="estype">Function</span> corresponding
|
|
to one of the interface’s <a class="dfnref" href="#dfn-operation">operations</a>
|
|
is invoked with the <span class="esvalue">null</span> or <span class="esvalue">undefined</span>
|
|
value as the <span class="esvalue">this</span> value, that the ECMAScript global
|
|
object will be used as the <span class="esvalue">this</span> value instead.
|
|
This is regardless of whether the calling code is in strict mode.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-operations">section 4.5.6</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#ImplicitThis">[ImplicitThis]</a> entails.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>The <a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
is intended for use on the <span class="idltype">Window</span>
|
|
<a class="dfnref" href="#dfn-interface">interface</a> as defined
|
|
in HTML5 (<a href="#ref-HTML5">[HTML5]</a>, section 5.2).</p>
|
|
</div>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>In the following example, the <span class="idltype">Window</span>
|
|
<a class="dfnref" href="#dfn-interface">interface</a> is defined
|
|
with the <a class="xattr" href="#ImplicitThis">[ImplicitThis]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[ImplicitThis]
|
|
interface Window {
|
|
...
|
|
attribute DOMString name;
|
|
void alert(DOMString message);
|
|
};</code></pre></div></div>
|
|
<p>Since the <span class="idltype">Window</span> object is used as
|
|
the ECMAScript global object, calls to its functions can be made
|
|
without an explicit object, even in strict mode:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">"use strict";
|
|
|
|
window.alert("hello"); <span class="comment">// Calling alert with an explicit window object works.</span>
|
|
alert("hello"); <span class="comment">// This also works, even though we are in strict mode.</span>
|
|
alert.call(null, "hello"); <span class="comment">// As does passing null explicitly as the this value.</span>
|
|
|
|
<span class="comment">// This does not apply to getters for attributes on the interface, though.</span>
|
|
<span class="comment">// The following will throw a TypeError.</span>
|
|
Object.getOwnPropertyDescriptor(Window.prototype, "name").get.call(null);</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="NamedConstructor" class="section">
|
|
<h4>4.3.8. [NamedConstructor]</h4>
|
|
<p>
|
|
If the <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
it indicates that the <a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a>
|
|
for the interface (often, the ECMAScript global object) will have a property with the
|
|
specified name whose value is a constructor function that can
|
|
create objects that implement the interface.
|
|
Multiple <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a> extended
|
|
attributes may appear on a given interface.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attribute <span class="rfc2119">MUST</span> either
|
|
<a class="dfnref" href="#dfn-xattr-identifier">take an identifier</a> or
|
|
<a class="dfnref" href="#dfn-xattr-named-argument-list">take a named argument list</a>.
|
|
The first form, <code>[NamedConstructor=<a class="sym" href="#prod-identifier">identifier</a>]</code>, has the same meaning as
|
|
using an empty argument list, <code>[NamedConstructor=<a class="sym" href="#prod-identifier">identifier</a>()]</code>. For each
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a> extended attribute
|
|
on the interface, there will be a way to construct an object that implements
|
|
the interface by passing the specified arguments to the constructor function
|
|
that is the value of the aforementioned property.
|
|
</p>
|
|
<p>
|
|
The identifier used for the named constructor <span class="rfc2119">MUST NOT</span>
|
|
be the same as that used by an <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attribute on another interface, <span class="rfc2119">MUST NOT</span>
|
|
be the same as an identifier of an interface (or <a class="dfnref" href="#dfn-exception">exception</a>)
|
|
that has an <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
(or <a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>),
|
|
and <span class="rfc2119">MUST NOT</span> be one of the
|
|
<a class="dfnref" href="#dfn-reserved-identifier">reserved identifiers</a>.
|
|
</p>
|
|
<p>
|
|
See <a href="#named-constructors">section 4.5.2</a>
|
|
below for details on how named constructors
|
|
are to be implemented.
|
|
</p>
|
|
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following IDL defines an interface that uses the
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a> extended
|
|
attribute.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[NamedConstructor=Audio,
|
|
NamedConstructor=Audio(DOMString src)]
|
|
interface HTMLAudioElement : HTMLMediaElement {
|
|
<span class="comment">// ...</span>
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation that supports this interface will
|
|
allow the construction of <span class="estype">HTMLAudioElement</span>
|
|
objects using the <span class="estype">Audio</span> constructor.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">typeof Audio; <span class="comment">// Evaluates to 'function'.</span>
|
|
|
|
var a1 = new Audio(); <span class="comment">// Creates a new object that implements</span>
|
|
<span class="comment">// HTMLAudioElement, using the zero-argument</span>
|
|
<span class="comment">// constructor.</span>
|
|
|
|
var a2 = new Audio('a.flac'); <span class="comment">// Creates an HTMLAudioElement using the</span>
|
|
<span class="comment">// one-argument constructor.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="NamespaceObject" class="section">
|
|
<h4>4.3.9. [NamespaceObject]</h4>
|
|
<p>
|
|
If the <a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on a <a class="dfnref" href="#dfn-module">module</a>,
|
|
it indicates that the hierarchy of that module and its descendant
|
|
modules will be reflected as <a class="dfnref" href="#dfn-namespace-object">namespace objects</a>.
|
|
<a class="dfnref" href="#dfn-interface-object">Interface objects</a> and
|
|
<a class="dfnref" href="#dfn-exception-interface-object">exception interface objects</a>
|
|
for <a class="dfnref" href="#dfn-interface">interfaces</a> and
|
|
<a class="dfnref" href="#dfn-exception">exceptions</a> defined in
|
|
a module annotated with <a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
(or in a descendant of such a module) will be placed on
|
|
a namespace object instead of the ECMAScript global object.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> be
|
|
specified on a module if is specified on one of its ancestor modules.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-modules">section 4.4</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines a <a class="dfnref" href="#dfn-module">module</a> hierarchy
|
|
where one of the modules is declared with the
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[NamespaceObject]
|
|
module acme {
|
|
|
|
exception DeviceException { };
|
|
|
|
module pim {
|
|
|
|
[Constructor]
|
|
interface Contact { };
|
|
|
|
[Constructor,
|
|
NamedConstructor=RecurringEvent(long freq)]
|
|
interface CalendarEvent { };
|
|
};
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation, there would exist
|
|
<a class="dfnref" href="#dfn-namespace-object">namespace objects</a>
|
|
for the <span class="idltype">acme</span> and <span class="idltype">pim</span>
|
|
<a class="dfnref" href="#dfn-module">modules</a>. The property
|
|
for the <span class="idltype">Device</span>
|
|
<a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>
|
|
would be on the <span class="idltype">acme</span> namespace object
|
|
and the properties for the <span class="idltype">Contact</span>
|
|
and <span class="idltype">CalendarEvent</span>
|
|
<a class="dfnref" href="#dfn-interface-object">interface objects</a>
|
|
would be on the <span class="idltype">pim</span> namespace object.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">acme; <span class="comment">// A namespace object.</span>
|
|
acme.pim; <span class="comment">// Another namespace object.</span>
|
|
|
|
acme.DeviceException; <span class="comment">// An exception interface object.</span>
|
|
acme.pim.Contact; <span class="comment">// An interface object.</span>
|
|
|
|
new acme.pim.Contact(); <span class="comment">// Creates an object implementing acme::pim::Contact.</span>
|
|
new acme.pim.RecurringEvent(10); <span class="comment">// Creates an object implementing acme::pim::CalendarEvent.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="NoInterfaceObject" class="section">
|
|
<h4>4.3.10. [NoInterfaceObject]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
it indicates that an
|
|
<a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
will not exist for the interface in the ECMAScript binding. Similarly,
|
|
if it appears on an <a class="dfnref" href="#dfn-exception">exception</a>
|
|
it indicates that an
|
|
<a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>
|
|
will not exist for the exception in the ECMAScript binding.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a> extended attribute
|
|
<span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
If the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a> extended attribute
|
|
is specified on an interface, then the <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> also be specified on that interface.
|
|
A <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a> extended attribute is fine,
|
|
however.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> be specified on an interface that has any
|
|
<a class="dfnref" href="#dfn-static-operation">static operations</a> defined on it.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a> extended attribute
|
|
<span class="rfc2119">SHOULD NOT</span> be used on interfaces that are not
|
|
solely used as <a class="dfnref" href="#dfn-supplemental-interface">supplemental</a> or
|
|
<a href="#Callback">callback</a> interfaces,
|
|
unless there are clear Web compatibility reasons for doing so.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-interfaces">section 4.2.16</a>
|
|
and <a href="#es-exceptions">section 4.9</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL
|
|
fragment</a> defines two interfaces, one whose interface object
|
|
is exposed on the ECMAScript global object, and one whose isn’t:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Storage {
|
|
void addEntry(unsigned long key, any value);
|
|
};
|
|
|
|
[NoInterfaceObject]
|
|
interface Query {
|
|
any lookupEntry(unsigned long key);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation of the above IDL would allow
|
|
manipulation of <span class="idltype">Storage</span>’s
|
|
prototype, but not <span class="idltype">Query</span>’s.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">typeof Storage; <span class="comment">// evaluates to "object"</span>
|
|
|
|
<span class="comment">// Add some tracing alert() call to Storage.addEntry.</span>
|
|
var fn = Storage.prototype.addEntry;
|
|
Storage.prototype.addEntry = function(key, value) {
|
|
alert('Calling addEntry()');
|
|
return fn.call(this, key, value);
|
|
};
|
|
|
|
typeof Query; <span class="comment">// evaluates to "undefined"</span>
|
|
var fn = Query.prototype.lookupEntry; <span class="comment">// exception, Query isn’t defined</span>
|
|
</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="OverrideBuiltins" class="section">
|
|
<h4>4.3.11. [OverrideBuiltins]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
it indicates that for a <a class="dfnref" href="#dfn-platform-object">platform object</a> implementing the interface,
|
|
properties corresponding to all of
|
|
the object’s <a class="dfnref" href="#dfn-supported-property-names">supported property names</a>
|
|
will appear to be on the object,
|
|
regardless of what other properties exist on the object or its
|
|
prototype chain. This means that named properties will always shadow
|
|
any properties that would otherwise appear on the object.
|
|
This is in contrast to the usual behavior, which is for named properties
|
|
to be exposed only if there is no property with the
|
|
same name on the object itself or somewhere on its prototype chain.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>
|
|
and <span class="rfc2119">MUST NOT</span> appear on an interface
|
|
that does not define a <a class="dfnref" href="#dfn-named-property-getter">named property getter</a>
|
|
or that also is declared with the <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See <a href="#indexed-and-named-properties">section 4.7.1</a>
|
|
and <a href="#defineownproperty">section 4.7.3</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines two <a class="dfnref" href="#dfn-interface">interfaces</a>,
|
|
one that has a <a class="dfnref" href="#dfn-named-property-getter">named property getter</a>
|
|
and one that does not.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface StringMap {
|
|
readonly attribute unsigned long length;
|
|
getter DOMString lookup(DOMString key);
|
|
};
|
|
|
|
[OverrideBuiltins]
|
|
interface StringMap2 {
|
|
readonly attribute unsigned long length;
|
|
getter DOMString lookup(DOMString key);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of these two interfaces,
|
|
getting certain properties on objects implementing
|
|
the interfaces will result in different values:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code"><span class="comment">// Obtain an instance of StringMap. Assume that it has "abc", "length" and</span>
|
|
<span class="comment">// "toString" as supported property names.</span>
|
|
var map1 = getStringMap();
|
|
|
|
<span class="comment">// This invokes the named property getter.</span>
|
|
map1.abc;
|
|
|
|
<span class="comment">// This fetches the "length" property on the object that corresponds to the</span>
|
|
<span class="comment">// length attribute.</span>
|
|
map1.length;
|
|
|
|
<span class="comment">// This fetches the "toString" property from the object's prototype chain.</span>
|
|
map1.toString;
|
|
|
|
|
|
<span class="comment">// Obtain an instance of StringMap2. Assume that it also has "abc", "length"</span>
|
|
<span class="comment">// and "toString" as supported property names.</span>
|
|
var map2 = getStringMap2();
|
|
|
|
<span class="comment">// This invokes the named property getter.</span>
|
|
map2.abc;
|
|
|
|
<span class="comment">// This also invokes the named property getter, despite the fact that the "length"</span>
|
|
<span class="comment">// property on the object corresponds to the length attribute.</span>
|
|
map2.length;
|
|
|
|
<span class="comment">// This too invokes the named property getter, despite the fact that "toString" is</span>
|
|
<span class="comment">// a property in map2's prototype chain.</span>
|
|
map2.toString;</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!--
|
|
<div id='PrototypeRoot' class='section'>
|
|
<h4>[PrototypeRoot]</h4>
|
|
|
|
<div class='ednote'>
|
|
<p>Ian suggests that <span class='xattr'>[PrototypeRoot]</span> might not need to exist.
|
|
<a href='http://www.w3.org/mid/Pine.LNX.4.62.0906200730520.16244@hixie.dreamhostps.com'>(Mail.)</a></p>
|
|
</div>
|
|
<p>
|
|
If the <a class='xattr' href='#PrototypeRoot'>[PrototypeRoot]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>
|
|
appears on an <a class='dfnref' href='#dfn-interface'>interface</a>
|
|
<var>A</var>, it indicates that it serves as the root of a prototype
|
|
ancestor hierarchy. For any interface <var>B</var> that has
|
|
<var>A</var> as an ancestor, each interface in the inheritance
|
|
tree starting with an interface that <var>B</var> inherits from and
|
|
ending with <var>A</var> will be a
|
|
<a class='dfnref' href='#dfn-prototype-ancestor'>prototype ancestor</a>
|
|
of <var>B</var>. It also plays a role in determining the value
|
|
of a host object’s internal <span class='prop'>[[Prototype]]</span>
|
|
property value when the object implements more than one interface.
|
|
See <a href='#interface-prototype-object'>section <?sref interface-prototype-object?></a>
|
|
and <a href='#host-objects'>section <?sref host-objects?></a> for details.
|
|
</p>
|
|
<p>
|
|
The <a class='xattr' href='#PrototypeRoot'>[PrototypeRoot]</a>
|
|
extended attribute <span class='rfc2119'>MUST</span> <a class='dfnref' href='#dfn-xattr-no-arguments'>take no arguments</a>,
|
|
and <span class='rfc2119'>MUST NOT</span> appear on an
|
|
<a class='dfnref' href='#dfn-interface'>interface</a> that
|
|
<a class='dfnref' href='#dfn-inherit'>inherits</a> from another
|
|
interface. An interface inheritance hierarchy
|
|
<span class='rfc2119'>MUST NOT</span> have multiple paths from
|
|
one interface to another that has the
|
|
<a class='xattr' href='#PrototypeRoot'>[PrototypeRoot]</a>
|
|
extended attribute.
|
|
</p>
|
|
<div class='example'>
|
|
<p>
|
|
The following <a class='dfnref' href='#dfn-idl-fragment'>IDL fragment</a>
|
|
defines a hierarchy of <a class='dfnref' href='#dfn-interface'>interfaces</a>
|
|
whose rootmost interface is annotated with the
|
|
<a class='xattr' href='#PrototypeRoot'>[PrototypeRoot]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>.
|
|
Other interfaces are defined to be implemented on objects that
|
|
implement this prototype root interface, but properties for
|
|
these other interfaces will be made available in the prototype
|
|
chain through a <a class='dfnref' href='#dfn-mixin-prototype-object'>mixin prototype object</a>.
|
|
</p>
|
|
<x:codeblock language='idl'>[PrototypeRoot]
|
|
interface Node {
|
|
readonly attribute unsigned short nodeType;
|
|
};
|
|
|
|
interface Element : Node {
|
|
void appendChild(Node n);
|
|
<span class='comment'>// ...</span>
|
|
};
|
|
|
|
interface HTMLElement : Element {
|
|
void focus();
|
|
<span class='comment'>// ...</span>
|
|
};
|
|
|
|
interface EventTarget {
|
|
void addEventListener(/* ... */);
|
|
<span class='comment'>// ...</span>
|
|
};
|
|
|
|
Node implements EventTarget;</x:codeblock>
|
|
<p>
|
|
An ECMAScript implementation implementing these interfaces would
|
|
have a prototype chain as follows, where <var>E</var> is an
|
|
instance of <span class='idltype'>HTMLElement</span>:
|
|
</p>
|
|
<div class='diagram'>
|
|
<object data='PrototypeRoot-example.svg' type='image/svg+xml' style='width: 37em; height: 45em' width='1' height='1'>
|
|
<img src='PrototypeRoot-example.png' width='500' height='608' alt='The prototype of E is the mixin prototype object for E. This mixin prototype object has an "addEventListener" property. The prototype of the mixin prototype object is the HTMLElement prototype object, whose prototype is the Element prototype object, whose prototype is the Node prototype object, whose prototype is the Object prototype object.'/>
|
|
</object>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
-->
|
|
|
|
<div id="PutForwards" class="section">
|
|
<h4>4.3.12. [PutForwards]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on a <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> declaration whose type is
|
|
an <a href="#idl-interface">interface type</a>,
|
|
it indicates that assigning to the attribute will have specific behavior.
|
|
Namely, the assignment is “forwarded” to the attribute (specified by
|
|
the extended attribute argument) on the object that is currently
|
|
referenced by the attribute being assigned to.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#PutForwards">[PutForwards]</a> extended
|
|
attribute <span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-identifier">take an identifier</a>.
|
|
Assuming that:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
<var>A</var> is the <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
on which the <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
extended attribute appears,
|
|
</li>
|
|
<li>
|
|
<var>I</var> is the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which <var>A</var> is declared,
|
|
</li>
|
|
<li>
|
|
<var>J</var> is the <a href="#idl-interface">interface type</a>
|
|
that <var>A</var> is declared to be of, and
|
|
</li>
|
|
<li>
|
|
<var>N</var> is the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
argument of the extended attribute,
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
then there <span class="rfc2119">MUST</span> be another
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> <var>B</var>
|
|
declared on <var>J</var> whose <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
is <var>N</var>. Assignment of a value to the attribute <var>A</var>
|
|
on an object implementing <var>I</var> will result in that value
|
|
being assigned to attribute <var>B</var> of the object that <var>A</var>
|
|
references, instead.
|
|
</p>
|
|
<p>
|
|
Note that <a class="xattr" href="#PutForwards">[PutForwards]</a>-annotated
|
|
<a class="dfnref" href="#dfn-attribute">attributes</a> can be
|
|
chained. That is, an attribute with the <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
can refer to an attribute that itself has that extended attribute.
|
|
There <span class="rfc2119">MUST NOT</span> exist a cycle in a
|
|
chain of forwarded assignments. A cycle exists if, when following
|
|
the chain of forwarded assignments, a particular attribute on
|
|
an <a class="dfnref" href="#dfn-interface">interface</a> is
|
|
encountered more than once.
|
|
</p>
|
|
<p>
|
|
An attribute with the <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> also be declared
|
|
with the <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See the <a href="#es-attributes">Attributes</a> section below for how
|
|
<a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
is to be implemented.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines interfaces for names and people.
|
|
The <a class="xattr" href="#PutForwards">[PutForwards]</a> extended
|
|
attribute is used on the <span class="idlattr">name</span> attribute
|
|
of the <span class="idltype">Person</span> interface to indicate
|
|
that assignments to that attribute result in assignments to the
|
|
<span class="idlattr">full</span> attribute of the
|
|
<span class="idltype">Person</span> object:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Name {
|
|
attribute DOMString full;
|
|
attribute DOMString family;
|
|
attribute DOMString given;
|
|
};
|
|
|
|
interface Person {
|
|
[PutForwards=full] readonly attribute Name name;
|
|
attribute unsigned short age;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In the ECMAScript binding, this would allow assignments to the
|
|
“name” property:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var p = getPerson(); <span class="comment">// Obtain an instance of Person.</span>
|
|
|
|
p.name = 'John Citizen'; <span class="comment">// This statement...</span>
|
|
p.name.full = 'John Citizen'; <span class="comment">// ...has the same behavior as this one.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="Replaceable" class="section">
|
|
<h4>4.3.13. [Replaceable]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on a <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
it indicates that setting the corresponding property on the
|
|
<a class="dfnref" href="#dfn-platform-object">platform object</a> will result in
|
|
an own property with the same name being created on the object
|
|
which has the value being assigned. This property will shadow
|
|
the accessor property corresponding to the attribute, which
|
|
exists on the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
An attribute with the <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> also be declared
|
|
with the <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-attributes">section 4.5.5</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#Replaceable">[Replaceable]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
that increments a counter, and an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
that exposes the counter’s value, which is initially 0:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Counter {
|
|
[Replaceable] readonly attribute unsigned long value;
|
|
void increment();
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Assigning to the “value” property
|
|
on a <a class="dfnref" href="#dfn-platform-object">platform object</a> implementing <span class="idltype">Counter</span>
|
|
will shadow the property that corresponds to the
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var counter = getCounter(); <span class="comment">// Obtain an instance of Counter.</span>
|
|
counter.value; <span class="comment">// Evaluates to 0.</span>
|
|
|
|
counter.hasOwnProperty("value"); <span class="comment">// Evaluates to false.</span>
|
|
Object.getPrototypeOf(counter).hasOwnProperty("value"); <span class="comment">// Evaluates to true.</span>
|
|
|
|
counter.increment();
|
|
counter.increment();
|
|
counter.value; <span class="comment">// Evaluates to 2.</span>
|
|
|
|
counter.value = 'a'; <span class="comment">// Shadows the property with one that is unrelated</span>
|
|
<span class="comment">// to Counter::value.</span>
|
|
|
|
counter.hasOwnProperty("value"); <span class="comment">// Evaluates to true.</span>
|
|
|
|
counter.increment();
|
|
counter.value; <span class="comment">// Evaluates to 'a'.</span>
|
|
|
|
delete counter.value; <span class="comment">// Reveals the original property.</span>
|
|
counter.value; <span class="comment">// Evaluates to 3.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="ReplaceableNamedProperties" class="section">
|
|
<h4>4.3.14. [ReplaceableNamedProperties]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
then for objects that
|
|
<a class="dfnref" href="#dfn-support-named-properties">support named properties</a>
|
|
but which do not have a <a class="dfnref" href="#dfn-named-property-setter">named property setter</a>,
|
|
attempting to set a property that corresponds to a named property will result in an
|
|
own property being defined on the object, rather than in the assignment failing,
|
|
which is the normal behavior.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>The assignment will normally fail because the <a href="#getownproperty">platform object
|
|
[[GetOwnProperty]] internal method</a> will expose named properties as
|
|
non-writable data properties.</p>
|
|
</div>
|
|
<p>
|
|
The <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> be declared on an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
that does not define a <a class="dfnref" href="#dfn-named-property-getter">named property getter</a>,
|
|
that does define a <a class="dfnref" href="#dfn-named-property-setter">named property setter</a> or
|
|
that also is declared with the <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
See <a href="#getownproperty">section 4.7.2</a>
|
|
and <a href="#defineownproperty">section 4.7.3</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
This <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> is intended
|
|
to be used by the <span class="idltype">Window</span> interface as defined in
|
|
HTML5 (<a href="#ref-HTML5">[HTML5]</a>, section 5.2). The interface exposes frames as properties on the <span class="idltype">Window</span>
|
|
object. Since the <span class="idltype">Window</span> object also serves as the
|
|
ECMAScript global object, variable declarations or assignments to the named properties
|
|
will result in them being replaced by the new value.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[ReplaceableNamedProperties]
|
|
interface Window {
|
|
getter any (DOMString name);
|
|
// ...
|
|
};</code></pre></div></div>
|
|
<p>
|
|
The following HTML document illustrates how the named properties on the
|
|
<span class="idltype">Window</span> object can be replaced:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">HTML</span></div><div class="blockContent"><pre class="code"><code class="html-code"><!DOCTYPE html>
|
|
<title>Replaceable named properties on Window</title>
|
|
<iframe name=abc></iframe>
|
|
<script>
|
|
window.abc; <span class="comment">// Evaluates to the iframe's Window object.</span>
|
|
abc = 1; <span class="comment">// Replaces the named property.</span>
|
|
window.abc; <span class="comment">// Evaluates to 1.</span>
|
|
</script></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="TreatNonCallableAsNull" class="section">
|
|
<h4>4.3.15. [TreatNonCallableAsNull]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
or <a class="dfnref" href="#dfn-operation">operation</a> argument whose type is
|
|
a <a class="dfnref" href="#dfn-nullable-type">nullable</a>
|
|
<a class="xattr" href="#Callback">[Callback]</a>-annotated
|
|
<a href="#idl-interface">interface type</a>, it indicates that any value
|
|
assigned to the attribute or passed as the operation argument
|
|
that is not a callable object will be converted to
|
|
the <span class="idlvalue">null</span> value.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> be specified
|
|
on an attribute or operation argument whose type is not an
|
|
interface that is annotated with <code>[Callback]</code> or
|
|
<code>[Callback=FunctionOnly]</code>.
|
|
</p>
|
|
<p>
|
|
Specifications <span class="rfc2119">SHOULD NOT</span> use <a href="#TreatNonCallableAsNull" class="xattr">[TreatNonCallableAsNull]</a>
|
|
unless required to specify the behavior of legacy APIs.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>The <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
is intended for use on <a href="http://www.w3.org/TR/2011/WD-html5-20110525/webappapis.html#event-handler-attributes">event handler IDL attributes</a>
|
|
defined in HTML5 (<a href="#ref-HTML5">[HTML5]</a>, section 6.1.6.1).</p>
|
|
</div>
|
|
<p>
|
|
See <a href="#es-nullable-type">section 4.2.18</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface that has one
|
|
attribute with the <a class="xattr" href="#TreatNonCallableAsNull">[TreatNonCallableAsNull]</a>
|
|
extended attribute and one without:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Callback=FunctionOnly]
|
|
interface EventHandler {
|
|
void eventOccurred(DOMString details);
|
|
};
|
|
|
|
interface Manager {
|
|
attribute EventHandler? handler1;
|
|
[TreatNonCallableAsNull] attribute EventHandler? handler2;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation, assigning a value that is not
|
|
callable (such as a <span class="estype">Number</span> value)
|
|
to handler1 will have different behavior from that when assigning
|
|
to handler2:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var manager = getManager(); <span class="comment">// Get an instance of Manager.</span>
|
|
|
|
manager.handler1 = function() { };
|
|
manager.handler1; <span class="comment">// Evaluates to the function.</span>
|
|
|
|
try {
|
|
manager.handler1 = 123; <span class="comment">// Throws a TypeError.</span>
|
|
} catch (e) {
|
|
}
|
|
|
|
manager.handler2 = function() { };
|
|
manager.handler2; <span class="comment">// Evaluates to the function.</span>
|
|
|
|
manager.handler2 = 123;
|
|
manager.handler2; <span class="comment">// Evaluates to null.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="TreatNullAs" class="section">
|
|
<h4>4.3.16. [TreatNullAs]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
or <a class="dfnref" href="#dfn-operation">operation</a> argument whose type is
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a>,
|
|
it indicates that a <span class="esvalue">null</span> value
|
|
assigned to the attribute or passed as the operation argument will be
|
|
handled differently from its default handling. Instead of being stringified
|
|
to “null”, which is the default,
|
|
it will be converted to the empty string “”.
|
|
</p>
|
|
<p>
|
|
If <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a> is specified on
|
|
an operation itself, then it indicates that a <a href="#es-user-objects">user object
|
|
implementing the interface</a> will have the return
|
|
value of the function that implements the operation
|
|
handled in the same way as for operation arguments
|
|
and attributes, as above.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>
|
|
extended attribute <span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-identifier">take the identifier</a>
|
|
<code>EmptyString</code>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a> extended attribute
|
|
<span class="rfc2119">MUST NOT</span> be specified on an operation argument,
|
|
attribute or operation return value whose type is not <a class="idltype" href="#idl-DOMString">DOMString</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>This means that even an attribute of type <span class="idltype">DOMString?</span> must not
|
|
use <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>, since <span class="idlvalue">null</span>
|
|
is a valid value of that type.</p>
|
|
</div>
|
|
<p>
|
|
See <a href="#es-DOMString">section 4.2.14</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#TreatNullAs">[TreatNullAs]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface that has one
|
|
attribute with the <a class="xattr" href="#TreatNullAs">[TreatNullAs]</a>
|
|
extended attribute, and one operation with an argument that has
|
|
the extended attribute:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dog {
|
|
attribute DOMString name;
|
|
[TreatNullAs=EmptyString] attribute DOMString owner;
|
|
|
|
boolean isMemberOfBreed([TreatNullAs=EmptyString] DOMString breedName);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation implementing the <span class="idltype">Dog</span>
|
|
interface would convert a <span class="esvalue">null</span> value
|
|
assigned to the “name” property or passed as the
|
|
argument to the <code>isMemberOfBreed</code> function
|
|
to the empty string rather than <code>"null"</code>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var d = getDog(); <span class="comment">// Assume d is a platform object implementing the Dog</span>
|
|
<span class="comment">// interface.</span>
|
|
|
|
d.name = null; <span class="comment">// This assigns the string "null" to the .name</span>
|
|
<span class="comment">// property.</span>
|
|
|
|
d.owner = null; <span class="comment">// This assigns the string "" to the .owner property.</span>
|
|
|
|
d.isMemberOfBreed(null); <span class="comment">// This passes the string "" to the isMemberOfBreed</span>
|
|
<span class="comment">// function.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="TreatUndefinedAs" class="section">
|
|
<h4>4.3.17. [TreatUndefinedAs]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on an <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
or <a class="dfnref" href="#dfn-operation">operation</a> argument whose type is
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> or <span class="idltype">DOMString?</span>,
|
|
it indicates that an <span class="esvalue">undefined</span> value
|
|
assigned to the corresponding property or passed as an argument to
|
|
the corresponding function will be handled differently from its
|
|
default handling, which is to stringify to
|
|
“undefined”:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the argument to <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
is <code>EmptyString</code>, then the value assigned to the
|
|
attribute or passed as the operation argument will be the empty string,
|
|
“”.
|
|
</li>
|
|
<li>
|
|
Otherwise, if the argument to <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
is <code>Null</code>, then the value assigned to the
|
|
attribute or passed as the operation argument will be the
|
|
<span class="idlvalue">null</span> value.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
If <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a> is specified on
|
|
an operation itself, then it indicates that a <a href="#es-user-objects">user object
|
|
implementing the interface</a> will have the return
|
|
value of the function that implements the operation
|
|
handled in the same way as for operation arguments
|
|
and attributes, as above.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
extended attribute <span class="rfc2119">MUST</span> <a class="dfnref" href="#dfn-xattr-identifier">take an identifier</a>:
|
|
either <code>EmptyString</code> or <code>Null</code>.
|
|
</p>
|
|
<p>
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=Null]</a>
|
|
<span class="rfc2119">MUST NOT</span> be specified on operation argument,
|
|
attribute or operation return value whose type is not <span class="idltype">DOMString?</span>,
|
|
and <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs=EmptyString]</a>
|
|
<span class="rfc2119">MUST NOT</span> be specified on operation argument,
|
|
attribute or operation return value whose type is neither
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> nor <span class="idltype">DOMString?</span>.
|
|
</p>
|
|
<p>
|
|
See <a href="#es-DOMString">section 4.2.14</a>
|
|
and <a href="#es-nullable-type">section 4.2.18</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines an interface that has one
|
|
attribute with the <a class="xattr" href="#TreatUndefinedAs">[TreatUndefinedAs]</a>
|
|
extended attribute, and one operation with an argument that has
|
|
the extended attribute:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Cat {
|
|
attribute DOMString name;
|
|
[TreatUndefinedAs=Null] attribute DOMString? owner;
|
|
|
|
boolean isMemberOfBreed([TreatUndefinedAs=EmptyString] DOMString breedName);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
An ECMAScript implementation implementing the <span class="idltype">Cat</span>
|
|
interface would convert an <span class="esvalue">undefined</span> value
|
|
assigned to the “name” and “owner”
|
|
properties and passed as the argument to the <code>isMemberOfBreed</code> function
|
|
all differently; the value would be converted to the string
|
|
“undefined”, the <span class="idlvalue">null</span>
|
|
value, and the empty string “”, respectively:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var c = getCat(); <span class="comment">// Obtain an instance of Cat.</span>
|
|
|
|
c.name = undefined; <span class="comment">// This assigns the string "undefined" to the</span>
|
|
<span class="comment">// .name property.</span>
|
|
|
|
c.owner = undefined; <span class="comment">// This assigns the null value to the</span>
|
|
<span class="comment">// .owner property.</span>
|
|
|
|
c.isMemberOfBreed(undefined); <span class="comment">// This passes the string "" to the</span>
|
|
<span class="comment">// isMemberOfBreed function.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="Unforgeable" class="section">
|
|
<h4>4.3.18. [Unforgeable]</h4>
|
|
|
|
<p>
|
|
If the <a class="xattr" href="#Unforgeable">[Unforgeable]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on a <a class="dfnref" href="#dfn-read-only">read only</a>
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>, it indicates
|
|
that the attribute will be reflected as an ECMAScript property in
|
|
a way that means its behavior cannot be modified and that performing
|
|
a property lookup on the object will always result in the attribute’s
|
|
property value being returned. In particular, the property will be
|
|
non-configurable and will exist as an own property on the object
|
|
itself rather than on its prototype.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Unforgeable">[Unforgeable]</a>
|
|
extended attribute <span class="rfc2119">MUST</span>
|
|
<a class="dfnref" href="#dfn-xattr-no-arguments">take no arguments</a>.
|
|
</p>
|
|
<p>
|
|
The <a class="xattr" href="#Unforgeable">[Unforgeable]</a>
|
|
extended attribute <span class="rfc2119">MUST NOT</span> appear on
|
|
anything other than a read only attribute. It also <span class="rfc2119">MUST NOT</span>
|
|
appear on an attribute on interface <var>A</var> if there exists
|
|
another interface <var>B</var> that
|
|
has <var>A</var> as an <a class="dfnref" href="#dfn-inherited-interfaces">inherited interface</a>.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>For example, the following IDL would be invalid:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
|
|
[Unforgeable] readonly attribute DOMString key;
|
|
};
|
|
|
|
interface B : A { };</code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
See <a href="#es-attributes">section 4.5.5</a>,
|
|
<a href="#indexed-and-named-properties">section 4.7.1</a> and
|
|
<a href="#defineownproperty">section 4.7.3</a>
|
|
for the specific requirements that the use of
|
|
<a class="xattr" href="#Unforgeable">[Unforgeable]</a> entails.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> defines
|
|
an interface that has two <a class="dfnref" href="#dfn-attribute">attributes</a>,
|
|
one of which is designated as <a class="xattr" href="#Unforgeable">[Unforgeable]</a>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface System {
|
|
[Unforgeable] readonly attribute DOMString username;
|
|
readonly attribute Date loginTime;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
In an ECMAScript implementation of the interface, the username attribute will be exposed as a non-configurable property on the
|
|
object itself:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var system = getSystem(); <span class="comment">// Get an instance of System.</span>
|
|
|
|
system.hasOwnProperty("username"); <span class="comment">// Evaluates to true.</span>
|
|
system.hasOwnProperty("loginTime"); <span class="comment">// Evaluates to false.</span>
|
|
System.prototype.hasOwnProperty("username"); <span class="comment">// Evaluates to false.</span>
|
|
System.prototype.hasOwnProperty("loginTime"); <span class="comment">// Evaluates to true.</span>
|
|
|
|
try {
|
|
<span class="comment">// This call would fail, since the property is non-configurable.</span>
|
|
Object.defineProperty(system, "username", { value: "administrator" });
|
|
} catch (e) { }
|
|
|
|
<span class="comment">// This defineProperty call would succeed, because System.prototype.loginTime</span>
|
|
<span class="comment">// is configurable.</span>
|
|
var forgedLoginTime = new Date(new Date() - 3600000);
|
|
Object.defineProperty(System.prototype, "loginTime", { value: forgedLoginTime });
|
|
|
|
system.loginTime; <span class="comment">// So this now evaluates to forgedLoginTime.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-modules" class="section">
|
|
<h3>4.4. Modules</h3>
|
|
|
|
<p>
|
|
The hierarchy of <a class="dfnref" href="#dfn-module">modules</a> in
|
|
an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a> can,
|
|
but need not be, reflected in an ECMAScript implementation. Whether
|
|
a module hierarchy is reflected or not depends on the use of the
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
</p>
|
|
<p>
|
|
For every module that is declared with the
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a> extended attribute,
|
|
and for every module that has an ancestor module declared with the
|
|
<a class="xattr" href="#NamespaceObject">[NamespaceObject]</a> extended attribute,
|
|
there exists a unique <dfn id="dfn-namespace-object">namespace object</dfn>, which
|
|
provides access to the <a class="dfnref" href="#dfn-interface-object">interface objects</a>
|
|
and <a class="dfnref" href="#dfn-exception-interface-object">exception interface objects</a>
|
|
for the <a class="dfnref" href="#dfn-interface">interfaces</a> and
|
|
<a class="dfnref" href="#dfn-exception">exceptions</a> declared in
|
|
the module.
|
|
</p>
|
|
<p>
|
|
The <dfn id="dfn-relevant-namespace-object">relevant namespace object</dfn>
|
|
for a module, interface or exception <var>A</var> is determined as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If <var>A</var> has an <a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>
|
|
and that module has a <a class="dfnref" href="#dfn-namespace-object">namespace object</a>,
|
|
than that namespace object is <var>A</var>’s
|
|
<a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a>.
|
|
</li>
|
|
<li>
|
|
Otherwise, <var>A</var>’s relevant namespace object is the ECMAScript global object.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
For every <a class="dfnref" href="#dfn-module">module</a> that has a
|
|
<a class="dfnref" href="#dfn-namespace-object">namespace object</a>,
|
|
a corresponding property <span class="rfc2119">MUST</span> exist on
|
|
the <a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a> for
|
|
the module. The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of the module, its value is the <a class="dfnref" href="#dfn-namespace-object">namespace object</a> for the module,
|
|
and the property has the attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-interfaces" class="section">
|
|
<h3>4.5. Interfaces</h3>
|
|
|
|
<p>
|
|
For every <a class="dfnref" href="#dfn-interface">interface</a> that is not declared with the
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,
|
|
a corresponding property <span class="rfc2119">MUST</span> exist on the
|
|
interface’s <a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a>.
|
|
The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the interface,
|
|
and its value is an object called the
|
|
<dfn id="dfn-interface-object">interface object</dfn>.
|
|
The property has the attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>.
|
|
The characteristics of an interface object are described in <a href="#interface-object">section 4.5.1</a>
|
|
below.
|
|
</p>
|
|
|
|
<p>
|
|
In addition, for every <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attribute on an interface, a corresponding property <span class="rfc2119">MUST</span>
|
|
exist on the interface’s <a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a>.
|
|
The name of the property is the
|
|
<a class="sym" href="#prod-identifier">identifier</a> that occurs directly after the
|
|
“<span class="sym">=</span>”, and its value is an object called a
|
|
<dfn id="dfn-named-constructor">named constructor</dfn>, which allows
|
|
construction of objects that implement the interface. The property has the
|
|
attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>.
|
|
The characteristics of a named constructor are described in
|
|
<a href="#named-constructors">section 4.5.2</a>
|
|
below.
|
|
</p>
|
|
|
|
<div id="interface-object" class="section">
|
|
<h4>4.5.1. Interface object</h4>
|
|
|
|
<p>
|
|
There exists an interface object for every <a class="dfnref" href="#dfn-interface">interface</a>
|
|
not declared with the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>. Interface objects
|
|
are always <a class="dfnref" href="#dfn-function-object">function objects</a>.
|
|
</p>
|
|
<p>
|
|
The <span class="prop">[[Class]]</span> property of the interface object <span class="rfc2119">MUST</span>
|
|
be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the interface.
|
|
</p>
|
|
<p>
|
|
The interface object also has properties that correspond to
|
|
the <a class="dfnref" href="#dfn-constant">constants</a> and
|
|
<a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
defined on that interface, as described in sections
|
|
<a href="#es-constants">4.5.4</a> and
|
|
<a href="#es-operations">4.5.6</a>
|
|
below.
|
|
</p>
|
|
<p>
|
|
The interface object <span class="rfc2119">MUST</span> also have a property named
|
|
“prototype” with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>
|
|
whose value is an object called the <dfn id="dfn-interface-prototype-object">interface prototype
|
|
object</dfn>. This object has properties
|
|
that correspond to the <a class="dfnref" href="#dfn-attribute">attributes</a> and
|
|
<a class="dfnref" href="#dfn-operation">operations</a> defined on the interface,
|
|
and is described in more detail in
|
|
<a href="#interface-prototype-object">section 4.5.3</a>
|
|
below.
|
|
</p>
|
|
|
|
<div id="es-interface-call" class="section">
|
|
<h5>4.5.1.1. Interface object [[Call]] method</h5>
|
|
|
|
<p>
|
|
If the <a class="dfnref" href="#dfn-interface">interface</a> is declared with a
|
|
<a class="xattr" href="#Constructor">[Constructor]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,
|
|
then the <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
can be called as a function to create an object that implements that
|
|
interface. Interfaces that do not have a constructor will throw
|
|
an exception when called as a function.
|
|
</p>
|
|
<!--
|
|
<p>
|
|
then the interface object <span class='rfc2119'>MUST</span> have a
|
|
<span class='prop'>[[Call]]</span> internal property, which allows
|
|
construction of objects that implement the given interface.
|
|
-->
|
|
<!-- The behavior
|
|
of this <span class='prop'>[[Construct]]</span> method is not
|
|
necessarily the same as that described for <span class='estype'>Function</span> objects in
|
|
section 13.2.2 of the
|
|
<cite>ECMAScript Language Specification, 5th Edition</cite>
|
|
<a href='#ref-ECMA-262'>[ECMA-262]</a>, but it
|
|
<span class='rfc2119'>MUST</span> return an object that implements
|
|
the given interface if it returns normally (that is, if it does not
|
|
throw an exception).
|
|
</p>-->
|
|
<p>
|
|
In order to define how overloaded constructor invocations are resolved, the
|
|
<dfn id="dfn-overload-resolution-algorithm">overload resolution algorithm</dfn>
|
|
is defined. Its input is an <a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>,
|
|
<var>S</var>, and a list of ECMAScript values, <var>arg</var><sub>0..<var>n</var>−1</sub>.
|
|
The algorithm behaves as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>entries</var> to a set with the same values as <var>S</var>.</li>
|
|
<li>Initialize <var>candidates</var> also to a set with the same values as <var>S</var>.</li>
|
|
<li>Let <var>maxarg</var> be the length of the longest type list of the entries in <var>S</var>.</li>
|
|
<li>Initialize <var>argcount</var> to be min(<var>maxarg</var>, <var>n</var>).</li>
|
|
|
|
<li>Let <var>undefcount</var> be the number of trailing <span class="estype">undefined</span> values in <var>arg</var><sub>0..<var>n</var>−1</sub>.</li>
|
|
<li>Initialize <var>j</var> to <var>undefcount</var>.</li>
|
|
<li>While <var>j</var> > 0:
|
|
<ol>
|
|
<li>If <var>candidates</var> has any entries whose type list is of length <var>n</var>−<var>j</var>,
|
|
then set <var>argcount</var> to <var>j</var> and break this while loop.</li>
|
|
<li>Set <var>j</var> to <var>j</var>−1.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Remove from <var>candidates</var> all entries whose type list is not of length <var>argcount</var>.</li>
|
|
<li>Initialize <var>i</var> to 0.</li>
|
|
<li>While <var>i</var> < <var>argcount</var>:
|
|
<ol>
|
|
<li>If not all entries in <var>entries</var> have identical types at position <var>i</var> in their type lists, then:
|
|
<ol>
|
|
<li>Initialize <var>types</var> to the set of IDL types { <a class="idltype" href="#idl-any">any</a> }.</li>
|
|
<li>Depending on the value of <var>arg</var><sub><var>i</var></sub>:
|
|
<dl class="switch">
|
|
<dt>An <span class="estype">Undefined</span>,
|
|
<span class="estype">Boolean</span> or
|
|
<span class="estype">Number</span> value</dt>
|
|
<dd>
|
|
Add to <var>types</var> the <a class="dfnref" href="#dfn-primitive-type">primitive types</a> and
|
|
<a class="dfnref" href="#dfn-nullable-type">nullable</a> primitive types.
|
|
</dd>
|
|
<dt>A <span class="estype">String</span> value</dt>
|
|
<dd>
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-DOMString">DOMString</a> and <span class="idltype">DOMString?</span> types.
|
|
</dd>
|
|
<dt><span class="esvalue">null</span></dt>
|
|
<dd>
|
|
Add to <var>types</var> all nullable types.
|
|
</dd>
|
|
<dt>A <a class="dfnref" href="#dfn-platform-array-object">platform array object</a></dt>
|
|
<dd>
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-object">object</a> type
|
|
and an <a href="#idl-array">array type</a> that corresponds to
|
|
the type of the IDL array that the platform array object represents.
|
|
</dd>
|
|
<dt>Any other <a class="dfnref" href="#dfn-platform-object">platform object</a></dt>
|
|
<dd>
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-object">object</a> type
|
|
and an <a href="#idl-interface">interface type</a>
|
|
for each <a class="dfnref" href="#dfn-interface">interface</a>
|
|
that is equal to, or is an <a class="dfnref" href="#dfn-inherited-interfaces">inherited interface</a> of, at least one
|
|
of the interfaces that the <a class="dfnref" href="#dfn-platform-object">platform object</a> implements.
|
|
</dd>
|
|
<dt>A native <span class="estype">Array</span> object</dt>
|
|
<dd>
|
|
(That is, a native object whose <span class="prop">[[Class]]</span> is “Array”.)
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-object">object</a> type,
|
|
an <a href="#idl-interface">interface type</a>
|
|
for each interface annotated with the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
and all <a href="#idl-array">array</a> and <a href="#idl-sequence">sequence types</a>.
|
|
</dd>
|
|
<dt>A native <span class="estype">Date</span> object</dt>
|
|
<dd>
|
|
(That is, a native object whose <span class="prop">[[Class]]</span> is “Date”.)
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-object">object</a> type,
|
|
an <a href="#idl-interface">interface type</a>
|
|
for each interface annotated with the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
and the <a href="#idl-Date">Date</a> type.
|
|
</dd>
|
|
<dt>Any other object</dt>
|
|
<dd>
|
|
Add to <var>types</var> the <a class="idltype" href="#idl-object">object</a> type
|
|
and an <a href="#idl-interface">interface type</a>
|
|
for each interface annotated with the <a class="xattr" href="#Callback">[Callback]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
</dd>
|
|
</dl>
|
|
</li>
|
|
<li>
|
|
Remove from <var>candidates</var> all entries with type list
|
|
<var>t</var> and boolean list <var>a</var> where
|
|
<var>a</var><sub><var>i</var></sub> is <span class="idlvalue">false</span>
|
|
and <var>t</var><sub><var>i</var></sub> ∉ <var>types</var>.
|
|
</li>
|
|
<li>
|
|
If there exists an entry in <var>candidates</var>
|
|
with type list <var>t</var> where
|
|
<var>t</var><sub><var>i</var></sub> ∈ <var>types</var>,
|
|
then remove from <var>R</var> all entries with type list
|
|
<var>t</var> where
|
|
<var>t</var><sub><var>i</var></sub> ∉ <var>types</var>.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>R</var>.</li>
|
|
</ol>
|
|
<p>
|
|
The internal <span class="prop">[[Call]]</span> method
|
|
of the interface object behaves as follows, assuming
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> is the list
|
|
of argument values passed to the constructor, and <var>I</var>
|
|
is the <a class="dfnref" href="#dfn-interface">interface</a>:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
If <var>I</var> was not declared with a <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>, then
|
|
throw a <span class="estype">TypeError</span>.
|
|
</li>
|
|
<li>
|
|
Let <var>id</var> be the identifier of interface <var>I</var>.
|
|
</li>
|
|
<li>
|
|
Initialize <var>S</var> to the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for constructors with <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count <var>n</var> (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Set <var>S</var> to the result of passing <var>S</var> and
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> to the
|
|
<a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> contains more than one entry, then the
|
|
constructor call is ambiguous. Remove all but one entry from
|
|
<var>S</var> according to rules specified in the description
|
|
of <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var>. If these rules do not sufficiently disambiguate the
|
|
call, then the behavior of the function call (including whether
|
|
it selects a particular overload or simply throws an exception)
|
|
is undefined.
|
|
</li>
|
|
<li>
|
|
Let <var>x</var> be the <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
that represents the constructor and <var>t</var><sub>0..<var>m</var>−1</sub> be the type
|
|
list of the single entry in <var>S</var>.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var><sub>0..<var>m</var>−1</sub> be a list
|
|
of IDL values, where <var>idlarg</var><sub><var>i</var></sub>
|
|
is the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>arg</var><sub><var>i</var></sub> to an IDL value. These conversions
|
|
<span class="rfc2119">MUST</span> be done in order from
|
|
<var>arg</var><sub><var>0</var></sub> to <var>arg</var><sub><var>m</var>−1</sub>.
|
|
</li>
|
|
<li>
|
|
Let <var>R</var> be the result of performing the actions listed in the description of
|
|
the constructor represented by <var>x</var>
|
|
with <var>idlarg</var><sub>0..<var>m</var>−1</sub>
|
|
as the argument values.
|
|
</li>
|
|
<li>
|
|
Return the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>R</var> to an ECMAScript <a href="#idl-interface">interface type</a> value
|
|
<var>I</var>.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
If the internal <span class="prop">[[Call]]</span> method
|
|
of the <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
returns normally, then it <span class="rfc2119">MUST</span>
|
|
return an object that implements interface <var>I</var>.
|
|
</p>
|
|
<p>
|
|
Interface objects for interfaces declared with a <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
extended attribute <span class="rfc2119">MUST</span> have a property named “length”
|
|
with attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>
|
|
whose value is a <span class="estype">Number</span> determined as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>id</var> be the identifier of interface <var>I</var>.
|
|
</li>
|
|
<li>
|
|
Initialize <var>S</var> to the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for constructors with
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count 0 (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Return the maximum argument list length of the constructors in the entries of <var>S</var>.
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<!--
|
|
<div id='es-interface-hasinstance' class='section'>
|
|
<h5>Interface object [[HasInstance]] method</h5>
|
|
|
|
<p>
|
|
The internal <span class='prop'>[[HasInstance]]</span> method of every
|
|
<a class='dfnref' href='#dfn-interface-object'>interface object</a>
|
|
<var>A</var> <span class='rfc2119'>MUST</span> behave as follows,
|
|
assuming <var>V</var> is the object
|
|
argument passed to <span class='prop'>[[HasInstance]]</span>:
|
|
</p>
|
|
<ol class='algorithm'>
|
|
<li>If <var>V</var> is not an object, return <span class='esvalue'>false</span>.</li>
|
|
<li>Let <var>O</var> be the result of calling the <span class='prop'>[[Get]]</span> method of <var>A</var> with property name “prototype”.</li>
|
|
<li>If <var>O</var> is not an object, throw a <span class='estype'>TypeError</span> exception.</li>
|
|
<li>If <var>V</var> is a host object that implements the
|
|
interface for which <var>O</var> is the <a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype object</a>,
|
|
return <span class='esvalue'>true</span>.</li>
|
|
<li>Repeat:
|
|
<ol>
|
|
<li>Set <var>V</var> to the value of the <span class='prop'>[[Prototype]]</span> internal property of <var>V</var>.</li>
|
|
<li>If <var>V</var> is <span class='esvalue'>null</span>, return <span class='esvalue'>false</span>.</li>
|
|
<li>If <var>O</var> and <var>V</var> refer to the same object,
|
|
return <span class='esvalue'>true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
-->
|
|
</div>
|
|
|
|
<div id="named-constructors" class="section">
|
|
<h4>4.5.2. Named constructors</h4>
|
|
|
|
<p>
|
|
A <a class="dfnref" href="#dfn-named-constructor">named constructor</a>
|
|
that exists due to one or more
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
with a given <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
is a <a class="dfnref" href="#dfn-function-object">function object</a>.
|
|
It <span class="rfc2119">MUST</span> have a <span class="prop">[[Call]]</span>
|
|
internal property, which allows construction of objects that
|
|
implement the interface on which the
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attributes appear. It behaves as follows, assuming
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> is the list
|
|
of argument values passed to the constructor, <var>id</var>
|
|
is the identifier of the constructor specified in the
|
|
extended attribute <a class="dfnref" href="#dfn-xattr-named-argument-list">named argument list</a>,
|
|
and <var>I</var> is the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which the <a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
extended attribute appears:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Initialize <var>S</var> to the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for constructors with <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count <var>n</var> (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Set <var>S</var> to the result of passing <var>S</var> and
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> to the
|
|
<a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> contains more than one entry, then the
|
|
constructor call is ambiguous. Remove all but one entry from
|
|
<var>S</var> according to rules specified in the description
|
|
of <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var>, or arbitrarily if no such rules exist.
|
|
</li>
|
|
<li>
|
|
Let <var>x</var> be the <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
that represents the constructor, and <var>t</var><sub>0..<var>m</var>−1</sub> be the type
|
|
list, of the single entry in <var>S</var>.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var><sub>0..<var>m</var>−1</sub> be a list
|
|
of IDL values, where <var>idlarg</var><sub><var>i</var></sub>
|
|
is the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>arg</var><sub><var>i</var></sub> to an IDL value of type
|
|
<var>t</var><sub><var>i</var></sub>. These conversions
|
|
<span class="rfc2119">MUST</span> be done in order from
|
|
<var>arg</var><sub><var>0</var></sub> to <var>arg</var><sub><var>m</var>−1</sub>.
|
|
</li>
|
|
<li>
|
|
Let <var>R</var> be the result of performing the actions listed in the description of
|
|
the constructor represented by <var>x</var>
|
|
with <var>idlarg</var><sub>0..<var>m</var>−1</sub>
|
|
as the argument values.
|
|
</li>
|
|
<li>
|
|
Return the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>R</var> to an ECMAScript
|
|
<a href="#idl-interface">interface type</a> value
|
|
<var>I</var>.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
If the internal <span class="prop">[[Call]]</span> method
|
|
of the <a class="dfnref" href="#dfn-named-constructor">named constructor</a>
|
|
returns normally, then it <span class="rfc2119">MUST</span>
|
|
return an object that implements interface <var>I</var>.
|
|
</p>
|
|
<p>
|
|
A named constructor <span class="rfc2119">MUST</span> have a property named “length”
|
|
with attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>
|
|
whose value is a <span class="estype">Number</span> determined as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Initialize <var>S</var> to the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for constructors with
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count 0 (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Return the maximum argument list length of the constructors in the entries of <var>S</var>.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
A named constructor <span class="rfc2119">MUST</span> also have a property named
|
|
“prototype” with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>
|
|
whose value is the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
for the <a class="dfnref" href="#dfn-interface">interface</a> on which the
|
|
<a class="xattr" href="#NamedConstructor">[NamedConstructor]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="interface-prototype-object" class="section">
|
|
<h4>4.5.3. Interface prototype object</h4>
|
|
|
|
<p>
|
|
There <span class="rfc2119">MUST</span> exist an
|
|
<a class="dfnref" href="#dfn-interface-prototype-object">interface prototype
|
|
object</a> for every <a class="dfnref" href="#dfn-interface">interface</a>
|
|
defined, regardless of whether the interface was declared with the
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
The interface prototype object for a particular interface has
|
|
properties that correspond to the <a class="dfnref" href="#dfn-attribute">attributes</a>
|
|
and <a class="dfnref" href="#dfn-operation">operations</a>
|
|
defined on that interface. These properties are described in more detail in
|
|
sections <a href="#es-attributes">4.5.5</a> and
|
|
<a href="#es-operations">4.5.6</a> below.
|
|
</p>
|
|
<p>
|
|
As with the <a class="dfnref" href="#dfn-interface-object">interface object</a>,
|
|
the interface prototype object also has properties that correspond to the
|
|
<a class="dfnref" href="#dfn-constant">constants</a> defined on that
|
|
interface, described in <a href="#es-operations">section
|
|
4.5.4</a> below.
|
|
</p>
|
|
<p>
|
|
If the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
extended attribute was not specified on the interface, then
|
|
the interface prototype object <span class="rfc2119">MUST</span>
|
|
also have a property named “constructor” with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span> whose value
|
|
is a reference to the interface object for the interface.
|
|
</p>
|
|
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
for a given interface <var>A</var> <span class="rfc2119">MUST</span> have an internal
|
|
<span class="prop">[[Prototype]]</span> property whose value is as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>A</var> is not declared to inherit from another interface, then the
|
|
value of the internal <span class="prop">[[Prototype]]</span> property
|
|
of <var>A</var> is the <span class="estype">Array</span> prototype object
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.4.4) if the interface
|
|
was declared with <a class="xattr" href="#ArrayClass">ArrayClass</a>,
|
|
or the <span class="estype">Object</span> prototype object otherwise
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.2.4).</li>
|
|
<li>Otherwise, <var>A</var> does <a class="dfnref" href="#dfn-inherit">inherit</a> from another
|
|
interface.
|
|
The value of the internal <span class="prop">[[Prototype]]</span> property of <var>A</var> is the
|
|
<a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
for the inherited interface.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
of an <a class="dfnref" href="#dfn-interface">interface</a> that is defined with
|
|
the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
will be accessible if the interface is used as a
|
|
<a class="dfnref" href="#dfn-supplemental-interface">non-supplemental interface</a>.
|
|
For example, with the following IDL:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[NoInterfaceObject]
|
|
interface Foo {
|
|
};
|
|
|
|
partial interface Window {
|
|
attribute Foo foo;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
it is not possible to access the interface prototype object through
|
|
the <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
(since it does not exist as <code>window.Foo</code>). However, an instance
|
|
of <span class="idltype">Foo</span> can expose the interface prototype
|
|
object by gettings its internal <span class="prop">[[Prototype]]</span>
|
|
property value – <code>Object.getPrototypeOf(window.foo)</code> in
|
|
this example.
|
|
</p>
|
|
<p>
|
|
If the interface is used solely as a
|
|
<a class="dfnref" href="#dfn-supplemental-interface">supplemental interface</a>,
|
|
then there will be no way to access its interface prototype object, since no
|
|
object will have the interface prototype object as its internal
|
|
<span class="prop">[[Prototype]]</span> property value. In such cases,
|
|
it is an acceptable optimization for this object not to exist.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!--
|
|
<div id='mixin-prototype' class='section'>
|
|
<h4>Mixin prototype objects</h4>
|
|
|
|
<p>
|
|
If an object implements any interfaces other than those as declared in the IDL,
|
|
then these interfaces are called <dfn id='dfn-mixin-interface'>mixin interfaces</dfn>
|
|
for the object. The <dfn id='dfn-mixin-prototype-object'>mixin prototype object</dfn>
|
|
for a given object <var>O</var> is an object as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
The object has properties that are the union of all properties that initially exist on <var>O</var>’s
|
|
<a class='dfnref' href='#dfn-mixin-interface'>mixin interfaces</a>’
|
|
<a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype objects</a>.
|
|
If there are multiple properties with the same name,
|
|
then it is undefined which of those properties ends up on
|
|
the mixin prototype object.
|
|
</li>
|
|
<li>
|
|
The object’s internal <span class='prop'>[[Prototype]]</span> property
|
|
value is a reference to the <a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype object</a>
|
|
for the most derived non-mixin interface that <var>O</var> implements,
|
|
or, if the object implements no non-mixin interfaces, a reference to the
|
|
<span class='estype'>Object</span> prototype object
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.2.4).</li>
|
|
</ul>
|
|
<p>
|
|
If two objects have the same set of <a class='dfnref' href='#dfn-mixin-interface'>mixin interfaces</a>,
|
|
then their <a class='dfnref' href='#dfn-mixin-prototype-object'>mixin prototype objects</a>
|
|
<span class='rfc2119'>MUST</span> be the same object.
|
|
</p>
|
|
|
|
XXX unfinished example
|
|
<div class='example'>
|
|
<p>
|
|
The following example illustrates a case when a <a class='dfnref' href='#dfn-mixin-protoype-object'>mixin prototype object</a>
|
|
will exist. Consider the following IDL:
|
|
</p>
|
|
<x:codeblock language='idl'>interface Animal {
|
|
DOMString latinName;
|
|
};
|
|
|
|
interface Human {
|
|
DOMString name;
|
|
};
|
|
|
|
interface LivingHuman {
|
|
unsigned short age;
|
|
};
|
|
|
|
interface
|
|
</div>
|
|
</div>
|
|
-->
|
|
|
|
<div id="es-constants" class="section">
|
|
<h4>4.5.4. Constants</h4>
|
|
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-constant">constant</a> defined on
|
|
an <a class="dfnref" href="#dfn-interface">interface</a> <var>A</var>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding property on
|
|
the <a class="dfnref" href="#dfn-interface-object">interface object</a>,
|
|
if it exists. The property has the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-constant">constant</a>.</li>
|
|
<li>The value of the property is that which is obtained by <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a> the <a class="dfnref" href="#dfn-constant">constant</a>’s IDL value to an ECMAScript value.</li>
|
|
<li>The property has attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>.</li>
|
|
</ul>
|
|
<p>
|
|
In addition, a property with the same characteristics <span class="rfc2119">MUST</span>
|
|
exist on the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-attributes" class="section">
|
|
<h4>4.5.5. Attributes</h4>
|
|
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-attribute">attribute</a> defined on
|
|
the <a class="dfnref" href="#dfn-interface">interface</a>, there
|
|
<span class="rfc2119">MUST</span> exist a corresponding property.
|
|
If the attribute was declared with the <a class="xattr" href="#Unforgeable">[Unforgeable]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,
|
|
then the property exists on every object that implements the
|
|
interface. Otherwise, it exists on the interface’s
|
|
<a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>.
|
|
</p>
|
|
<p>
|
|
The characteristics of these properties are as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-attribute">attribute</a>.
|
|
</li>
|
|
<li>
|
|
The property has attributes <span class="descriptor">{ [[Get]]: <var>G</var>, [[Set]]: <var>S</var>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <var>configurable</var> }</span>,
|
|
where:
|
|
<ul>
|
|
<li><var>configurable</var> is <span class="esvalue">false</span> if the attribute was
|
|
declared with the <a class="xattr" href="#Unforgeable">[Unforgeable]</a> extended attribute and <span class="esvalue">true</span> otherwise;</li>
|
|
<li><var>G</var> is the <a class="dfnref" href="#dfn-attribute-getter">attribute getter</a>, defined below; and</li>
|
|
<li><var>S</var> is the <a class="dfnref" href="#dfn-attribute-setter">attribute setter</a>, also defined below.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
The <dfn id="dfn-attribute-getter">attribute getter</dfn> is a <span class="estype">Function</span>
|
|
object whose behavior when invoked is as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>If <var>O</var> is not a <a class="dfnref" href="#dfn-platform-object">platform object</a> that implements the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which the attribute was declared, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>
|
|
Let <var>idlValue</var> be the result of performing the actions listed in the description of the attribute that occur when getting
|
|
(or those listed in the description of the inherited attribute, if this attribute is declared to
|
|
<a class="dfnref" href="#dfn-inherit-getter">inherit its getter</a>),
|
|
with <var>O</var> as the object.
|
|
</li>
|
|
<li>
|
|
Let <var>V</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
the <var>idlValue</var> for this attribute to an ECMAScript value.
|
|
</li>
|
|
<li>
|
|
Return <var>V</var>.
|
|
</li>
|
|
</ol>
|
|
The value of the <span class="estype">Function</span> object’s “length”
|
|
property is the <span class="estype">Number</span> value <span class="esvalue">0</span>.
|
|
</li>
|
|
<li>
|
|
The <dfn id="dfn-attribute-setter">attribute setter</dfn> is <span class="esvalue">undefined</span>
|
|
if the attribute is declared <code>readonly</code> and has neither a
|
|
<a class="xattr" href="#PutForwards">[PutForwards]</a> nor a <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> declared on it.
|
|
Otherwise, it is a <span class="estype">Function</span> object whose behavior when invoked is as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>If <var>O</var> is not a <a class="dfnref" href="#dfn-platform-object">platform object</a> that implements the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which the attribute was declared, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Let <var>V</var> be the value of the first argument passed to the <span class="estype">Function</span>,
|
|
or <span class="esvalue">undefined</span> is no arguments were passed.</li>
|
|
<li>If the attribute is declared with a <a class="xattr" href="#PutForwards">[PutForwards]</a>
|
|
extended attribute, then:
|
|
<ol>
|
|
<li>Let <var>Q</var> be the result of calling the <span class="prop">[[Get]]</span> method
|
|
on <var>O</var> using the identifier of the attribute as the property name.</li>
|
|
<li>If <var>Q</var> is not an object, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Let <var>A</var> be the attribute identified by the <a class="xattr" href="#PutForwards">[PutForwards]</a> extended attribute.</li>
|
|
<li>Call the <span class="prop">[[Put]]</span> method on <var>Q</var>
|
|
using the identifier of <var>A</var> as the property name and <var>V</var> as the value.</li>
|
|
<li>Return.</li>
|
|
</ol>
|
|
</li>
|
|
<li>If the attribute is declared with a <a class="xattr" href="#Replaceable">[Replaceable]</a>
|
|
extended attribute, then:
|
|
<ol>
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>If <var>O</var> is not an instance of the interface on which the attribute was declared,
|
|
then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Let <var>P</var> be the identifier of the attribute.</li>
|
|
<li>Call the <span class="prop">[[DefineOwnProperty]]</span> method of <var>O</var>
|
|
passing property name <var>P</var>, Property Descriptor
|
|
<span class="desc">{ [[Value]]: <var>V</var>, [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>,
|
|
and <b>false</b>.</li>
|
|
<li>Return <span class="esvalue">undefined</span>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Let <var>idlValue</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>V</var> to an IDL value.</li>
|
|
<li>Perform the actions listed in the description of the attribute that occur when setting,
|
|
with <var>O</var> as the object and <var>idlValue</var> as the value.</li>
|
|
<li>Return <span class="esvalue">undefined</span>.</li>
|
|
</ol>
|
|
The value of the <span class="estype">Function</span> object’s “length”
|
|
property is the <span class="estype">Number</span> value <span class="esvalue">1</span>.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
Note that attempting to assign to a property corresponding to a
|
|
<a class="dfnref" href="#dfn-read-only">read only</a> <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
results in different behavior depending on whether the script doing so is in strict mode.
|
|
When in strict mode, such an assignment will result in a <span class="estype">TypeError</span>
|
|
being thrown. When not in strict mode, the assignment attempt will be ignored.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-operations" class="section">
|
|
<h4>4.5.6. Operations</h4>
|
|
|
|
<p>
|
|
For each unique <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of an <!--non-<a class='dfnref' href='#dfn-omittable'>omittable</a>-->
|
|
<a class="dfnref" href="#dfn-operation">operation</a>
|
|
defined on the <a class="dfnref" href="#dfn-interface">interface</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding property on
|
|
the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
(if it is a <a class="dfnref" href="#dfn-regular-operation">regular operation</a>)
|
|
or the <a class="dfnref" href="#dfn-interface-object">interface object</a>
|
|
(if it is a <a class="dfnref" href="#dfn-static-operation">static operation</a>),
|
|
unless the <a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for that <a class="dfnref" href="#dfn-identifier">identifier</a> and <a class="dfnref" href="#dfn-operation">operation</a>
|
|
and with an argument count of 0 (for the ECMAScript language binding) has no
|
|
entries.
|
|
</p>
|
|
<p>
|
|
The characteristics of such a corresponding property are as follows:
|
|
</p>
|
|
<ul>
|
|
<li>The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a>.</li>
|
|
<li>
|
|
The property has attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>.
|
|
</li>
|
|
<li>
|
|
The value of the property is a <span class="estype">Function</span> object whose
|
|
behavior is as follows,
|
|
assuming <var>id</var> is the
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> is the list
|
|
of argument values passed to the function
|
|
and <var>I</var> is the <a class="dfnref" href="#dfn-interface">interface</a>:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>O</var> be an object as follows:
|
|
<ul>
|
|
<li>
|
|
If the <a class="dfnref" href="#dfn-interface">interface</a> on which the
|
|
<a class="dfnref" href="#dfn-operation">operation</a> appears has an
|
|
<a class="xattr" href="#ImplicitThis">[ImplicitThis]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,
|
|
and the <span class="esvalue">this</span> value is <span class="esvalue">null</span>
|
|
or <span class="esvalue">undefined</span>, then <var>O</var> is
|
|
the ECMAScript global object associated with the <span class="estype">Function</span> object.
|
|
</li>
|
|
<li>
|
|
Otherwise, <var>O</var> is the result of calling ToObject on the
|
|
<span class="esvalue">this</span> value.
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
If <var>O</var> is not a <a class="dfnref" href="#dfn-platform-object">platform object</a>
|
|
that implements interface <var>I</var>, throw a <span class="estype">TypeError</span>.
|
|
</li>
|
|
<li>
|
|
Initialize <var>S</var> to the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for <a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
(if the operation is a regular operation) or for
|
|
<a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
(if the operation is a static operation) with
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count <var>n</var> (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Set <var>S</var> to the result of passing <var>S</var> and
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> to the
|
|
<a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
|
|
</li>
|
|
<li>
|
|
If <var>S</var> contains more than one entry, then the
|
|
operation call is ambiguous. Remove all but one entry from
|
|
<var>S</var> according to rules specified in the description
|
|
of <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var>, or arbitrarily if no such rules exist.
|
|
</li>
|
|
<li>
|
|
Let <var>op</var> be the operation and <var>t</var><sub>0..<var>m</var>−1</sub>
|
|
be the type list of the single entry in <var>S</var>.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var><sub>0..<var>m</var>−1</sub> be a list
|
|
of IDL values, where <var>idlarg</var><sub><var>i</var></sub>
|
|
is the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>arg</var><sub><var>i</var></sub> to an IDL value. These conversions
|
|
<span class="rfc2119">MUST</span> be done in order from
|
|
<var>arg</var><sub><var>0</var></sub> to <var>arg</var><sub><var>m</var>−1</sub>.
|
|
</li>
|
|
<li>
|
|
Let <var>R</var> be the result of performing the actions listed in the description of
|
|
operation <var>op</var> with <var>idlarg</var><sub>0..<var>m</var>−1</sub>
|
|
as the argument values.
|
|
</li>
|
|
<li>
|
|
Return the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>R</var> to an ECMAScript value of
|
|
the type <var>op</var> is declared to return.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
The value of the <span class="estype">Function</span> object’s “length”
|
|
property is a <span class="estype">Number</span> determined as follows:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>S</var> be the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for <a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
(if the operation is a regular operation) or for
|
|
<a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
(if the operation is a static operation) with
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
<var>id</var> on <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> and with argument count 0 (for the ECMAScript language binding).
|
|
</li>
|
|
<li>
|
|
Return the maximum argument list length of the functions in the entries of <var>S</var>.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
|
|
<p id="es-stringifier">
|
|
In addition, if the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
has a <a class="dfnref" href="#dfn-stringifier">stringifier</a>, then
|
|
a property <span class="rfc2119">MUST</span> exist on
|
|
the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
whose name is “toString”,
|
|
with attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>
|
|
and whose value is a
|
|
<span class="estype">Function</span> object. If <code>stringifier</code>
|
|
was specified on an <a class="dfnref" href="#dfn-attribute">attribute</a> <var>A</var>, then the
|
|
function, when invoked,
|
|
<span class="rfc2119">MUST</span> behave as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>If <var>O</var> is not an object that implements the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
on which <var>A</var> was declared, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>
|
|
Let <var>V</var> be the result of invoking the <span class="prop">[[Get]]</span> method of <var>O</var>
|
|
with <var>P</var> as the argument.
|
|
</li>
|
|
<li>Return ToString(<var>V</var>).</li>
|
|
</ol>
|
|
<p>
|
|
If <code>stringifier</code>
|
|
was specified on an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
with an identifier <var>P</var>, then
|
|
the function, when invoked,
|
|
<span class="rfc2119">MUST</span> behave as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>
|
|
Let <var>F</var> be the result of invoking the <span class="prop">[[Get]]</span> method of object
|
|
<var>O</var> with <var>P</var> as the argument.
|
|
</li>
|
|
<li>If <var>F</var> is not callable, throw a <span class="estype">TypeError</span>.</li>
|
|
<li>Let <var>V</var> be the result of invoking the <span class="prop">[[Call]]</span> method of <var>F</var>,
|
|
using <var>O</var> as the <span class="esvalue">this</span> value
|
|
and passing no arguments.</li>
|
|
<li>Return ToString(<var>V</var>).</li>
|
|
</ol>
|
|
<p>
|
|
If <code>stringifier</code>
|
|
was specified on an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
with no identifier,
|
|
then the behavior of the function
|
|
is the <a class="dfnref" href="#dfn-stringification-behavior">stringification behavior</a>
|
|
of the interface, as described in the prose for the interface.
|
|
</p>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="es-implements-statements" class="section">
|
|
<h3>4.6. Implements statements</h3>
|
|
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
of an interface <var>A</var> <span class="rfc2119">MUST</span> have a copy of
|
|
each property that corresponds to one of the
|
|
<a class="dfnref" href="#dfn-constant">constants</a>,
|
|
<a class="dfnref" href="#dfn-attribute">attributes</a> or
|
|
<a class="dfnref" href="#dfn-operation">operations</a> that exist on
|
|
all of the interface prototype objects of <var>A</var>’s
|
|
<a class="dfnref" href="#dfn-consequential-interfaces">consequential interfaces</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-platform-objects" class="section">
|
|
<h3>4.7. Platform objects implementing interfaces</h3>
|
|
|
|
<p>
|
|
Every <a class="dfnref" href="#dfn-platform-object">platform object</a> is associated with a global environment, just
|
|
as the <a class="dfnref" href="#dfn-initial-object">initial objects</a> are.
|
|
It is the responsibility of specifications using Web IDL to state
|
|
which global environment (or, by proxy, which global object) each platform
|
|
object is associated with.
|
|
</p>
|
|
<p>
|
|
The <dfn id="dfn-primary-interface">primary interface</dfn> of a platform object
|
|
that implements one or more interfaces is the most-derived <a class="dfnref" href="#dfn-supplemental-interface">non-supplemental interface</a>
|
|
that it implements. The value of the internal <span class="prop">[[Prototype]]</span>
|
|
property of the platform object is the <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype object</a>
|
|
of the <a class="dfnref" href="#dfn-primary-interface">primary interface</a>
|
|
from the <a class="dfnref" href="#dfn-platform-object">platform object</a>’s associated global environment.
|
|
</p>
|
|
<!--
|
|
<p>
|
|
The value of the host object’s internal <span class='prop'>[[Prototype]]</span>
|
|
property is determined as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the host object implements no <a class='dfnref' href='#dfn-interface'>interfaces</a>,
|
|
then its internal <span class='prop'>[[Prototype]]</span> property
|
|
value is a reference to the <span class='estype'>Object</span>
|
|
prototype object from the object’s associated global environment.
|
|
</li>
|
|
<li>
|
|
If the host object implements a single
|
|
<a class='dfnref' href='#dfn-interface'>interface</a>, then its
|
|
internal <span class='prop'>[[Prototype]]</span> property is a
|
|
reference to the
|
|
<a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype object</a>
|
|
from the object’s associated global environment for that interface.
|
|
</li>
|
|
<li>
|
|
Otherwise, if the host object has a <a class='dfnref' href='#dfn-primary-prototype-interface'>primary prototype interface</a>
|
|
and implements no interfaces other than its primary
|
|
prototype interface and all of its ancestors, then the value of
|
|
the internal <span class='prop'>[[Prototype]]</span> property is
|
|
a reference to the
|
|
<a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype object</a>
|
|
from the host object’s associated global environment
|
|
for the host object’s primary prototype interface.
|
|
</li>
|
|
<li>
|
|
Otherwise, the host object implements at least two
|
|
<a class='dfnref' href='#dfn-interface'>interfaces</a>, and has no
|
|
<a class='dfnref' href='#dfn-primary-prototype-interface'>primary prototype interface</a>
|
|
or implements some interfaces other than its primary prototype
|
|
interface and all of its ancestors. The value of the
|
|
internal <span class='prop'>[[Prototype]]</span> property is
|
|
a reference to the <a class='dfnref' href='#dfn-host-object-mixin-prototype-object'>host object mixin prototype object</a>
|
|
for the host object (defined below).
|
|
</li>
|
|
</ul>
|
|
-->
|
|
<p>
|
|
The value of the internal <span class="prop">[[Class]]</span>
|
|
property of a platform object that implements one or more interfaces
|
|
<span class="rfc2119">MUST</span> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of
|
|
the <a class="dfnref" href="#dfn-primary-interface">primary interface</a>
|
|
of the platform object.
|
|
</p>
|
|
<!--
|
|
of that interface.
|
|
determined as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the host object implements a single
|
|
<a class='dfnref' href='#dfn-interface'>interface</a>, then the
|
|
value of the internal <span class='prop'>[[Class]]</span>
|
|
property <span class='rfc2119'>MUST</span> be the
|
|
<a class='dfnref' href='#dfn-identifier'>identifier</a>
|
|
of that interface.
|
|
</li>
|
|
<li>
|
|
Otherwise, if the host object has a
|
|
<a class='dfnref' href='#dfn-primary-prototype-interface'>primary prototype interface</a>,
|
|
then the value of the internal <span class='prop'>[[Class]]</span>
|
|
property <span class='rfc2119'>MUST</span> be the
|
|
identifier of that interface.
|
|
</li>
|
|
<li>
|
|
Otherwise, no particular value is required to be used for the
|
|
value of the internal <span class='prop'>[[Class]]</span>
|
|
property.
|
|
</li>
|
|
</ul>
|
|
<div class='ednote'>
|
|
<p>Should there be more restrictions on the <span class='prop'>[[Class]]</span>?
|
|
<a href='http://www.w3.org/mid/Pine.LNX.4.62.0903072358030.2690@hixie.dreamhostps.com'>(Mail.)</a></p>
|
|
</div>
|
|
|
|
<div id='host-object-mixin-prototype' class='section'>
|
|
<h4>Host object mixin prototype object</h4>
|
|
|
|
<p>
|
|
The <dfn id='dfn-host-object-mixin-prototype-object'>host object mixin prototype object</dfn>
|
|
for a given host object is an object as follows:
|
|
</p>
|
|
<ul>
|
|
<li>The object has properties that are the union of all
|
|
properties that exist on the <a class='dfnref' href='#dfn-interface'>interfaces</a>
|
|
that the host object implements and which are not the host object’s
|
|
<a class='dfnref' href='#dfn-primary-prototype-interface'>primary prototype interface</a>
|
|
or one of its ancestors.</li>
|
|
<li>The object’s internal <span class='prop'>[[Prototype]]</span> property value
|
|
is a reference to the <a class='dfnref' href='#dfn-interface-prototype-object'>interface prototype object</a>
|
|
for the host object’s <a class='dfnref' href='#dfn-primary-prototype-interface'>primary prototype interface</a>,
|
|
or, if the host object has no primary prototype interface, a reference to the
|
|
<span class='estype'>Object</span> prototype object. The
|
|
prototype object chosen for the <span class='prop'>[[Prototype]]</span> property
|
|
value is the one from the host object’s associated global environment.</li>
|
|
</ul>
|
|
<p>
|
|
If two host objects implement the same set of
|
|
<a class='dfnref' href='#dfn-interface'>interfaces</a>,
|
|
have references to <a class='dfnref' href='#dfn-host-object-mixin-prototype-object'>host object mixin prototype objects</a>
|
|
as their internal <span class='prop'>[[Prototype]]</span> property values,
|
|
and are both associated with the same global environment,
|
|
then these host object mixin prototype objects
|
|
<span class='rfc2119'>MUST</span> be the same object.
|
|
</p>
|
|
</div>
|
|
-->
|
|
|
|
<div id="indexed-and-named-properties" class="section">
|
|
<h4>4.7.1. Indexed and named properties</h4>
|
|
|
|
<p>
|
|
If a <a class="dfnref" href="#dfn-platform-object">platform object</a> implements an <a class="dfnref" href="#dfn-interface">interface</a> that
|
|
<a class="dfnref" href="#dfn-support-indexed-properties">supports indexed</a> or
|
|
<a class="dfnref" href="#dfn-support-named-properties">named properties</a>,
|
|
the object will appear to have additional properties that correspond to the
|
|
object’s indexed and named properties. These properties are not “real” own
|
|
properties on the object, but are made to look like they are by being exposed
|
|
by the <span class="prop">[[GetOwnProperty]]</span> internal method.
|
|
</p>
|
|
<p>
|
|
It is permissible for an object to implement multiple interfaces that support indexed properties.
|
|
However, if so, and there are conflicting definitions as to the object’s
|
|
<a class="dfnref" href="#dfn-supported-property-indices">supported property indices</a>,
|
|
or if one of the interfaces is a <a class="dfnref" href="#dfn-supplemental-interface">supplemental interface</a> for the
|
|
platform object, then it is undefined what additional properties the object will appear to
|
|
have, or what its exact behavior will be with regard to its indexed properties.
|
|
The same applies for named properties.
|
|
</p>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-indexed-property-getter">indexed property getter</a>
|
|
that is defined on the derived-most interface that the
|
|
platform object implements is the one that defines the behavior
|
|
when indexing the object with an array index. Similarly for
|
|
<a class="dfnref" href="#dfn-indexed-property-setter">indexed property setters</a>,
|
|
<a class="dfnref" href="#dfn-indexed-property-deleter">deleters</a> and
|
|
<a class="dfnref" href="#dfn-indexed-property-creator">creators</a>.
|
|
This way, the definitions of these special operations from
|
|
ancestor interfaces can be overridden.
|
|
</p>
|
|
|
|
<p>
|
|
Platform objects implementing an interface that supports indexed or named properties cannot be fixed; if <code>Object.freeze</code>, <code>Object.seal</code>
|
|
or <code>Object.preventExtensions</code> is called on one of these objects, these the function
|
|
<span class="rfc2119">MUST</span> throw a <span class="estype">TypeError</span>.
|
|
</p>
|
|
|
|
<p>
|
|
The name of each property that appears to exist due to an object supporting indexed properties
|
|
is an <dfn id="dfn-array-index-property-name">array index property name</dfn>, which is a property
|
|
name <var>P</var> for which the following algorithm returns <span class="esvalue">true</span>:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>i</var> be ToUint32(<var>P</var>).</li>
|
|
<li>Let <var>s</var> be ToString(<var>i</var>).</li>
|
|
<li>If <var>s</var> ≠ <var>P</var> or <var>i</var> = 2<sup>32</sup> − 1, then return <span class="esvalue">false</span>.</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
|
|
<!--
|
|
<p>
|
|
Specifications can state that certain named properties are <dfn id='dfn-resolved-before-prototype-properties'>resolved
|
|
before prototype properties</dfn>. This means that such named properties will be resolved after real own
|
|
properties on the object (as with all non-<a class='xattr' href='#OverrideBuiltins'>[OverrideBuiltins]</a> named
|
|
properties), but before properties from the prototype chain. Specifications <span class='rfc2119'>SHOULD NOT</span>
|
|
declare any named properties to be <a href='#dfn-resolved-before-prototype-properties'>resolved before prototype properties</a>
|
|
unless this is required to specify the behavior of legacy APIs.
|
|
</p>
|
|
<div class='note'>
|
|
<p>At the time of writing, the only known justifiable use of named properties that are
|
|
<a href='#dfn-resolved-before-prototype-properties'>resolved before prototype properties</a>
|
|
is the <span class='esvalue'>Window</span> interface defined in HTML5 (<a href='#ref-HTML5'>[HTML5]</a>, section 5.2).</p>
|
|
</div>
|
|
-->
|
|
<p>
|
|
The <dfn id="dfn-named-property-visibility">named property visibility algorithm</dfn> is used to determine if
|
|
a given named property is exposed on an object. Some named properties are not exposed on an object
|
|
depending on whether the <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> was used. The algorithm
|
|
operates as follows, with property name <var>P</var> and object <var>O</var>:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>O</var> implements an <a class="dfnref" href="#dfn-interface">interface</a> with
|
|
an <a class="xattr" href="#Unforgeable">[Unforgeable]</a>-annotated <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
whose <a class="dfnref" href="#dfn-identifier">identifier</a> is <var>P</var>, then return false.</li>
|
|
<li>If <var>P</var> is not a <a class="dfnref" href="#dfn-supported-property-names">supported property name</a>
|
|
of <var>O</var>, then return false.</li>
|
|
<li>If <var>O</var> implements an interface that has the <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>, then return true.</li>
|
|
<li>If <var>O</var> has an own property named <var>P</var>, then return false.</li>
|
|
<!--
|
|
<li>If <var>P</var> is to be <a class='dfnref' href='#dfn-resolved-before-prototype-properties'>resolved before prototype properties</a>, then return true.</li>
|
|
-->
|
|
<li>Let <var>prototype</var> be the value of the internal <span class="prop">[[Prototype]]</span> property of <var>O</var>.</li>
|
|
<li>If <var>prototype</var> is <span class="esvalue">null</span>, then return true.</li>
|
|
<li>If the result of calling the <span class="prop">[[HasProperty]]</span> internal method on <var>prototype</var> with property name <var>P</var> is <span class="esvalue">true</span>, then return false.</li>
|
|
<li>Return true.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>This should ensure that for objects with named properties, property resolution is done in the following order:</p>
|
|
<ol>
|
|
<li>Indexed properties.</li>
|
|
<li>Unforgeable attributes.</li>
|
|
<li>Then, if <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>:
|
|
<ol>
|
|
<li>Named properties.</li>
|
|
<li>Own properties.</li>
|
|
<li>Properties from the prototype chain.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, if not <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>:
|
|
<ol>
|
|
<li>Own properties.</li>
|
|
<!--
|
|
<li>Any named properties to be <a class='dfnref' href='#dfn-resolved-before-prototype-properties'>resolved before prototype properties</a>.</li>
|
|
-->
|
|
<li>Properties from the prototype chain.</li>
|
|
<!--
|
|
<li>Any other named properties.</li>
|
|
-->
|
|
<li>Named properties.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
<p>
|
|
Support for <a class="dfnref" href="#dfn-getter">getters</a> is
|
|
handled by the <a href="#defineownproperty">platform object [[GetOwnProperty]] method</a>
|
|
defined in section 4.7.2,
|
|
for <a class="dfnref" href="#dfn-creator">creators</a> and
|
|
<a class="dfnref" href="#dfn-setter">setters</a>
|
|
by the <a href="#defineownproperty">platform object [[DefineOwnProperty]] method</a>
|
|
defined in section 4.7.3, and
|
|
for <a class="dfnref" href="#dfn-deleter">deleters</a>
|
|
by the <a href="#delete">platform object [[Delete]] method</a>
|
|
defined in section 4.7.4.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="getownproperty" class="section">
|
|
<h4>4.7.2. Platform object [[GetOwnProperty]] method</h4>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[GetOwnProperty]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-object">platform object</a> <var>O</var> that implements an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
which <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed</a> or
|
|
<a class="dfnref" href="#dfn-support-named-properties">named properties</a>
|
|
<span class="rfc2119">MUST</span> behave as follows when called with property name <var>P</var>:
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>
|
|
If <var>O</var> <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed properties</a>
|
|
and <var>P</var> is an <a class="dfnref" href="#dfn-array-index-property-name">array index property name</a>, then:
|
|
<ol>
|
|
<li>Let <var>index</var> be the result of calling ToUint32(<var>P</var>).</li>
|
|
<li>If <var>index</var> is a <a class="dfnref" href="#dfn-supported-property-indices">supported property index</a>, then:
|
|
<ol>
|
|
<li>Let <var>operation</var> be the operation used to declare the indexed property getter.</li>
|
|
|
|
<li>Let <var>value</var> be an uninitialized variable.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then
|
|
set <var>value</var> to the result of performing the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-determine-the-value-of-an-indexed-property">determine the value of an indexed property</a>
|
|
with <var>index</var> as the index.</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier. Set <var>value</var> to the result
|
|
of performing the steps listed in the description of <var>operation</var> with <var>index</var> as the only argument value.</li>
|
|
|
|
<li>Let <var>desc</var> be a newly created property descriptor (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.10) with no fields.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Value]]</span> to the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>value</var> to an ECMAScript value.</li>
|
|
<li>If <var>O</var> implements an interface with an <a class="dfnref" href="#dfn-indexed-property-setter">indexed property setter</a>, then set
|
|
<var>desc</var>.<span class="prop">[[Writable]]</span> to <span class="esvalue">true</span>, otherwise set it to
|
|
<span class="esvalue">false</span>.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Enumerable]]</span> and <var>desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">true</span>.</li>
|
|
<li>Return <var>desc</var>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>If <var>O</var> <a class="dfnref" href="#dfn-support-named-properties">supports named properties</a>, then:
|
|
<ol>
|
|
<li>If the result of running the <a class="dfnref" href="#dfn-named-property-visibility">named property visibility algorithm</a> with
|
|
property name <var>P</var> and object <var>O</var> is true, then:
|
|
<ol>
|
|
<li>Let <var>operation</var> be the operation used to declare the named property getter.</li>
|
|
|
|
<li>Let <var>value</var> be an uninitialized variable.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then
|
|
set <var>value</var> to the result of performing the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-determine-the-value-of-a-named-property">determine the value of a named property</a>
|
|
with <var>P</var> as the name.</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier. Set <var>value</var> to the result
|
|
of performing the steps listed in the description of <var>operation</var> with <var>P</var> as the only argument value.</li>
|
|
|
|
<li>Let <var>desc</var> be a newly created property descriptor (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.10) with no fields.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Value]]</span> to the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>value</var> to an ECMAScript value.</li>
|
|
<li>If <var>O</var> implements an interface with a <a class="dfnref" href="#dfn-named-property-setter">named property setter</a> and
|
|
<var>O</var> does not implement an interface with the <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>, then set
|
|
<var>desc</var>.<span class="prop">[[Writable]]</span> to <span class="esvalue">true</span>, otherwise set it to
|
|
<span class="esvalue">false</span>.</li>
|
|
<li>Set <var>desc</var>.<span class="prop">[[Enumerable]]</span> and <var>desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">true</span>.</li>
|
|
<li>Return <var>desc</var>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Return the result of calling the default <span class="prop">[[GetOwnProperty]]</span> internal method (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.12.1) on <var>O</var> passing <var>P</var> as the argument.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="defineownproperty" class="section">
|
|
<h4>4.7.3. Platform object [[DefineOwnProperty]] method</h4>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[DefineOwnProperty]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-object">platform object</a> <var>O</var> that implements an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
which <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed</a> or
|
|
<a class="dfnref" href="#dfn-support-named-properties">named properties</a>
|
|
<span class="rfc2119">MUST</span> behave as follows when called with property name <var>P</var>,
|
|
property descriptor <var>Desc</var> and boolean flag <var>Throw</var>.
|
|
The term “Reject” is used as defined in
|
|
<a href="#platform-array-object-defineownproperty">section 4.2.20.2</a> above.
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>Set <var>Desc</var>.<span class="prop">[[Configurable]]</span> to <span class="esvalue">true</span>.</li>
|
|
<li>
|
|
If <var>O</var> <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed properties</a> and
|
|
<var>P</var> is an <a class="dfnref" href="#dfn-array-index-property-name">array index property name</a>, then:
|
|
<ol>
|
|
<li>If the result of calling IsDataDescriptor(<var>Desc</var>) is <span class="esvalue">false</span>, then Reject.</li>
|
|
<li>Let <var>index</var> be the result of calling ToUint32(<var>P</var>).</li>
|
|
<li>Let <var>creating</var> be true if <var>index</var> is not a <a class="dfnref" href="#dfn-supported-property-indices">supported property index</a>, and false otherwise.</li>
|
|
<li>If <var>creating</var> is true and <var>O</var> does not implement an interface with an <a class="dfnref" href="#dfn-indexed-property-creator">indexed property creator</a>, then Reject.</li>
|
|
<li>If <var>creating</var> is false and <var>O</var> does not implement an interface with an <a class="dfnref" href="#dfn-indexed-property-setter">indexed property setter</a>, then Reject.</li>
|
|
<li>Let <var>operation</var> be the operation used to declare the indexed property creator if <var>creating</var> is true,
|
|
or the indexed property setter if <var>creating</var> is false.</li>
|
|
<li>Let <var>T</var> be the type of the second argument of <var>operation</var>.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a> <var>Desc</var>.<span class="prop">[[Value]]</span> to an IDL value of type <var>T</var>.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then:
|
|
<ol>
|
|
<li>If <var>creating</var> is true, then perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-set-the-value-of-a-new-indexed-property">set the value of a new indexed property</a>
|
|
with <var>index</var> as the index and <var>value</var> as the value.</li>
|
|
<li>Otherwise, <var>creating</var> is false. Perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-set-the-value-of-an-existing-indexed-property">set the value of an existing indexed property</a>
|
|
with <var>index</var> as the index and <var>value</var> as the value.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier. Perform the steps listed in the description of
|
|
<var>operation</var> with <var>index</var> and <var>value</var> as the two argument values.</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>
|
|
If <var>O</var> <a class="dfnref" href="#dfn-support-named-properties">supports named properties</a> and <var>P</var>
|
|
is not the <a class="dfnref" href="#dfn-identifier">identifier</a> of an <a class="xattr" href="#Unforgeable">[Unforgeable]</a>-annotated <a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
on an interface that <var>O</var> implements, then:
|
|
<ol>
|
|
<li>Let <var>creating</var> be true if <var>P</var> is not a <a class="dfnref" href="#dfn-supported-property-names">supported property name</a>, and false otherwise.</li>
|
|
<li>If <var>creating</var> is false and <var>O</var> implements an interface with the <a class="xattr" href="#ReplaceableNamedProperties">[ReplaceableNamedProperties]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>, then:
|
|
<ol>
|
|
<li>If the result of calling IsAccessorDescriptor(<var>Desc</var>) is <span class="esvalue">true</span>, then:
|
|
<ol>
|
|
<li>Create an own accessor property named <var>P</var> on <var>O</var> whose <span class="prop">[[Get]]</span>,
|
|
<span class="prop">[[Set]]</span>, <span class="prop">[[Enumerable]]</span> and <span class="prop">[[Configurable]]</span>
|
|
attribute values are described by <var>Desc</var>. If the value of an attribute field of <var>Desc</var> is absent,
|
|
the attribute of the newly created property is set to its default value (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.6.1).</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise:
|
|
<ol>
|
|
<li>Create an own data property named <var>P</var> on <var>O</var> whose <span class="prop">[[Value]]</span>,
|
|
<span class="prop">[[Writable]]</span>, <span class="prop">[[Enumerable]]</span> and <span class="prop">[[Configurable]]</span>
|
|
attribute values are described by <var>Desc</var>. If the value of an attribute field of <var>Desc</var> is absent,
|
|
the attribute of the newly created property is set to its default value (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.6.1).</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, if <var>O</var> implements an interface with the <a class="xattr" href="#OverrideBuiltins">[OverrideBuiltins]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a> or <var>O</var> does not have an own property
|
|
named <var>P</var>, then:
|
|
<ol>
|
|
<li>If <var>creating</var> is false and <var>O</var> does not implement an interface with a <a class="dfnref" href="#dfn-named-property-setter">named property setter</a>, then Reject.</li>
|
|
<li>If <var>creating</var> is false or <var>O</var> implements an interface with a <a class="dfnref" href="#dfn-named-property-creator">named property creator</a>, then:
|
|
<ol>
|
|
<li>If the result of calling IsDataDescriptor(<var>Desc</var>) is <span class="esvalue">false</span>, then Reject.</li>
|
|
<li>Let <var>operation</var> be the operation used to declare the named property creator if <var>creating</var> is true,
|
|
or the named property setter if <var>creating</var> is false.</li>
|
|
<li>Let <var>T</var> be the type of the second argument of <var>operation</var>.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a> <var>Desc</var>.<span class="prop">[[Value]]</span> to an IDL value of type <var>T</var>.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then:
|
|
<ol>
|
|
<li>If <var>creating</var> is true, then perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-set-the-value-of-a-new-named-property">set the value of a new named property</a>
|
|
with <var>P</var> as the name and <var>value</var> as the value.</li>
|
|
<li>Otherwise, <var>creating</var> is false. Perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-set-the-value-of-an-existing-named-property">set the value of an existing named property</a>
|
|
with <var>P</var> as the name and <var>value</var> as the value.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier. Perform the steps listed in the description of
|
|
<var>operation</var> with <var>index</var> and <var>value</var> as the two argument values.</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>Call the default <span class="prop">[[DefineOwnProperty]]</span> internal method (<a href="#ref-ECMA-262">[ECMA-262]</a>, section 8.12.9) on <var>O</var> passing <var>P</var>, <var>Desc</var>, and <var>Throw</var> as arguments.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="delete" class="section">
|
|
<h4>4.7.4. Platform object [[Delete]] method</h4>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[Delete]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-object">platform object</a> <var>O</var> that implements an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
which <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed</a> or
|
|
<a class="dfnref" href="#dfn-support-named-properties">named properties</a>
|
|
<span class="rfc2119">MUST</span> behave as follows when called with property name <var>P</var>
|
|
and boolean flag <var>Throw</var>. The term “Reject” is used as defined in
|
|
<a href="#platform-array-object-defineownproperty">section 4.2.20.2</a> above.
|
|
</p>
|
|
|
|
<ol class="algorithm">
|
|
<li>
|
|
If <var>O</var> <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed properties</a> and
|
|
<var>P</var> is an <a class="dfnref" href="#dfn-array-index-property-name">array index property name</a>, then:
|
|
<ol>
|
|
<li>Let <var>index</var> be the result of calling ToUint32(<var>P</var>).</li>
|
|
<li>If <var>index</var> is not a <a class="dfnref" href="#dfn-supported-property-indices">supported property index</a>, then return <span class="esvalue">true</span>.</li>
|
|
<li>If <var>O</var> does not implement an interface with an <a class="dfnref" href="#dfn-indexed-property-deleter">indexed property deleter</a>, then Reject.</li>
|
|
<li>Let <var>operation</var> be the operation used to declare the indexed property deleter.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then:
|
|
<ol>
|
|
<li>Perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-delete-an-existing-indexed-property">delete an existing indexed property</a>
|
|
with <var>index</var> as the index.</li>
|
|
<li>If the steps indicated that the deletion failed, then Reject.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier:
|
|
<ol>
|
|
<li>Perform the steps listed in description of <var>operation</var> with <var>index</var> as the only argument value.</li>
|
|
<li>If <var>operation</var> was declared with a <a class="dfnref" href="#dfn-return-type">return type</a> of <a class="idltype" href="#idl-boolean">boolean</a>
|
|
and the steps returned <span class="idlvalue">false</span>, then Reject.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>
|
|
If <var>O</var> <a class="dfnref" href="#dfn-support-named-properties">supports named properties</a> and
|
|
the result of calling the <a class="dfnref" href="#dfn-named-property-visibility">named property visibility algorithm</a>
|
|
with property name <var>P</var> and object <var>O</var> is true, then:
|
|
<ol>
|
|
<li>If <var>O</var> does not to implement an interface with a <a class="dfnref" href="#dfn-named-property-deleter">named property deleter</a>, then Reject.</li>
|
|
<li>Let <var>operation</var> be the operation used to declare the named property deleter.</li>
|
|
<li>If <var>operation</var> was defined without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then:
|
|
<ol>
|
|
<li>Perform the steps listed in the interface description to
|
|
<a class="dfnref" href="#dfn-delete-an-existing-named-property">delete an existing named property</a>
|
|
with <var>P</var> as the name.</li>
|
|
<li>If the steps indicated that the deletion failed, then Reject.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Otherwise, <var>operation</var> was defined with an identifier:
|
|
<ol>
|
|
<li>Perform the steps listed in description of <var>operation</var> with <var>P</var> as the only argument value.</li>
|
|
<li>If <var>operation</var> was declared with a <a class="dfnref" href="#dfn-return-type">return type</a> of <a class="idltype" href="#idl-boolean">boolean</a>
|
|
and the steps returned <span class="idlvalue">false</span>, then Reject.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>If <var>O</var> has an own property with name <var>P</var>, then:
|
|
<ol>
|
|
<li>If the property is not configurable, then Reject.</li>
|
|
<li>Otherwise, remove the property from <var>O</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <span class="esvalue">true</span>.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="call" class="section">
|
|
<h4>4.7.5. Platform object [[Call]] method</h4>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[Call]]</span> method of every
|
|
<a class="dfnref" href="#dfn-platform-object">platform object</a> <var>O</var> that implements an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<var>I</var> with at least one <a class="dfnref" href="#dfn-legacy-caller">legacy caller</a>
|
|
<span class="rfc2119">MUST</span> behave as follows, assuming
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> is the list of argument
|
|
values passed to <span class="prop">[[Call]]</span>:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Initialize <var>S</var> to the <a class="dfnref" href="#dfn-effective-overload-set">effective overload</a>
|
|
for legacy callers on <var>I</var> and with argument count <var>n</var> (for the
|
|
ECMAScript language binding).</li>
|
|
<li>Set <var>S</var> to be the result of passing <var>S</var> and
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> to the
|
|
<a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>.</li>
|
|
<li>If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.</li>
|
|
<li>If <var>S</var> contains more than one entry, then the call is ambiguous. Remove all but
|
|
one entry from <var>S</var> according to the rules specified in the description of
|
|
<a class="dfnref" href="#dfn-interface">interface</a> <var>I</var>, or arbitrarily
|
|
if no such rules exist.</li>
|
|
<li>Let <var>op</var> be the operation and <var>t</var><sub>0..<var>m</var>−1</sub> be the type list
|
|
of the single entry in <var>S</var>.</li>
|
|
<li>Let <var>idlarg</var><sub>0..<var>m</var>−1</sub> be a list of IDL values,
|
|
where <var>idlarg</var><sub><var>i</var></sub> is the result of
|
|
<a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>arg</var><sub><var>i</var></sub> to an IDL value.</li>
|
|
<li>Perform the actions listed in the description of legacy caller <var>op</var> with
|
|
<var>idlarg</var><sub>0..<var>m</var>−1</sub> as the argument values. These conversions
|
|
<span class="rfc2119">MUST</span> be done in order from
|
|
<var>arg</var><sub><var>0</var></sub> to <var>arg</var><sub><var>m</var>−1</sub>.</li>
|
|
<li>Return the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
the return value from those actions to an ECMAScript value of the type
|
|
<var>op</var> is declared to return (or <span class="esvalue">undefined</span>
|
|
if <var>op</var> is declared to return <a class="idltype" href="#idl-void">void</a>).</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="property-enumeration" class="section">
|
|
<h4>4.7.6. Property enumeration</h4>
|
|
|
|
<p>
|
|
This document does not define a complete property enumeration order
|
|
for all <a class="dfnref" href="#dfn-platform-object">platform objects</a> implementing <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
(or for <a href="#es-exception-objects">platform objects representing exceptions</a>).
|
|
However, if a platform object implements an interface that
|
|
<a class="dfnref" href="#dfn-support-indexed-properties">supports indexed</a> or
|
|
<a class="dfnref" href="#dfn-support-named-properties">named properties</a>, then
|
|
properties on the object <span class="rfc2119">MUST</span> be
|
|
enumerated in the following order:
|
|
</p>
|
|
<ol>
|
|
<li>If the object <a class="dfnref" href="#dfn-support-indexed-properties">supports indexed properties</a>, then
|
|
the object’s <a class="dfnref" href="#dfn-supported-property-indices">supported property indices</a> are
|
|
enumerated first, in numerical order.</li>
|
|
<li>If the object <a class="dfnref" href="#dfn-support-named-properties">supports named properties</a>, then
|
|
the object’s <a class="dfnref" href="#dfn-supported-property-names">supported property names</a> are
|
|
enumerated next, in the order given in the definition of the set of supported property names.</li>
|
|
<li>Finally, any enumerable own properties or properties from the object’s prototype chain are then enumerated,
|
|
in no defined order.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>Future versions of the ECMAScript specification may define a total order for property enumeration.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-user-objects" class="section">
|
|
<h3>4.8. User objects implementing interfaces</h3>
|
|
|
|
<p>
|
|
As described in <a href="#idl-objects">section 3.8 above</a>,
|
|
some <a class="dfnref" href="#dfn-interface">interfaces</a> can be
|
|
implemented in script by an ECMAScript native object.
|
|
The following cases determine whether a given native object
|
|
is considered to be a user object implementing an interface with
|
|
the required characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the <code>[Callback=FunctionOnly]</code> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
appears on the interface, then the native object is considered to
|
|
implement that interface only if it is a <span class="estype">Function</span>
|
|
object. The <span class="estype">Function</span> object itself is the
|
|
implementation of the <a class="dfnref" href="#dfn-operation">operation</a>
|
|
(or set of overloaded operations, if multiple operations with the same
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> are defined on
|
|
the interface).
|
|
</li>
|
|
<li>
|
|
Otherwise, if the interface is a <a class="dfnref" href="#dfn-single-operation-interface">single operation interface</a>
|
|
but the <a class="xattr" href="#Callback">[Callback]</a>
|
|
extended attribute on the interface does not have the <code>FunctionOnly</code>
|
|
argument, then any native object is considered to implement that interface.
|
|
The implementation of the operation (or set of overloaded operations) is
|
|
as follows:
|
|
<ul>
|
|
<li>If the native object is a <span class="estype">Function</span> object and the
|
|
<a class="xattr" href="#Callback">[Callback]</a> extended attribute
|
|
does not have the <code>PropertyOnly</code> argument, then the
|
|
implementation of the operation (or set of overloaded operations) is
|
|
the <span class="estype">Function</span> object itself.</li>
|
|
<li>Otherwise, the native object is not a <span class="estype">Function</span> object
|
|
or the interface did have <code>[Callback=PropertyOnly]</code> specified on it.
|
|
The implementation of the operation (or set of overloaded operations) is
|
|
the result of invoking the internal <span class="prop">[[Get]]</span> method
|
|
on the native object with a property name that is the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of the operation.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
Otherwise, the interface is not a <a class="dfnref" href="#dfn-single-operation-interface">single operation interface</a>.
|
|
Any native object is considered to implement the interface.
|
|
For each operation declared on the interface with a given <a class="dfnref" href="#dfn-identifier">identifier</a>, the implementation
|
|
is the result of invoking <span class="prop">[[Get]]</span> on the native object with a
|
|
property name that is that identifier.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
A <a class="dfnref" href="#dfn-user-object">user object</a>’s
|
|
<a class="dfnref" href="#dfn-operation">operation</a> is called
|
|
with a list of IDL argument values <var>idlarg</var><sub>0..<var>n</var>−1</sub> by
|
|
following the algorithm below. The <dfn id="dfn-callback-this-value">callback this value</dfn>
|
|
is the value to use as the <span class="esvalue">this</span> value
|
|
when calling the native object’s operation implementation internal
|
|
<span class="prop">[[Call]]</span> method. By default, the native object
|
|
itself is used as the <a class="dfnref" href="#dfn-callback-this-value">callback this value</a>,
|
|
however this <span class="rfc2119">MAY</span> be overridden by other
|
|
specifications.
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the native object that is the <a class="dfnref" href="#dfn-user-object">user object</a> implementing the <a class="dfnref" href="#dfn-interface">interface</a>.</li>
|
|
<li>Let <var>X</var> be the implementation of the operation. If <var>O</var> is a <span class="estype">Function</span> object that itself is
|
|
considered to be the implementation of the operation, then <var>X</var> is <var>O</var>. Otherwise, <var>X</var> is the result of calling
|
|
the internal <span class="prop">[[Get]]</span> method of <var>O</var> with the identifier of the operation as the property name.</li>
|
|
<li>If Type(<var>X</var>) is not Object, throw a <span class="estype">TypeError</span> exception.</li>
|
|
<li>If <var>X</var> does not implement the internal <span class="prop">[[Call]]</span> method, throw a <span class="estype">TypeError</span> exception.</li>
|
|
<li>
|
|
Let <var>arg</var><sub>0..<var>n</var>−1</sub> be a list of
|
|
ECMAScript values, where <var>arg</var><sub><var>i</var></sub> is the result
|
|
of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>idlarg</var><sub><var>i</var></sub> to an ECMAScript value.
|
|
</li>
|
|
<li>Let <var>R</var> be the result of invoking the <span class="prop">[[Call]]</span> method of <var>X</var>, providing the <a class="dfnref" href="#dfn-callback-this-value">callback this value</a> as the <span class="esvalue">this</span> value and <var>arg</var><sub>0..<var>n</var>−1</sub> as the argument values.</li>
|
|
<li>
|
|
If the operation’s return type is <a class="idltype" href="#idl-void">void</a>, return.
|
|
</li>
|
|
<li>
|
|
Return the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a>
|
|
<var>R</var> to an IDL value of the same type as the operation’s return type.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
Note that native ECMAScript objects need not have
|
|
properties corresponding to <a class="dfnref" href="#dfn-constant">constants</a>
|
|
on them to be considered as <a class="dfnref" href="#dfn-user-object">user objects</a>
|
|
implementing <a class="dfnref" href="#dfn-interface">interfaces</a> that happen
|
|
to have constants declared on them.
|
|
</p>
|
|
<p>
|
|
The value of a <a class="dfnref" href="#dfn-user-object">user object</a>’s
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> is retrieved using the
|
|
following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the native object that is the <a class="dfnref" href="#dfn-user-object">user object</a> implementing the <a class="dfnref" href="#dfn-interface">interface</a>.</li>
|
|
<li>Let <var>P</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the attribute.</li>
|
|
<li>Let <var>R</var> be the result of invoking the <span class="prop">[[Get]]</span> method of <var>O</var> with property name <var>P</var>.</li>
|
|
<li>Return the result of <a class="dfnref" href="#dfn-convert-ecmascript-to-idl-value">converting</a> <var>R</var> to an IDL value of the same type as the attribute’s type.</li>
|
|
</ol>
|
|
<p>
|
|
The value of a <a class="dfnref" href="#dfn-user-object">user object</a>’s
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> is set using the
|
|
following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the native object that is the <a class="dfnref" href="#dfn-user-object">user object</a> implementing the <a class="dfnref" href="#dfn-interface">interface</a>.</li>
|
|
<li>Let <var>P</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the attribute.</li>
|
|
<li>Let <var>V</var> be the IDL value to be assigned to the attribute.</li>
|
|
<li>Let <var>W</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a> <var>V</var> to an ECMAScript value.</li>
|
|
<li>Invoke the <span class="prop">[[Put]]</span> method of <var>O</var> with property name <var>P</var> and value <var>W</var>.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="es-exceptions" class="section">
|
|
<h3>4.9. Exceptions</h3>
|
|
|
|
<p>
|
|
For every <a class="dfnref" href="#dfn-exception">exception</a> that is not declared with the
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>,
|
|
a corresponding property <span class="rfc2119">MUST</span> exist on the
|
|
exception’s <a class="dfnref" href="#dfn-relevant-namespace-object">relevant namespace object</a>.
|
|
The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the exception,
|
|
and its value is an object called the
|
|
<dfn id="dfn-exception-interface-object">exception interface object</dfn>,
|
|
which provides access to any <a class="dfnref" href="#dfn-constant">constants</a> that
|
|
have been associated with the exception. The property has the
|
|
attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>.
|
|
</p>
|
|
|
|
<div id="es-exception-interface-object" class="section">
|
|
<h4>4.9.1. Exception interface object</h4>
|
|
|
|
<p>
|
|
The exception interface object for a given <a class="dfnref" href="#dfn-exception">exception</a>
|
|
<span class="rfc2119">MUST</span> be a <a class="dfnref" href="#dfn-function-object">function object</a>.
|
|
</p>
|
|
<p>
|
|
If any <a class="dfnref" href="#dfn-constant">constants</a> have been declared
|
|
on the exception, then the exception interface object will have
|
|
properties corresponding to these constants as described in
|
|
<a href="#es-exception-constants">section 4.9.3</a>
|
|
below.
|
|
</p>
|
|
<p>
|
|
The exception interface object <span class="rfc2119">MUST</span> also have a property named
|
|
“prototype” with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>
|
|
whose value is an object called the <dfn id="dfn-exception-interface-prototype-object">exception interface prototype
|
|
object</dfn>. This object also provides access to the constants
|
|
that are declared on the exception.
|
|
</p>
|
|
|
|
<div id="es-exception-call" class="section">
|
|
<h5>4.9.1.1. Exception interface object [[Call]] method</h5>
|
|
|
|
<p>
|
|
The internal <span class="prop">[[Call]]</span> method of an
|
|
<a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>
|
|
<span class="rfc2119">MUST</span> behave as follows, assuming
|
|
<var>arg</var><sub>0..<var>n</var>−1</sub> is the list
|
|
of argument values passed to the function, and <var>E</var>
|
|
is the <a class="dfnref" href="#dfn-interface">exception</a>
|
|
corresponding to the exception interface object:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be a new object whose <span class="prop">[[Prototype]]</span>
|
|
internal property is set to the <a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>
|
|
and whose <span class="prop">[[Class]]</span> internal property
|
|
is set to the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of <var>E</var>.</li>
|
|
<li>If <var>n</var> > 0, then:
|
|
<ol>
|
|
<li>Let <var>S</var> be the result of calling ToString(<var>arg</var><sub>0</sub>).</li>
|
|
<li>Call the <span class="prop">[[DefineOwnProperty]]</span> internal method of <var>O</var> passing
|
|
“message”, Property Descriptor <span class="descriptor">{ [[Value]]: <var>S</var>,
|
|
[[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>,
|
|
[[Configurable]]: <span class="esvalue">true</span> }</span>, and <span class="esvalue">false</span>
|
|
as arguments.</li>
|
|
</ol></li>
|
|
<li>Return <var>O</var>.</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-exception-interface-prototype-object" class="section">
|
|
<h4>4.9.2. Exception interface prototype object</h4>
|
|
|
|
<p>
|
|
There <span class="rfc2119">MUST</span> exist an
|
|
<a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype object</a>
|
|
for every <a class="dfnref" href="#dfn-exception">exception</a>
|
|
defined, regardless of whether the exception was declared with the
|
|
<a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
The exception interface prototype object for a particular exception has
|
|
properties that correspond to the <a class="dfnref" href="#dfn-constant">constants</a>
|
|
and <a class="dfnref" href="#dfn-exception-field">exception fields</a>
|
|
defined on the exception. These properties are described in more detail in
|
|
sections <a href="#es-exception-constants">4.9.3</a>
|
|
and <a href="#es-exception-fields">4.9.4</a>,
|
|
below.
|
|
</p>
|
|
<p>
|
|
The exception interface prototype object for a given exception <span class="rfc2119">MUST</span>
|
|
have an internal <span class="prop">[[Prototype]]</span> property whose value is as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the <a class="dfnref" href="#dfn-exception">exception</a> is declared to
|
|
<a class="dfnref" href="#dfn-inherit-exception">inherit</a> from another
|
|
exception, then the value of the internal <span class="prop">[[Prototype]]</span> property is the
|
|
<a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype object</a>
|
|
for the inherited exception.</li>
|
|
<li>Otherwise, the exception is not declared to inherit from another exception. The
|
|
value of the internal <span class="prop">[[Prototype]]</span> property
|
|
is the <span class="estype">Error</span> prototype object
|
|
(<a href="#ref-ECMA-262">[ECMA-262]</a>, section 15.11.3.1).</li>
|
|
</ul>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
As with <a class="dfnref" href="#dfn-interface-prototype-object">interface prototype objects</a>,
|
|
<a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype objects</a>
|
|
can be accessible even if declared with <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
since it is possible to get the internal <span class="prop">[[Prototype]]</span> property
|
|
of an exception object.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
There <span class="rfc2119">MUST</span> be a property named “name”
|
|
on the exception interface prototype object with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>
|
|
and whose value is the <a class="dfnref" href="#dfn-identifier">identifier</a> of
|
|
the exception.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>If an exception is thrown with a specific <a class="dfnref" href="#dfn-exception-type">type</a>,
|
|
then the rules in <a href="#es-throwing-exceptions">section 4.11</a>
|
|
below will create a shadowing “name” property on the
|
|
exception object itself.</p>
|
|
</div>
|
|
<p>
|
|
If the <a class="xattr" href="#NoInterfaceObject">[NoInterfaceObject]</a>
|
|
extended attribute was not specified on the exception, then
|
|
there <span class="rfc2119">MUST</span> also be a property named “constructor”
|
|
on the exception interface prototype object with attributes
|
|
<span class="descriptor">{ [[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">false</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>
|
|
and whose value is a reference to the exception interface object for the exception.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-exception-constants" class="section">
|
|
<h4>4.9.3. Constants</h4>
|
|
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-constant">constant</a> defined on
|
|
the <a class="dfnref" href="#dfn-exception">exception</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding property on
|
|
the <a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>,
|
|
if it exists, if the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of the constant is not “prototype”. The property has the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the constant.</li>
|
|
<li>The value of the property is the ECMAScript value that is equivalent to the constant’s IDL value, according
|
|
to the rules in <a href="#es-type-mapping">section 4.2</a> above.</li>
|
|
<li>The property has attributes <span class="descriptor">{ [[Writable]]: <span class="esvalue">false</span>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">false</span> }</span>.</li>
|
|
</ul>
|
|
<p>
|
|
In addition, a property with the same characteristics <span class="rfc2119">MUST</span>
|
|
exist on the <a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype object</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-exception-fields" class="section">
|
|
<h4>4.9.4. Exception fields</h4>
|
|
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-exception-field">exception field</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding property on
|
|
the <a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype object</a>,
|
|
whose characteristics are as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
The name of the property is the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-exception-field">exception field</a>.
|
|
</li>
|
|
<li>
|
|
The property has attributes <span class="descriptor">{ [[Get]]: <var>G</var>, [[Enumerable]]: <span class="esvalue">true</span>, [[Configurable]]: <span class="esvalue">true</span> }</span>,
|
|
where <var>G</var> is the <a class="dfnref" href="#dfn-exception-field-getter">exception field getter</a>,
|
|
defined below.
|
|
</li>
|
|
<li>
|
|
The <dfn id="dfn-exception-field-getter">exception field getter</dfn> is a <span class="estype">Function</span>
|
|
object whose behavior when invoked is as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be the result of calling ToObject on the <span class="esvalue">this</span> value.</li>
|
|
<li>If <var>O</var> is not a <a href="#es-exception-objects">platform object representing an exception</a>
|
|
for the <a class="dfnref" href="#dfn-exception">exception</a>
|
|
on which the exception field was declared, then throw a <span class="estype">TypeError</span>.</li>
|
|
<li>
|
|
Let <var>idlValue</var> be the IDL value of <var>O</var>’s exception field.
|
|
</li>
|
|
<li>
|
|
Let <var>V</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
the <var>idlValue</var> to an ECMAScript value.
|
|
</li>
|
|
<li>
|
|
Return <var>V</var>.
|
|
</li>
|
|
</ol>
|
|
The value of the <span class="estype">Function</span> object’s “length”
|
|
property is the <span class="estype">Number</span> value <span class="esvalue">0</span>.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="es-exception-objects" class="section">
|
|
<h3>4.10. Exception objects</h3>
|
|
|
|
<p>
|
|
Objects representing particular IDL <a class="dfnref" href="#dfn-exception">exceptions</a>
|
|
are <a class="dfnref" href="#dfn-platform-object">platform objects</a>. Such objects
|
|
can only represent a single exception, and also cannot simultaneously
|
|
represent an exception and implement an <a class="dfnref" href="#dfn-interface">interface</a>.
|
|
</p>
|
|
<p>
|
|
Every platform object representing an exception in ECMAScript is associated with a global environment, just
|
|
as the <a class="dfnref" href="#dfn-initial-object">initial objects</a> are.
|
|
When an exception object is created by calling an <a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>,
|
|
either normally or as part of a <code>new</code> expression, then the global environment
|
|
of the newly created object is associated with <span class="rfc2119">MUST</span> be the same as for the
|
|
interface object itself.
|
|
</p>
|
|
<p>
|
|
The value of the internal <span class="prop">[[Prototype]]</span>
|
|
property of the exception object <span class="rfc2119">MUST</span> be the <a class="dfnref" href="#dfn-exception-interface-prototype-object">exception interface prototype object</a>
|
|
from the global environment the exception object is associated with.
|
|
</p>
|
|
<p>
|
|
The value of the internal <span class="prop">[[Class]]</span>
|
|
property of the exception object <span class="rfc2119">MUST</span>
|
|
be the <a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
of the <a class="dfnref" href="#dfn-exception">exception</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-throwing-exceptions" class="section">
|
|
<h3>4.11. Throwing exceptions</h3>
|
|
|
|
<p>
|
|
First, we define the <dfn id="dfn-current-global-environment">current global environment</dfn>
|
|
as the result of running the following algorithm:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>F</var> be the <span class="estype">Function</span> object used
|
|
as the <span class="esvalue">this</span> value in the top-most call
|
|
on the ECMAScript call stack where <var>F</var> corresponds to an IDL
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>,
|
|
<a class="dfnref" href="#dfn-operation">operation</a>,
|
|
<a href="#idl-indexed-properties">indexed property</a>,
|
|
<a href="#idl-named-properties">named property</a>,
|
|
<a href="#Constructor">constructor</a>,
|
|
<a class="dfnref" href="#dfn-named-constructor">named constructor</a>,
|
|
<a class="dfnref" href="#dfn-stringifier">stringifier</a>,
|
|
<a href="#es-exception-call">exception constructor</a> or
|
|
<a class="dfnref" href="#dfn-exception-field-getter">exception field getter</a>.
|
|
</li>
|
|
<li>
|
|
If <var>F</var> corresponds to an attribute, operation or stringifier, then return
|
|
the global environment associated with the
|
|
<a class="dfnref" href="#dfn-interface">interface</a> that definition appears on.
|
|
</li>
|
|
<li>
|
|
Otherwise, if <var>F</var> corresponds to an indexed or named property, then return
|
|
the global environment associated with the interface that
|
|
the index or named property getter, setter, creator or deleter was defined on.
|
|
</li>
|
|
<li>
|
|
Otherwise, if <var>F</var> is a named constructor for an interface, or is
|
|
an <a class="dfnref" href="#dfn-interface-object">interface object</a> for an
|
|
interface that is a constructor, then return the global environment
|
|
associated with that interface.
|
|
</li>
|
|
<li>
|
|
Otherwise, if <var>F</var> is an exception field getter, then return
|
|
the global environment associated with the exception on which the
|
|
exception field was defined.
|
|
</li>
|
|
<li>
|
|
Otherwise, <var>F</var> is an exception interface object that is a constructor.
|
|
Return the global environment associated with that exception.
|
|
</li>
|
|
</ol>
|
|
<p>
|
|
When an IDL <a class="dfnref" href="#dfn-exception">exception</a> <var>E</var>
|
|
<var>E</var> is to be <a class="dfnref" href="#dfn-throw">thrown</a>,
|
|
with optional type <var>T</var> and optional message <var>M</var>, the following steps
|
|
<span class="rfc2119">MUST</span> be followed:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>G</var> be the <a class="dfnref" href="#dfn-current-global-environment">current global environment</a>.</li>
|
|
|
|
<li>Let <var>X</var> be the <a class="dfnref" href="#dfn-exception-interface-object">exception interface object</a>
|
|
for <var>E</var> from the global environment <var>G</var>.</li>
|
|
|
|
<li>Let <var>args</var> be a list of ECMAScript
|
|
values. If the optional message <var>M</var> was specified, then this list
|
|
has a single element whose value is the result of
|
|
<a class="dfnref" href="#dfn-convert-idl-to-ecmascript-value">converting</a>
|
|
<var>M</var> to a <span class="estype">String</span> value.
|
|
Otherwise, the list is empty.</li>
|
|
|
|
<li>Let <var>O</var> be the result of running the steps in
|
|
<a href="#es-exception-call">section 4.9.1.1</a>
|
|
above with <var>X</var> as the exception and
|
|
<var>args</var> as the argument list.</li>
|
|
|
|
<li>If the optional type <var>T</var> was specified, then
|
|
call the <span class="prop">[[DefineOwnProperty]]</span> internal method of <var>O</var> passing
|
|
“name”, Property Descriptor <span class="descriptor">{ [[Value]]: <var>T</var>,
|
|
[[Writable]]: <span class="esvalue">true</span>, [[Enumerable]]: <span class="esvalue">true</span>,
|
|
[[Configurable]]: <span class="esvalue">true</span> }</span>, and <span class="esvalue">false</span>
|
|
as arguments.</li>
|
|
|
|
<li>Throw <var>O</var>.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
The above algorithm does not restrict <a class="dfnref" href="#es-exception-objects">platform objects representing exceptions</a>
|
|
propagating out of a <span class="estype">Function</span> to be
|
|
ones that are associated with the global environment
|
|
where that <span class="estype">Function</span> object originated.
|
|
For example, consider the IDL:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">exception NumberError { };
|
|
|
|
interface A {
|
|
|
|
<span class="comment">/**
|
|
* Calls computeSquareRoot on m, passing x as its argument.
|
|
*/</span>
|
|
float doComputation(MathUtils m, float x);
|
|
};
|
|
|
|
interface MathUtils {
|
|
<span class="comment">/**
|
|
* If x is negative, throws a NumberError exception. Otherwise, returns
|
|
* the square root of x.
|
|
*/</span>
|
|
float computeSquareRoot(float x);
|
|
};</code></pre></div></div>
|
|
<p>
|
|
If we pass a <span class="idltype">MathUtils</span> object from
|
|
a different global environment to doComputation, then the exception
|
|
thrown will be from that global environment:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">
|
|
var a = getA(); // An A object from this global environment.
|
|
var m = otherWindow.getMathUtils(); // A MathUtils object from a different global environment.
|
|
|
|
a instanceof Object; // Evaluates to true.
|
|
m instanceof Object; // Evaluates to false.
|
|
m instanceof otherWindow.Object; // Evaluates to true.
|
|
|
|
try {
|
|
a.doComputation(m, -1);
|
|
} catch (e) {
|
|
e instanceof NumberError; // Evaluates to false.
|
|
e instanceof otherWindow.NumberError; // Evaluates to true.
|
|
}</code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
Any requirements in this document to throw an instance of an ECMAScript built-in
|
|
<span class="estype">Error</span> <span class="rfc2119">MUST</span> use
|
|
the built-in from the <a class="dfnref" href="#dfn-current-global-environment">current global environment</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="es-handling-exceptions" class="section">
|
|
<h3>4.12. Handling exceptions</h3>
|
|
|
|
<p>
|
|
None of the algorithms or processing requirements in the
|
|
ECMAScript language binding catch ECMAScript exceptions. Whenever
|
|
an ECMAScript <span class="esvalue">Function</span> is invoked due
|
|
to requirements in this section and that <span class="esvalue">Function</span>
|
|
ends due to an exception being thrown, that exception
|
|
<span class="rfc2119">MUST</span> propagate to the caller, and if
|
|
not caught there, to its caller, and so on.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
defines two <a class="dfnref" href="#dfn-interface">interfaces</a>
|
|
and an <a class="dfnref" href="#dfn-exception">exception</a>.
|
|
The <code>valueOf</code> attribute on <span class="idltype">ExceptionThrower</span>
|
|
is defined to throw an exception whenever an attempt is made
|
|
to get its value.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface Dahut {
|
|
attribute DOMString type;
|
|
};
|
|
|
|
exception SomeException {
|
|
};
|
|
|
|
interface ExceptionThrower {
|
|
<span class="comment">// This attribute always throws a SomeException and never returns a value.</span>
|
|
attribute long valueOf<!-- getraises(SomeException)-->;
|
|
};</code></pre></div></div>
|
|
<p>
|
|
Assuming an ECMAScript implementation supporting this interface,
|
|
the following code demonstrates how exceptions are handled:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">ECMAScript</span></div><div class="blockContent"><pre class="code"><code class="es-code">var d = getDahut(); <span class="comment">// Obtain an instance of Dahut.</span>
|
|
var et = getExceptionThrower(); <span class="comment">// Obtain an instance of ExceptionThrower.</span>
|
|
|
|
try {
|
|
d.type = { toString: function() { throw "abc"; } };
|
|
} catch (e) {
|
|
<span class="comment">// The string "abc" is caught here, since as part of the conversion</span>
|
|
<span class="comment">// from the native object to a string, the anonymous function</span>
|
|
<span class="comment">// was invoked, and none of the [[DefaultValue]], ToPrimitive or</span>
|
|
<span class="comment">// ToString algorithms are defined to catch the exception.</span>
|
|
}
|
|
|
|
try {
|
|
d.type = { toString: { } };
|
|
} catch (e) {
|
|
<span class="comment">// An exception is caught here, since an attempt is made to invoke</span>
|
|
<span class="comment">// [[Call]] on the native object that is the value of toString</span>
|
|
<span class="comment">// property.</span>
|
|
}
|
|
|
|
d.type = et;
|
|
<span class="comment">// An uncaught SomeException exception is thrown here, since the</span>
|
|
<span class="comment">// [[DefaultValue]] algorithm attempts to get the value of the</span>
|
|
<span class="comment">// "valueOf" property on the ExceptionThrower object. The exception</span>
|
|
<span class="comment">// propagates out of this block of code.</span></code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-binding" class="section">
|
|
<h2>5. Java binding</h2>
|
|
|
|
<p>
|
|
This section describes how definitions written with the IDL defined in
|
|
<a href="#idl">section 3</a> correspond to particular constructs
|
|
in Java 5 <a href="#ref-JLS3">[JLS3]</a>.
|
|
</p>
|
|
|
|
<div id="java-names" class="section">
|
|
<h3>5.1. Names</h3>
|
|
|
|
<p>
|
|
Since Java has a number of reserved words in the language, some identifiers
|
|
of Java constructs corresponding to IDL definitions need to be escaped
|
|
to avoid conflicts. A name is <dfn id="dfn-java-escaped">Java escaped</dfn>
|
|
as follows:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
If the name is a Java reserved word, then the Java escaped name is the
|
|
name prefixed with a <span class="char">U+005F LOW LINE ("_")</span>
|
|
character.
|
|
</li>
|
|
<li>
|
|
Otherwise, the name is not a Java reserved word. The Java escaped name
|
|
is simply the name.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
At the time of publication, the list of Java reserved words is the following:
|
|
<code>abstract</code>,
|
|
<code>assert</code>,
|
|
<code>boolean</code>,
|
|
<code>break</code>,
|
|
<code>byte</code>,
|
|
<code>case</code>,
|
|
<code>catch</code>,
|
|
<code>char</code>,
|
|
<code>class</code>,
|
|
<code>const</code>,
|
|
<code>continue</code>,
|
|
<code>default</code>,
|
|
<code>do</code>,
|
|
<code>double</code>,
|
|
<code>else</code>,
|
|
<code>enum</code>,
|
|
<code>extends</code>,
|
|
<code>final</code>,
|
|
<code>finally</code>,
|
|
<code>float</code>,
|
|
<code>for</code>,
|
|
<code>goto</code>,
|
|
<code>if</code>,
|
|
<code>implements</code>,
|
|
<code>import</code>,
|
|
<code>instanceof</code>,
|
|
<code>int</code>,
|
|
<code>interface</code>,
|
|
<code>long</code>,
|
|
<code>native</code>,
|
|
<code>new</code>,
|
|
<code>package</code>,
|
|
<code>private</code>,
|
|
<code>protected</code>,
|
|
<code>public</code>,
|
|
<code>return</code>,
|
|
<code>short</code>,
|
|
<code>static</code>,
|
|
<code>strictfp</code>,
|
|
<code>super</code>,
|
|
<code>switch</code>,
|
|
<code>synchronized</code>,
|
|
<code>this</code>,
|
|
<code>throw</code>,
|
|
<code>throws</code>,
|
|
<code>transient</code>,
|
|
<code>try</code>,
|
|
<code>void</code>,
|
|
<code>volatile</code>,
|
|
<code>while</code>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-type-mapping" class="section">
|
|
<h3>5.2. Java type mapping</h3>
|
|
|
|
<p>
|
|
This section describes how types in the IDL map to types
|
|
in Java.
|
|
</p>
|
|
<p>
|
|
Each sub-section below describes how values of a given IDL type
|
|
are represented in Java. For each IDL type, it is described how
|
|
Java values are <dfn id="dfn-convert-java-to-idl-value">converted to an IDL value</dfn>
|
|
when passed as an argument to a Java method (corresponding
|
|
to an <a class="dfnref" href="#dfn-operation">operation</a> or
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>). Conversely,
|
|
it is described how IDL values of that type are
|
|
<dfn id="dfn-convert-idl-to-java-value">converted to Java values</dfn>
|
|
when being used as the value of a Java final variable (corresponding
|
|
to a <a class="dfnref" href="#dfn-constant">constant</a>) or when
|
|
returned from a Java method (corresponding to an operation,
|
|
attribute or <a class="dfnref" href="#dfn-exception-field">exception field</a>).
|
|
</p>
|
|
|
|
<div id="java-any" class="section">
|
|
<h4>5.2.1. any</h4>
|
|
<p>
|
|
The <a class="idltype" href="#idl-any">any</a> IDL type corresponds to a
|
|
Java <span class="javatype">java.lang.Object</span> value.
|
|
</p>
|
|
<p>
|
|
How to <a class="dfnref" href="#dfn-convert-java-to-idl-value">convert a Java value</a>
|
|
to an IDL <a class="idltype" href="#idl-any">any</a> value depends on the
|
|
type of the Java value:
|
|
</p>
|
|
<dl class="switch">
|
|
<dt>A <span class="javatype">java.lang.Boolean</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>booleanValue()</code> method on the
|
|
<span class="javatype">java.lang.Boolean</span> object to an IDL
|
|
<a class="idltype" href="#idl-boolean">boolean</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Byte</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>byteValue()</code> method on the
|
|
<span class="javatype">java.lang.Byte</span> object to an IDL
|
|
<a class="idltype" href="#idl-byte">byte</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Short</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>shortValue()</code> method on the
|
|
<span class="javatype">java.lang.Short</span> object to an IDL
|
|
<a class="idltype" href="#idl-short">short</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Integer</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>intValue()</code> method on the
|
|
<span class="javatype">java.lang.Integer</span> object to an IDL
|
|
<a class="idltype" href="#idl-long">long</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Long</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>longValue()</code> method on the
|
|
<span class="javatype">java.lang.Long</span> object to an IDL
|
|
<a class="idltype" href="#idl-long-long">long long</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Float</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>floatValue()</code> method on the
|
|
<span class="javatype">java.lang.Float</span> object to an IDL
|
|
<a class="idltype" href="#idl-float">float</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.Double</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling the <code>doubleValue()</code> method on the
|
|
<span class="javatype">java.lang.Double</span> object to an IDL
|
|
<a class="idltype" href="#idl-float">float</a> value.
|
|
</dd>
|
|
<dt>A <span class="javatype">java.lang.String</span> object</dt>
|
|
<dd>
|
|
The IDL value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the <span class="javatype">java.lang.String</span> object to an IDL
|
|
<a class="idltype" href="#idl-DOMString">DOMString</a> value.
|
|
</dd>
|
|
<dt>An array object</dt>
|
|
<dd>
|
|
The IDL value is the <a href="#idl-sequence">IDL sequence</a> obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the Java array object to a sequence, as described in
|
|
<a href="#java-sequence">section 5.2.19</a> below.
|
|
</dd>
|
|
<dt>An object that implements a <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a></dt>
|
|
<dd>
|
|
The IDL value is the <a href="#idl-array">IDL array</a> obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the Java object to an array, as described in
|
|
<a href="#java-array">section 5.2.20</a> below.
|
|
</dd>
|
|
<dt>An object of any other class</dt>
|
|
<dd>
|
|
The IDL value is an <a class="idltype" href="#idl-object">object</a> value
|
|
that references the same object.
|
|
</dd>
|
|
<dt><span class="javavalue">null</span></dt>
|
|
<dd>
|
|
The IDL value is the <span class="idlvalue">null</span>
|
|
<span class="idltype">object?</span> value.
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
How to <a class="dfnref" href="#dfn-convert-idl-to-java-value">convert</a>
|
|
an IDL <a class="idltype" href="#idl-any">any</a> value to a Java
|
|
<span class="javatype">java.lang.Object</span> value depends on the
|
|
<a class="dfnref" href="#dfn-specific-type">specific type</a> of the IDL value:
|
|
</p>
|
|
<dl class="switch">
|
|
<dt>A value of a <a class="dfnref" href="#dfn-primitive-type">primitive type</a></dt>
|
|
<dd>
|
|
<p>
|
|
The Java value is the result of
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the IDL value of the given type to a Java value, and then passing
|
|
that value to the static method according to the following table:
|
|
</p>
|
|
<table class="vert">
|
|
<tr>
|
|
<th>IDL type</th>
|
|
<th>Method</th>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-boolean">boolean</a></td>
|
|
<td><code>java.lang.Boolean.valueOf(boolean)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-byte">byte</a></td>
|
|
<td><code>java.lang.Byte.valueOf(byte)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-octet">octet</a></td>
|
|
<td><code>java.lang.Byte.valueOf(byte)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-short">short</a></td>
|
|
<td><code>java.lang.Short.valueOf(short)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-short">unsigned short</a></td>
|
|
<td><code>java.lang.Short.valueOf(short)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-long">long</a></td>
|
|
<td><code>java.lang.Integer.valueOf(int)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-long">unsigned long</a></td>
|
|
<td><code>java.lang.Integer.valueOf(int)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-long-long">long long</a></td>
|
|
<td><code>java.lang.Long.valueOf(long)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a></td>
|
|
<td><code>java.lang.Long.valueOf(long)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-float">float</a></td>
|
|
<td><code>java.lang.Float.valueOf(float)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-double">double</a></td>
|
|
<td><code>java.lang.Double.valueOf(double)</code></td>
|
|
</tr>
|
|
</table>
|
|
</dd>
|
|
<dt>An IDL value of any other type</dt>
|
|
<dd>
|
|
To obtain a Java value, the rules for converting the <a class="dfnref" href="#dfn-specific-type">specific type</a>
|
|
of the IDL <a class="idltype" href="#idl-any">any</a> value as described
|
|
in the remainder of this section are performed.
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<div id="java-void" class="section">
|
|
<h4>5.2.2. void</h4>
|
|
|
|
<p>
|
|
The only place that the <a class="idltype" href="#idl-void">void</a> type may appear
|
|
in IDL is as the <a class="dfnref" href="#dfn-return-type">return type</a>
|
|
of an <a class="dfnref" href="#dfn-operation">operation</a>. Methods on Java objects
|
|
that implement an operation whose IDL specifies a <a class="idltype" href="#idl-void">void</a>
|
|
return type <span class="rfc2119">MUST</span> be declared to have a return type of <span class="javatype">void</span>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-boolean" class="section">
|
|
<h4>5.2.3. boolean</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-boolean">boolean</a> values are represented by
|
|
Java <span class="javatype">boolean</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">boolean</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-boolean">boolean</a>
|
|
that represents the same truth value as the Java
|
|
<span class="javatype">boolean</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-boolean">boolean</a> value to a Java
|
|
value is the Java <span class="javatype">boolean</span> that
|
|
represents the same truth value as the IDL
|
|
<a class="idltype" href="#idl-boolean">boolean</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-byte" class="section">
|
|
<h4>5.2.4. byte</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-byte">byte</a> values are
|
|
represented by Java <span class="javatype">byte</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">byte</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-byte">byte</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">byte</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-byte">byte</a> value to a Java
|
|
value is the Java <span class="javatype">byte</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-byte">byte</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-octet" class="section">
|
|
<h4>5.2.5. octet</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-octet">octet</a> values are represented by
|
|
Java <span class="javatype">byte</span> values. Note that while
|
|
the IDL <a class="idltype" href="#idl-octet">octet</a> type is unsigned, with a
|
|
range of [0, 255], the Java <span class="javatype">byte</span> type
|
|
is signed, with a range of [−128, 127].
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">Conversion</a>
|
|
of an <a class="idltype" href="#idl-octet">octet</a> value to a
|
|
<span class="javatype">byte</span> is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the <a class="idltype" href="#idl-octet">octet</a> value to convert.</li>
|
|
<li>If <var>x</var> < 128, return the <span class="javatype">byte</span> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> ≥ 128. Return the <span class="javatype">byte</span> whose value is <var>x</var> − 256.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as having the
|
|
<a class="idltype" href="#idl-octet">octet</a> value stored in
|
|
an <span class="javatype">int</span> and casting it to a
|
|
<span class="javatype">byte</span>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">Conversion</a>
|
|
of a <span class="javatype">byte</span> to an
|
|
<a class="idltype" href="#idl-octet">octet</a> is performed as
|
|
follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the <span class="javatype">byte</span> value to decode.</li>
|
|
<li>If <var>x</var> ≥ 0, return the <a class="idltype" href="#idl-octet">octet</a> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> < 0. Return the <a class="idltype" href="#idl-octet">octet</a> whose value is <var>x</var> + 256.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as performing a bit-wise AND of the
|
|
<span class="javatype">byte</span> value with the
|
|
<span class="javatype">int</span> constant
|
|
<span class="javavalue">0xff</span>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-short" class="section">
|
|
<h4>5.2.6. short</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-short">short</a> values are
|
|
represented by Java <span class="javatype">short</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">short</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-short">short</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">short</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-short">short</a> value to a Java
|
|
value is the Java <span class="javatype">short</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-short">short</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-unsigned-short" class="section">
|
|
<h4>5.2.7. unsigned short</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> values are
|
|
represented by Java <span class="javatype">short</span> values. Note that while
|
|
the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> type is unsigned, with a
|
|
range of [0, 65535], the Java <span class="javatype">short</span> type
|
|
is signed, with a range of [−32768, 32767].
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">Conversion</a>
|
|
of an IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value to a
|
|
Java <span class="javatype">short</span> is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value to convert.</li>
|
|
<li>If <var>x</var> < 32768, return the Java <span class="javatype">short</span> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> ≥ 32768. Return the Java <span class="javatype">short</span> whose value is <var>x</var> − 65536.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as having the <a class="idltype" href="#idl-unsigned-short">unsigned short</a> value stored in
|
|
an <span class="javatype">int</span> and casting it to a <span class="javatype">short</span>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">Conversion</a>
|
|
of a Java <span class="javatype">short</span> to an IDL
|
|
<a class="idltype" href="#idl-unsigned-short">unsigned short</a> value
|
|
is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the Java <span class="javatype">short</span> value to decode.</li>
|
|
<li>If <var>x</var> ≥ 0, return the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> < 0. Return the IDL <a class="idltype" href="#idl-unsigned-short">unsigned short</a> whose value is <var>x</var> + 65536.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as performing a bit-wise AND of the <span class="javatype">short</span> value
|
|
with the <span class="javatype">int</span> constant <span class="javavalue">0xffff</span>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-long" class="section">
|
|
<h4>5.2.8. long</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-long">long</a> values are
|
|
represented by Java <span class="javatype">int</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">int</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-long">long</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">int</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-long">long</a> value to a Java
|
|
value is the Java <span class="javatype">int</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-short">short</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-unsigned-long" class="section">
|
|
<h4>5.2.9. unsigned long</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> values are
|
|
represented by Java <span class="javatype">int</span> values. Note that while
|
|
the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> type is unsigned, with a
|
|
range of [0, 4294967295], the Java <span class="javatype">int</span> type
|
|
is signed, with a range of [−2147483648, 2147483647].
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">Conversion</a>
|
|
of an IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value to a
|
|
Java <span class="javatype">int</span> is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value to convert.</li>
|
|
<li>If <var>x</var> < 2147483648, return the Java <span class="javatype">int</span> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> ≥ 2147483648. Return the Java <span class="javatype">int</span> whose value is <var>x</var> − 4294967296.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as having the <a class="idltype" href="#idl-unsigned-long">unsigned long</a> value stored in
|
|
a Java <span class="javatype">long</span> and casting it to an <span class="javatype">int</span>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">Conversion</a>
|
|
of a Java <span class="javatype">int</span> to an IDL
|
|
<a class="idltype" href="#idl-unsigned-long">unsigned long</a> value
|
|
is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the Java <span class="javatype">int</span> value to decode.</li>
|
|
<li>If <var>x</var> ≥ 0, return the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> < 0. Return the IDL <a class="idltype" href="#idl-unsigned-long">unsigned long</a> whose value is <var>x</var> + 4294967296.</li>
|
|
</ol>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
In Java this is the same as performing a bit-wise AND of the <span class="javatype">int</span> value
|
|
with the <span class="javatype">long</span> constant <span class="javavalue">0xffffffffL</span>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-long-long" class="section">
|
|
<h4>5.2.10. long long</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-long-long">long long</a> values are
|
|
represented by Java <span class="javatype">long</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">long</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-long-long">long long</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">long</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-long-long">long long</a> value to a Java
|
|
value is the Java <span class="javatype">long</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-long-long">long long</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-unsigned-long-long" class="section">
|
|
<h4>5.2.11. unsigned long long</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> values are
|
|
represented by Java <span class="javatype">long</span> values. Note that while
|
|
the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> type is unsigned, with a
|
|
range of [0, 18446744073709551615], the Java <span class="javatype">long</span> type
|
|
is signed, with a range of [−9223372036854775808, 9223372036854775807].
|
|
</p>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">Conversion</a>
|
|
of an IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value to a
|
|
Java <span class="javatype">long</span> is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value to convert.</li>
|
|
<li>If <var>x</var> < 18446744073709551616, return the Java <span class="javatype">long</span> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> ≥ 18446744073709551616. Return the Java <span class="javatype">long</span> whose value is <var>x</var> − 18446744073709551615.</li>
|
|
</ol>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">Conversion</a>
|
|
of a Java <span class="javatype">long</span> to an IDL
|
|
<a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> value
|
|
is performed as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>x</var> be the Java <span class="javatype">long</span> value to decode.</li>
|
|
<li>If <var>x</var> ≥ 0, return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> whose value is <var>x</var>.</li>
|
|
<li>Otherwise <var>x</var> < 0. Return the IDL <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> whose value is <var>x</var> + 18446744073709551615.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="java-float" class="section">
|
|
<h4>5.2.12. float</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-float">float</a> values are
|
|
represented by Java <span class="javatype">float</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">float</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-float">float</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">float</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-float">float</a> value to a Java
|
|
value is the Java <span class="javatype">float</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-float">float</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-double" class="section">
|
|
<h4>5.2.13. double</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-double">double</a> values are
|
|
represented by Java <span class="javatype">double</span> values.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
a Java <span class="javatype">double</span> value to an IDL value
|
|
is the IDL <a class="idltype" href="#idl-double">double</a>
|
|
that represents the same numeric value as the Java
|
|
<span class="javatype">double</span>.
|
|
</p>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-double">double</a> value to a Java
|
|
value is the Java <span class="javatype">double</span> that
|
|
represents the same numeric value as the IDL
|
|
<a class="idltype" href="#idl-double">double</a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-DOMString" class="section">
|
|
<h4>5.2.14. DOMString</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-DOMString">DOMString</a> values are
|
|
represented by Java <span class="estype">java.lang.String</span> reference
|
|
values.
|
|
</p>
|
|
<p>
|
|
A Java <span class="javatype">java.lang.String</span> reference value is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-DOMString">DOMString</a> value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the value is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>
|
|
Otherwise, return the IDL <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
value that represents the same sequence of <a class="dfnref" href="#dfn-code-unit">code units</a> as the one
|
|
the Java <span class="javatype">java.lang.String</span> value
|
|
represents.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-DOMString">DOMString</a> value to a Java
|
|
<span class="javatype">java.lang.String</span> value is a
|
|
<span class="javatype">java.lang.String</span>
|
|
object that represents the same sequence of characters that the
|
|
IDL <a class="idltype" href="#idl-DOMString">DOMString</a> represents.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-object" class="section">
|
|
<h4>5.2.15. object</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-object">object</a> values are
|
|
represented by Java <span class="estype">java.lang.Object</span> reference
|
|
values.
|
|
</p>
|
|
<p>
|
|
A Java <span class="javatype">java.lang.Object</span> reference value is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-object">object</a> value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the value is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>
|
|
Otherwise, return the IDL <a class="idltype" href="#idl-object">object</a> value that
|
|
is a reference to the same object.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
The result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
an IDL <a class="idltype" href="#idl-object">object</a> value to a Java
|
|
value is a Java <span class="javatype">java.lang.Object</span> value
|
|
that is a reference to the same object.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-interface" class="section">
|
|
<h4>5.2.16. Interface types</h4>
|
|
|
|
<p>
|
|
IDL <a href="#idl-interface">interface type</a> values are
|
|
represented by Java references of the corresponding Java interface type.
|
|
(See <a href="#java-interfaces">section 5.4</a> below
|
|
for how IDL <a class="dfnref" href="#dfn-interface">interfaces</a> have
|
|
corresponding Java interfaces.)
|
|
</p>
|
|
<p>
|
|
A Java value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a href="#idl-interface">interface type</a> value
|
|
by running the following algorithm (where <var>I</var> is the <a class="dfnref" href="#dfn-interface">interface</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>V</var> is a <a class="dfnref" href="#dfn-platform-object">platform object</a> that implements <var>I</var>,
|
|
then return the IDL <a href="#idl-interface">interface type</a> value that represents a reference to that platform object.</li>
|
|
<li>If <var>V</var> is a <a class="dfnref" href="#dfn-user-object">user object</a> that is considered to implement <var>I</var>
|
|
according to the rules in <a href="#java-user-objects">section 5.6</a>,
|
|
then return the IDL <a href="#idl-interface">interface type</a> value that represents a reference to that user object.</li>
|
|
<li>Otherwise, <var>V</var> is an object that implements the Java interface for <var>I</var> but <var>I</var> is
|
|
not annotated with the <a class="xattr" href="#Callback">[Callback]</a> <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>.
|
|
Throw a <span class="javatype">java.lang.IllegalArgumentException</span>.</li>
|
|
</ol>
|
|
<p>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">Conversions from</a> IDL
|
|
<a href="#idl-interface">interface type</a> values to Java values
|
|
are performed in the same way as that for the IDL
|
|
<a class="idltype" href="#idl-object">object</a> type.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-dictionary" class="section">
|
|
<h4>5.2.17. Dictionary types</h4>
|
|
|
|
<p>
|
|
IDL <a href="#idl-dictionary">dictionary type</a> values are
|
|
represented by Java references to objects of the
|
|
<span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span> class.
|
|
Each <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a> that is
|
|
<a class="dfnref" href="#dfn-present">present</a>
|
|
corresponds to an entry in the <span class="javatype">HashMap</span>.
|
|
</p>
|
|
<p>
|
|
A Java <span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span> reference value
|
|
<var>O</var> is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a href="#idl-dictionary">dictionary type</a> value
|
|
by running the following algorithm (where <var>D</var> is the <a class="dfnref" href="#dfn-dictionary">dictionary</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>O</var> is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>Let <var>dict</var> be an empty dictionary value of type <var>D</var>;
|
|
every <a class="dfnref" href="#dfn-dictionary-member">dictionary member</a>
|
|
is initially considered to be <a class="dfnref" href="#dfn-present">not present</a>.</li>
|
|
<li>Let <var>dictionaries</var> be a list consisting of <var>D</var> and all of <var>D</var>’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>,
|
|
in order from least to most derived.</li>
|
|
<li>For each dictionary <var>dictionary</var> in <var>dictionaries</var>, in order:
|
|
<ol>
|
|
<li>For each dictionary member <var>member</var> declared on <var>dictionary</var>, in order:
|
|
<ol>
|
|
<li>Let <var>key</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of <var>member</var>.</li>
|
|
<li>Let <var>javaKey</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a> <var>key</var> to a <span class="javatype">java.lang.String</span>.</li>
|
|
<li>Let <var>present</var> be the result of calling the <code>containsKey</code> method on <var>O</var> with <var>javaKey</var> as the only argument.</li>
|
|
<li>If <var>present</var> is true, then:
|
|
<ol>
|
|
<li>Let <var>value</var> be the result of calling the <code>get</code> method on <var>O</var> <var>javaKey</var> as the only argument.</li>
|
|
<li>Let <var>idlValue</var> be the result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a> <var>value</var> to an IDL value whose type is the type <var>member</var> is declared to be of.</li>
|
|
<li>Set the dictionary member on <var>dict</var> with key name <var>key</var> to the value <var>idlValue</var>. This dictionary member is considered to be <a class="dfnref" href="#dfn-present">present</a>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>dict</var>.</li>
|
|
</ol>
|
|
<p>
|
|
An IDL <a href="#idl-dictionary">dictionary type</a> value <var>V</var> is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a> to a Java
|
|
<span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span> reference value
|
|
by running the following algorithm (where <var>D</var> is the <a class="dfnref" href="#dfn-dictionary">dictionary</a>):
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>O</var> be a new <span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span> object.</li>
|
|
<li>Let <var>dictionaries</var> be a list consisting of <var>D</var> and all of <var>D</var>’s <a class="dfnref" href="#dfn-inherited-dictionaries">inherited dictionaries</a>,
|
|
in order from least to most derived.</li>
|
|
<li>For each dictionary <var>dictionary</var> in <var>dictionaries</var>, in order:
|
|
<ol>
|
|
<li>For each dictionary member <var>member</var> declared on <var>dictionaries</var>, in order:
|
|
<ol>
|
|
<li>Let <var>key</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of <var>member</var>.</li>
|
|
<li>Let <var>javaKey</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a> <var>key</var> to a <span class="javatype">java.lang.String</span>.</li>
|
|
<li>If the dictionary member named <var>key</var> is <a class="dfnref" href="#dfn-present">present</a> on <var>V</var>, then:
|
|
<ol>
|
|
<li>Let <var>idlValue</var> be the value of <var>member</var> on <var>V</var>.</li>
|
|
<li>Let <var>value</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a> <var>idlValue</var> to a Java value
|
|
as if <var>value</var> were an IDL <a class="idltype" href="#idl-any">any</a> value.</li>
|
|
<li>Call the <code>put</code> method on <var>O</var> with arguments <var>javaKey</var> and <var>value</var>.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>O</var>.</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div id="java-nullable-type" class="section">
|
|
<h4>5.2.18. Nullable types — <var>T</var>?</h4>
|
|
|
|
<p>
|
|
IDL <a class="dfnref" href="#dfn-nullable-type">nullable type</a>
|
|
values are represented with Java object references of a particular
|
|
class, as determined by the table below:
|
|
</p>
|
|
<table class="vert">
|
|
<tr>
|
|
<th>Nullable type</th>
|
|
<th>Java class</th>
|
|
<th>Method to get value</th>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-boolean">boolean</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Boolean</span></td>
|
|
<td><code>booleanValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-byte">byte</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Byte</span></td>
|
|
<td><code>byteValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-octet">octet</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Byte</span></td>
|
|
<td><code>byteValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-short">short</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Short</span></td>
|
|
<td><code>shortValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-unsigned-short">unsigned short</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Short</span></td>
|
|
<td><code>shortValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-long">long</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Integer</span></td>
|
|
<td><code>intValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-unsigned-long">unsigned long</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Integer</span></td>
|
|
<td><code>intValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-long-long">long long</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Long</span></td>
|
|
<td><code>longValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-unsigned-long-long">unsigned long long</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Long</span></td>
|
|
<td><code>longValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-float">float</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Float</span></td>
|
|
<td><code>floatValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-double">double</a>?</span></td>
|
|
<td><span class="javatype">java.lang.Double</span></td>
|
|
<td><code>doubleValue()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-DOMString">DOMString</a>?</span></td>
|
|
<td><span class="javatype">java.lang.String</span></td>
|
|
<td>–</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Interface type <span class="idltype"><var>T</var>?</span></td>
|
|
<td>The Java interface corresponding to IDL type <var>T</var></td>
|
|
<td>–</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Dictionary type <span class="idltype"><var>T</var>?</span></td>
|
|
<td><span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span></td>
|
|
<td>–</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-sequence">sequence<<var>T</var>></a>?</span></td>
|
|
<td><span class="javatype"><var>U</var>[]</span>, where <var>U</var> is the Java type used to represent the IDL type <var>T</var></td>
|
|
<td>–</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="idltype"><a href="#idl-array"><var>T</var>[]</a>?</span></td>
|
|
<td>The <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a> for IDL type <var>T</var></td>
|
|
<td>–</td>
|
|
</tr>
|
|
</table>
|
|
<p>
|
|
How to <a class="dfnref" href="#dfn-convert-java-to-idl-value">convert a Java value</a>
|
|
of one of the above classes to an IDL nullable type <span class="idltype"><var>T</var>?</span>
|
|
depends on the object reference value and the type <var>T</var>:
|
|
</p>
|
|
<dl class="switch">
|
|
<dt>If the object reference value is <span class="javavalue">null</span></dt>
|
|
<dd>
|
|
The IDL value is the <span class="idlvalue">null</span> <span class="idltype"><var>T</var>?</span> value.
|
|
</dd>
|
|
<dt>If the value is not an object of the right type for <var>T</var> according to the table above</dt>
|
|
<dd>
|
|
Throw a <span class="javatype">java.lang.IllegalArgumentException</span>.
|
|
</dd>
|
|
<dt>If <var>T</var> is a <a class="dfnref" href="#dfn-primitive-type">primitive type</a></dt>
|
|
<dd>
|
|
Let <var>method</var> be the method indicated in the table above for type <var>T</var>.
|
|
The IDL value is a <span class="idltype"><var>T</var>?</span> whose value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the result of calling <var>method</var> on the object to type <var>T</var>.
|
|
</dd>
|
|
<dt>Anything else</dt>
|
|
<dd>
|
|
The IDL value is a <span class="idltype"><var>T</var>?</span> whose value is obtained
|
|
by <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
the object reference value to type <var>T</var>.
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
How to <a class="dfnref" href="#dfn-convert-idl-to-java-value">convert</a>
|
|
an IDL nullable type value to a Java value depends on
|
|
its value and the <a class="dfnref" href="#dfn-inner-type">inner type</a>:
|
|
</p>
|
|
<dl class="switch">
|
|
<dt>If the IDL value is <span class="idlvalue">null</span></dt>
|
|
<dd>
|
|
The Java value is <span class="javavalue">null</span>.
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> nullable <a class="dfnref" href="#dfn-primitive-type">primitive</a> value</dt>
|
|
<dd>
|
|
<p>
|
|
The Java value is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the IDL <a class="dfnref" href="#dfn-inner-type">inner type</a> to a Java value, and then passing
|
|
that value to the static method according to the following table,
|
|
where <var>T</var> is the IDL <a class="dfnref" href="#dfn-inner-type">inner type</a>:
|
|
</p>
|
|
<table class="vert">
|
|
<tr>
|
|
<th><var>T</var></th>
|
|
<th>Method</th>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-boolean">boolean</a></td>
|
|
<td><code>java.lang.Boolean.valueOf(boolean)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-byte">byte</a></td>
|
|
<td><code>java.lang.Byte.valueOf(byte)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-octet">octet</a></td>
|
|
<td><code>java.lang.Byte.valueOf(byte)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-short">short</a></td>
|
|
<td><code>java.lang.Short.valueOf(short)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-short">unsigned short</a></td>
|
|
<td><code>java.lang.Short.valueOf(short)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-long">long</a></td>
|
|
<td><code>java.lang.Integer.valueOf(int)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-long">unsigned long</a></td>
|
|
<td><code>java.lang.Integer.valueOf(int)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-long-long">long long</a></td>
|
|
<td><code>java.lang.Long.valueOf(long)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a></td>
|
|
<td><code>java.lang.Long.valueOf(long)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-float">float</a></td>
|
|
<td><code>java.lang.Float.valueOf(float)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a class="idltype" href="#idl-double">double</a></td>
|
|
<td><code>java.lang.Double.valueOf(double)</code></td>
|
|
</tr>
|
|
</table>
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> <span class="idltype">DOMString?</span> value</dt>
|
|
<dd>
|
|
The Java value is a <span class="javatype">java.lang.String</span> object representing
|
|
the same sequence of <a class="dfnref" href="#dfn-code-unit">code units</a> as the <span class="idltype">DOMString?</span> value.
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> <span class="idltype">sequence<<var>T</var>>?</span> value</dt>
|
|
<dd>
|
|
The Java value is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the IDL sequence value to a Java array object, as described in
|
|
<a href="#java-sequence">section 5.2.19</a> below.
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> <span class="idltype"><var>T</var>[]?</span> value</dt>
|
|
<dd>
|
|
The Java value is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the IDL array value to a Java object implementing the <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
for <var>T</var>, as described in <a href="#java-sequence">section 5.2.20</a> below.
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> nullable <a href="#idl-interfaces">dictionary type</a> value</dt>
|
|
<dd>
|
|
The Java value is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the IDL dictionary value to a Java <span class="javatype">java.util.HashMap<java.lang.String,java.lang.Object></span>
|
|
object, as described in
|
|
<a href="#java-sequence">section 5.2.17</a> above.
|
|
</dd>
|
|
<dt>If the IDL value is a non-<span class="idlvalue">null</span> nullable <a href="#idl-interfaces">interface type</a> or <span class="idltype">object?</span> value</dt>
|
|
<dd>
|
|
The Java value is a reference to the same object.
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<div id="java-sequence" class="section">
|
|
<h4>5.2.19. Sequences — sequence<<var>T</var>></h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> values are
|
|
represented by Java arrays of type <var>U</var>, where <var>U</var> is the Java type used to
|
|
represent the IDL type <var>T</var>.
|
|
</p>
|
|
<p>
|
|
A Java array <var>A</var> of type <var>U</var> is <a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>If <var>A</var> is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>Let <var>n</var> be the length of the array <var>A</var>.</li>
|
|
<li>Initialize <var>S</var><sub>0..<var>n</var>−1</sub> to be an IDL sequence with elements of type <var>T</var>, where each element is uninitialized.</li>
|
|
<li>Initialize <var>i</var> to be 0.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>E</var> be the value value of <var>A</var> at index <var>i</var>.</li>
|
|
<li>Set <var>S</var><sub><var>i</var></sub> to the result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
<var>E</var> to an IDL value of type <var>T</var>.</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>S</var>.</li>
|
|
</ol>
|
|
<p>
|
|
An IDL sequence value <var>S</var><sub>0..<var>n</var>−1</sub> of type
|
|
<a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converted</a>
|
|
to a Java array of type <var>U</var> object as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>A</var> be a new Java array object with element type <var>U</var> and length <var>n</var>.</li>
|
|
<li>Initialize <var>i</var> to be 0.</li>
|
|
<li>While <var>i</var> < <var>n</var>:
|
|
<ol>
|
|
<li>Let <var>E</var> be the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
<var>S</var><sub><var>i</var></sub> to a Java value of type <var>U</var>.</li>
|
|
<li>Set element <var>i</var> of the array <var>A</var> to the value <var>E</var>.</li>
|
|
<li>Set <var>i</var> to <var>i</var> + 1.</li>
|
|
</ol>
|
|
</li>
|
|
<li>Return <var>A</var>.</li>
|
|
</ol>
|
|
<p>
|
|
A Java object implementing an <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with an <a class="dfnref" href="#dfn-operation">operation</a> declared to return
|
|
a <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a> value
|
|
<span class="rfc2119">MUST NOT</span> return <span class="javavalue">null</span> from the corresponding method.
|
|
Similarly, a <a class="dfnref" href="#dfn-getter-method">getter method</a> for an IDL
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a> <span class="rfc2119">MUST NOT</span>
|
|
return <span class="javavalue">null</span> if the attribute
|
|
is declared to be of type <a class="idltype" href="#idl-sequence">sequence<<var>T</var>></a>.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-array" class="section">
|
|
<h4>5.2.20. Arrays — <var>T</var>[]</h4>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-array"><var>T</var>[]</a> values are
|
|
represented by Java objects implementing a particular interface,
|
|
known as the <dfn id="dfn-java-array-interface">Java array interface</dfn>,
|
|
depending on the type <var>T</var>.
|
|
</p>
|
|
<p>
|
|
For each of the <a class="dfnref" href="#dfn-primitive-type">primitive types</a>
|
|
there <span class="rfc2119">MUST</span> exist a corresponding
|
|
<a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
of the following form:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">package org.w3c.dom;
|
|
|
|
public interface <var>PrimitiveName</var>Array {
|
|
int getLength();
|
|
void setLength(int length);
|
|
<var>PrimitiveType</var> getElement(int index);
|
|
void setElement(int index, <var>PrimitiveType</var> value);
|
|
}</code></pre></div></div>
|
|
<p>
|
|
where <var>PrimitiveName</var> is the <a class="dfnref" href="#dfn-type-name">type name</a>
|
|
of the primitive type and <var>PrimitiveType</var> is the Java type used
|
|
to represent it.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
For example, the <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
for the <span class="idltype">octet[]</span> type is:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">package org.w3c.dom;
|
|
|
|
public interface OctetArray {
|
|
int getLength();
|
|
void setLength(int length);
|
|
byte getElement(int index);
|
|
void setElement(int index, byte value);
|
|
}</code></pre></div></div>
|
|
</div>
|
|
<p>
|
|
There <span class="rfc2119">MUST</span> also exist the following interface, <span class="javatype">org.w3c.dom.ObjectArray<<var>E</var>></span>:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">package org.w3c.dom;
|
|
|
|
public interface ObjectArray<E> {
|
|
int getLength();
|
|
void setLength(int length);
|
|
E getElement(int index);
|
|
void setElement(int index, E value);
|
|
}</code></pre></div></div>
|
|
<p>
|
|
This interface, parameterized by the Java type used to represent array element
|
|
type <var>T</var>, is the corresponding <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
for <var>T</var>.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
For example, the <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
for the <span class="idltype">DOMString[]?[]</span> type is
|
|
<span class="javatype">org.w3c.dom.ObjectArray<java.lang.ObjectArray<java.lang.String>></span>.
|
|
</p>
|
|
</div>
|
|
|
|
<p>
|
|
A Java object that implements a <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
represents a given <a href="#idl-array">IDL array</a> value of type <span class="idltype"><var>T</var>[]</span>.
|
|
The methods on the object that implement that interface <span class="rfc2119">MUST</span> behave as follows:
|
|
</p>
|
|
<dl>
|
|
<dt><code>getLength()</code></dt>
|
|
<dd>
|
|
<p>This method returns the current length of the <a href="#idl-array">IDL array</a> value.</p>
|
|
</dd>
|
|
|
|
<dt><code>setLength(<var>length</var>)</code></dt>
|
|
<dd>
|
|
<p>When called on an object representing a <a class="dfnref" href="#dfn-fixed-length">variable length</a>
|
|
array, this method sets the length of the array to <var>length</var>. When the array is lengthened, the new
|
|
elements are set to the IDL value that results from <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting to an IDL value</a> the
|
|
<a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#96595">default value</a>
|
|
of the Java type that <var>T</var> corresponds to (<a href="#ref-JLS3">[JLS3]</a>, section 4.12.5).</p>
|
|
|
|
<p>When called on an object representing a <a class="dfnref" href="#dfn-fixed-length">fixed length</a>
|
|
array, this method throws a <span class="javatype">java.lang.UnsupportedOperationException</span>.</p>
|
|
</dd>
|
|
|
|
<dt><code>getElement(<var>index</var>)</code></dt>
|
|
<dd>
|
|
<p>This method returns the IDL value of type <var>T</var> at the represented array’s index <var>index</var>
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converted to a Java value</a>.</p>
|
|
</dd>
|
|
|
|
<dt><code>setElement(<var>index</var>, <var>value</var>)</code></dt>
|
|
<dd>
|
|
<p>When called on an object representing an array that is not <a class="dfnref" href="#dfn-read-only-array">read only</a>,
|
|
this method sets the IDL value at the represented array’s index <var>index</var> to
|
|
the result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
<var>value</var> to an IDL value of type <var>T</var>.</p>
|
|
|
|
<p>When called on an object representing an array that is <a class="dfnref" href="#dfn-read-only-array">read only</a>,
|
|
this method throws a <span class="javatype">java.lang.UnsupportedOperationException</span>.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<p>
|
|
A Java reference value <var>O</var> for an object implementing a
|
|
<a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
is <a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a> to an
|
|
<a href="#idl-array">IDL array</a> value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If <var>O</var> is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>Otherwise, if <var>O</var> is an object implementing a <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
corresponding to a <a class="dfnref" href="#dfn-primitive-type">primitive type</a>, then the IDL array value
|
|
is the array value that <var>O</var> represents. The type of the IDL array value is
|
|
<span class="idltype"><var>T</var>[]</span>, where <var>T</var> is the primitive type.</li>
|
|
<li>Otherwise, if <var>O</var> is an object implementing <span class="javatype">org.w3c.dom.ObjectArray<<var>E</var>></span>,
|
|
then the IDL array value is the array value that <var>O</var> represents. The type of
|
|
the IDL array value is the IDL type that <var>E</var> corresponds to.</li>
|
|
</ul>
|
|
|
|
<p>
|
|
An <a href="#idl-array">IDL array</a> value <var>A</var> of type <span class="idltype"><var>T</var>[]</span>
|
|
is <a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a> to a
|
|
Java value whose type is an object implementing the <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
corresponding to <var>T</var>, as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If <var>A</var> is already represented by an object implementing a <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>,
|
|
then the Java value is that object.</li>
|
|
<li>Otherwise, the Java value is newly created object implementing the <a class="dfnref" href="#dfn-java-array-interface">Java array interface</a>
|
|
that corresponds to <var>T</var>.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="java-Date" class="section">
|
|
<h3>5.2.21. Date</h3>
|
|
|
|
<p>
|
|
IDL <a class="idltype" href="#idl-Date">Date</a> values are
|
|
represented by Java <span class="estype">java.util.Date</span> reference
|
|
values.
|
|
</p>
|
|
<p>
|
|
A Java <span class="javatype">java.lang.Date</span> reference value is
|
|
<a class="dfnref" href="#dfn-convert-java-to-idl-value">converted</a>
|
|
to an IDL <a class="idltype" href="#idl-Date">Date</a> value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the value is <span class="javavalue">null</span>, then throw a <span class="javatype">java.lang.NullPointerException</span>.</li>
|
|
<li>Let <var>m</var> be the millisecond that the <span class="javatype">java.util.Date</span> object represents.</li>
|
|
<li>If <var>m</var> cannot be represented by an IDL <a class="idltype" href="#idl-Date">Date</a> value, then return the <span class="idlvalue">undefined</span> IDL <a class="idltype" href="#idl-Date">Date</a> value.</li>
|
|
<li>Return the IDL <a class="idltype" href="#idl-Date">Date</a> value that represents <var>m</var>.</li>
|
|
</ul>
|
|
<p>
|
|
An IDL <a class="idltype" href="#idl-Date">Date</a> value is
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converted</a>
|
|
to a <span class="javatype">java.lang.Date</span> reference value as follows:
|
|
</p>
|
|
<ul>
|
|
<li>If the value is the <span class="idlvalue">undefined</span> IDL <a class="idltype" href="#idl-Date">Date</a> value, then return
|
|
a newly created <span class="javatype">java.util.Date</span> object as if by calling <code>new java.util.Date(Long.MIN_VALUE)</code>.</li>
|
|
<li>Otherwise, return a newly created <span class="javatype">java.util.Date</span>
|
|
object that represents the same millisecond that the IDL <span class="idlvalue">Date</span> value does.</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-modules" class="section">
|
|
<h3>5.3. Modules</h3>
|
|
|
|
<p>
|
|
Every IDL <a class="dfnref" href="#dfn-module">module</a> corresponds to a Java package,
|
|
whose name is the result of taking the module’s
|
|
<a class="dfnref" href="#dfn-prefixed-name">prefixed name</a>, replacing every
|
|
<a class="dfnref" href="#dfn-double-colon">double colon</a> with “.”, and then removing the leading “.”.
|
|
</p>
|
|
<p>
|
|
Definitions inside an IDL <a class="dfnref" href="#dfn-module">module</a>
|
|
correspond to Java constructs declared to be in the package for
|
|
that module.
|
|
</p>
|
|
<div class="example"><div class="exampleHeader">Example</div>
|
|
<p>
|
|
The following <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
|
|
will result in four Java interfaces existing:
|
|
<span class="javatype">org.w3c.dom.Document</span>,
|
|
<span class="javatype">org.w3c.dom.html.HTMLDocument</span>,
|
|
<span class="javatype">org.foo.FooDocument</span> and
|
|
<span class="javatype">org.foo.ext.ExtendedFooDocument</span>.
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">module dom {
|
|
interface Document {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
};
|
|
|
|
module html {
|
|
interface HTMLDocument {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
};
|
|
|
|
[Prefix=org]
|
|
module foo {
|
|
interface FooDocument {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
|
|
module ext {
|
|
interface ExtendedFooDocument {
|
|
<span class="comment">// ...</span>
|
|
};
|
|
};
|
|
};</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!--
|
|
<div id='java-extended-attributes' class='section'>
|
|
<h3>Java-specific extended attributes</h3>
|
|
|
|
<p>
|
|
This section defines a single
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>
|
|
whose presence affects only the Java binding.
|
|
</p>
|
|
</div>
|
|
-->
|
|
|
|
<div id="java-interfaces" class="section">
|
|
<h3>5.4. Interfaces</h3>
|
|
|
|
<p>
|
|
For every supported IDL <a class="dfnref" href="#dfn-interface">interface</a>,
|
|
there <span class="rfc2119">MUST</span> exist a corresponding public Java interface
|
|
whose name is the <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> of the IDL interface
|
|
and which resides in the Java package corresponding to the interface’s
|
|
<a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>
|
|
(or the default package, if there is no enclosing module).
|
|
</p>
|
|
<p>
|
|
The Java interface for an interface <var>A</var> <span class="rfc2119">MUST</span> be declared to extend the following
|
|
Java interfaces:
|
|
</p>
|
|
<ul>
|
|
<li>the Java interface that corresponds to the interface from which <var>A</var>
|
|
<a class="dfnref" href="#dfn-inherit">inherits</a>, if it does inherit from one, and</li>
|
|
<li>the Java interfaces that correspond to each interface on the right-hand side of
|
|
an <a class="dfnref" href="#dfn-implements-statement">implements statement</a> where <var>A</var>
|
|
is on the left-hand side.</li>
|
|
</ul>
|
|
<p>
|
|
If the IDL interface has one or more <a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
declared on it, then there <span class="rfc2119">MUST</span> also exist
|
|
a public, abstract Java class, which also resides in the Java
|
|
package corresponding to the interface’s enclosing module
|
|
(or the default package, if there is no enclosing module).
|
|
This class is known as the <dfn id="dfn-utility-class">utility class</dfn>
|
|
for the IDL interface, and provides access to the static operations.
|
|
The name of the Java class is the concatenation
|
|
of the <a class="dfnref" href="#dfn-identifier">identifier</a> of the IDL interface
|
|
and the string “Utils”. If this name is already
|
|
the name of a Java class or interface, due to IDL definitions, then
|
|
the name of the Java class is prefixed with a single
|
|
<span class="char">U+005F LOW LINE ("_")</span> character
|
|
so as not to conflict.
|
|
</p>
|
|
|
|
<div id="java-constants" class="section">
|
|
<h4>5.4.1. Constants</h4>
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-constant">constant</a> defined on
|
|
the IDL <a class="dfnref" href="#dfn-interface">interface</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding constant declared on the Java interface
|
|
with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The constant has no modifiers.</li>
|
|
<li>
|
|
The type of the constant is the Java type that corresponds to the type of
|
|
the IDL constant, according to the rules in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
<li>
|
|
The name of the constant is the <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> of the constant.
|
|
</li>
|
|
<li>
|
|
The value of the constant is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the constant’s IDL value to a Java value, according to the rules
|
|
in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="java-operations" class="section">
|
|
<h4>5.4.2. Operations</h4>
|
|
<p>
|
|
The <a class="dfnref" href="#dfn-operation">operations</a> defined on
|
|
an IDL <a class="dfnref" href="#dfn-interface">interface</a>
|
|
will result in one or more methods being declared on the Java interface (for
|
|
<a class="dfnref" href="#dfn-regular-operation">regular operations</a>)
|
|
or on a Java utility class (for <a class="dfnref" href="#dfn-static-operation">static operations</a>).
|
|
</p>
|
|
<p>
|
|
For each unique identifier <var>id</var> of the
|
|
<a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
declared on the IDL interface:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
For each entry <<var>op</var>, <var>types</var>, <var>any</var>> in the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for <a class="dfnref" href="#dfn-regular-operation">regular operations</a>
|
|
with identifier <var>id</var> on the IDL interface and with argument
|
|
count <var>0</var> (for the Java language binding), there <span class="rfc2119">MUST</span>
|
|
exist a method on the Java interface whose name, its <dfn id="dfn-java-method-name">Java method name</dfn>,
|
|
is determined as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>identifier</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-operation">operation</a>.</li>
|
|
<li>Initialize <var>name</var> to be <var>identifier</var> <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>.</li>
|
|
<li>If <var>name</var> is the same as the name of
|
|
one of the methods defined on <span class="javatype">java.lang.Object</span>,
|
|
then prepend a single <span class="char">U+005F LOW LINE ("_")</span> character to <var>name</var>.</li>
|
|
<li>The name of the method is <var>name</var>.</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
For each unique identifier <var>id</var> of the
|
|
<a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
declared on the IDL interface:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
For each entry <<var>op</var>, <var>types</var>, <var>any</var>> in the
|
|
<a class="dfnref" href="#dfn-effective-overload-set">effective overload set</a>
|
|
for <a class="dfnref" href="#dfn-static-operation">static operations</a>
|
|
with identifier <var>id</var> on the IDL interface and with argument
|
|
count <var>0</var> (for the Java language binding), there <span class="rfc2119">MUST</span>
|
|
exist a method on the <a class="dfnref" href="#dfn-utility-class">utility class</a>
|
|
whose name is its <a class="dfnref" href="#dfn-java-method-name">Java method name</a>
|
|
and which is declared with modifiers <code>public static final</code>.
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
For each identifierless <a class="dfnref" href="#dfn-special-operation">special operation</a>
|
|
declared on the IDL interface of the following types,
|
|
</p>
|
|
<ul>
|
|
<li><a href="#dfn-indexed-property-getter">indexed property getter</a></li>
|
|
<li><a href="#dfn-indexed-property-setter">indexed property setter</a></li>
|
|
<li><a href="#dfn-indexed-property-creator">indexed property creator</a></li>
|
|
<li><a href="#dfn-indexed-property-deleter">indexed property deleter</a></li>
|
|
<li><a href="#dfn-named-property-getter">named property getter</a></li>
|
|
<li><a href="#dfn-named-property-setter">named property setter</a></li>
|
|
<li><a href="#dfn-named-property-creator">named property creator</a></li>
|
|
<li><a href="#dfn-named-property-deleter">named property deleter</a></li>
|
|
<li><a href="#dfn-legacy-caller">legacy caller</a></li>
|
|
</ul>
|
|
<p>
|
|
there <span class="rfc2119">MUST</span> exist a method on the Java interface whose
|
|
name is determined based on the type of special operation:
|
|
</p>
|
|
<table class="vert">
|
|
<tr><th>Type</th><th>Name</th></tr>
|
|
<tr><td>indexed or named property getter</td><td>“_get”</td></tr>
|
|
<tr><td>indexed or named property setter</td><td>“_set”</td></tr>
|
|
<tr><td>indexed or named property creator</td><td>“_create”</td></tr>
|
|
<tr><td>indexed or named property deleter</td><td>“_delete”</td></tr>
|
|
<tr><td>caller</td><td>“_call”</td></tr>
|
|
</table>
|
|
<p>
|
|
For all of the above operations – regular, static, and the abovementioned
|
|
special operations – their corresponding Java methods have the following
|
|
characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
The return type of the method is the Java type that corresponds to the operation
|
|
<a class="dfnref" href="#dfn-return-type">return type</a>, according to the rules in
|
|
<a href="#java-type-mapping">section 5.2</a> above.
|
|
</li>
|
|
<li>
|
|
The method has an argument for each type, in order, that is in <var>types</var>. The type of
|
|
method argument <var>j</var> is the Java type that corresponds to the IDL type <var>types</var><sub><var>j</var></sub>,
|
|
according to the rules in <a href="#java-type-mapping">section 5.2</a>
|
|
above. If the length of <var>types</var> is the length of the
|
|
argument list <var>op</var> is declared with, and <var>op</var> is a
|
|
<a class="dfnref" href="#dfn-variadic-operation">variadic operation</a>,
|
|
then the method is a <em>variable arity method</em> (<a href="#ref-JLS3">[JLS3]</a>,
|
|
section 8.4.1).
|
|
</li>
|
|
<!--
|
|
<li>
|
|
If <var>op</var> has IDL <a class='dfnref' href='#dfn-exception'>exceptions</a>
|
|
listed in the <a class='sym' href='#prod-Raises'>Raises</a> clause, then the
|
|
method <span class='rfc2119'>SHOULD</span> have a <code>throws</code>
|
|
clause specifying all of the Java exception classes that correspond
|
|
to those IDL exceptions, and no others. Otherwise, if <var>op</var> has no
|
|
exceptions listed in the <a class='sym' href='#prod-Raises'>Raises</a> clause,
|
|
then the method <span class='rfc2119'>SHOULD NOT</span> have a <code>throws</code>
|
|
clause.
|
|
</li>
|
|
-->
|
|
<li>
|
|
An implementation of this method <span class="rfc2119">MUST</span>
|
|
perform the following steps:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>arg</var><sub>0..<var>n</var>−1</sub> be the list
|
|
of Java argument values passed to the method.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var><sub>0..<var>n</var>−1</sub> be
|
|
a list of IDL values, where <var>idlarg</var><sub><var>i</var></sub>
|
|
is the result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
<var>arg</var><sub><var>i</var></sub> to an IDL value
|
|
of the type that the <var>i</var>th argument is declared to be.
|
|
</li>
|
|
<li>
|
|
Let <var>R</var> be the result of performing the actions listed in the description of the operation
|
|
<var>op</var> with <var>idlarg</var><sub>0..<var>n</var>−1</sub>
|
|
as the argument values.
|
|
</li>
|
|
<li>
|
|
If the actions performed in the previous step resulted in an
|
|
exception being thrown, then allow that exception to propagate
|
|
out from this algorithm. Otherwise, return the result of
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
<var>R</var> to a Java value of the type <var>op</var>
|
|
is declared to return.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="java-attributes" class="section">
|
|
<h4>5.4.3. Attributes</h4>
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-attribute">attribute</a> defined on
|
|
the IDL <a class="dfnref" href="#dfn-interface">interface</a> that does not
|
|
<a class="dfnref" href="#dfn-inherit-getter">inherit its getter</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding <dfn id="dfn-getter-method">getter method</dfn>
|
|
declared on the Java interface with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The method has no modifiers.</li>
|
|
<li>
|
|
The return type of the method is the Java type that corresponds to the attribute type,
|
|
according to the rules in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
<li>
|
|
The name of the method is determined as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>identifier</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-attribute">attribute</a>.</li>
|
|
<li>Initialize <var>name</var> to be the string “get”.</li>
|
|
<li>Let <var>ucIdentifier</var> be <var>identifier</var> with first character uppercased,
|
|
as if passed to the <code>java.lang.Character.toUpperCase()</code> method.</li>
|
|
<li>If there exists another attribute on the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with identifier <var>ucIdentifier</var>, then append a single <span class="char">U+005F LOW LINE ("_")</span>
|
|
character to <var>name</var>.</li>
|
|
<li>Append <var>ucIdentifier</var> to <var>name</var>.</li>
|
|
<li>If there exists a <a class="dfnref" href="#dfn-constant">constant</a> or
|
|
<a class="dfnref" href="#dfn-operation">operation</a> on the interface with
|
|
identifier <var>name</var>, or if <var>name</var> is the same as the name of
|
|
one of the methods defined on <span class="javatype">java.lang.Object</span>,
|
|
then prepend a single <span class="char">U+005F LOW LINE ("_")</span> character to <var>name</var>.</li>
|
|
<li>The name of the method is <var>name</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
The method has no arguments.
|
|
</li>
|
|
<li>
|
|
An implementation of this method <span class="rfc2119">MUST</span>
|
|
perform the following steps:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>V</var> be the IDL value that results from
|
|
performing the actions listed for getting the corresponding attribute
|
|
in the description of the interface.
|
|
</li>
|
|
<li>
|
|
If the actions performed in the previous step resulted in an
|
|
exception being thrown, then allow that exception to propagate
|
|
out from this algorithm. Otherwise, return the result of
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
<var>V</var> to a Java value of the type <var>op</var>
|
|
is declared to return.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
<!--
|
|
<p>
|
|
In addition, the method <span class='rfc2119'>SHOULD</span> have a <code>throws</code>
|
|
clause specifying all of the Java exception classes that correspond to the IDL
|
|
<a class='dfnref' href='#dfn-exception'>exceptions</a> that are listed in the
|
|
<a class='sym' href='#prod-GetRaises'>GetRaises</a> clause of the attribute, and no others.
|
|
</p>
|
|
-->
|
|
<p>
|
|
For each attribute defined on the IDL interface that is not
|
|
<a class="dfnref" href="#dfn-read-only">read only</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding <dfn id="dfn-setter-method">setter method</dfn>
|
|
declared on the Java interface with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The method has no modifiers.</li>
|
|
<li>
|
|
The return type of the method is <span class="javatype">void</span>.
|
|
</li>
|
|
<li>
|
|
The name of the method is determined as follows:
|
|
<ol class="algorithm">
|
|
<li>Let <var>identifier</var> be the <a class="dfnref" href="#dfn-identifier">identifier</a> of the <a class="dfnref" href="#dfn-attribute">attribute</a>.</li>
|
|
<li>Initialize <var>name</var> to be the string “set”.</li>
|
|
<li>Let <var>ucIdentifier</var> be <var>identifier</var> with first character uppercased,
|
|
as if passed to the <code>java.lang.Character.toUpperCase()</code> method.</li>
|
|
<li>If there exists another attribute on the <a class="dfnref" href="#dfn-interface">interface</a>
|
|
with identifier <var>ucIdentifier</var>, then append a single <span class="char">U+005F LOW LINE ("_")</span>
|
|
character to <var>name</var>.</li>
|
|
<li>Append <var>ucIdentifier</var> to <var>name</var>.</li>
|
|
<li>If there exists a <a class="dfnref" href="#dfn-constant">constant</a> or
|
|
<a class="dfnref" href="#dfn-operation">operation</a> on the interface with
|
|
identifier <var>name</var>, or if <var>name</var> is the same as the name of
|
|
one of the methods defined on <span class="javatype">java.lang.Object</span>,
|
|
then prepend a single <span class="char">U+005F LOW LINE ("_")</span> character to <var>name</var>.</li>
|
|
<li>The name of the method is <var>name</var>.</li>
|
|
</ol>
|
|
</li>
|
|
<li>
|
|
The method has a single argument whose type is the Java type that corresponds
|
|
to the attribute type, according to the rules in
|
|
<a href="#java-type-mapping">section 5.2</a> above.
|
|
</li>
|
|
<li>
|
|
An implementation of this method <span class="rfc2119">MUST</span>
|
|
perform the following steps:
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>arg</var> be the Java value that was passed as the
|
|
argument to the method.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var> be the result of <a class="dfnref" href="#dfn-convert-java-to-idl-value">converting</a>
|
|
<var>arg</var> to an IDL value of the type the attribute is declared to be.
|
|
</li>
|
|
<li>
|
|
Perform the actions for setting the corresponding attribute
|
|
with the value <var>idlarg</var> listed in the description of the interface.
|
|
</li>
|
|
<li>
|
|
If the actions performed in the previous step resulted in an
|
|
exception being thrown, then allow that exception to propagate
|
|
out from this algorithm.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
<!--
|
|
<p>
|
|
In addition, the method <span class='rfc2119'>SHOULD</span> have a <code>throws</code>
|
|
clause specifying all of the Java exception classes that correspond to the IDL
|
|
exceptions that are listed in the
|
|
<a class='sym' href='#prod-SetRaises'>SetRaises</a> clause of the attribute, and no others.
|
|
</p>
|
|
-->
|
|
<!--
|
|
<p>
|
|
For each attribute defined on the IDL interface that is
|
|
<a class='dfnref' href='#dfn-read-only'>read only</a> and is declared with the
|
|
<a class='xattr' href='#PutForwards'>[PutForwards]</a>
|
|
<a class='dfnref' href='#dfn-extended-attribute'>extended attribute</a>, there
|
|
<span class='rfc2119'>MUST</span> be a corresponding setter method
|
|
declared on the Java interface with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The method has no modifiers.</li>
|
|
<li>
|
|
The return type of the method is <span class='javatype'>void</span>.
|
|
</li>
|
|
<li>
|
|
The tentative name of the method is a
|
|
<span class='char'>U+0073 LATIN SMALL S ("s")</span> character, followed by a
|
|
<span class='char'>U+0065 LATIN SMALL E ("e")</span> character, followed by a
|
|
<span class='char'>U+0074 LATIN SMALL T ("t")</span> character, followed by
|
|
the first character of the identifier of the attribute
|
|
uppercased (as if passed to the <code>java.lang.Character.toUpperCase()</code>
|
|
method), followed by the remaining characters from the identifier of the attribute.
|
|
The name of the method is the Java escaped
|
|
tenative name of the method prefixed with the smallest number
|
|
of <span class='char'>U+005F LOW LINE ("_")</span> characters required to make the
|
|
name not equal to the name of a constant or method declared on the Java interface or one of the
|
|
methods on the <span class='javatype'>java.lang.Object</span> class.
|
|
</li>
|
|
<li>
|
|
The method has a single argument whose type is the Java type that corresponds
|
|
to the type of the attribute identified by the <a class='xattr' href='#PutForwards'>[PutForwards]</a>
|
|
extended attribute on the interface type that
|
|
this attribute is declared to be of, according to the rules in
|
|
<a href='#java-type-mapping'>section <?sref java-type-mapping?></a> <?sdir java-type-mapping?>.
|
|
</li>
|
|
<li>
|
|
An implementation of this method <span class='rfc2119'>MUST</span>
|
|
perform the following steps:
|
|
<ol class='algorithm'>
|
|
<li>
|
|
Let <var>arg</var> be the Java value that was passed as the
|
|
argument to the method.
|
|
</li>
|
|
<li>
|
|
Let <var>idlarg</var> be the result of <a class='dfnref' href='#dfn-convert-java-to-idl-value'>converting</a>
|
|
<var>arg</var> to an IDL value of the type the forwarded-to attribute
|
|
is declared to be.
|
|
</li>
|
|
<li x:step='a'>
|
|
Perform the actions for setting the corresponding attribute
|
|
with the value <var>idlarg</var> listed in the description of the interface.
|
|
</li>
|
|
<li>
|
|
If the actions performed in the previous step resulted in an
|
|
exception being thrown, then allow that exception to propagate
|
|
out from this algorithm.
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
In addition, the method <span class='rfc2119'>SHOULD</span> have a <code>throws</code>
|
|
clause specifying all of the Java exception classes that correspond to the IDL
|
|
exceptions that are listed in the
|
|
<a class='sym' href='#prod-SetRaises'>SetRaises</a> clause of the attribute
|
|
identified by the <a class='xattr' href='#PutForwards'>[PutForwards]</a>
|
|
extended attribute on the interface type that
|
|
this attribute is declared to be of, and no others.
|
|
</p>
|
|
-->
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-platform-objects" class="section">
|
|
<h3>5.5. Platform objects implementing interfaces</h3>
|
|
<p>
|
|
A Java <a class="dfnref" href="#dfn-platform-object">platform object</a> that implements an IDL <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<span class="rfc2119">MUST</span> be of a Java class which implements the Java interface
|
|
that corresponds to the IDL interface.
|
|
</p>
|
|
<p>
|
|
If the IDL interface has a <a class="dfnref" href="#dfn-stringifier">stringifier</a>,
|
|
the <code>String toString()</code> method
|
|
<span class="rfc2119">MUST</span> be overridden to allow
|
|
stringification of the object as required by the IDL
|
|
interface. If the <code>stringifier</code> keyword
|
|
was used on an <a class="dfnref" href="#dfn-attribute">attribute</a> <var>A</var>,
|
|
then, assuming <var>O</var> is the object on which
|
|
the method was invoked, the behavior of the overridden
|
|
<code>toString</code> method <span class="rfc2119">MUST</span>
|
|
be as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>R</var> be the result of invoking the <a class="dfnref" href="#dfn-getter-method">getter
|
|
method</a> on <var>O</var> that corresponds to the IDL
|
|
<a class="dfnref" href="#dfn-attribute">attribute</a>
|
|
<var>A</var>.
|
|
</li>
|
|
<li>Return <var>R</var>.</li>
|
|
</ol>
|
|
<p>
|
|
Otherwise, if the <code>stringifier</code> keyword
|
|
was used on an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
<var>O</var> with an <a class="dfnref" href="#dfn-identifier">identifier</a>,
|
|
then, assuming <var>O</var> is the object on which
|
|
the method was invoked, the behavior of the overridden
|
|
<code>toString</code> method <span class="rfc2119">MUST</span>
|
|
be as follows:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>
|
|
Let <var>R</var> be the result of invoking the method on <var>O</var> that corresponds to the IDL
|
|
<a class="dfnref" href="#dfn-operation">operation</a>
|
|
<var>O</var>, passing no arguments.
|
|
</li>
|
|
<li>Return <var>R</var>.</li>
|
|
</ol>
|
|
<p>
|
|
Otherwise, if the <code>stringifier</code> keyword
|
|
was used on an <a class="dfnref" href="#dfn-operation">operation</a>
|
|
without an <a class="dfnref" href="#dfn-identifier">identifier</a>, then
|
|
the behavior of the overridden <code>toString()</code>
|
|
method is the <a class="dfnref" href="#dfn-stringification-behavior">stringification behavior</a>
|
|
of the IDL interface, as described in the prose for the IDL interface.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="java-user-objects" class="section">
|
|
<h3>5.6. User objects implementing interfaces</h3>
|
|
|
|
<p>
|
|
A Java <a class="dfnref" href="#dfn-user-object">user object</a> that implements an IDL <a class="dfnref" href="#dfn-interface">interface</a>
|
|
<span class="rfc2119">MUST</span> be of a Java class that implements the Java interface
|
|
that corresponds to the IDL interface, either by implementing the interface directly
|
|
on that class or by inheriting from another class that implements the interface.
|
|
</p>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>For example, with the following IDL:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">[Callback]
|
|
interface Base {
|
|
void f();
|
|
};
|
|
|
|
[Callback]
|
|
interface Derived : Base {
|
|
void g();
|
|
};</code></pre></div></div>
|
|
<p>the Java implementation would provide the following interfaces:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">public interface Base {
|
|
void f();
|
|
}
|
|
|
|
public interface Derived extends Base {
|
|
void g();
|
|
}</code></pre></div></div>
|
|
<p>and <a class="dfnref" href="#dfn-user-object">user objects</a> implementing <span class="idltype">Derived</span>
|
|
could be defined like the following:</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code"><span class="comment">// Directly implementing the interface</span>
|
|
class DerivedImpl1 implements Derived {
|
|
public void f() { ... }
|
|
public void g() { ... }
|
|
}
|
|
|
|
<span class="comment">// Inheriting from a class that implements the interface</span>
|
|
class DerivedImpl2 extends DerivedImpl1 { }</code></pre></div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-exceptions" class="section">
|
|
<h3>5.7. Exceptions</h3>
|
|
<p>
|
|
For every IDL <a class="dfnref" href="#dfn-exception">exception</a>, there
|
|
<span class="rfc2119">MUST</span> exist a corresponding Java class
|
|
whose name is the <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> of the IDL exception and which
|
|
resides in the Java package corresponding to the exception’s
|
|
<a class="dfnref" href="#dfn-enclosing-module">enclosing module</a>.
|
|
</p>
|
|
<p>
|
|
The Java class <span class="rfc2119">MUST</span> have only the <code>public</code> modifier.
|
|
If the IDL exception <a class="dfnref" href="#dfn-inherit-exception">inherits</a> from another
|
|
exception, then the Java class <span class="rfc2119">MUST</span> be declared to extend
|
|
the Java class corresponding to that inherited exception. Otherwise, the Java class <span class="rfc2119">MUST</span>
|
|
be declared to extend <span class="javatype">java.lang.RuntimeException</span>.
|
|
</p>
|
|
<p>
|
|
The class <span class="rfc2119">MUST</span> also have constructors and methods with definitions as follows,
|
|
where <var>ExceptionName</var> is the name of the class:
|
|
</p>
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">Java</span></div><div class="blockContent"><pre class="code"><code class="java-code">public <var>ExceptionName</var>() {
|
|
}
|
|
|
|
public <var>ExceptionName</var>(String message) {
|
|
super(message);
|
|
}
|
|
|
|
public <var>ExceptionName</var>(String message, Throwable cause) {
|
|
super(message, cause);
|
|
}
|
|
|
|
public <var>ExceptionName</var>(Throwable cause) {
|
|
super(cause);
|
|
}</code></pre></div></div>
|
|
<div id="java-exception-constants" class="section">
|
|
<h4>5.7.1. Constants</h4>
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-constant">constant</a> defined on the
|
|
exception, there
|
|
<span class="rfc2119">MUST</span> be a corresponding constant declared on the Java class
|
|
with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The constant has no modifiers.</li>
|
|
<li>
|
|
The type of the constant is the Java type that corresponds to the type of
|
|
the IDL constant, according to the rules in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
<li>
|
|
The name of the constant is the <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> of the constant.
|
|
</li>
|
|
<li>
|
|
The value of the constant is the result of <a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
the constant’s IDL value to a Java value, according to the rules
|
|
in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="java-exception-fields" class="section">
|
|
<h4>5.7.2. Exception fields</h4>
|
|
<p>
|
|
For each <a class="dfnref" href="#dfn-exception-field">exception field</a> defined on the
|
|
<a class="dfnref" href="#dfn-exception">exception</a>, there
|
|
<span class="rfc2119">MUST</span> be a corresponding instance variable declared on the Java class
|
|
with the following characteristics:
|
|
</p>
|
|
<ul>
|
|
<li>The instance variable has only the modifier <code>public</code>.</li>
|
|
<li>
|
|
The type of the instance variable is the Java type that corresponds to the type of
|
|
the IDL exception field, according to the rules in <a href="#java-type-mapping">section 5.2</a>
|
|
above.
|
|
</li>
|
|
<li>
|
|
The name of the instance variable is the <a class="dfnref" href="#dfn-java-escaped">Java escaped</a>
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a> of the exception field.
|
|
</li>
|
|
<li>
|
|
The instance variable is not declared with an initializer.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="java-exception-throwing" class="section">
|
|
<h4>5.8. Throwing exceptions</h4>
|
|
<p>
|
|
When an <a class="dfnref" href="#dfn-exception">exception</a> of type
|
|
<var>E</var> is to be <a class="dfnref" href="#dfn-throw">thrown</a>,
|
|
with an optional message <var>M</var>, the following steps
|
|
<span class="rfc2119">MUST</span> be followed:
|
|
</p>
|
|
<ol class="algorithm">
|
|
<li>Let <var>C</var> be the corresponding Java class for <var>E</var>.</li>
|
|
<li>Let <var>O</var> be the result of constructing a new object of class <var>C</var>.
|
|
When invoking the constructor, the result of
|
|
<a class="dfnref" href="#dfn-convert-idl-to-java-value">converting</a>
|
|
<var>M</var> to a <span class="javatype">java.lang.String</span> object to
|
|
is used as the constructor’s sole argument, if <var>M</var> was specified.
|
|
If <var>M</var> was not specified, no arguments are passed to the constructor.</li>
|
|
<li>Throw <var>O</var>.</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="common" class="section">
|
|
<h2>6. Common definitions</h2>
|
|
|
|
<p>
|
|
This section specifies some common definitions that all
|
|
<a class="dfnref" href="#dfn-conforming-implementation">conforming implementations</a>
|
|
<span class="rfc2119">MUST</span> support.
|
|
</p>
|
|
|
|
<div id="common-DOMTimeStamp" class="section">
|
|
<h3>6.1. DOMTimeStamp</h3>
|
|
|
|
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">typedef unsigned long long DOMTimeStamp;</code></pre></div></div>
|
|
<p>
|
|
The <span class="idltype">DOMTimeStamp</span> type is used for representing
|
|
a number of milliseconds, either as an absolute time (relative to some epoch)
|
|
or as a relative amount of time. Specifications that use this type will need
|
|
to define how the number of milliseconds is to be interpreted.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="extensibility" class="section">
|
|
<h2>7. Extensibility</h2>
|
|
|
|
<p class="norm">This section is informative.</p>
|
|
|
|
<p>
|
|
Extensions to language binding requirements can be specified
|
|
using <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
that do not conflict with those defined in this document. Extensions for
|
|
private, project-specific use should not be included in
|
|
<a class="dfnref" href="#dfn-idl-fragment">IDL fragments</a>
|
|
appearing in other specifications. It is recommended that extensions
|
|
that are required for use in other specifications be coordinated
|
|
with the group responsible for work on <cite>Web IDL</cite>, which
|
|
at the time of writing is the
|
|
<a href="http://www.w3.org/2008/webapps/">W3C Web Applications Working Group</a>,
|
|
for possible inclusion in a future version of this document.
|
|
</p>
|
|
<p>
|
|
Extensions to any other aspect of the IDL language are
|
|
strongly discouraged.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="referencing" class="section">
|
|
<h2>8. Referencing this specification</h2>
|
|
|
|
<p class="norm">This section is informative.</p>
|
|
|
|
<p>
|
|
It is expected that other specifications that define DOM interfaces
|
|
using a <a class="dfnref" href="#dfn-conforming-idl-fragment">conforming
|
|
IDL fragment</a> will reference this specification. It is suggested
|
|
that those specifications include a sentence such as the following,
|
|
to indicate that the IDL is to be interpreted as described in this
|
|
specification:
|
|
</p>
|
|
<blockquote>
|
|
<p>
|
|
The IDL fragment in Appendix A of this specification must be interpreted
|
|
as required for <em>conforming IDL fragments</em>, as described in the
|
|
“Web IDL” specification. <a class="placeholder">[WEBIDL]</a>
|
|
</p>
|
|
</blockquote>
|
|
<p>
|
|
In addition, it is suggested that the conformance class for user
|
|
agents in referencing specifications be linked to the
|
|
<a class="dfnref" href="#dfn-conforming-implementation">conforming
|
|
implementation</a> class from this specification:
|
|
</p>
|
|
<blockquote>
|
|
<p>
|
|
A conforming FooML user agent must also be a
|
|
<em>conforming implementation</em> of the IDL fragment in Appendix A
|
|
of this specification, as described in the
|
|
“Web IDL” specification. <a class="placeholder">[WEBIDL]</a>
|
|
</p>
|
|
</blockquote>
|
|
</div>
|
|
|
|
<div id="acknowledgements" class="section">
|
|
<h2>9. Acknowledgements</h2>
|
|
|
|
<p class="norm">This section is informative.</p>
|
|
|
|
<p>
|
|
The editor would like to thank the following people for contributing
|
|
to this specification:
|
|
Glenn Adams,
|
|
David Andersson,
|
|
L. David Baron,
|
|
Robin Berjon,
|
|
Giovanni Campagna,
|
|
Brendan Eich,
|
|
Gorm Haug Eriksen,
|
|
David Flanagan,
|
|
Aryeh Gregor,
|
|
Marcin Hanclik,
|
|
Jed Hartman,
|
|
Dominique Hazaël-Massieux,
|
|
Ian Hickson,
|
|
Björn Höhrmann,
|
|
Dimitry Golubovsky,
|
|
Kartikaya Gupta,
|
|
James Graham,
|
|
Aryeh Gregor,
|
|
Magnus Kristiansen,
|
|
Mark Miller,
|
|
Lachlan Hunt,
|
|
Oliver Hunt,
|
|
Jim Jewett,
|
|
Anne van Kesteren,
|
|
Jim Ley,
|
|
Travis Leithead,
|
|
Kevin Lindsey,
|
|
Ms2ger,
|
|
Andrew Oakley,
|
|
岡坂 史紀 (Shiki Okasaka),
|
|
Simon Pieters,
|
|
Andrei Popescu,
|
|
Tim Renouf,
|
|
Jonas Sicking,
|
|
Garrett Smith,
|
|
Geoffrey Sneddon,
|
|
Josh Soref,
|
|
Maciej Stachowiak,
|
|
Jeff Walden,
|
|
Allen Wirfs-Brock,
|
|
Collin Xu and
|
|
Boris Zbarsky.
|
|
</p>
|
|
<p>
|
|
Special thanks also go to Sam Weinig for maintaining this document
|
|
while the editor was unavailable to do so.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="appendices">
|
|
<div id="idl-grammar" class="section">
|
|
<h2>A. IDL grammar</h2>
|
|
|
|
<p>
|
|
This section defines an LL(1) grammar whose start symbol,
|
|
<a class="sym" href="#prod-Definitions">Definitions</a>, matches an
|
|
entire <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>.
|
|
</p>
|
|
|
|
<p>
|
|
Each production in the grammar has on its right hand side either a
|
|
non-zero sequence of terminal and non-terminal symbols, or an
|
|
epsilon (ε) which indicates no symbols. Symbols that begin with
|
|
an uppercase letter are non-terminal symbols. Symbols within quotes
|
|
are terminal symbols that are matched with the exact text between
|
|
the quotes. Symbols that begin with a lowercase letter are terminal
|
|
symbols that are matched by the regular expressions (using Perl 5 regular
|
|
expression syntax <a href="#ref-PERLRE">[PERLRE]</a>) as follows:
|
|
</p>
|
|
<table class="grammar">
|
|
<tr>
|
|
<td id="prod-integer" class="sym">integer</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">-?(0([0-7]*|[Xx][0-9A-Fa-f]+)|[1-9][0-9]*)</td>
|
|
</tr>
|
|
<tr>
|
|
<td id="prod-float" class="sym">float</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)</td>
|
|
</tr>
|
|
<tr>
|
|
<td id="prod-identifier" class="sym">identifier</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">[A-Z_a-z][0-9A-Z_a-z]*</td>
|
|
</tr>
|
|
<tr>
|
|
<td id="prod-string" class="sym">string</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">"[^"]*"</td>
|
|
</tr>
|
|
<tr>
|
|
<td id="prod-whitespace" class="sym">whitespace</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">[\t\n\r ]+|[\t\n\r ]*((//.*|/\*.*?\*/)[\t\n\r ]*)+</td>
|
|
</tr>
|
|
<tr>
|
|
<td id="prod-other" class="sym">other</td>
|
|
<td class="regex">=</td>
|
|
<td class="regex">[^\t\n\r 0-9A-Z_a-z]</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>
|
|
The tokenizer operates on a sequence of Unicode characters
|
|
<a href="#ref-UNICODE">[UNICODE]</a>.
|
|
When tokenizing, the longest possible match <span class="rfc2119">MUST</span> be used. For example, if the input
|
|
text is “<span class="input">a1</span>”, it is tokenized as a single <span class="sym">identifier</span>,
|
|
and not as a separate <span class="sym">identifier</span> and <span class="sym">integer</span>.
|
|
If the longest possible match could match both an <span class="sym">identifier</span> and
|
|
one of the quoted terminal symbols from the grammar, it <span class="rfc2119">MUST</span> be tokenized as the quoted
|
|
terminal symbol. Thus, the input text “<span class="input">long</span>” is tokenized as the quoted terminal symbol
|
|
<span class="sym">"long"</span> rather than an <span class="sym">identifier</span> called “long”.
|
|
</p>
|
|
<p>
|
|
The IDL syntax is case sensitive, both for the quoted terminal symbols
|
|
used in the grammar and the values used for
|
|
<span class="sym">identifier</span> terminals. Thus, for
|
|
example, the input text “<span class="input">Const</span>” is tokenized as
|
|
an <span class="sym">identifier</span> rather than the quoted
|
|
terminal symbol <span class="sym">"const"</span>, an
|
|
<a class="dfnref" href="#dfn-interface">interface</a> with
|
|
<a class="dfnref" href="#dfn-identifier">identifier</a>
|
|
“A” is distinct from one named “a”, and an
|
|
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
|
|
<span class="xattr">[constructor]</span> will not be recognized as
|
|
the <a class="xattr" href="#Constructor">[Constructor]</a>
|
|
extended attribute.
|
|
</p>
|
|
<p>
|
|
Implicitly, the <span class="sym">whitespace</span> terminal is allowed between every terminal
|
|
in the input text being parsed. Such <span class="sym">whitespace</span> terminals, which
|
|
actually encompass both whitespace and comments, are ignored while parsing.
|
|
</p>
|
|
|
|
<p>
|
|
The following LL(1) grammar, starting with <a class="sym" href="#prod-Definitions">Definitions</a>,
|
|
matches an <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>:
|
|
</p>
|
|
|
|
<table class="grammar"><tr id="prod-Definitions"><td><span class="prod-number">[1]</span></td><td><a class="sym" href="#proddef-Definitions">Definitions</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Definition">Definition</a> <a class="sym" href="#prod-Definitions">Definitions</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Definition"><td><span class="prod-number">[2]</span></td><td><a class="sym" href="#proddef-Definition">Definition</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-NormalDefinition">NormalDefinition</a> <br /> |
|
|
<a class="sym" href="#prod-PartialInterface">PartialInterface</a></span></td></tr><tr id="prod-NormalDefinition"><td><span class="prod-number">[3]</span></td><td><a class="sym" href="#proddef-NormalDefinition">NormalDefinition</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Module">Module</a> <br /> |
|
|
<a class="sym" href="#prod-Interface">Interface</a> <br /> |
|
|
<a class="sym" href="#prod-Dictionary">Dictionary</a> <br /> |
|
|
<a class="sym" href="#prod-Exception">Exception</a> <br /> |
|
|
<a class="sym" href="#prod-Typedef">Typedef</a> <br /> |
|
|
<a class="sym" href="#prod-ImplementsStatement">ImplementsStatement</a></span></td></tr><tr id="prod-Module"><td><span class="prod-number">[4]</span></td><td><a class="sym" href="#proddef-Module">Module</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"module" <a class="sym" href="#prod-identifier">identifier</a> "{" <a class="sym" href="#prod-Definitions">Definitions</a> "}" ";"</span></td></tr><tr id="prod-Interface"><td><span class="prod-number">[5]</span></td><td><a class="sym" href="#proddef-Interface">Interface</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"interface" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> "}" ";"</span></td></tr><tr id="prod-PartialInterface"><td><span class="prod-number">[6]</span></td><td><a class="sym" href="#proddef-PartialInterface">PartialInterface</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"partial" "interface" <a class="sym" href="#prod-identifier">identifier</a> "{" <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> "}" ";"</span></td></tr><tr id="prod-Inheritance"><td><span class="prod-number">[7]</span></td><td><a class="sym" href="#proddef-Inheritance">Inheritance</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">":" <a class="sym" href="#prod-ScopedName">ScopedName</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-InterfaceMembers"><td><span class="prod-number">[8]</span></td><td><a class="sym" href="#proddef-InterfaceMembers">InterfaceMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-InterfaceMember">InterfaceMember</a> <a class="sym" href="#prod-InterfaceMembers">InterfaceMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-InterfaceMember"><td><span class="prod-number">[9]</span></td><td><a class="sym" href="#proddef-InterfaceMember">InterfaceMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Const">Const</a> <br /> |
|
|
<a class="sym" href="#prod-AttributeOrOperation">AttributeOrOperation</a></span></td></tr><tr id="prod-Dictionary"><td><span class="prod-number">[10]</span></td><td><a class="sym" href="#proddef-Dictionary">Dictionary</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"dictionary" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-DictionaryMembers">DictionaryMembers</a> "}" ";"</span></td></tr><tr id="prod-DictionaryMembers"><td><span class="prod-number">[11]</span></td><td><a class="sym" href="#proddef-DictionaryMembers">DictionaryMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-DictionaryMember">DictionaryMember</a> <a class="sym" href="#prod-DictionaryMembers">DictionaryMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-DictionaryMember"><td><span class="prod-number">[12]</span></td><td><a class="sym" href="#proddef-DictionaryMember">DictionaryMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-DefaultValue">DefaultValue</a> ";"</span></td></tr><tr id="prod-DefaultValue"><td><span class="prod-number">[13]</span></td><td><a class="sym" href="#proddef-DefaultValue">DefaultValue</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"=" <a class="sym" href="#prod-ConstValue">ConstValue</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Exception"><td><span class="prod-number">[14]</span></td><td><a class="sym" href="#proddef-Exception">Exception</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"exception" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-Inheritance">Inheritance</a> "{" <a class="sym" href="#prod-ExceptionMembers">ExceptionMembers</a> "}" ";"</span></td></tr><tr id="prod-ExceptionMembers"><td><span class="prod-number">[15]</span></td><td><a class="sym" href="#proddef-ExceptionMembers">ExceptionMembers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-ExceptionMember">ExceptionMember</a> <a class="sym" href="#prod-ExceptionMembers">ExceptionMembers</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Typedef"><td><span class="prod-number">[16]</span></td><td><a class="sym" href="#proddef-Typedef">Typedef</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"typedef" <a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr><tr id="prod-ImplementsStatement"><td><span class="prod-number">[17]</span></td><td><a class="sym" href="#proddef-ImplementsStatement">ImplementsStatement</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ScopedName">ScopedName</a> "implements" <a class="sym" href="#prod-ScopedName">ScopedName</a> ";"</span></td></tr><tr id="prod-Const"><td><span class="prod-number">[18]</span></td><td><a class="sym" href="#proddef-Const">Const</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"const" <a class="sym" href="#prod-ConstType">ConstType</a> <a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-ConstValue">ConstValue</a> ";"</span></td></tr><tr id="prod-ConstValue"><td><span class="prod-number">[19]</span></td><td><a class="sym" href="#proddef-ConstValue">ConstValue</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-BooleanLiteral">BooleanLiteral</a> <br /> |
|
|
<a class="sym" href="#prod-integer">integer</a> <br /> |
|
|
<a class="sym" href="#prod-float">float</a> <br /> |
|
|
<a class="sym" href="#prod-string">string</a> <br /> |
|
|
"null"</span></td></tr><tr id="prod-BooleanLiteral"><td><span class="prod-number">[20]</span></td><td><a class="sym" href="#proddef-BooleanLiteral">BooleanLiteral</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"true" <br /> |
|
|
"false"</span></td></tr><tr id="prod-AttributeOrOperation"><td><span class="prod-number">[21]</span></td><td><a class="sym" href="#proddef-AttributeOrOperation">AttributeOrOperation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"stringifier" <a class="sym" href="#prod-StringifierAttributeOrOperation">StringifierAttributeOrOperation</a> <br /> |
|
|
<a class="sym" href="#prod-Attribute">Attribute</a> <br /> |
|
|
<a class="sym" href="#prod-Operation">Operation</a></span></td></tr><tr id="prod-StringifierAttributeOrOperation"><td><span class="prod-number">[22]</span></td><td><a class="sym" href="#proddef-StringifierAttributeOrOperation">StringifierAttributeOrOperation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Attribute">Attribute</a> <br /> |
|
|
<a class="sym" href="#prod-OperationRest">OperationRest</a> <br /> |
|
|
";"</span></td></tr><tr id="prod-Attribute"><td><span class="prod-number">[23]</span></td><td><a class="sym" href="#proddef-Attribute">Attribute</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Inherit">Inherit</a> <a class="sym" href="#prod-ReadOnly">ReadOnly</a> "attribute" <a class="sym" href="#prod-AttributeType">AttributeType</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr><tr id="prod-ReadOnly"><td><span class="prod-number">[24]</span></td><td><a class="sym" href="#proddef-ReadOnly">ReadOnly</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"readonly" <br /> |
|
|
ε</span></td></tr><tr id="prod-Inherit"><td><span class="prod-number">[25]</span></td><td><a class="sym" href="#proddef-Inheritance">Inherit</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"inherit" <br /> |
|
|
ε</span></td></tr><tr id="prod-Operation"><td><span class="prod-number">[26]</span></td><td><a class="sym" href="#proddef-Operation">Operation</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Qualifiers">Qualifiers</a> <a class="sym" href="#prod-OperationRest">OperationRest</a></span></td></tr><tr id="prod-Qualifiers"><td><span class="prod-number">[27]</span></td><td><a class="sym" href="#proddef-Qualifiers">Qualifiers</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"static" <br /> |
|
|
<a class="sym" href="#prod-Specials">Specials</a></span></td></tr><tr id="prod-Specials"><td><span class="prod-number">[28]</span></td><td><a class="sym" href="#proddef-Specials">Specials</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Special">Special</a> <a class="sym" href="#prod-Specials">Specials</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Special"><td><span class="prod-number">[29]</span></td><td><a class="sym" href="#proddef-Special">Special</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"getter" <br /> |
|
|
"setter" <br /> |
|
|
"creator" <br /> |
|
|
"deleter" <br /> |
|
|
"legacycaller"</span></td></tr><tr id="prod-OperationRest"><td><span class="prod-number">[30]</span></td><td><a class="sym" href="#proddef-OperationRest">OperationRest</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ReturnType">ReturnType</a> <a class="sym" href="#prod-OptionalIdentifier">OptionalIdentifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")" ";"</span></td></tr><tr id="prod-OptionalIdentifier"><td><span class="prod-number">[31]</span></td><td><a class="sym" href="#proddef-OptionalIdentifier">OptionalIdentifier</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-ArgumentList"><td><span class="prod-number">[32]</span></td><td><a class="sym" href="#proddef-ArgumentList">ArgumentList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Argument">Argument</a> <a class="sym" href="#prod-Arguments">Arguments</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Arguments"><td><span class="prod-number">[33]</span></td><td><a class="sym" href="#proddef-Arguments">Arguments</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"," <a class="sym" href="#prod-Argument">Argument</a> <a class="sym" href="#prod-Arguments">Arguments</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Argument"><td><span class="prod-number">[34]</span></td><td><a class="sym" href="#proddef-Argument">Argument</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttributeList">ExtendedAttributeList</a> <a class="sym" href="#prod-Optional">Optional</a> <a class="sym" href="#prod-Type">Type</a> <a class="sym" href="#prod-Ellipsis">Ellipsis</a> <a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="prod-Optional"><td><span class="prod-number">[35]</span></td><td><a class="sym" href="#proddef-Optional">Optional</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"optional" <br /> |
|
|
ε</span></td></tr><tr id="prod-Ellipsis"><td><span class="prod-number">[36]</span></td><td><a class="sym" href="#proddef-Ellipsis">Ellipsis</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"..." <br /> |
|
|
ε</span></td></tr><tr id="prod-ExceptionMember"><td><span class="prod-number">[37]</span></td><td><a class="sym" href="#proddef-ExceptionMember">ExceptionMember</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Const">Const</a> <br /> |
|
|
<a class="sym" href="#prod-ExceptionField">ExceptionField</a></span></td></tr><tr id="prod-ExceptionField"><td><span class="prod-number">[38]</span></td><td><a class="sym" href="#proddef-ExceptionField">ExceptionField</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AttributeType">AttributeType</a> <a class="sym" href="#prod-identifier">identifier</a> ";"</span></td></tr><tr id="prod-ExtendedAttributeList"><td><span class="prod-number">[39]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeList">ExtendedAttributeList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <a class="sym" href="#prod-ExtendedAttributes">ExtendedAttributes</a> "]" <br /> |
|
|
ε</span></td></tr><tr id="prod-ExtendedAttributes"><td><span class="prod-number">[40]</span></td><td><a class="sym" href="#proddef-ExtendedAttributes">ExtendedAttributes</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"," <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <a class="sym" href="#prod-ExtendedAttributes">ExtendedAttributes</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-ExtendedAttribute"><td><span class="prod-number">[41]</span></td><td><a class="sym" href="#proddef-ExtendedAttribute">ExtendedAttribute</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
"(" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> ")" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
"[" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "]" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
"{" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "}" <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
<br /> |
|
|
<a class="sym" href="#prod-Other">Other</a> <a class="sym" href="#prod-ExtendedAttributeRest">ExtendedAttributeRest</a>
|
|
</span></td></tr><tr id="prod-ExtendedAttributeRest"><td><span class="prod-number">[42]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeRest">ExtendedAttributeRest</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-ExtendedAttributeInner"><td><span class="prod-number">[43]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeInner">ExtendedAttributeInner</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
"(" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> ")" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
"[" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "]" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
"{" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a> "}" <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
<a class="sym" href="#prod-OtherOrComma">OtherOrComma</a> <a class="sym" href="#prod-ExtendedAttributeInner">ExtendedAttributeInner</a>
|
|
<br /> |
|
|
ε
|
|
</span></td></tr><tr id="prod-Other"><td><span class="prod-number">[44]</span></td><td><a class="sym" href="#proddef-Other">Other</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">
|
|
<a class="sym" href="#prod-integer">integer</a> <br /> |
|
|
<a class="sym" href="#prod-float">float</a> <br /> |
|
|
<a class="sym" href="#prod-identifier">identifier</a> <br /> |
|
|
<a class="sym" href="#prod-string">string</a> <br /> |
|
|
<a class="sym" href="#prod-other">other</a>
|
|
<br /> |
|
|
"..." <br /> |
|
|
":" <br /> |
|
|
"::" <br /> |
|
|
";" <br /> |
|
|
"<" <br /> |
|
|
"=" <br /> |
|
|
">" <br /> |
|
|
"?"
|
|
<br /> |
|
|
"Date" <br /> |
|
|
"DOMString" <br /> |
|
|
"any" <br /> |
|
|
"attribute" <br /> |
|
|
"boolean" <br /> |
|
|
"byte"
|
|
<br /> |
|
|
"legacycaller" <br /> |
|
|
"const" <br /> |
|
|
"creator" <br /> |
|
|
"deleter" <br /> |
|
|
"double"
|
|
<br /> |
|
|
"exception" <br /> |
|
|
"false" <br /> |
|
|
"float" <br /> |
|
|
"getter" <br /> |
|
|
"implements"
|
|
<br /> |
|
|
"inherit" <br /> |
|
|
"interface" <br /> |
|
|
"long" <br /> |
|
|
"module" <br /> |
|
|
"null" <br /> |
|
|
"object" <br /> |
|
|
"octet"
|
|
<br /> |
|
|
"optional" <br /> |
|
|
"sequence"
|
|
<br /> |
|
|
"setter" <br /> |
|
|
"short" <br /> |
|
|
"static" <br /> |
|
|
"stringifier" <br /> |
|
|
"true" <br /> |
|
|
"typedef"
|
|
<br /> |
|
|
"unsigned" <br /> |
|
|
"void"
|
|
</span></td></tr><tr id="prod-OtherOrComma"><td><span class="prod-number">[45]</span></td><td><a class="sym" href="#proddef-OtherOrComma">OtherOrComma</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Other">Other</a> <br /> |
|
|
","</span></td></tr><tr id="prod-Type"><td><span class="prod-number">[46]</span></td><td><a class="sym" href="#proddef-Type">Type</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AttributeType">AttributeType</a> <br /> |
|
|
<a class="sym" href="#prod-SequenceType">SequenceType</a></span></td></tr><tr id="prod-SequenceType"><td><span class="prod-number">[47]</span></td><td><a class="sym" href="#proddef-SequenceType">SequenceType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"sequence" "<" <a class="sym" href="#prod-Type">Type</a> ">" <a class="sym" href="#prod-Null">Null</a></span></td></tr><tr id="prod-AttributeType"><td><span class="prod-number">[48]</span></td><td><a class="sym" href="#proddef-AttributeType">AttributeType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-PrimitiveOrStringType">PrimitiveOrStringType</a> <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
<a class="sym" href="#prod-ScopedName">ScopedName</a> <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"object" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"Date" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"any" <a class="sym" href="#prod-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a></span></td></tr><tr id="prod-ConstType"><td><span class="prod-number">[49]</span></td><td><a class="sym" href="#proddef-ConstType">ConstType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-PrimitiveOrStringType">PrimitiveOrStringType</a> <a class="sym" href="#prod-Null">Null</a></span></td></tr><tr id="prod-PrimitiveOrStringType"><td><span class="prod-number">[50]</span></td><td><a class="sym" href="#proddef-PrimitiveOrStringType">PrimitiveOrStringType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-UnsignedIntegerType">UnsignedIntegerType</a> <br /> |
|
|
"boolean" <br /> |
|
|
"byte" <br /> |
|
|
"octet" <br /> |
|
|
"float" <br /> |
|
|
"double" <br /> |
|
|
"DOMString"</span></td></tr><tr id="prod-UnsignedIntegerType"><td><span class="prod-number">[51]</span></td><td><a class="sym" href="#proddef-UnsignedIntegerType">UnsignedIntegerType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"unsigned" <a class="sym" href="#prod-IntegerType">IntegerType</a> <br /> |
|
|
<a class="sym" href="#prod-IntegerType">IntegerType</a></span></td></tr><tr id="prod-IntegerType"><td><span class="prod-number">[52]</span></td><td><a class="sym" href="#proddef-IntegerType">IntegerType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"short" <br /> |
|
|
"long" <a class="sym" href="#prod-OptionalLong">OptionalLong</a></span></td></tr><tr id="prod-OptionalLong"><td><span class="prod-number">[53]</span></td><td><a class="sym" href="#proddef-OptionalLong">OptionalLong</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"long" <br /> |
|
|
ε</span></td></tr><tr id="prod-TypeSuffix"><td><span class="prod-number">[54]</span></td><td><a class="sym" href="#proddef-TypeSuffix">TypeSuffix</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" "]" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
"?" <a class="sym" href="#prod-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-TypeSuffixStartingWithArray"><td><span class="prod-number">[55]</span></td><td><a class="sym" href="#proddef-TypeSuffixStartingWithArray">TypeSuffixStartingWithArray</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"[" "]" <a class="sym" href="#prod-TypeSuffix">TypeSuffix</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-Null"><td><span class="prod-number">[56]</span></td><td><a class="sym" href="#proddef-Null">Null</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"?" <br /> |
|
|
ε</span></td></tr><tr id="prod-ReturnType"><td><span class="prod-number">[57]</span></td><td><a class="sym" href="#proddef-ReturnType">ReturnType</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-Type">Type</a> <br /> |
|
|
"void"</span></td></tr><tr id="prod-ScopedName"><td><span class="prod-number">[58]</span></td><td><a class="sym" href="#proddef-ScopedName">ScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-AbsoluteScopedName">AbsoluteScopedName</a> <br /> |
|
|
<a class="sym" href="#prod-RelativeScopedName">RelativeScopedName</a></span></td></tr><tr id="prod-AbsoluteScopedName"><td><span class="prod-number">[59]</span></td><td><a class="sym" href="#proddef-AbsoluteScopedName">AbsoluteScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"::" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a></span></td></tr><tr id="prod-RelativeScopedName"><td><span class="prod-number">[60]</span></td><td><a class="sym" href="#proddef-RelativeScopedName">RelativeScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a></span></td></tr><tr id="prod-ScopedNameParts"><td><span class="prod-number">[61]</span></td><td><a class="sym" href="#proddef-ScopedNameParts">ScopedNameParts</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines">"::" <a class="sym" href="#prod-identifier">identifier</a> <a class="sym" href="#prod-ScopedNameParts">ScopedNameParts</a> <br /> |
|
|
ε</span></td></tr><tr id="prod-ExtendedAttributeNoArgs"><td><span class="prod-number">[62]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeNoArgs">ExtendedAttributeNoArgs</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="prod-ExtendedAttributeArgList"><td><span class="prod-number">[63]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeArgList">ExtendedAttributeArgList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")"</span></td></tr><tr id="prod-ExtendedAttributeIdent"><td><span class="prod-number">[64]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeIdent">ExtendedAttributeIdent</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-identifier">identifier</a></span></td></tr><tr id="prod-ExtendedAttributeScopedName"><td><span class="prod-number">[65]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeScopedName">ExtendedAttributeScopedName</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-ScopedName">ScopedName</a></span></td></tr><tr id="prod-ExtendedAttributeNamedArgList"><td><span class="prod-number">[66]</span></td><td><a class="sym" href="#proddef-ExtendedAttributeNamedArgList">ExtendedAttributeNamedArgList</a></td><td class="prod-mid">→</td><td class="prod-rhs"><span class="prod-lines"><a class="sym" href="#prod-identifier">identifier</a> "=" <a class="sym" href="#prod-identifier">identifier</a> "(" <a class="sym" href="#prod-ArgumentList">ArgumentList</a> ")"</span></td></tr></table>
|
|
<div class="note"><div class="noteHeader">Note</div>
|
|
<p>
|
|
The choices listed for the <a class="sym" href="#prod-Other">Other</a>
|
|
non-terminal are all of the terminal symbols except for
|
|
<span class="sym">"("</span>, <span class="sym">")"</span>,
|
|
<span class="sym">"["</span>, <span class="sym">"]"</span>,
|
|
<span class="sym">"{"</span>, <span class="sym">"}"</span>
|
|
and <span class="sym">","</span>.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
While the <a class="sym" href="#prod-ExtendedAttribute">ExtendedAttribute</a>
|
|
non-terminal matches any non-empty sequence of terminal symbols (as long as any
|
|
parentheses, square brackets or braces are balanced, and the
|
|
<span class="sym">","</span> token appears only within those balanced brackets),
|
|
only a subset of those
|
|
possible sequences are used by the <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a>
|
|
defined in this specification — see
|
|
<a href="#idl-extended-attributes">section 3.10</a>
|
|
for the syntaxes that are used by these extended attributes.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="references" class="section">
|
|
<h2>B. References</h2>
|
|
|
|
<div id="normative-references" class="section">
|
|
<h3>B.1. Normative references</h3>
|
|
|
|
<dl>
|
|
<dt id="ref-ECMA-262">[ECMA-262]</dt>
|
|
<dd>
|
|
<cite><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript Language Specification, 5th Edition</a></cite>,
|
|
P. Lakshman and A. Wirfs-Brock, Editors. Ecma International, December 2009. Available at http://www.ecma-international.org/publications/standards/Ecma-262.htm.
|
|
</dd>
|
|
<dt id="ref-IEEE-754">[IEEE-754]</dt>
|
|
<dd>
|
|
<cite>IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985)</cite>.
|
|
Institute of Electrical and Electronics Engineers, 1985.
|
|
</dd>
|
|
<dt id="ref-JLS3">[JLS3]</dt>
|
|
<dd>
|
|
<cite><a href="http://java.sun.com/docs/books/jls/">The Java Language Specification, Third Edition</a></cite>.
|
|
J. Gosling, et al. Upper Saddle River, New Jersey, Addison-Wesley, 2005.
|
|
Available at http://java.sun.com/docs/books/jls/.
|
|
</dd>
|
|
<dt id="ref-PERLRE">[PERLRE]</dt>
|
|
<dd>
|
|
<cite><a href="http://search.cpan.org/dist/perl/pod/perlre.pod">Perl regular expressions (Perl 5.8.8)</a></cite>.
|
|
The Perl Foundation, February 2006. Available at http://www.perl.com/doc/manual/html/pod/perlre.html.
|
|
</dd>
|
|
<dt id="ref-RFC2119">[RFC2119]</dt>
|
|
<dd>
|
|
<cite><a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a></cite>,
|
|
S. Bradner. IETF, March 1997. Available at http://tools.ietf.org/html/rfc2119.
|
|
</dd>
|
|
<dt id="ref-RFC2781">[RFC2781]</dt>
|
|
<dd>
|
|
<cite><a href="http://tools.ietf.org/html/rfc2781">UTF-16, an encoding of ISO 10646</a></cite>,
|
|
P. Hoffmann and F. Yergeau. IETF, February 2000. Available at http://tools.ietf.org/html/rfc2781.
|
|
</dd>
|
|
<dt id="ref-UNICODE">[UNICODE]</dt>
|
|
<dd>
|
|
<cite><a href="http://www.unicode.org/standard/versions/">The Unicode Standard</a></cite>,
|
|
Version 6.0 or later. The Unicode Consortium. Mountain View, California, 2011.
|
|
ISBN 978-1-936213-01-6. Available at http://www.unicode.org/versions/Unicode6.0.0/.
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
<div id="informative-references" class="section">
|
|
<h3>B.2. Informative references</h3>
|
|
|
|
<dl>
|
|
<dt id="ref-DOM3CORE">[DOM3CORE]</dt>
|
|
<dd>
|
|
<cite><a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/">Document Object Model (DOM) Level 3 Core Specification</a></cite>.
|
|
A. Le Hors, et al., Editors. World Wide Web Consortium, April 2004. Available at http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/.
|
|
</dd>
|
|
<dt id="ref-HTML5">[HTML5]</dt>
|
|
<dd>
|
|
<cite><a href="http://www.w3.org/TR/2011/WD-html5-20110525/">HTML5</a></cite>.
|
|
I. Hickson, Editor. World Wide Web Consortium, May 2011. Available at http://www.w3.org/TR/2011/WD-html5-20110525/.
|
|
</dd>
|
|
<dt id="ref-OMGIDL">[OMGIDL]</dt>
|
|
<dd>
|
|
<cite><a href="http://www.omg.org/cgi-bin/doc?formal/08-01-04.pdf">CORBA 3.1 – OMG IDL Syntax and Semantics chapter</a></cite>.
|
|
Object Management Group, January 2008. Available at http://www.omg.org/cgi-bin/doc?formal/08-01-04.pdf.
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="changes" class="section">
|
|
<h2>C. Changes</h2>
|
|
<p>
|
|
The following is a list of substantial changes to the document on each publication.
|
|
</p>
|
|
<dl class="changes">
|
|
<dt>27 September 2011 – LCWD #2</dt>
|
|
<!--
|
|
<dt>Current editor’s draft</dt>
|
|
-->
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Changed exceptions to have an intrinsic type, and added recommendations
|
|
to specification authors on how to name exception types.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed <code>inherits getter</code> to <code>inherit</code>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Renamed “callers” to “legacy callers” to discourage their use.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added <span class="xattr">[EnforceRange]</span> which will cause an
|
|
exception to be thrown if an ECMAScript <span class="estype">Number</span>
|
|
is out of range (after rounding).
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Tweaked <span class="xattr">[Clamp]</span> so that it rounds to nearest
|
|
rather than floors.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Recommend against using <span class="xattr">[NoInterfaceObject]</span>
|
|
for non-supplemental interfaces.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added <span class="xattr">[ArrayClass]</span>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made trailing ECMAScript <span class="esvalue">undefined</span> values
|
|
in function calls be equivalent to missing optional parameters.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed <span class="xattr">[CopyInheritedPrototype]</span>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made the length property on platform array objects non-configurable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed <code>omittable</code>, since nobody is using it (and probably won’t,
|
|
unless considering non-ECMAScript language bindings). Instead, identifierless
|
|
special operations will map to methods with special names in the Java
|
|
language binding, rather than being left out altogether.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallows <span class="xattr">[NoInterfaceObject]</span> on interfaces
|
|
that have static operations.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed named properties “resolved before prototype properties”.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made ECMAScript namespace object properties enumerable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed raises, setraises and getraises clauses since they do not add any value.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added the <span class="xattr">[TreatNonCallableAsNull]</span> extended attribute.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made type conversion from an ECMAScript non-object value to an IDL dictionary value
|
|
throw an exception.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Specified that the “prototype” property of a named constructor
|
|
has the same value as the one on the interface object.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Specify <span class="prop">[[Call]]</span> for operations and add
|
|
an <span class="xattr">[ImplicitThis]</span> extended attribute
|
|
for use on <span class="idltype">Window</span>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Tweaked the names of Java getter and setter methods to avoid
|
|
conflicts with other interface members.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallowed definitions with special ECMAScript property names
|
|
and if they begin with a leading underscore.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Modified the overload resolution algorithm so that it works
|
|
with sequence types.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallows consequential interfaces from defining interface members whose
|
|
identifiers are the same as any of those on the original interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Renamed “name getter”, “index getter” and friends to “named property getter”,
|
|
“indexed property getter” and so on, since that’s a more accurate description
|
|
of what they are.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed the optional <code>in</code> keyword from arguments, since it serves no
|
|
useful purpose.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>12 July 2011 – LCWD #1</dt>
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Added some green boxes illustrating the syntax of the different IDL
|
|
constructs.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added IDL syntax to declare that a writable attribute inherits its
|
|
getter behavior from a read only attribute of the same name in
|
|
on an ancestor interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made all interface objects be <span class="estype">Function</span> objects,
|
|
regardless of whether they have a constructor.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added the notion of named properties being “resolved before prototype properties”
|
|
to handle the <span class="estype">Window</span> object’s odd treatment
|
|
of named properties.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Specified attributes of ECMAScript properties corresponding to stringifiers,
|
|
making them non-enumerable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Introduced the terms “platform object” and “user object” to distinguish
|
|
between objects provided by the implementation and those created and
|
|
supplied by the user of an API. Most of mentions of ECMAScript native
|
|
objects were replaced with “user object” and host objects with
|
|
“platform object”. Specific requirements on what ECMAScript objects can
|
|
be passed to platform objects expecting non-<span class="xattr">[Callback]</span>
|
|
interface types are now given.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an <span class="xattr">[Unforgeable]</span> extended attribute
|
|
to require properties corresponding to IDL attributes be non-configurable
|
|
and to appear as own properties on the object rather than on the prototype.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Allowed <span class="xattr">[Callback]</span> interfaces to inherit from
|
|
other <span class="xattr">[Callback]</span> interfaces.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed array host object prototype objects, since they didn’t have any
|
|
useful properties on them. Instead, the <span class="prop">[[Prototype]]</span>
|
|
of array host objects are now required to be the <span class="estype">Array</span>
|
|
prototype object.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[CopyInheritedPrototype]</span> extended attribute.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added support for partial interface definitions.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed mixin prototype objects from the ECMAScript binding. At the IDL level,
|
|
objects may now only implement a single inheritance hierarchy of interfaces,
|
|
plus any supplemental interfaces that are required due to “implements” statements.
|
|
Interface prototype objects for interfaces on the left-hand side of an
|
|
“implements” statement now also get properties for members of the interface
|
|
on the right-hand side of the statement.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Tweaked the ECMAScript overload resolution algorithm so that passing too few arguments
|
|
will result in an exception being thrown and passing more arguments than the longest
|
|
overload will mean those extra arguments will be ignored. Distinguishing which
|
|
overload is called when the overloads have the same argument list length is now
|
|
performed only on arguments where across all of the overloads, not all of
|
|
the types at that position are the same.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[ReplaceableNamedProperties]</span> extended attribute to control
|
|
whether named properties on an object can be replaced by assigning to them.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Required that ECMAScript host objects that support indexed and named properties
|
|
and for array host objects refuse to be fixed.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed the “toString” property from array host
|
|
objects, so that the one inherited from the
|
|
<span class="value">Array</span> prototype object is used instead.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the implementation requirements for ECMAScript host objects
|
|
that support indexed and named properties, and for array host objects,
|
|
to use specific <span class="prop">[[GetOwnProperty]]</span>
|
|
and <span class="prop">[[DefineOwnProperty]]</span> behavior, instead of
|
|
in terms of setting and removing own properties on the object.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallowed sequence and dictionary types from being used as an array
|
|
element type.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[Clamp]</span> extended attribute to control
|
|
how ECMAScript <span class="estype">Number</span> values are converted to
|
|
IDL integer values.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added the dictionary type and allowed <span class="idlvalue">null</span> to be specified
|
|
as the value of a constant or the default value of a dictionary member.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <a class="idltype" href="#idl-Date">Date</a> IDL type.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Point out that special operations for indexed and named properties can be overridden.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added requirements on the property enumeration order for indexed
|
|
and named properties.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Required that multiple ECMAScript global environments have independent
|
|
copies of interface objects, interface prototype objects, etc., and
|
|
defined which global environment’s objects are used when an exception
|
|
is thrown.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallowed sequence types from being used as attribute types.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed <span class="idlvalue">null</span> from the set of values for
|
|
interface types, <span class="idlvalue">object</span> and array types,
|
|
allowed those types to be nullable, and updated the overload resolution
|
|
algorithm to account for these changes.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made calling an ECMAScript <span class="estype">Function</span> that
|
|
corresponds to an IDL operation throw a <span class="estype">TypeError</span>
|
|
if the <span class="esvalue">this</span> value isn’t an object that
|
|
implements the right interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Add constructors to Java classes corresponding to IDL exceptions.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Define what it means to throw an IDL exception with a given message.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added “constructor” properties back to interface prototype objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Allowed exceptions to inherit from other exceptions, so that they can be more consistent
|
|
with native ECMAScript errors and so that we can move away from defining and using
|
|
integer exception codes.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Required that when calling an ECMAScript <span class="estype">Function</span> that
|
|
corresponds to an IDL interface, the argument values are converted to IDL values
|
|
in order from left to right.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made properties corresponding to operations enumerable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the interface object and exception interface object properties
|
|
on the global object to be configurable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a signed 8 bit integer types named <a class="idltype" href="#idl-byte">byte</a>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Expanded the allowable types for constants to include <a class="idltype" href="#idl-DOMString">DOMString</a>
|
|
and nullable primitives.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added support for static operations.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Fixed errors in the <span class="sym">float</span> and
|
|
<span class="sym">integer</span> grammar terminals.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added productions for array types to the grammar, which were missing.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a section for common IDL definitions that all conforming
|
|
implementations must support, the first entry in which is
|
|
a definition for the <span class="idltype">DOMTimeStamp</span>
|
|
type.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>21 October 2010 – WD</dt>
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Made constructors due to <span class="xattr">[Constructor]</span> and
|
|
<span class="xattr">[NamedConstructor]</span> callable. Their behavior
|
|
when called is the same as when used in a <code>new</code> expression.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Updated the ECMAScript language binding to target ECMAScript 5th edition,
|
|
the biggest part of which is that now interface attributes are
|
|
implemented as accessor properties.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Ensure that corresponding properties do not exist for constants,
|
|
attributes and operations named “constructor” or “toString”
|
|
if they would conflict with other requirements to have properties
|
|
with those names.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Moved properties corresponding to attributes from host object
|
|
instances to their interface prototype objects. Similarly, moved
|
|
properties corresponding to exception fields from host exception
|
|
objects to their exception interface prototype objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallow both <span class="xattr">[PutForwards]</span> and
|
|
<span class="xattr">[Replaceable]</span> appearing on the same
|
|
attribute.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Required that callable objects corresponding to operations
|
|
be <span class="estype">Function</span> objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the “constructor” property
|
|
on interface prototype objects to be writable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the “prototype” property on
|
|
interface and exception objects be non-enumerable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Allowed callers to be overloaded.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Defined the “length” property on
|
|
<span class="estype">Function</span> objects that correspond to operations and constructors.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed sequences to be passed by value, and added an array type
|
|
for ordered lists of values that are passed by reference.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed interface forward declarations and the requirement that interfaces
|
|
be declared before use.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made the <code>in</code> keyword in argument lists optional.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the <code>Object</code>,
|
|
<code>TRUE</code> and <code>FALSE</code>
|
|
keywords to be all lowercase.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Dropped <span class="xattr">[Optional]</span> and <span class="xattr">[Variadic]</span>
|
|
in favor of <code>optional</code> and <code>...</code> syntax.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Dropped <span class="xattr">[ImplementedOn]</span> in favor of an
|
|
<code>implements</code> statement.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Dropped <span class="xattr">[ExceptionConsts]</span> in favor of allowing
|
|
constants to be defined directly on exceptions. Defining constants on
|
|
modules is now disallowed.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed <span class="xattr">[Constructor]</span> and <span class="xattr">[PutForwards]</span>
|
|
to be an ECMAScript-specific extended attribute.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Turned <span class="xattr">[Callable]</span>,
|
|
<span class="xattr">[IndexGetter]</span>,
|
|
<span class="xattr">[IndexSetter]</span>,
|
|
<span class="xattr">[IndexCreator]</span>,
|
|
<span class="xattr">[IndexDeleter]</span>,
|
|
<span class="xattr">[NameGetter]</span>,
|
|
<span class="xattr">[NameSetter]</span>,
|
|
<span class="xattr">[NameCreator]</span>,
|
|
<span class="xattr">[NameDeleter]</span> and
|
|
<span class="xattr">[Stringifies]</span> into real Web IDL syntax
|
|
using <code>caller</code>, <code>getter</code>, <code>setter</code>,
|
|
<code>creator</code>, <code>deleter</code> and <code>stringifier</code>.
|
|
Dropped <span class="xattr">[NoIndexingOperations]</span> in favor of
|
|
an <code>omittable</code> keyword that can be used on the above
|
|
six special operations.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed boxed valuetypes and replaced them with the concept
|
|
of nullable types.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added <span class="xattr">[NamespaceObject]</span> to allow
|
|
reflecting module hierarchies in ECMAScript.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Disallowed specifying <span class="xattr">[Callback]</span> on
|
|
interfaces that do not match the criteria for interfaces that
|
|
can be implemented by native objects, and disallowed the use
|
|
of the <code>FunctionOnly</code> and
|
|
<code>PropertyOnly</code> identifiers unless
|
|
the interface has only a single operation (or multiple operations,
|
|
as long as they all have the same identifier).
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made corresponding indexed properties and ECMAScript properties
|
|
for operations enumerable.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Outlawed having both <span class="xattr">[NoInterfaceObject]</span> and
|
|
<span class="xattr">[Constructor]</span> on an interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Required that identical mixin prototype objects are in fact
|
|
the same object.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Renamed <span class="xattr">[Null]</span> and <span class="xattr">[Undefined]</span>
|
|
to <span class="xattr">[TreatNullAs]</span> and <span class="xattr">[TreatUndefinedAs]</span>.
|
|
They are now honored when values are returned from native object implemented
|
|
operations and attributes.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added algorithms for getting and setting values of attributes on
|
|
native object implementations of interfaces.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added <span class="xattr">[OverrideBuiltins]</span>, which makes
|
|
name getters prefer named properties instead of properties on the object itself.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Fixed bugs in the host object <span class="prop">[[Put]]</span>
|
|
algorithm (now <span class="prop">[[DefineOwnProperty]]</span>)
|
|
so that name and index creators are actually
|
|
invoked, and restructured it as well as the host object
|
|
<span class="prop">[[Delete]]</span>
|
|
algorithm so that they are easier to read.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Provided language binding independent advice on handling user
|
|
implemented interfaces that throw exceptions or return values
|
|
of inappropriate types.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Renamed the awkwardly worded “object implementing an interface” type
|
|
to “interface type”.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an <span class="xattr">[AllowAny]</span> ECMAScript-specific
|
|
extended attribute on operation arguments, which indicates that
|
|
any type of ECMAScript value is allowed to be passed to that
|
|
argument.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the definition of the effective overload set to take
|
|
into account the number of arguments passed, so that it can
|
|
be used to resolve overloaded calls properly in the
|
|
presence of variadic operations.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
<!--Renamed <span class='idltype'>DOMString</span> to <span class='idltype'>string</span>,
|
|
removed it from the list of primitive types, and allowed it-->
|
|
Removed <a class="idltype" href="#idl-DOMString">DOMString</a> from the list
|
|
of primitive types, removed <span class="idlvalue">null</span>
|
|
from its set of values, and allowed it to
|
|
be distinguished from primitive types in the overload
|
|
resolution algorithm. The <span class="xattr">[Callback]</span>
|
|
extended attribute is now also taken into account when a
|
|
native object is passed as an argument.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Defined exception handling for algorithms that call in
|
|
to user ECMAScript code.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an algorithm for converting a sequence of 16 bit
|
|
unsigned integer code units into a sequence of Unicode
|
|
characters.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <a class="idltype" href="#idl-double">double</a> type for double
|
|
precision floating point numbers.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Define <span class="prop">[[Class]]</span> for host objects
|
|
that implement a single interface, regardless of whether
|
|
it is annotated with <span class="xattr">[PrototypeRoot]</span>.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>19 December 2008 – WD</dt>
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[NoIndexingOperations]</span>
|
|
extended attribute to indicate that operations annotated
|
|
with named property or indexed property extended attributes
|
|
won’t result in functions, if the language binding supports
|
|
object indexing.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the way extended attributes are parsed in the grammar
|
|
and filled out the Extensibility section to mention how
|
|
extended attributes not defined in this document can be used.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Fixed some bugs in the rules for converting <a class="idltype" href="#idl-float">float</a>
|
|
and <a class="idltype" href="#idl-unsigned-long-long">unsigned long long</a> to ECMAScript
|
|
<span class="estype">Number</span> values, and vice versa.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added <span class="xattr">[Prefix]</span> to change the default
|
|
mapping of modules to language binding namespacing constructs.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Allowed interfaces with constants to be implemented by
|
|
ECMAScript native objects. This specifically allows
|
|
implementation of a DOM Level 2 Traversal
|
|
<span class="idltype">NodeFilter</span> object in script.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[Callable]</span>
|
|
extended attribute, which can be used to indicate
|
|
the behavior of calling an object as a function.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed a bogus requirement that
|
|
<span class="xattr">[PutForwards]</span> identify an
|
|
attribute whose type is the same as the attribute that
|
|
has the <span class="xattr">[PutForwards]</span>, and
|
|
disallowed cycles of forwarding assignments.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[Replaceable]</span> extended
|
|
attribute that can be placed on an attribute to indicate
|
|
that the corresponding ECMAScript property can be
|
|
replaced.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a requirement that <span class="xattr">[Stringifies]</span>
|
|
not be specified on an interface that also declares an
|
|
interface member named <code>toString</code>.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Changed the DOMString type to be a sequence of 16 bit
|
|
code units, rather than a sequence of Unicode characters.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Reworded the ECMAScript type mapping section so
|
|
that it can be more easily referenced from other
|
|
sections of the document.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Renamed <span class="xattr">[NativeObject]</span> to
|
|
<span class="xattr">[Callback]</span>, and gave it an
|
|
additional <code>PropertyOnly</code> argument.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an <span class="xattr">[Optional]</span> extended
|
|
attribute to make certain kinds of operation overloading
|
|
able to be specified more succinctly.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Reworked operation overloading in IDL so that it is
|
|
much more restrictive. Updated the overloaded
|
|
operation and constructor resolution in ECMAScript accordingly.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Specified the behavior of index and name getters
|
|
in ECMAScript as being in terms of additional properties
|
|
that are placed on the host object. Added
|
|
<span class="xattr">[IndexCreator]</span>,
|
|
<span class="xattr">[IndexDeleter]</span>,
|
|
<span class="xattr">[NameCreator]</span> and
|
|
<span class="xattr">[NameDeleter]</span> to handle
|
|
more aspects of these properties. The definition
|
|
of <span class="prop">[[Get]]</span> for host objects
|
|
is removed, but <span class="prop">[[Put]]</span> is
|
|
expanded to handle index and name creators/setters,
|
|
and <span class="prop">[[Delete]]</span> is now specified
|
|
to handle index and name deleters.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Specified the value of <span class="prop">[[Class]]</span>
|
|
for host objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed the suggestion to perform tricksy multiple inheritance
|
|
simulation in ECMAScript with a mandated way to map multiple
|
|
inheritance into a single inheritance prototype chain. Added
|
|
<span class="xattr">[ImplementedOn]</span> and
|
|
<span class="xattr">[PrototypeRoot]</span> to help with this.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made an explicit mention of the <cite>Web Interface Definition
|
|
Language (WIDL)</cite> W3C Member submission in the Status
|
|
of this Document section.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>29 August 2008 – WD</dt>
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Added an <span class="xattr">[NamedConstructor]</span> extended attribute
|
|
to handle peculiarities like HTML5’s <code>Image</code> constructor.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
<span class="xattr">[Constructor]</span> extended attributes may now
|
|
take an argument list, and more than one can be used on an interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[NativeObject]</span> extended attribute
|
|
that restricts which interfaces may be implemented by ECMAScript
|
|
native objects, and updated the “Native objects implementing interfaces”
|
|
section to be more restricted and precise.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Moved <span class="xattr">[NoInterfaceObject]</span> into the
|
|
ECMAScript-specific extended attributes section.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Fixed errors in a couple of algorithms that were introduced by
|
|
steps being renumbered.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Properties corresponding to IDL constants are now ReadOnly.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Removed <span class="xattr">[NoNull]</span>, and added
|
|
<span class="xattr">[Null]</span> and <span class="xattr">[Undefined]</span>
|
|
in its place.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Made <a class="idltype" href="#idl-DOMString">DOMString</a> an intrinsic type,
|
|
but still allow it to be defined as a boxed sequence of
|
|
unsigned shorts for compatibility with already published IDL
|
|
fragments.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
ECMAScript host object constructors (specified with
|
|
<span class="xattr">[Constructor]</span>) now must return an
|
|
object that implements the interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Tweaked the abstract and introduction so that it is clear that
|
|
Web IDL can be used for specifications that define not only a
|
|
DOM, but any interface.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Clarified the behavior of passing a
|
|
non-<span class="esvalue">null</span>,
|
|
non-<span class="estype">Object</span>
|
|
value to a host object that expects a boxed valuetype.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>Renamed document to <cite>Web IDL</cite>.</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>10 April 2008 – WD</dt>
|
|
<dd>
|
|
<ul>
|
|
<li>
|
|
<p>
|
|
Restricted boxed valuetypes to boxing only types that cannot
|
|
already have <span class="idlvalue">null</span>.</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Reworked how operation overloading is specified
|
|
(the <span class="xattr">[Overloads]</span> extended attribute
|
|
is no longer needed), and how ECMAScript disambiguates
|
|
calls to overloaded operations.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>Filled in the “Host exception objects” section.</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an exception interface prototype object for constants
|
|
to live in. Added constants to interface objects, interface
|
|
prototype objects, exception interface objects and exception
|
|
interface prototype objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>Tweaked the behavior of sequences in ECMAScript.</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an editorial note about the possibility of somehow
|
|
specifying HTML5’s <code>Image</code> constructor.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added a <span class="xattr">[NoInterfaceObject]</span> extended attribute,
|
|
which prevents an ECMAScript interface object being created for the interface
|
|
on which it appears.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>Added a <span class="xattr">[Stringifies]</span> extended attribute.</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Fixed small bugs in <span class="prop">[[HasProperty]]</span>,
|
|
<span class="prop">[[Get]]</span> and <span class="prop">[[Put]]</span>
|
|
algorithms for ECMAScript host objects.
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<p>
|
|
Added an editorial note about the possibility of an extended
|
|
attribute that specifies what properties get enumerated in
|
|
a for..in loop in ECMAScript.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</dd>
|
|
<dt>17 October 2007 – FPWD</dt>
|
|
<dd>
|
|
<ul>
|
|
<li><p>Initial publication.</p></li>
|
|
</ul>
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|