You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Broken example for vm.runInDebugContext(code) #4862
undefined:1
var util = require("util");
^
ReferenceError: require is not defined
at <anonymous>:1:12
As the definition of runInDebugContext is vm.runInDebugContext(code) I thought I could feed arbitrary code. It appears that this context does not by default have access to all the node bits in the main context (this is a guess).
As the definition of runInDebugContext is vm.runInDebugContext(code) I thought I could feed arbitrary code. It appears that this context does not by default have access to all the node bits in the main context (this is a guess).
That's correct. It's a clean slate JS VM with debugger bits but no node bits. It's similar to vm.runInNewContext(code) in that respect, except that doesn't even have debugger bits.
@bnoordhuis ahhh. That makes a lot of sense. I'll dig into the debugger source and see how it sets up the environment. That is a bit out of scope for this issue though, so I'll try and put together a working example for VM and perhaps some documentation about the context
Activity
MylesBorins commentedon Jan 25, 2016
/cc @nodejs/documentation
bnoordhuis commentedon Jan 25, 2016
Oh, that's because you need to start the debugger first now before you have access to
Debug.scripts(). I'd swap it out for a different example.bnoordhuis commentedon Jan 25, 2016
Like this:
MylesBorins commentedon Jan 25, 2016
@bnoordhuis can you share an example of running arbitrary in a vm context?
I think I can get a test for #4819 by running some code in a debug context, but perhaps I am missing some... context (sorry couldn't help it).
When I try something like
I get
As the definition of runInDebugContext is
vm.runInDebugContext(code)I thought I could feed arbitrary code. It appears that this context does not by default have access to all the node bits in the main context (this is a guess).I'll dig into the c++ and report back
bnoordhuis commentedon Jan 25, 2016
That's correct. It's a clean slate JS VM with debugger bits but no node bits. It's similar to
vm.runInNewContext(code)in that respect, except that doesn't even have debugger bits.MylesBorins commentedon Jan 25, 2016
@bnoordhuis ahhh. That makes a lot of sense. I'll dig into the debugger source and see how it sets up the environment. That is a bit out of scope for this issue though, so I'll try and put together a working example for VM and perhaps some documentation about the context
yorickvP commentedon May 14, 2016
Did you figure out how to do it?
doc: update vm.runInDebugContext() example
doc: update vm.runInDebugContext() example
doc: update vm.runInDebugContext() example