Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for “global contour” #33

Open
kriskowal opened this issue Oct 28, 2020 · 1 comment
Open

Add support for “global contour” #33

kriskowal opened this issue Oct 28, 2020 · 1 comment

Comments

@kriskowal
Copy link
Member

The global contour is a scope that overshadows globalThis when evaluating “global code”. The global contour is the scope that persists variable declarations between calls to evaluate global code. Framed as a feature of compartments, we could add a “global” option to compartment.evaluate that signifies this evaluation mode and persists the global contour between calls.

compartment.evaluate("const example = 42;");
compartment.evaluate("example"); // 42
compartment.evaluate("const example = 101;"); // throws SyntaxError: Identifier 'example' has already been declared

Ideally, we could reconcile the global lexicals and global contour. However, evaluating global code should not be able to introduce variables that would overshadow globals in modules from the same compartment.

The global contour is a mutable property bag that must enforce rules for the order and behavior variable declarations.

The name “global contour” is reviled by all, but thankfully need not appear in code. Alternative suggestions are very welcome.

@Jamesernator
Copy link

So interestingly the ShadowRealm doesn't support the "global contour" based on the spec for PerformShadowRealmEval.

i.e. As specced currently this throws an error (and v8's experimental implementation confirms this):

shadowRealm.evaluate(`let x = 42`);
// throws a ReferenceError *inside* the ShadowRealm (exposed as TypeError outside)
shadowRealm.evaluate(`x`);

With the new changes to the proposal, we could plausibly add this as functionality to Evaluator. Currently Evaluator simply provides an eval function, and eval doesn't use the global contour. Perhaps we should just provide a evaluator.evaluateScript which uses script semantics rather than eval semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants