<p>A <dfnclass="dfn-paneled"data-dfn-type="dfn"data-export=""id="dfn-nullable-type">nullable type</dfn> is an IDL type constructed
from an existing type (called the <dfnclass="dfn-paneled"data-dfn-type="dfn"data-export=""id="dfn-inner-type">inner type</dfn>),
which just allows the additional value <emu-val>null</emu-val> to be a member of its set of values. <adata-link-type="dfn"href="#dfn-nullable-type"id="ref-for-dfn-nullable-type-12">Nullable types</a> are represented in IDL by placing a <spanclass="char">U+003F QUESTION MARK ("?")</span> character after an existing type. The inner type must not
be <codeclass="idl"><adata-link-type="idl"href="#idl-any"id="ref-for-idl-any-6">any</a></code>,
another nullable type, or a <adata-link-type="dfn"href="#dfn-union-type"id="ref-for-dfn-union-type-11">union type</a> that itself has <adata-link-type="dfn"href="#dfn-includes-a-nullable-type"id="ref-for-dfn-includes-a-nullable-type-3">includes a nullable type</a> or has a dictionary or record type as one of its <adata-link-type="dfn"href="#dfn-flattened-union-member-types"id="ref-for-dfn-flattened-union-member-types-5">flattened member types</a>.</p>
which just allows the additional value <emu-val>null</emu-val> to be a member of its set of values. <adata-link-type="dfn"href="#dfn-nullable-type"id="ref-for-dfn-nullable-type-12">Nullable types</a> are represented in IDL by placing a <spanclass="char">U+003F QUESTION MARK ("?")</span> character after an existing type.
<p>a <adata-link-type="dfn"href="#dfn-union-type"id="ref-for-dfn-union-type-11">union type</a> that itself has <adata-link-type="dfn"href="#dfn-includes-a-nullable-type"id="ref-for-dfn-includes-a-nullable-type-3">includes a nullable type</a> or has a dictionary or record type as one of its <adata-link-type="dfn"href="#dfn-flattened-union-member-types"id="ref-for-dfn-flattened-union-member-types-5">flattened member types</a>.</p>
</ul>
<pclass="note"role="note">Note: Although dictionary and record types can in general be nullable,
they cannot when used
as the type of an operation argument or a dictionary member.</p>
they cannot when used as the type of an operation argument or a dictionary member.</p>
<p>Nullable type constant values in IDL are represented in the same way that
constant values of their <adata-link-type="dfn"href="#dfn-inner-type"id="ref-for-dfn-inner-type-5">inner type</a> would be represented, or with the <emu-t>null</emu-t> token.</p>
<p>The <adata-link-type="dfn"href="#dfn-type-name"id="ref-for-dfn-type-name-23">type name</a> of a nullable type
for the eventual results of a deferred (and possibly asynchronous) computation
result of an asynchronous operation”.
See <ahref="https://tc39.github.io/ecma262/#sec-promise-objects">section 25.4</a> of the ECMAScript specification for details on the semantics of promise objects.</p>
<p>Promise types are non-nullable, but <var>T</var> may be nullable.</p>
<p>There is no way to represent a promise value in IDL.</p>
<p>The <adata-link-type="dfn"href="#dfn-type-name"id="ref-for-dfn-type-name-26">type name</a> of a promise type
is the concatenation of the type name for <var>T</var> and
<p>IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-3">promise type</a> values are
<p>IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-4">promise type</a> values are
represented by ECMAScript <emu-val>Promise</emu-val> objects.</p>
<div class="algorithm" data-algorithm="convert an ECMAScript value to promise" id="es-to-promise">
<p>An ECMAScript value <var>V</var> is <a data-link-type="dfn" href="#dfn-convert-ecmascript-to-idl-value" id="ref-for-dfn-convert-ecmascript-to-idl-value-32">converted</a> to an IDL <a class="idl-code" data-link-type="interface" href="#idl-promise" id="ref-for-idl-promise-1">Promise<var>T</var></a> value as follows:</p>
<li data-md="">
<p>Let <var>promise</var> be the result of calling <var>resolve</var> with <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-promise-constructor">%Promise%</a> as the <emu-val>this</emu-val> value and <var>V</var> as the single argument value.</p>
<li data-md="">
<p>Return the IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-4">promise type</a> value that is a reference to the
<p>Return the IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-5">promise type</a> value that is a reference to the
same object as <var>promise</var>.</p>
</ol>
</div>
<p id="promise-to-es"> The result of <a data-link-type="dfn" href="#dfn-convert-idl-to-ecmascript-value" id="ref-for-dfn-convert-idl-to-ecmascript-value-31">converting</a> an IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-5">promise type</a> value to an ECMAScript
<p id="promise-to-es"> The result of <a data-link-type="dfn" href="#dfn-convert-idl-to-ecmascript-value" id="ref-for-dfn-convert-idl-to-ecmascript-value-31">converting</a> an IDL <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-6">promise type</a> value to an ECMAScript
value is the <emu-val>Promise</emu-val> value that represents a reference to the same object that the
<div class="algorithm" data-algorithm="perform some steps once a promise is settled">
<p>One can <dfn data-dfn-type="dfn" data-export="" data-lt="upon settling" id="dfn-perform-steps-once-promise-is-settled">perform some steps once a promise is settled<a class="self-link" href="#dfn-perform-steps-once-promise-is-settled"></a></dfn>.
be used on anything other than a <a data-link-type="dfn" href="#dfn-regular-operation" id="ref-for-dfn-regular-operation-10">regular</a> or <a data-link-type="dfn" href="#dfn-static-operation" id="ref-for-dfn-static-operation-8">static</a> <a data-link-type="dfn" href="#dfn-operation" id="ref-for-dfn-operation-41">operation</a> whose <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-4">return type</a> is an <a data-link-type="dfn" href="#idl-interface" id="ref-for-idl-interface-11">interface type</a> or
a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-7">promise type</a>.</p>
a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-8">promise type</a>.</p>
<p>As an example, this extended attribute is suitable for use on
<p>And then, if an exception was thrown:</p>
<ol>
<li data-md="">
<p>If <var>op</var> has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-5">return type</a> that is a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-8">promise type</a>, then:</p>
<p>If <var>op</var> has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-5">return type</a> that is a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-9">promise type</a>, then:</p>
<ol>
<li data-md="">
<p>Let <var>reject</var> be the initial value of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-promise-constructor">%Promise%</a>.reject.</p>
<li data-md="">
<p>If <var>completion</var> is a normal completion, return <var>completion</var>.</p>
<li data-md="">
<p>If <var>completion</var> is an abrupt completion and the operation has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-7">return type</a> that is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-9">promise type</a>, return <var>completion</var>.</p>
<p>If <var>completion</var> is an abrupt completion and the operation has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-7">return type</a> that is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-10">promise type</a>, return <var>completion</var>.</p>
<li data-md="">
<p>Let <var>reject</var> be the initial value of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-promise-constructor">%Promise%</a>.reject.</p>
<li data-md="">
<li data-md="">
<p>If <var>completion</var> is a normal completion, return <var>completion</var>.</p>
<li data-md="">
<p>If <var>completion</var> is an abrupt completion and the attribute’s type is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-10">promise type</a>, return <var>completion</var>.</p>
<p>If <var>completion</var> is an abrupt completion and the attribute’s type is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-11">promise type</a>, return <var>completion</var>.</p>
<li data-md="">
<p>Let <var>reject</var> be the initial value of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-promise-constructor">%Promise%</a>.reject.</p>
<li data-md="">
<li data-md="">
<p>If <var>completion</var> is a normal completion, return <var>completion</var>.</p>
<li data-md="">
<p>If <var>completion</var> is an abrupt completion and the callback function has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-8">return type</a> that is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-11">promise type</a>, return <var>completion</var>.</p>
<p>If <var>completion</var> is an abrupt completion and the callback function has a <a data-link-type="dfn" href="#dfn-return-type" id="ref-for-dfn-return-type-8">return type</a> that is <em>not</em> a <a data-link-type="dfn" href="#dfn-promise-type" id="ref-for-dfn-promise-type-12">promise type</a>, return <var>completion</var>.</p>
<li data-md="">
<p>Let <var>reject</var> be the initial value of <a data-link-type="dfn" href="https://tc39.github.io/ecma262/#sec-promise-constructor">%Promise%</a>.reject.</p>
0 comments on commit
7366419