joyent/node — Issue #2488: Add a --frozenGlobal flag
Author: thejh
Created: 2012-01-08 14:38:50+00:00
State: open

How about adding a flag `--frozenGlobal` that, just before the user code gets executed, does `Object.freeze(global)`? Code example:

a=1
console.log(a)

Effect:

ReferenceError: a is not defined
at Object. (/home/jann/tmp/test.js:2:13)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)

It would be even cooler to already get an error on assignment to global, not just on usage, but that would probably require making the global object a proxy.