how to determine source information of callback in v8

允我心安 提交于 2019-12-10 12:08:31

问题


Is it possible to determine the source information (file, line number, column number) of a callback in v8?

function foo(callback) {
    var x = callback();
    if (typeof x !== "string") {
        //hmmm, x is not as expected, I want to know more about the callback.
    }
}

回答1:


I'm not aware that you can do this in JavaScript, but if you can debug it, it should show you the file/line etc..

I guess doing that would depend exactly on your setup and I've never done it myself - it looks like node (uses v8) has some sort of support for that .

Might be useful?: v8 DebuggerProtocol




回答2:


callsite helps with this.

It exposes __stack global variable which can be used to get the stack trace. And __line which is the current line number.



来源:https://stackoverflow.com/questions/8871874/how-to-determine-source-information-of-callback-in-v8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!