2013-09-26 40 views
0

我想要做一些有趣的事情,需要我在javascipt中運行一條語句,這個語句需要shows all the objects that are present in the current context在我的上下文中打印所有內容

這些對象可能只是由我或nodejs環境創建的。

這是促進在JavaScript?

一個用途可以用於調試目的。

+1

簡短的回答:這是不可能的。 – fardjad

回答

0

從js級別不可能。你可以從調試器中獲得所有的幀和閉包範圍變量(並且它很容易自動化 - require('_debugger')。如果這是你準備嘗試的東西,我可以解釋V8 debugger protocol的細節,併爲它構建在node.js客戶端上。 :

從節點核心調試器客戶端的基本用法:

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! 
    }); 

}); 

請首先嚐試使用「調試程序」關鍵字,結果檢查,然後繼續設置/從你的腳本改變斷點

看看它是如何的used in node,在node-vim-debugger如果缺了點什麼參考V8 debugger protocol documentation

注意,您必須從腳本訪問similar API正在調試自己,怎麼看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); 
+0

謝謝。我想知道如何在nodejs客戶端中構建。 –

+0

它沒有記錄/內部(但?)。我會更新回答。 –