Repository navigation
Broken example for vm.runInDebugContext(code) #4862
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
on Jan 25, 2016 /cc @nodejs/documentation
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.Like this:
> vm.runInDebugContext('Debug').findScript(process.exit).name 'node.js' > vm.runInDebugContext('Debug').findScript(process.emit).name 'events.js'@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
const Debug = vm.runInDebugContext('var util = require("util");');I get
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).I'll dig into the c++ and report back
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
Did you figure out how to do it?
- added a commit that references this issue
on May 17, 2016 - added 2 commits that reference this issue
on May 18, 2016
The current example fails
The error I receive is
Debug.scripts().forEach(function(script) { ^ illegal accessWill do more research and post in this thread