Enable `def` to work outside the SES environment.
* Include `def` and `Nat` in SES exports.
* Fix deepFreeze so that it returns its argument (like `Object.freeze`).
* Make `def` only deepFreeze if `Object.prototype` is frozen. Otherwise
just freeze. This is a hack to provide an interim fix for
MODIFY
src/bundle/deepFreeze.js
src/bundle/deepFreeze.js
// https://github.com/google/caja/blob/master/src/com/google/caja/ses/repairES5.js
// then copied from proposal-frozen-realms deep-freeze.js
-export function deepFreeze(primordialRoots) {
+export function deepFreeze(root) {
const { freeze, getOwnPropertyDescriptors, getPrototypeOf } = Object;
const { ownKeys } = Reflect;
@@ -27,13 +27,13 @@ export function deepFreeze(primordialRoots) {
const frozenSet = new WeakSet();
/**
- * "deepFreeze()" acts like "Object.freeze()", except that:
+ * "innerDeepFreeze()" acts like "Object.freeze()", except that:
*
* To deepFreeze an object is to freeze it and all objects transitively
* reachable from it via transitive reflective property and prototype
* traversal.
*/
- function deepFreeze(node) {
+ function innerDeepFreeze(node) {
// Objects that we have frozen in this round.
const freezingSet = new Set();
@@ -112,7 +112,8 @@ export function deepFreeze(primordialRoots) {
commit();
}
- deepFreeze(primordialRoots);
+ innerDeepFreeze(root);
+ return root;
}

MODIFY
src/bundle/def.js
src/bundle/def.js
import { deepFreeze } from './deepFreeze.js';
export function def(node) {
+ // TODO HACK return a shallow freeze unless Object.prototype is frozen.
+ // This detects whether we are in a SES realm.
+
// TODO: this currently does too much work: it doesn't remember what's been
// frozen already, so it will re-freeze things like Function.prototype
// every time. To fix this, deepFreeze() needs to be turned into a
@@ -23,6 +26,10 @@ export function def(node) {
// as a global should close over the Freezer and deliver it here.
// deepFreezePrimordials() should use that same Freezer
+ if (Object.isFrozen(Object.prototype)) {
deepFreeze(node);
+ } else {
+ Object.freeze(node);
+ }
return node;
}

MODIFY
src/index.js
src/index.js
// limitations under the License.
import SES from './SES.js';
+import { def, Nat } from './bundle/index.js';
export default SES;
+export { def, Nat, SES };
// f = compileExpr(source); then f(imports) can only affect 'imports'
//exports.compileExpr = function(exprSrc, opt_mitigateOpts) { };

Enable `def` to work outside the SES environment.

* Include `def` and `Nat` in SES exports.
* Fix deepFreeze so that it returns its argument (like `Object.freeze`).
* Make `def` only deepFreeze if `Object.prototype` is frozen. Otherwise
  just freeze. This is a hack to provide an interim fix for
  https://github.com/Agoric/SES/issues/13.