I hope the following makes sense, it is impreciseI have a question. Does SES entirely do away with the "scope chain" and all passing by shared visibility, trading that for explicit object members, or are lexical scopes still available?
If lexical scopes are still available, can the global symbols, that represent immutables, get assigned new representations? That is, can core features get turned off after we're done using them, likefunction = function(x){ throw }; // we have all the functions we need, further attempts to compile more will fail.
Can the immutables be lexically hidden?
By allowing hiding, you might be able to avoid having to construct a new eval function with each realm unless you really need one. That is,leave "eval" out of the core language, and put in its place evalFactory(topRealm), withvar eval = evalFactory(immutableGlobal);// or even bettereval = function(dummySrc) { throw } // not sure how to spell thisas an available compatability shimso eval, when needed, could get clobbered with whatever realm you want the evalling to happen in, instead of requiring all realms, even realms that aren't planning on evalling anything, to have one.
--A circular pizza with radius Z and thickness A has a volume of PI (Z*Z) A
_______________________________________________
cap-talk mailing list
cap-...@mail.eros-os.org
http://www.eros-os.org/mailman/listinfo/cap-talk
On Fri, Mar 18, 2016 at 10:44 PM, Mark S. Miller <eri...@google.com> wrote:On Fri, Mar 18, 2016 at 6:34 PM, David Nicol <david...@gmail.com> wrote:I hope the following makes sense, it is impreciseI have a question. Does SES entirely do away with the "scope chain" and all passing by shared visibility, trading that for explicit object members, or are lexical scopes still available?Lexical scopes are still exactly as available as they are otherwise. SES does nothing whatsoever to change that. Historically, one of the many things that motivated me to fight so hard to get true lexical scoping into ES5/strict was that the SES-shim needed it. But now that we have it, SES does nothing to change it.
what about "variable hoisting" seeming to re-order things? I ask just because it's confusing coming from Perl, where you can redeclare the same local symbol repeatedly if you want, to Javascript where you can only declare a symbol once per scope.
If lexical scopes are still available, can the global symbols, that represent immutables, get assigned new representations? That is, can core features get turned off after we're done using them, likefunction = function(x){ throw }; // we have all the functions we need, further attempts to compile more will fail.I don't understand the question. "function" is a keyword. It cannot be used as a variable name.
I should have writtenfunction function(){throw};orvar function = function(x){ throw };as if the keywords are plain symbols like coder-declared ones.
Can the immutables be lexically hidden?Good question. Yes and no.You can hide the original global name bindings by several means. The fresh global of a new ses realm is a plain mutable object. It initially inherits from the proto-global, but you can change that. To have full control, you can put what you want on the global and then do "freshGlobal.__proto__ = null" (or use Reflect.setPrototypeOf). By wrapping any code you execute in a prelude and postlude that shadows globals and hides the global object itself, you can also change the bindings of these names.However, this does not enable you to deny access to the intrinsics that can be reached by syntax. For example, the expression "[]" in any SES realm will create an array that initially inherits from the proto-SES realm's Array.prototype, independent of the scoping environment in which that code executes. That's why we require everything in the proto-SES realm to be transitively immutable and powerless. We assume these objects cannot be denied.Of course, a code rewriting strategy can change what is reachable by syntax. But SES does nothing to either help or hurt rewrite-based enforcement.
so allowing unlimited external access to eval() may become safe from side effects, but not from resource-starving DOS attacks; it still isn't recommended.
By allowing hiding, you might be able to avoid having to construct a new eval function with each realm unless you really need one. That is,leave "eval" out of the core language, and put in its place evalFactory(topRealm)
I'm sorry, I don't understand the suggestion. What does evalFactory do?
evalFactory is supposed to generate an eval function whose scope chain stops at the argument, which is expected to be a scope, if the with statement caused new vars declared within its block to go in the scope (which it doesn't) it would be like sofunction evalFactory(S){return function ( src ) {fancyWritingWith(S) { eval(src) }};};
SES still isn't about creating little languages that are invoked with a near-native eval keyword, and that isn't a criticism of it.
Thanks
It is now ready for comments at https://github.com/FUDCo/ses-realm
It's valid strict JavaScript, but the semantics are different. Now all the instances share a single state instead of each call creating a separate state. JavaScript hoists vars to the top of the enclosing function block or program production.
the point i was trying to make is when
makeCounter is untrusted code, and we can eval untrusted code into a
confined space, and makeCounter can do such a thing, we can load
confined code, but passing objects created by the untrusted code to
multiple parties seems delicate.
Not really familiar with javascript, but to slightly modify one of
your examples from one of your talks
"use strict";
var count = 0;
function makeCounter() {
// Moved var count = 0 from here to above
// appears to be valid strict javascript afaict
return def({
incr: function() { return ++count;},
decr: function () { return --count;}
});
}
with the comment in the bottom of the slide:
"A tamper-proof record of lexical closures encapsulating state is a
defensive object"
so this is 'defensive' rather than 'confined',
confinement then
happens through multiple evaluations of the source code (rather than
the evaluator causing error due to the evaluation of the function
makeCounter being called in a context where the 'count' variable does
not exist, did I get that correct?
so say if I wanted a Diary object which contains alice/bob/carols
secrets, and ensures the separation of those secrets, you need to
evaluate this source multiple times?