Home

Awesome

Compartments

Stage: 1

Champions:

Emeritus:

Synopsis

Compartments are a mechanism for isolating and providing limited power to programs within a shared realm. Each compartment shares the intrinsics of a realm, but a different set of evaluators (eval, Function, and a new evaluator, Module) and a global object. Having a separate global object allows each compartment to be granted access to only those powerful objects it needs, its own isolated evaluators, powerless constructors, and shared prototypes.

The Compartments proposal was approved for Stage 1 (exploration of a problem) with the charter, "to compartmentalize host behaviors". The problem we set out to solve was excess authority flowing from global scope and host behaviors into third-party dependencies and plugins in large applications. Through exploring this problem, we discovered that the bulk of the solution, by weight, was virtualizing the EcmaScript module loader. Provided an EcmaScript module loader, we could then build a solution for isolating code for both scripts and modules.

Over the course of two years, we refined the Compartment class to account for the need to make and import bundles, emulate various host module specifier namespaces, link modules between multiple compartments, and support non-EcmaScript module languages.

We then began working with champions of module blocks, module fragments, deferred import, and import reflection to ensure these proposals were coherent. From these discussions, we discovered a set of lower-level interfaces from which compartments could be constructed in user code that were more coherent with these other proposals.

With that, the Compartments proposal consists of five layers:

Motivating use cases for module proposal features illustrates the motivation for each feature from the layers of this Compartments proposal and related module proposals.