From 37ff443bf16773bffdc73982d22744d82ad1416b 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. - 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 https://github.com/w3c/IndexedDB/pull/231 --- index.bs | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index 800c55358..1287a4f35 100644 --- a/index.bs +++ b/index.bs @@ -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
 {
     "GEOMETRY": {
         "aliasOf": "GEOMETRY-1"
+    },
+    "BIGINT": {
+        "href": "https://tc39.github.io/proposal-bigint/",
+        "title": "BigInt Specification",
+        "publisher": "TC39",
+        "status": "Stage 3 proposal"
     }
 }
 
@@ -1591,7 +1600,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). @@ -1733,6 +1743,7 @@ The following extended attributes are applicable to constants: BooleanLiteral FloatLiteral integer + bigint "null" @@ -3467,6 +3478,9 @@ the following algorithm returns true.
numeric types +
+
+ bigint
string types @@ -3501,6 +3515,7 @@ the following algorithm returns true. ● ● ● + ● numeric types @@ -3513,11 +3528,26 @@ the following algorithm returns true. ● ● ● + ● + + + bigint + + + + ● + ● + ● + ● + ● + ● + ● string types + ● ● @@ -3531,6 +3561,7 @@ the following algorithm returns true. + ● @@ -3544,6 +3575,7 @@ the following algorithm returns true. + ● ● @@ -3557,6 +3589,7 @@ the following algorithm returns true. + (a) ● ● @@ -3570,6 +3603,7 @@ the following algorithm returns true. + ● @@ -3583,6 +3617,7 @@ the following algorithm returns true. + ● @@ -3596,6 +3631,7 @@ the following algorithm returns true. + @@ -5355,7 +5391,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=], @@ -5463,6 +5499,7 @@ type. "boolean" "byte" "octet" + "bigint"
@@ -5578,6 +5615,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 @@ -6864,6 +6913,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}}. @@ -7294,6 +7346,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

@@ -7988,13 +8061,21 @@ 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 Type(|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 Type(|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 Type(|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 Type(|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=] @@ -8002,9 +8083,15 @@ that correspond to the union’s [=member types=]. 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}}. @@ -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 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 @@ -13568,6 +13665,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 =