Skip to content

miyaokamarina/environment-metadata-proposal

Repository files navigation

Custom metadata for Lexical Environments and execution context stacks

Stage: Not presented.

Open questions

The name

Environment Metadata: LGTM, but probably there are better alternatives.

How to work with async callbacks

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.

Semantics explained

  • Lex is Lexical Environment.
  • Rec is Lex’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');
};

About

Custom metadata for Lexical Environments and execution context stacks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published