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.

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 22, 2018
1 parent 2b1a990 commit 7cfcc0e
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,21 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
text: NewTarget; url: sec-built-in-function-objects
text: Number Type; url: sec-ecmascript-language-types-number-type
text: JSON.stringify; url: sec-json.stringify
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 @@ -3010,6 +3019,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 @@ -3044,6 +3056,7 @@ the following algorithm returns <i>true</i>.
<td>●</td>
<td>●</td>
<td>●</td>
<td>●</td>
</tr>
<tr>
<th>numeric types</th>
Expand All @@ -3056,11 +3069,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 @@ -3074,6 +3102,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 @@ -3087,6 +3116,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 @@ -3100,6 +3130,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 @@ -3113,6 +3144,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 @@ -3126,6 +3158,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 @@ -3139,6 +3172,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 @@ -4783,7 +4817,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 @@ -4892,6 +4926,7 @@ type.
"boolean"
"byte"
"octet"
"bigint"
</pre>

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


<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 @@ -6290,6 +6337,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 @@ -6720,6 +6770,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 @@ -9957,6 +10028,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 @@ -13046,6 +13127,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 7cfcc0e

Please sign in to comment.