Skip to content

Instantly share code, notes, and snippets.

@dherman
Last active September 7, 2024 17:42
Show Gist options
  • Save dherman/7568885 to your computer and use it in GitHub Desktop.
Save dherman/7568885 to your computer and use it in GitHub Desktop.
ES6 Realms API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.

Realms

A realm object abstracts the notion of a distinct global environment.

Extensible web: This is the dynamic equivalent of a same-origin <iframe> without DOM.

Realm Constructor

r = new Realm(options,      // {
                            //   eval: {
                            //     direct: {
                            //       translate: ((string) -> string)?,
                            //       fallback: ((any, ...any) -> any)?
                            //.    }?,
                            //     indirect: ((string) -> any)?
                            //   }?,
                            //   Function: ((string, string, ("function" | "function*")) -> function)?
                            // }?
              initializer); // ((object) -> any)?

Every component of the constructor argument is optional (meaning that it can be undefined and will be provided with a default behavior).

The initializer object is passed an object containing the standard ECMAScript builtins for a global object. A host environment may also provide additional builtins specific to the host environment. (For example, the browser would provide atob and btoa and other standard browser globals that are not tied to the DOM.) The this binding of the initializer function is provided as the new realm object. This can be used to initialize the realm, for example:

var realm = new Realm(options, function(builtins) {
    Object.mixin(this.global, builtins);
});

Realm Properties

global

The global object associated with the realm.

Realm Methods

eval

Synchronously execute a top-level script.

Extensible web: This is the dynamic equivalent of a <script> in HTML.

// eval : (string) -> any
v = r.eval(src)

Loaders

This section describes how the Loader class is extended to integrate with custom realms.

Loader Constructor

l = new Loader({
  realm,      // Realm?
  ...
}) // : Loader<ModuleAddress, ModuleSource>

Loader Properties

realm

Returns the realm associated with the loader.

global

Convenience: returns the global associated with the loader's realm.

@zloirock
Copy link

Is this proposal alive?

@trusktr
Copy link

trusktr commented Apr 18, 2016

This is the dynamic equivalent of a same-origin <iframe> without DOM.

Is there access to the same DOM as in the main global scope? Or just no DOM at all like a Web Worker?

@azu
Copy link

azu commented Apr 24, 2016

@caridy
Copy link

caridy commented Apr 30, 2016

yeah, we are actually moving to https://github.com/caridy/proposal-realms, where https://github.com/FUDCo/proposal-frozen-realms is a related (dependent of realms) effort, we will be working on both at the same time :)

@erights
Copy link

erights commented Apr 30, 2016

Does https://github.com/caridy/proposal-realms subsume this proposal? Can we just consider that one to be the latest?

@caridy
Copy link

caridy commented Aug 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment