From ce037747f7cd00805e6e5c50038944877dec5286 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 22 Feb 2018 16:32:31 +0100 Subject: [PATCH] Add bigint type 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. 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 https://github.com/w3c/IndexedDB/pull/231 --- index.bs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 66a0fd434..e5608e1b8 100644 --- a/index.bs +++ b/index.bs @@ -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
 {
     "GEOMETRY": {
         "aliasOf": "GEOMETRY-1"
+    },
+    "BIGINT": {
+        "href": "https://tc39.github.io/proposal-bigint/",
+        "title": "BigInt Specification",
+        "publisher": "TC39",
+        "status": "Stage 3 proposal"
     }
 }
 
@@ -1171,7 +1180,8 @@ constant declaration gives the value of the constant, which can be one of the two boolean literal tokens (true and false), the null token, an -integer token, +integer token, a +bigint token, a float token, or one of the three special floating point constant values (-Infinity, Infinity and NaN). @@ -1312,6 +1322,7 @@ The following extended attributes are applicable to constants: BooleanLiteral FloatLiteral integer + bigint "null" @@ -3010,6 +3021,9 @@ the following algorithm returns true.
numeric types +
+
+ bigint
string types @@ -3044,6 +3058,7 @@ the following algorithm returns true. ● ● ● + ● numeric types @@ -3056,11 +3071,26 @@ the following algorithm returns true. ● ● ● + ● + + + bigint + + + + ● + ● + ● + ● + ● + ● + ● string types + ● ● @@ -3074,6 +3104,7 @@ the following algorithm returns true. + ● @@ -3087,6 +3118,7 @@ the following algorithm returns true. + ● ● @@ -3100,6 +3132,7 @@ the following algorithm returns true. + (a) ● ● @@ -3113,6 +3146,7 @@ the following algorithm returns true. + ● @@ -3126,6 +3160,7 @@ the following algorithm returns true. + ● @@ -3139,6 +3174,7 @@ the following algorithm returns true. + @@ -4783,7 +4819,7 @@ the [=integer types=], {{unrestricted double}}. The primitive types are -{{boolean}} and the [=numeric types=]. +{{boolean}}, {{bigint}} and the [=numeric types=]. The string types are {{DOMString}}, all [=enumeration types=], @@ -4892,6 +4928,7 @@ type. "boolean" "byte" "octet" + "bigint"
@@ -5007,6 +5044,18 @@ The [=type name=] of the
 {{octet}} type is “Octet”.
 
 
+

bigint

+ +The {{bigint}} type is an arbitrary integer, unrestricted in range. + +{{bigint}} constant values in IDL are +represented with bigint +tokens. + +The [=type name=] of the +{{bigint}} type is “BigInt”. + +

short

The {{short}} type is a signed integer @@ -6290,6 +6339,9 @@ ECMAScript value type. 1. If Type(|V|) is Number, then return the result of converting |V| to an {{unrestricted double}}. + 1. If Type(|V|) is [=BigInt=], then + return the result of converting |V| + to an {{bigint}}. 1. If Type(|V|) is String, then return the result of converting |V| to a {{DOMString}}. @@ -6720,6 +6772,27 @@ value when its bit pattern is interpreted as an unsigned 64 bit integer. {{unrestricted double}} value.
+

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 [=?=] ToBigInt(|V|). + 1. Return the IDL {{bigint}} value that represents the same numeric + value as |x|. +
+ +
+ + 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. +
+

DOMString

@@ -9957,6 +10030,16 @@ Note: The HTML Standard defines how a security check is performed. [[!HTML]] then remove from |S| all other entries. + 1. Otherwise: if Type(|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 @@ -13046,6 +13129,11 @@ expression syntax [[!PERLRE]]) as follows: = /-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)/ + + bigint + = + /-?([1-9][0-9]*|0[Xx][0-9A-Fa-f]+|0[0-7]*)n/ + identifier =