checkpoint some sketches
MODIFY
index.js
index.js
'use strict';
-const SES = require('./src/SES');
-
-module.exports = SES;
+module.exports = require('./src/index.js');

MODIFY
src/index.js
src/index.js
-module.exports = require("./SES.js");
+var Realm = require('../proposal-realms/shim/src/realm.js').default;
+let SES = require("./SES.js");
+
+// f2 = tamperProof(f1); now f2 is safe against some things
+exports.tamperProof = function() { };
+exports.constFunc = function() {};
+
+// f = compileExpr(source); then f(imports) can only affect 'imports'
+exports.compileExpr = function(exprSrc, opt_mitigateOpts) { };
+
+class SESRealm extends Realm {
+ // eval exprSrc inside the realm, with access only to the realm's globals,
+ // and return the result
+ eval(exprSrc) {},
+ // eval exprSrc inside the realm, with access to the realm's globals, plus
+ // any properties of opt_endowments
+ confine(exprSrc, opt_endowments, opt_mitigateOpts) {},
+ // Function constructor which can only access realm's globals
+ Function() {},
+
+}
+
+exports.SESRealm = SESRealm;
+

MODIFY
src/startSES.js
src/startSES.js
@@ -2168,3 +2168,5 @@ ses.startSES = function(global,
ses.logger.error('initSES failed.');
}
};
+
+exports.cajaVM = cajaVM;

MODIFY
test/test.js
test/test.js
@@ -23,10 +23,35 @@ test('realm smoketest', function(t) {
t.end();
});
-test('activate', function(t) {
- const r = new Realm();
- r.global.startSES = SES.startSES;
- r.evaluate('startSES()');
+test('compileExpr', function(t) {
+ let f = SES.compileExpr("a = b+1; a+2");
+ let env = {a: 10, b: 20};
+ t.equal(f(env), 23);
+ t.equal(env.a, 21);
+ t.end();
+});
+
+test('eval', function(t) {
+ const r = new SES.SESRealm();
+ t.equal(r.eval('1+2'), 3);
+
+ let hidden = 1;
+ t.equal(r.eval('hidden+1'), new Error("something something"));
+
+ r.eval('a = 10');
+ t.equal(r.global.a, 10);
+
t.end();
});
+test('confine', function(t) {
+ const r = new SES.SESRealm();
+ r.eval('a = 10');
+ t.equal(r.global.a, 10);
+ let endowments = {b: 10, c: 20};
+ t.equal(r.confine('b += 1; a = c+2; 3'), 3);
+ t.equal(endowments.b, 11);
+ t.equal(r.global.a, 22);
+
+ t.end();
+});

checkpoint some sketches