Fix #1832: Browser compiler should run code using globally-scoped eval #5047
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1832. The top of that thread suggests that we use script (DOM) injection rather than plain
eval
to execute scripts that users enter in browser contexts, such as Try CoffeeScript, to boost performance dramatically. By the end of the thread, it’s established that the reason script injection is so much faster is that we were usingeval
in the context of the CoffeeScript compiler; if we usewindow.eval
instead, to use a global context and exclude all the local variables accessible where we’re making theeval
call, thewindow.eval
method is ever so slightly faster still than script injection. It’s also compatible with Node, socake test:browser
still works (if we first detect whether to callwindow.eval
orglobal.eval
). The performance tests are still accessible here: http://web.archive.org/web/20130326103111/http://jsperf.com:80/eval-vs-script/6The other changes you see in this PR turn off variable name mangling in our minification, which was previously happening because the presence of the
eval
call was automatically disabling mangling in the scope thateval
had access to; now that we’re using a globally-scopedeval
, that no longer happens, and the browser compiler breaks when full mangling is enabled. And finally, one of the browser-based tests was broken by #5028, and I included the fix here.So yes, in the simplest sense #1832 could’ve been resolved seven years ago by adding just seven characters (changing
eval
towindow.eval
). Sorry it took so long.