简体   繁体   中英

Could an ECMA-262-conformant JavaScript implementation have `2n` be the maximum BigInt size?

As far as I can tell, the ECMASCRIPT spec doesn't say what the minimum maximum size for a BigInt value is, it just says "arbitrary precision" , which seems in this context to mean "implementation-defined" .

Does this mean that a JS engine could throw a RangeError on BigInt(3) and still conform to the spec?

Yes, this would be a conforming (albeit silly) implementation. In a discussion on the BigInt proposal it was mentioned that

[The maximally allowed BigInt] is not specified. Implementations can choose their own limits. This matches other things in JavaScript, like the size of the stack, or max length of TypedArrays, which are also implementation-defined.

There's also an open ecma262 issue that ponders whether to " define minimum or maximum guaranteed sizes for various resources ", but nothing came out of this yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM