IE8上的多个框架JS的完整调用堆栈 [英] Full callstack for multiple frames JS on IE8

查看:178
本文介绍了IE8上的多个框架JS的完整调用堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



调用堆栈时,我需要在Internet Explorer 8上的JavaScript中发生异常时获取完整的调用堆栈。必须将日志发送给开发人员。
我不能使用调试器,因为最终用户不必处理这个问题。



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



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



基于Active Scripts技术的解决方案提供了ScriptEngine类型的对象:
IHTMLDocument :: get_Script(IDispatch ** p)



* 我可以从IE8中找出要用于给定上下文的链接ScriptEngine ,以提取构建callstack的必要信息?

解决方案

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



在每个框架中定义下一个简单函数:

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

下一个功能只适用于顶部框架:

  function populateStack(fn){
var perFrames = []; (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(\\\
));
}

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

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

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

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

我花了一对几小时,尝试恢复精确的顺序,调用哪些函数,但没有找到解决方案。只有部分顺序(框架内的函数正确排序)在该代码中可用。



如果您有多个不同版本代码的服务器,那么您可以添加一个代码,分析功能体,并通过这些代码获取有关呼叫顺序的更多信息。



希望,这有助于: - )


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?

解决方案

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 :-)

这篇关于IE8上的多个框架JS的完整调用堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆