Unlimited block scopes
I like the idea of scopes which have the limited ability to be read-from and or written-into in order to perform secure operations
A ***blockscope*** would have this functionality
blockscope[ [params [, params]*]* ]{
}
let a = "a"
let a2 = "a2"
let a3 = "a3"
let b,c = blockscope[ let innerScopeA = a ]{
a // referenceError: "a" is undefined
a2 // referenceError: "a2" is undefined
a3 // referenceError: "a3" is undefined
innerScopeA // "a"
let B = "B"
let C = "C"
return B,C
}
innerScopeA // referenceError: "innerScopeA" is undefined
blockscope[ a,b,c,f = Worker("myfile.js") ]{
innerScopeA // referenceError: "innerScopeA" is undefined
a // "a"
b // "B"
c // "C"
let msg = f.postMessage(a,b,c)
let d = blockscope[]{
let D = "D"
blockscope[]{
let e = "e"
blockscope[]{
let g = "g"
}
}
return D
}
d // "D"
}
d // referenceError: "d" is undefined
I see the interesting pattern with with + Proxy in many sandbox-like solutions. The main usage is to capture free variable access. What if we provide a modern syntax for this task?
Indeed compartments are a way to create a new global scope, and the shim does use with for that to happen. Compartments are a bit heavy weight for this specific case however.
It definitely wouldn't be web compatible, and was the original intent for with. However @awbjs suggests a very simple change to the spec to opt out of that behavior (through a symbol on the scope object). We've never pushed for it since there seem to be little appetite to change legacy with.
Given how little with is used in practice, I'm not even convinced this is useful unless it would somehow simplify implementations, so yeah, I don't plan to push that issue much.