createSES.js: create a global SES.harden
MODIFY
src/bundle/createSES.js
src/bundle/createSES.js
@@ -133,7 +133,9 @@ You probably want a Compartment instead, like:
const b = r.evaluate(creatorStrings);
b.createSESInThisRealm(r.global, creatorStrings, r);
- // b.removeProperties(r.global);
+
+ // Allow harden to be accessible via the SES global.
+ r.global.SES.harden = harden;
if (options.consoleMode === 'allow') {
const s = `(${makeConsole})`;

MODIFY
src/bundle/whitelist.js
src/bundle/whitelist.js
@@ -859,6 +859,7 @@ export default {
SES: {
confine: t,
confineExpr: t,
+ harden: t,
},
Nat: j,

MODIFY
test/test.js
test/test.js
@@ -47,6 +47,15 @@ test('SESRealm has SES.confine', t => {
t.end();
});
+test('SESRealm.SES has harden', t => {
+ const s = SES.makeSESRootRealm();
+ const obj = s.evaluate(`SES.harden({a})`, { a: 123 });
+ t.equal(obj.a, 123, `expected object`);
+ t.throws(() => (obj.a = 'ignored'));
+ t.equal(obj.a, 123, `hardened object retains value`);
+ t.end();
+});
+
test('SESRealm.SES wraps exceptions', t => {
const s = SES.makeSESRootRealm();
function fail() {

createSES.js: create a global SES.harden