ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

9.2 PrivateEnvironment Records

A PrivateEnvironment Record is a specification mechanism used to track Private Names based upon the lexical nesting structure of ClassDeclarations and ClassExpressions in ECMAScript code. They are similar to, but distinct from, Environment Records. Each PrivateEnvironment Record is associated with a ClassDeclaration or ClassExpression. Each time such a class is evaluated, a new PrivateEnvironment Record is created to record the Private Names declared by that class.

Each PrivateEnvironment Record has the fields defined in Table 23.

Table 23: PrivateEnvironment Record Fields
Field Name Value Type Meaning
[[OuterPrivateEnvironment]] a PrivateEnvironment Record or null The PrivateEnvironment Record of the nearest containing class. null if the class with which this PrivateEnvironment Record is associated is not contained in any other class.
[[Names]] a List of Private Names The Private Names declared by this class.

9.2.1 PrivateEnvironment Record Operations

The following abstract operations are used in this specification to operate upon PrivateEnvironment Records:

9.2.1.1 NewPrivateEnvironment ( outerPrivEnv )

The abstract operation NewPrivateEnvironment takes argument outerPrivEnv (a PrivateEnvironment Record or null) and returns a PrivateEnvironment Record. It performs the following steps when called:

  1. Let names be a new empty List.
  2. Return the PrivateEnvironment Record { [[OuterPrivateEnvironment]]: outerPrivEnv, [[Names]]: names }.

9.2.1.2 ResolvePrivateIdentifier ( privEnv, identifier )

The abstract operation ResolvePrivateIdentifier takes arguments privEnv (a PrivateEnvironment Record) and identifier (a String) and returns a Private Name. It performs the following steps when called:

  1. Let names be privEnv.[[Names]].
  2. For each Private Name pn of names, do
    1. If pn.[[Description]] is identifier, then
      1. Return pn.
  3. Let outerPrivEnv be privEnv.[[OuterPrivateEnvironment]].
  4. Assert: outerPrivEnv is not null.
  5. Return ResolvePrivateIdentifier(outerPrivEnv, identifier).