Stage NaN Draft / December 30, 2019

Environment Metadata

1Executable Code and Execution Contexts

1.1Lexical Environments

1.1.1Lexical Environment Operations

1.1.1.1NewDeclarativeEnvironment ( E )

  1. Let env be a new Lexical Environment.
  2. Let envRec be a new declarative Environment Record containing no bindings.
  3. Set env's EnvironmentRecord to envRec.
  4. Set the outer lexical environment reference of env to E.
  5. Let outerRec be E's EnvironmentRecord.
  6. Set envRec.[[Metadata]] to outerRec.[[Metadata]].
  7. Return env.

1.1.1.2NewObjectEnvironment ( O, E )

  1. Let env be a new Lexical Environment.
  2. Let envRec be a new object Environment Record containing O as the binding object.
  3. Set env's EnvironmentRecord to envRec.
  4. Set the outer lexical environment reference of env to E.
  5. Let outerRec be E's EnvironmentRecord.
  6. Set envRec.[[Metadata]] to outerRec.[[Metadata]].
  7. Return env.

1.1.1.3NewGlobalEnvironment ( G, thisValue )

  1. Let env be a new Lexical Environment.
  2. Let objRec be a new object Environment Record containing G as the binding object.
  3. Let dclRec be a new declarative Environment Record containing no bindings.
  4. Let globalRec be a new global Environment Record.
  5. Set globalRec.[[ObjectRecord]] to objRec.
  6. Set globalRec.[[GlobalThisValue]] to thisValue.
  7. Set globalRec.[[DeclarativeRecord]] to dclRec.
  8. Set globalRec.[[VarNames]] to a new empty List.
  9. Set globalRec.[[Metadata]] to ! ObjectCreate(null).
  10. Set env's EnvironmentRecord to globalRec.
  11. Set the outer lexical environment reference of env to null.
  12. Return env.

1.1.1.4NewModuleEnvironment ( E )

  1. Let env be a new Lexical Environment.
  2. Let envRec be a new module Environment Record containing no bindings.
  3. Set env's EnvironmentRecord to envRec.
  4. Set the outer lexical environment reference of env to E.
  5. Let outerRec be E's EnvironmentRecord.
  6. Set envRec.[[Metadata]] to outerRec.[[Metadata]].
  7. Return env.

1.2Jobs and Job Queues

1.2.1EnqueueJob ( queueName, job, arguments )

  1. Assert: Type(queueName) is String and its value is the name of a Job Queue recognized by this implementation.
  2. Assert: job is the name of a Job.
  3. Assert: arguments is a List that has the same number of elements as the number of parameters required by job.
  4. Let callerContext be the running execution context.
  5. Let callerRealm be callerContext's Realm.
  6. Let callerScriptOrModule be callerContext's ScriptOrModule.
  7. Let callerRec be EnvironmentRecord of callerContext's LexicalEnvironment.
  8. Let meta be callerRec.[[Metadata]].
  9. Let pending be PendingJob { [[Job]]: job, [[Arguments]]: arguments, [[Realm]]: callerRealm, [[ScriptOrModule]]: callerScriptOrModule, [[HostDefined]]: undefined, [[Metadata]]: meta }.
  10. Perform any implementation or host environment defined processing of pending. This may include modifying the [[HostDefined]] field or any other field of pending.
  11. Add pending at the back of the Job Queue named by queueName.
  12. Return NormalCompletion(empty).

1.3RunJobs ( )

  1. Perform ? InitializeHostDefinedRealm().
  2. In an implementation-dependent manner, obtain the ECMAScript source texts (see clause 10) and any associated host-defined values for zero or more ECMAScript scripts and/or ECMAScript modules. For each such sourceText and hostDefined, do
    1. If sourceText is the source code of a script, then
      1. Perform EnqueueJob("ScriptJobs", ScriptEvaluationJob, « sourceText, hostDefined »).
    2. Else,
      1. Assert: sourceText is the source code of a module.
      2. Perform EnqueueJob("ScriptJobs", TopLevelModuleEvaluationJob, « sourceText, hostDefined »).
  3. Repeat,
    1. Suspend the running execution context and remove it from the execution context stack.
    2. Assert: The execution context stack is now empty.
    3. Let nextQueue be a non-empty Job Queue chosen in an implementation-defined manner. If all Job Queues are empty, the result is implementation-defined.
    4. Let nextPending be the PendingJob record at the front of nextQueue. Remove that record from nextQueue.
    5. Let newContext be a new execution context.
    6. Set newContext's Function to null.
    7. Set newContext's Realm to nextPending.[[Realm]].
    8. Set newContext's ScriptOrModule to nextPending.[[ScriptOrModule]].
    9. Set newContext's LexicalEnvironment's EnvironmentRecord.[[Metadata]] to ! ObjectCreate(nextPending.[[Metadata]]). NOTE: Absolutely unsure what to do here ¯_(ツ)_/¯
    10. Push newContext onto the execution context stack; newContext is now the running execution context.
    11. Perform any implementation or host environment defined job initialization using nextPending.
    12. Let result be the result of performing the abstract operation named by nextPending.[[Job]] using the elements of nextPending.[[Arguments]] as its arguments.
    13. If result is an abrupt completion, perform HostReportErrorsresult.[[Value]] »).

2Ordinary and Exotic Objects Behaviours

2.1ECMAScript Function Objects

2.1.1[[Call]] ( thisArgument, argumentsList )

2.1.1.1PrepareForOrdinaryCall ( F, newTarget )

  1. Assert: Type(newTarget) is Undefined or Object.
  2. Let callerContext be the running execution context.
  3. Let calleeContext be a new ECMAScript code execution context.
  4. Set the Function of calleeContext to F.
  5. Let calleeRealm be F.\[\[Realm]].
  6. Set the Realm of calleeContext to calleeRealm.
  7. Set the ScriptOrModule of calleeContext to F.\[\[ScriptOrModule]].
  8. Let localEnv be NewFunctionEnvironment(F, newTarget).
  9. Perform ! PrepareCelleeEnvironment(callerContext, calleeContext).
  10. Set the LexicalEnvironment of calleeContext to localEnv.
  11. Set the VariableEnvironment of calleeContext to localEnv.
  12. If callerContext is not already suspended, suspend callerContext.
  13. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
  14. NOTE: Any exception objects produced after this point are associated with calleeRealm.
  15. Return calleeContext.

2.1.1.2PrepareCelleeEnvironment ( callerContext, calleeContext )

When the abstract operation PrepareCalleeEnvironment is called with execution context callerContext and execution context calleeContext, the following steps are taken:

  1. Let callerRec be EnvironmentRecord of callerContext's LexicalEnvironment.
  2. Let calleeRec be EnvironmentRecord of calleeContext's LexicalEnvironment.
  3. Set calleeRec.[[Metadata]] to ! ObjectCreate(callerRec.[[Metadata]]).
  4. Return NormalCompletion(empty).

3The Global Object

3.1Other Properties of the Global Object

3.1.1Reflect

See 4.1.

4Environment Metadata

4.1The EnvironmentMetadata Object

The EnvironmentMetadata Object:

  • is the intrinsic object %EnvironmentMetadata%.
  • is the initial value of the "EnvironmentMetadata" property of the global object.
  • is an ordinary object.
  • has a [[Prototype]] internal slot whose value is %Object.prototype%.
  • is not a function object.
  • does not have a [[Construct]] internal method; it cannot be used as a constructor with the new operator.
  • does not have a [[Call]] internal method; it cannot be invoked as a function.

4.2EnvironmentMetadata.delete ( propertyKey )

When the delete function is called with argument propertyKey, the following steps are taken:

  1. Let key be ? ToPropertyKey(propertyKey).
  2. Let lex be current execution context's LexicalEnvironment.
  3. Let rec be lex's EnvironmentRecord.
  4. Let meta be rec.[[Metadata]].
  5. Return ! meta.[[Delete]](key).

4.3EnvironmentMetadata.get ( propertyKey )

When the get function is called with argument propertyKey, the following steps are taken:

  1. Let key be ? ToPropertyKey(propertyKey).
  2. Let lex be current execution context's LexicalEnvironment.
  3. Let rec be lex's EnvironmentRecord.
  4. Let meta be rec.[[Metadata]].
  5. Return ! meta.[[Get]](key, meta).

4.4EnvironmentMetadata.has ( propertyKey )

When the has function is called with argument propertyKey, the following steps are taken:

  1. Let key be ? ToPropertyKey(propertyKey).
  2. Let lex be current execution context's LexicalEnvironment.
  3. Let rec be lex's EnvironmentRecord.
  4. Let meta be rec.[[Metadata]].
  5. Return ! meta.[[HasProperty]](key).

4.5EnvironmentMetadata.propagate ()

When the propagate function is called, the following steps are taken:

  1. Let key be ? ToPropertyKey(propertyKey).
  2. Let lex be current execution context's LexicalEnvironment.
  3. Let rec be lex's EnvironmentRecord.
  4. Let meta be rec.[[Metadata]].
  5. If meta.[[Prototype]] is null, then
    1. Throw a TypeError exception.
  6. Else,
    1. Set rec.[[Metadata]] to meta.[[Prototype]].
    2. Return NormalCompletion(empty).

4.6EnvironmentMetadata.set ( propertyKey, value )

When the set function is called with arguments propertyKey and value, the following steps are taken:

  1. Let key be ? ToPropertyKey(propertyKey).
  2. Let lex be current execution context's LexicalEnvironment.
  3. Let rec be lex's EnvironmentRecord.
  4. Let meta be rec.[[Metadata]].
  5. Return ! meta.[[Set]](key, value, meta).

ACopyright & Software License

Copyright Notice

© 2019 Ecma International, Yuri Zemskov

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.