Stage 1 Draft / January 27, 2019

Extended Numeric Literals

Introduction

This document is a Stage 1 draft specification for extended numeric literals in JavaScript. For a high-level overview of the design, motivation and semantics, see the explainer document. This document focuses on exact specification mechanics.

1Syntax

PrimaryExpression[Yield, Await]:this IdentifierReference[?Yield, ?Await] Literal ArrayLiteral[?Yield, ?Await] ObjectLiteral[?Yield, ?Await] FunctionExpression ClassExpression[?Yield, ?Await] GeneratorExpression AsyncFunctionExpression RegularExpressionLiteral TemplateLiteral[?Yield, ?Await, ~Tagged] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] ExtendedNumericLiteral ExtendedNumericLiteral::NumericLiteral~IdentifierName

2Semantics

2.1Runtime Semantics: Evaluation

ExtendedNumericLiteral::NumericLiteral~IdentifierPart
  1. Let string be a String consisting of the code units which constitute NumericLiteral.
  2. let number be the result of evaluating NumericLiteral.
  3. Let realm be the current Realm Record.
  4. Let literalRegistry be realm.[[LiteralMap]].
  5. For each element e of literalRegistry, do
    1. If ! SameValue(e.[[String]], string) is true, then
      1. Return e.[[Object]].
  6. Let object be ! ObjectCreate(null).
  7. Perform ! CreateDataProperty(object, "string", string).
  8. Perform ! CreateDataProperty(object, "number", number).
  9. Perform SetIntegrityLevel(object, "frozen").
  10. Append the Record{[[String]]: string, [[Object]]: object} to literalRegistry.
  11. Let ident be numeric__ IdentifierPart parsed as an Identifer.
  12. Let tag be the result of evaluating ident.
  13. Return ? Call(undefined, tag, object).

2.2Realms

Table 1: Realm Record Fields
Field Name Value Meaning
[[LiteralMap]] A List of Record { [[Site]]: Parse Node, [[Object]]: Object}. Literal objects are canonicalized separately for each realm using its Realm Record's [[TemplateMap]]. Each [[Site]] value is a Parse Node the numeric part of the ExtendedNumericLiteral. The associated [[Object]] value is the corresponding literal object that is passed to a numeric literal function. Note
Once a Parse Node becomes unreachable, the corresponding [[Object]] is also unreachable, and it would be unobservable if an implementation removed the pair from the [[LiteralMap]] list.