-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix: pass vm scrip options through #2238
Conversation
Can you update the corresponding documentation in README? |
Done! 🙂 |
Why not use the options argument to the |
Oh, that's a very good point! That works for my use case then. Feel free to close if you don't want this 🙂 |
@domenic actually, that doesn't seem to work. This snippet hangs forever: const vm = require('vm');
const script = new vm.Script('while(true){}', {timeout: 1000});
script.runInContext(vm.createContext()); While this snippet throws a timeout error: const vm = require('vm');
const script = new vm.Script('while(true){}');
script.runInContext(vm.createContext(), {timeout: 1000}); Not sure if it's a bug in Node, or something with how scripts are executed. This is running node 8.11.1 |
To my eyes it looks like |
@SimenB Could you file an issue at https://github.com/nodejs/node? I'd be happy to look at it over there! |
Done! nodejs/node#20982 |
This is apparently faulty docs, so the PR is back on the table, I think :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test to the runVMScript tests?
README.md
Outdated
@@ -282,6 +282,8 @@ dom.window.ran === 3; | |||
|
|||
This is somewhat-advanced functionality, and we advise sticking to normal DOM APIs (such as `window.eval()` or `document.createElement("script")`) unless you have very specific needs. | |||
|
|||
`runVMScript` also takes an `options` object as its second argument. See the [Node docs](https://nodejs.org/api/vm.html#vm_script_runincontext_contextifiedsandbox_options) for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits:
- I've tried to stick with adding parens for function/method names, so
runVMScript()
. - I've tried to stick to Node.js instead of Node.
Also maybe we should update the header to runVMScript(script[, options])
? Dunno, could go either way.
@domenic sorry, I completely forgot about this! I've rebased, addressed your comments on the docs and added a test 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, thank you!
In order to prevent scripts from potentially running forever, it'd be great to be able to pass a
timeout
to it.Docs: https://nodejs.org/api/vm.html#vm_script_runincontext_contextifiedsandbox_options