Stage: Not presented.
Environment Metadata: LGTM, but probably there are better alternatives.
It’s pretty straightforward to pass metadata between contexts when we work with sync calls. But it becomes more complicated, when we should pass across async operations (e.g. from the context in which the DOM event handler was set up to the context in which the callback was called; or the same for NodeJS callbacks).
The Zones protospec states that some of this semantics are implementation-dependent, but probably there is a better way.
Lex
is Lexical Environment.Rec
isLex
’s Environment Record.
a.js
:
// Rec.[[Metadata]] = Object.create(null)
import { b } from './b.js';
// rec.[[Metadata]].answer = 42
EnvironmentMetadata.set('answer', 42);
// The PrepareForOrdinaryCall sets b’s _calleeContext_’s
// [[Metadata]] to Object.create(Rec.[[Metadata]]).
b(); // 42
b.js
:
// Rec.[[Metadata]] = Object.create(null)
export const b = () => {
// Rec.[[Metadata]].answer
return EnvironmentMetadata.get('answer');
};