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

feat(ses): Support global lexicals #356

Merged
merged 14 commits into from
Jul 5, 2020
Prev Previous commit
Next Next commit
Copying by descriptor is in fact necessary
  • Loading branch information
kriskowal committed Jul 4, 2020
commit dd3e7339977cbe77c94148ffd36ff0f4a0b8bf52
17 changes: 11 additions & 6 deletions packages/ses/src/compartment-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import * as babel from '@agoric/babel-standalone';
// Both produce:
// Error: 'default' is not exported by .../@agoric/babel-standalone/babel.js
import { makeModuleAnalyzer } from '@agoric/transform-module';
import { assign, freeze, getOwnPropertyNames, entries } from './commons.js';
import {
assign,
create,
defineProperties,
getOwnPropertyNames,
getOwnPropertyDescriptors,
entries,
} from './commons.js';
import { createGlobalObject } from './global-object.js';
import { performEval } from './evaluate.js';
import { getCurrentRealmRec } from './realm-rec.js';
Expand Down Expand Up @@ -201,11 +208,9 @@ export class Compartment {

// TODO just pass globalLexicals as globalObject
// https://github.com/Agoric/SES-shim/issues/365
const localObject = freeze({
__proto__: null,
...globalLexicals,
...endowments,
});
const localObject = create(null);
defineProperties(localObject, getOwnPropertyDescriptors(globalLexicals));
defineProperties(localObject, getOwnPropertyDescriptors(endowments));

return performEval(realmRec, source, globalObject, localObject, {
globalTransforms,
Expand Down
15 changes: 11 additions & 4 deletions packages/ses/src/module-instance.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { performEval } from './evaluate.js';
import { getCurrentRealmRec } from './realm-rec.js';
import { getDeferredExports } from './module-proxy.js';
import { create, entries, keys, freeze, defineProperty } from './commons.js';
import {
create,
getOwnPropertyDescriptors,
entries,
keys,
freeze,
defineProperty,
} from './commons.js';

// q, for enquoting strings in error messages.
const q = JSON.stringify;
Expand Down Expand Up @@ -46,9 +53,9 @@ export const makeModuleInstance = (

// {_localName_: accessor} proxy traps for globalThis, globalLexicals, and
// live bindings.
// There must be no accessor properties on globalLexicals so we take a
// snapshot of enumerable properties.
const localObject = { __proto__: null, ...globalLexicals };
// The globalLexicals object is frozen and the corresponding properties of
// localObject must be immutable, so we copy the descriptors.
const localObject = create(null, getOwnPropertyDescriptors(globalLexicals));

// {_localName_: init(initValue) -> initValue} used by the
// rewritten code to initialize exported fixed bindings.
Expand Down