IE8 上多帧 JS 的完整调用堆栈

发布于 2024-10-09 10:02:05 字数 620 浏览 5 评论 0原文

当 Internet Explorer 8 上的 JavaScript 发生异常时,我需要获取完整的调用堆栈。函数调用可能发生在数量较大的帧之间。

将日志发送给开发人员所需的调用堆栈。 我无法使用调试器,因为最终用户不必处理这个问题。

当前的 JavaScript 解决方案提供了它可以生成调用堆栈(http://eriwen.com/javascript/js -堆栈跟踪/)。它基于arguments.callee.caller。但如果该函数是从当前帧外部调用的,则调用者返回零(未定义)。因此获得的callstack是不完整的。

在这种情况下我可以获得调用该函数的框架的名称吗?

基于活动脚本技术的解决方案给出了 ScriptEngine 类型的对象: IHTMLDocument::get_Script(IDispatch ** p)

但是将对象“script”转换到接口 IActiveScript 失败。

*我可以从 IE8 中获取用于给定上下文 ScriptEngine 的链接,以提取构建调用堆栈所需的信息吗?

I need to get a full call stack when an exception occurs in JavaScript on Internet Explorer 8. Function calls may occur between frames whose number is large.

Call stack necessary to send logs to the developers.
I cannot use a debugger, because the end user does not have to deal with this problem.

The current solution for JavaScripts provided it can generate callstack (http://eriwen.com/javascript/js-stack-trace/). It is based on arguments.callee.caller. But the caller returns zero ( undefined ) if the function was called from outside the current frame. Thus callstack obtained is incomplete.

Can I get the name of a frame from which the function was called in this case?

Solution based on Active Scripts Technology gives an object of type ScriptEngine:
IHTMLDocument:: get_Script (IDispatch ** p)

But casting object "script" to the interface IActiveScript fails.

*Can I get out of IE8 the link to be used for a given context ScriptEngine, to extract the necessary information to construct the callstack?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-10-16 10:02:05

我找到了一些方法,可能有用。它利用了回调的思想。

在每一帧定义下一个简单函数:

function getCaller() { return arguments.callee.caller; }

并且下一个函数仅适用于顶部框架:

function populateStack(fn) {
    var perFrames = [];
    for (var i = 0; i < windows.length; i++) {
        var win = windows[i];
        var func = (win == this) ? fn : win.getCaller();
        var localStack = [];
        while (func) {
            localStack.push(getFuncName(func));
            func = func.caller;
        }
        perFrames.push(getWinName(win) + ": " + localStack.join(", "));
    }
    alert(perFrames.join("\n"));
}

function getWinName(win) {
    var m = win.location.toString().match(/^.*\/(.*)$/);
    return m[1];
}

function getFuncName(func) {
    var m = func.toString().match(/^function\s*(\w*)\(/);
    return m[1] || "anonymous";
}

窗口应该是包含所有窗口对象(即框架)的顶部框架的数组。
用法:

window.top.populateStack.call(window, arguments.callee);

我花了几个小时,试图恢复调用函数的确切顺序,但没有找到解决方案。该代码中仅提供部分顺序(函数在框架内正确排序)。

如果您有多个具有不同版本代码的服务器,那么您可以添加一段代码,该代码将分析函数体并通过该代码获取有关调用顺序的更多信息。

希望这有帮助:-)

I've found some way, which may be usefull. It utilizes the idea of callbacks.

Define next simple function at every frame:

function getCaller() { return arguments.callee.caller; }

and next functions only for top frame:

function populateStack(fn) {
    var perFrames = [];
    for (var i = 0; i < windows.length; i++) {
        var win = windows[i];
        var func = (win == this) ? fn : win.getCaller();
        var localStack = [];
        while (func) {
            localStack.push(getFuncName(func));
            func = func.caller;
        }
        perFrames.push(getWinName(win) + ": " + localStack.join(", "));
    }
    alert(perFrames.join("\n"));
}

function getWinName(win) {
    var m = win.location.toString().match(/^.*\/(.*)$/);
    return m[1];
}

function getFuncName(func) {
    var m = func.toString().match(/^function\s*(\w*)\(/);
    return m[1] || "anonymous";
}

windows should be an array at the top frame containing all window objects (i.e. frames).
Usage:

window.top.populateStack.call(window, arguments.callee);

I've spent a pair of hours, trying to restore exact order, in which functions was called, but have found no solution. Only partial order (functions are correctly sorted within frames) is available in that code.

If you have several servers with different versions of code, then you may add a code, which will analyze function bodies and through that obtain more information about call order.

Hope, this helps :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文