Any objections?
FWIW -- stripping JSOPTION_VAROBJFIX breaks me according to my hg log.
*thinking*
I'm about 99% sure the problem is that using varobjfix forces all unbound
var declarations to be on the same global object, which is not the semantic
expected by CommonJS modules when I use JS_CompileFile (or similar) to load
them.
Of course, there are workarounds, like dynamically re-writing the module to
run in a closure, but that's obnoxious and makes some other stuff
impossible. ('other stuff' - other people's legacy code -- but frankly, API
has changed so much that no old code works with new spidermonkey anyhow)
Conclusion - from my POV - force it on if not doing so is a constant perf
hit for the engine or the coders, please try to leave it optional if it's
not. For me it means a couple days of re-engineering and a potential perf
/ RAM hit. The RAM hit is because there is no way that I know of to parse a
script piece-meal, so I'd have to load it into RAM in order to wrap it in a
closure.
I'd recommend checking in with MikeM, I forget exactly what he does with his
super-globals in his web server, but I bet this would affect that.... CCing
Mike with this message.
Wes
PS: Upon further reflection, does this mean that all loaded scripts will
have the same global object if they are on the same context? If so, a
documentation warning or something might be applicable for anybody who cares
about sandboxing.
--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
Not so strange from my POV, I'm using this in some cases, mainly for
sandboxing, so I prefer to have the option.
Regards.
Salvador Ortiz.
Luke
JSOPTION_VAROBJFIX affects only where declared global variables go.
Undeclared globals (created by assignment to free variables) go on the
last object on the scope chain.
Unless you rule those out by making them errors (ES5 strict mode does
this), I don't see how you can rely on the lack of JSOPTION_VAROBJFIX
safely.
/be
Right -- when I say "unbound vars", I mean variables which are declared with
var but not in a function.
CommonJS effectively places a var object on the scope chain between each
module and the global object. Most implementations achieve this effect by
wrapping every module in a function before compiling it, however it can be
implemented in SpiderMonkey by simply passing a new object to
JS_ExecuteScript(), after directly loading the module with JS_CompileFile().
For example, consider the following CommonJS module and program. Recall that
CommonJS modules are dynamically loaded singletons.The correct answer is 3:
/** Program: program.js */
var a = 2;
var b = 1;
var aMod = require("./a");
print(aMod.a() + a);
/** Module: a.js */
var a = b;
exports.a = function() { return a };
CommonJS explicitly leaves the behaviour of un-var'd objects (which would be
errors in strict ES5) undefined, as there is no reasonable way to implement
the desired semantic (undeclared variables stay trapped at the module level
without percolating to the program [global object]) in a conformant ES3 or
ES5 environment.
This ambiguity will obviously be a source of bugs in poorly-written CommonJS
modules. Locally, we run JSOPTIONS_STRICT all the time, and often turn
warnings into errors. With the exception of eval'd code, we catch these
errors early with our build system.
Wes