-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use node's vm module to run in clean context #55
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @arthurnn (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
As suggested by Joshua Peek in a previous issue. Node's vm module gives us full control over the globals passed to the context the code is run in. In order to do this we store our code as a JS string, wrap it in an IFFE (to support the `return` symantics we use for all runtimes) vm.runInNewContext is called with {filename: "(execjs)"} in order to have the proper filename appear in backtraces. Normally this string is inserted into backtraces via a gsub in external_runtime.rb which replaces the filename. See https://nodejs.org/api/vm.html
This is unfortunate. It seems that this hits an issue with node 0.10 where it does not show line numbers for syntax errors when using the |
I don't think we should care about node 0.10 since it will be stop receiving updates in a couple of weeks: https://github.com/nodejs/LTS#lts-schedule |
I did some manual bisecting between node versions. It seems like Node 0.11.12 is the first version for which syntax errors inside of The unfortunate thing is that widely used ubuntu versions, precise (12.04) and trusty (14.04), still ship with old node versions (this is what our travis workers are using). However, the breakage here is pretty minor. The only issue is that syntax errors don't include the correct stacktrace. Maybe that is an acceptable compromise for these old node versions. |
@jhawthorn not sure why but according to Travis tests are passing fine in Node v0.10 (linux) and failing with Node 6.0.0 (osx). I updated the .travis.yml to display the version of Node used. |
This really would be a fantastic improvement. I just used ExecJS for something and was baffled to get a fresh environment each time. |
As suggested by Joshua Peek in a previous issue. Node's vm module gives us full control over the globals passed to the context the code is run in.
In order to do this we store our code as a JS string, wrap it in an IFFE (to support the
return
symantics we use for all runtimes)vm.runInNewContext
is called with{filename: "(execjs)"}
in order to have the proper filename appear in backtraces. Normally this string is inserted into backtraces via a gsub in external_runtime.rb whichreplaces the filename.
See https://nodejs.org/api/vm.html