0

I am trying to do something funny with nodejs that requires me to run a single statement in javascipt that shows all the objects that are present in the current context.

These objects might be just created by me or by the nodejs environment.

Is this facilitated in javascript ?

One use can be for debugging purposes.

1
  • 1
    Short answer: it's not possible.
    – fardjad
    Commented Sep 26, 2013 at 6:44

1 Answer 1

0

Not possible from js level. You can get all frame and closure scope variables from debugger (and it's very easy to automate - require('_debugger'). If this is something you ready to try I can explain details of V8 debugger protocol and built in node.js client for it.

Update:

Basic usage of debugger client from node core:

var DebuggerClient = require('_debugger').Client;
var dc = new DebuggerClient();
dc.connect(5858);  // you need to start your script with "node --debug-brk=5858 script-to-debug.js"

// listen breakpoint:
dc.on('break', function(res) {
   // sctipt id, line, location here
   dc.reqBacktrace(function(err, res) {
      // res.frames array
   });

   dc.reqScopes(function(scopes) {
      // SCOPES! TADAM!
   });

});

Try first using "debugger" keyword, inspect results, then continue with setting/changing breakpoints from your script.

See how it's used in node, in node-vim-debugger and if something missing refer to V8 debugger protocol documentation

Note that you have access to similar API from the script being debugged itself, see how it is used to set breakpoint at the beginning of the script

// script is a reference to Script object, see "vm" module
global.v8debug.Debug.setBreakPoint(script, 0, 0);
2
  • Thanks. I would like to know about build in nodejs client. Commented Sep 26, 2013 at 7:15
  • It's not documented/internal (yet?). I'll update to answer. Commented Sep 26, 2013 at 9:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.