我如何以编程方式访问v8调试器变量列表

时间:2015-01-29 13:43:28

标签: node.js

我正在写一个AOP容器。 我想获得app.js脚本中包含的对象和函数列表。 我可以看到所有这些都可用于NodeClipse V8 Debugger Variables列表。

问题是:我需要编写哪些代码才能访问V8 Debugger Variables列表?

谢谢, 利奥

1 个答案:

答案 0 :(得分:0)

用于Node.js的NodeClipse Eclipse插件不适用于嵌入式V8调试器。 相反,我访问了JavaScript应用程序模块导出以使用Node.js应用程序进行反射,因为“this”对象为空。 这是代码:

app.js code:

var business_object = require('./user.js');

var node_framework = require('./trace-meldaround.js');

var user = new business_object.User('Leo');


var trace = new node_framework.Trace('Hello Meld App');

trace.doTrace();

user.sayHello();

user.sayGoodBye();


user.js code:

var User = function(name){
    this.name = name;
    };

    User.prototype.sayHello = function(){
        console.log('hello ' + this.name);
    };

    User.prototype.sayGoodBye = function(){
        console.log('Good Bye ' + this.name);
    };

    exports.User = User;



trace-meldaround.js Code:
var meld, joinPoint;


meld = require('./meld.js');
joinPoint = meld.joinpoint;

var log4js = require('./node_framework/log4js-node-master/lib/log4js'); // include log4js

log4js.configure({ // configure to use all types in different files.
    appenders: [
        {   type: 'file',
            filename: '../logs/error.log', // specify the path where u want logs folder error.log
            category: 'error',
            maxLogSize: 20480,
            backups: 10
        },
        {   type: 'file',
            filename: '../logs/info.log', // specify the path where u want logs folder info.log
            category: 'info',
            maxLogSize: 20480,
            backups: 10
        },
        {   type: 'file',
            filename: '../logs/debug.log', // specify the path where u want logs folder debug.log
            category: 'debug',
            maxLogSize: 20480,
            backups: 10
        }
    ]
});

var loggerinfo = log4js.getLogger('info'); // initialize the var to use.
var loggererror = log4js.getLogger('error'); // initialize the var to use.
var loggerdebug = log4js.getLogger('debug'); // initialize the var to use.

var Trace = function(AppName){
    this.appName = AppName;
    };


    Trace.prototype.doTrace = function(){

        function sayMeld(jp) {           
            console.log('meldaround function called for Application : ' + Trace.constructor.AppName);

            console.log('JoinPoint Method: ' +  jp.method);
            console.log('JoinPoint Target: ' + jp.target);
            console.log('JoinPoint Args: ' + jp.args.toString());
            console.log('JoinPoint Result: ' + jp.result);
            console.log('JoinPoint Exception: ' + jp.exception);
            loggerinfo.info('Calling Method: ' + jp.method);
            loggererror.info('This is Error Logger');
            loggerdebug.info('JoinPoint Method: ' +  jp.method);
            loggerdebug.info('JoinPoint Target: ' + jp.target);
            loggerdebug.info('JoinPoint Args: ' + jp.args.toString());
            loggerdebug.info('JoinPoint Result: ' + jp.result);
            loggerdebug.info('JoinPoint Exception: ' + jp.exception);           
        }


        var appObjects = module.parent.children;       
        var methods = [];
        var objects = [];

        for (var i=0; i<appObjects.length;i++){   
            if (typeof appObjects[i] == 'object'){
                    objects.push(appObjects[i]);

                    var funcObj = appObjects[i].exports;
                    if (typeof funcObj == 'object')
                    {
                        for (var key in funcObj){
                            var k =0;
                            var prototypeObj = funcObj[key].prototype;
                            methods[i] = [];
                            for (var proto in prototypeObj){                                                                                                
                                 methods[i][k] = proto;
                                 k++;
                            }                                                                               
                        }
                    }                   
                }
        }


        for (var j=0; j<objects.length; j++){
            var ObjectName;
            for (var key2 in objects[j].exports){               
                ObjectName = key2;
                console.log(objects[j].exports[ObjectName].prototype);

                for (var n=0; n<methods[j].length; n++){
                    if (ObjectName != 'Trace'){
                    meld.around(objects[j].exports[ObjectName].prototype, methods[j][n], function(joinPoint){
                        sayMeld(joinPoint);

                        joinPoint.proceed();
                    });   
                    }
                }

            }                       
    }

    };

    exports.Trace = Trace;