Skip to content

Commit

Permalink
Add bigint type
Browse files Browse the repository at this point in the history
This patch adds a bigint type to WebIDL with the following properties:
- bigint corresponds directly to BigInt
- The conversion from JS is based on ToBigInt, namely it throws on Number.
- bigint is not grouped as a "numeric" type, as this category is often
  used to refer to types which have a JavaScript representation of Number.
- bigint is included in the overloading resolution algorithm, and it's
  possible to overload a function for BigInt and numeric arguments.
- bigint constants are provided with syntax analogous to JS.
- bigint is included in the es-to-union algorithm. For good measure, symbol
  is added as well (it appears to have been missing).

Although it may be on the early side for such a change, the lack of
BigInt WebIDL integration is already coming up in some designs for integrating
BigInt with the Web Platform, such as w3c/IndexedDB#231
  • Loading branch information
littledan committed Feb 23, 2018
1 parent 4e32b14 commit 37ff443
Showing 1 changed file with 106 additions and 4 deletions.
110 changes: 106 additions & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,21 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
text: own property; url: sec-own-property
text: Property Descriptor; url: sec-property-descriptor-specification-type
text: realm; url: realm
urlPrefix: https://tc39.github.io/proposal-bigint/; spec: BIGINT
text: ToBigInt; url: #sec-to-bigint; type: abstract-op
text: BigInt; url: #sec-ecmascript-language-types-bigint-type; type: dfn
</pre>

<pre class=biblio>
{
"GEOMETRY": {
"aliasOf": "GEOMETRY-1"
},
"BIGINT": {
"href": "https://tc39.github.io/proposal-bigint/",
"title": "BigInt Specification",
"publisher": "TC39",
"status": "Stage 3 proposal"
}
}
</pre>
Expand Down Expand Up @@ -1591,7 +1600,8 @@ constant declaration gives the value of the constant, which can be
one of the two boolean literal tokens (<emu-t>true</emu-t>
and <emu-t>false</emu-t>),
the <emu-t>null</emu-t> token, an
<emu-t class="regex"><a href="#prod-integer">integer</a></emu-t> token,
<emu-t class="regex"><a href="#prod-integer">integer</a></emu-t> token, a
<emu-t class="regex"><a href="#prod-bigint">bigint</a></emu-t> token,
a <emu-t class="regex"><a href="#prod-float">float</a></emu-t> token,
or one of the three special floating point constant values
(<emu-t>-Infinity</emu-t>, <emu-t>Infinity</emu-t> and <emu-t>NaN</emu-t>).
Expand Down Expand Up @@ -1733,6 +1743,7 @@ The following extended attributes are applicable to constants:
BooleanLiteral
FloatLiteral
integer
bigint
"null"
</pre>

Expand Down Expand Up @@ -3467,6 +3478,9 @@ the following algorithm returns <i>true</i>.
</div></th>
<th><div>
<span>numeric types</span>
</div></th>
<th><div>
<span>bigint</span>
</div></th>
<th><div>
<span>string types</span>
Expand Down Expand Up @@ -3501,6 +3515,7 @@ the following algorithm returns <i>true</i>.
<td>●</td>
<td>●</td>
<td>●</td>
<td>●</td>
</tr>
<tr>
<th>numeric types</th>
Expand All @@ -3513,11 +3528,26 @@ the following algorithm returns <i>true</i>.
<td>●</td>
<td>●</td>
<td>●</td>
<td>●</td>
</tr>
<tr>
<th>bigint</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>
</tr>
<tr>
<th>string types</th>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
<td>●</td>
<td>●</td>
Expand All @@ -3531,6 +3561,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
<td>●</td>
<td></td>
Expand All @@ -3544,6 +3575,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
<td>●</td>
<td>●</td>
Expand All @@ -3557,6 +3589,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td>(a)</td>
<td>●</td>
<td>●</td>
Expand All @@ -3570,6 +3603,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
<td></td>
<td>●</td>
Expand All @@ -3583,6 +3617,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
<td>●</td>
</tr>
Expand All @@ -3596,6 +3631,7 @@ the following algorithm returns <i>true</i>.
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td class="belowdiagonal"></td>
<td></td>
</tr>
</table>
Expand Down Expand Up @@ -5355,7 +5391,7 @@ the [=integer types=],
{{unrestricted double}}.

The <dfn id="dfn-primitive-type" export>primitive types</dfn> are
{{boolean}} and the [=numeric types=].
{{boolean}}, {{bigint}} and the [=numeric types=].

The <dfn id="dfn-string-type" export>string types</dfn> are
{{DOMString}}, all [=enumeration types=],
Expand Down Expand Up @@ -5463,6 +5499,7 @@ type.
"boolean"
"byte"
"octet"
"bigint"
</pre>

<pre class="grammar" id="prod-UnrestrictedFloatType">
Expand Down Expand Up @@ -5578,6 +5615,18 @@ The [=type name=] of the
{{octet}} type is "<code>Octet</code>".


<h4 id="idl-bigint" interface>bigint</h4>

The {{bigint}} type is an arbitrary integer, unrestricted in range.

{{bigint}} constant values in IDL are
represented with <emu-t class="regex"><a href="#prod-bigint">bigint</a></emu-t>
tokens.

The [=type name=] of the
{{bigint}} type is “BigInt”.


<h4 oldids="dom-short" id="idl-short" interface>short</h4>

The {{short}} type is a signed integer
Expand Down Expand Up @@ -6864,6 +6913,9 @@ ECMAScript value type.
1. If <a abstract-op>Type</a>(|V|) is Number, then
return the result of <a href="#es-to-unrestricted-double">converting</a> |V|
to an {{unrestricted double}}.
1. If <a abstract-op>Type</a>(|V|) is [=BigInt=], then
return the result of <a href="#es-to-bigint">converting</a> |V|
to an {{bigint}}.
1. If <a abstract-op>Type</a>(|V|) is String, then
return the result of <a href="#es-DOMString">converting</a> |V|
to a {{DOMString}}.
Expand Down Expand Up @@ -7294,6 +7346,27 @@ value when its bit pattern is interpreted as an unsigned 64 bit integer.
{{unrestricted double}} value.
</div>

<h4 id="es-bigint">bigint</h4>

<div id="es-to-bigint" algorithm="convert an ECMAScript value to a bigint">

An ECMAScript value |V| is [=converted to an IDL value|converted=]
to an IDL {{bigint}} value by running the following algorithm:

1. Let |x| be [=?=] <a abstract-op>ToBigInt</a>(|V|).
1. Return the IDL {{bigint}} value that represents the same numeric
value as |x|.
</div>

<div id="bigint-to-es" algorithm="convert a bigint to an ECMAScript value">

The result of [=converted to an ECMAScript value|converting=]
an IDL {{bigint}} value to an ECMAScript value is a [=BigInt=]:

1. Return the [=BigInt=] value that represents the same numeric value
as the IDL {{bigint}} value.
</div>


<h4 id="es-DOMString">DOMString</h4>

Expand Down Expand Up @@ -7988,23 +8061,37 @@ that correspond to the union’s [=member types=].
1. If |types| includes {{object}}, then return the IDL value
that is a reference to the object |V|.
1. If <a abstract-op>Type</a>(|V|) is Boolean, then:
1. If |types| includes a {{boolean}},
1. If |types| includes {{boolean}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{boolean}}.
1. If <a abstract-op>Type</a>(|V|) is Number, then:
1. If |types| includes a [=numeric type=],
then return the result of [=converted to an IDL value|converting=]
|V| to that [=numeric type=].
1. If <a abstract-op>Type</a>(|V|) is Symbol, then:
1. If |types| includes {{symbol}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{symbol}}
1. If <a abstract-op>Type</a>(|V|) is [=BigInt=], then:
1. If |types| includes {{bigint}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{bigint}}
1. If |types| includes a [=string type=],
then return the result of
[=converted to an IDL value|converting=]
|V| to that type.
1. If |types| includes a [=numeric type=],
then return the result of [=converted to an IDL value|converting=]
|V| to that [=numeric type=].
1. If |types| includes a {{boolean}},
1. If |types| includes {{boolean}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{boolean}}.
1. If |types| includes {{symbol}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{symbol}}.
1. If |types| includes a {{bigint}},
then return the result of [=converted to an IDL value|converting=]
|V| to {{bigint}}.
1. [=ECMAScript/Throw=] a {{ECMAScript/TypeError}}.
</div>

Expand Down Expand Up @@ -10592,6 +10679,16 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]]

then remove from |S| all other entries.

1. Otherwise: if <a abstract-op>Type</a>(|V|) is [=BigInt=]
and there is an entry in |S| that has one of the following types at position |i| of its type list,
* {{bigint}}
* a [=nullable type|nullable=] {{bigint}}
* an [=annotated type=] whose [=annotated types/inner type=] is one of the above types
* a [=union type=], [=nullable type|nullable=] union type, or [=annotated type|annotated=] union type
that has one of the above types in its [=flattened member types=]

then remove from |S| all other entries.

1. Otherwise: if there is an entry in |S| that has one of the following types at position |i| of its type list,
* a [=string type=]
* a [=nullable type|nullable=] version of any of the above types
Expand Down Expand Up @@ -13568,6 +13665,11 @@ expression syntax [[!PERLRE]]) as follows:
<td><code>=</code></td>
<td><code class="regex"><span class="mute">/</span>-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)<span class="mute">/</span></code></td>
</tr>
<tr>
<td id="prod-bigint"><emu-t class="regex">bigint</emu-t></td>
<td><code>=</code></td>
<td><code class="regex"><span class="mute">/</span>-?([1-9][0-9]*|0[Xx][0-9A-Fa-f]+|0[0-7]*)n<span class="mute">/</span></code></td>
</tr>
<tr>
<td id="prod-identifier"><emu-t class="regex">identifier</emu-t></td>
<td><code>=</code></td>
Expand Down

0 comments on commit 37ff443

Please sign in to comment.