Skip to content
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

Broken example for vm.runInDebugContext(code) #4862

Closed
MylesBorins opened this issue Jan 25, 2016 · 7 comments
Closed

Broken example for vm.runInDebugContext(code) #4862

MylesBorins opened this issue Jan 25, 2016 · 7 comments
Assignees
Labels
doc Issues and PRs related to the documentations. vm Issues and PRs related to the vm subsystem.

Comments

@MylesBorins
Copy link
Member

The current example fails

const Debug = vm.runInDebugContext('Debug');
Debug.scripts().forEach(function(script) { console.log(script.name); });

The error I receive is

Debug.scripts().forEach(function(script) {
      ^
illegal access

Will do more research and post in this thread

@MylesBorins MylesBorins added doc Issues and PRs related to the documentations. vm Issues and PRs related to the vm subsystem. labels Jan 25, 2016
@MylesBorins
Copy link
Member Author

/cc @nodejs/documentation

@bnoordhuis
Copy link
Member

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
Copy link
Member

Like this:

> vm.runInDebugContext('Debug').findScript(process.exit).name
'node.js'

> vm.runInDebugContext('Debug').findScript(process.emit).name
'events.js'

@MylesBorins
Copy link
Member Author

@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

@bnoordhuis
Copy link
Member

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.

@MylesBorins
Copy link
Member Author

@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

@MylesBorins MylesBorins self-assigned this Jan 25, 2016
@yorickvP
Copy link

Did you figure out how to do it?

bnoordhuis added a commit to bnoordhuis/io.js that referenced this issue May 16, 2016
The debugger needs to be active now before one is allowed to query the
list of scripts.  Replace the example with one that works without
installing a debug event listener first.

Fixes: nodejs#4862
PR-URL: nodejs#6757
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
evanlucas pushed a commit that referenced this issue May 17, 2016
The debugger needs to be active now before one is allowed to query the
list of scripts.  Replace the example with one that works without
installing a debug event listener first.

Fixes: #4862
PR-URL: #6757
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue May 18, 2016
The debugger needs to be active now before one is allowed to query the
list of scripts.  Replace the example with one that works without
installing a debug event listener first.

Fixes: #4862
PR-URL: #6757
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue May 18, 2016
The debugger needs to be active now before one is allowed to query the
list of scripts.  Replace the example with one that works without
installing a debug event listener first.

Fixes: #4862
PR-URL: #6757
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants