Mark S. Miller (2013-09-29T01:19:47.000Z)
domenic at domenicdenicola.com (2013-10-13T02:20:00.208Z)
Actually, for this, confine isn't quite what you want, since you're providing the entire extensible virtual global. (The confine function's second argument is just the additions to the default powerless virtual global.) You want compileExpr from https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/startSES.js#783 or the similar compileModule. To avoid the need for even mild translation, I rephrased your example to assign to the bar property of the pseudo-top-level "this". ``` > var env = {foo: 1}; undefined > cajaVM.compileExpr('this.bar = foo+1')(env); 2 > env.bar 2 ``` With mild translation (see the rewriteTopLevelVars mitigation option), you could use compileModule instead and have your original source string appear as you wrote it. Such mitigation unfortunately requires a full parser, and so is only available when SES is bundled with https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/mitigateGotchas.js. Caja does bundle these together. ES6 module loaders will make much of this mechanism unnecessary, while still enabling us to continue to support old SES code that uses the current API.