J
Java script Dude
To all Mozilla JS Guru's (IE dudes welcome),
I have spent the last three years developing complex DHTML
applications that must work in IE 5.5sp2+ but I use Mozilla 1.3+** to
do all my development. I have build some cross browser debuggers so my
users can send me verbose debug dumps. I have some success but have
come to a roadblock with the basic underlying JavaScript models.
The only way to get a complete stack in IE is to use the
window.onerror handler. At this point by surfing the
arguments.callee.caller... you can navigate the call stack to the
originating point of the error. This works but it goes against the
first basic rule of debugging which is to handle the error as close to
the source as possible using try{...}catch(e){...} blocks.
Unfortunately in Mozilla, you cannot surf the stack by using
arguments.callee.caller from window.onerror handler :|
In Mozilla, they have error.stack which contains the full stack and
it works great but is only available if you use try/catch blocks.
However, in IE there is no stack property of error therefore if you
handle the error with a try/catch you will only know from the current
stack position (where it is handled) to the first level. All calls
after the current function/method are lost :[ ... Example - stack a(),
b(), c(), d(), e(), f() has error at e() and try/catch is at c(), in
IE you can only get a()-b()-c() and you will not know if the error
happened at c(), d(), e(), or f().
Here is some possible IE / Moz debugging solutions:
1) My current Production version- use try/catch blocks but put
them in as many error prone places and as close to error source
points. When error occurs store error state in global data structure.
Throw the error up and ultimately handle the error in window.onerror.
At window.onerror, read if global debug exists and use data and
possibly traverse call stack to originating call. ( In IE, you still
loose the stack from the point where it is handled :[. But in Mozilla
I get great debugging :] )
2) Possibility 1 - Structure code such that try/catches only
operate in Mozilla. This would need simple server side code to serve
up JavaScript with try/catch blocks if Mozilla and comment them out if
IE.
3) Possibility 2 - Find a way to get the error object in Mozilla
when handling error in window.onerror. Have not found any way to get
this yet and I am tempted to download the Mozilla source and write the
patch myself.
4) Possibility 3 - Find a way to get the stack from the source
error in IE when using try/catch. IE currently does not have a stack
property of error (Huge design flaw). I would never even dream of
suggesting this as a bug to Microsoft as I am morally against having
to pay to report bugs. Also I would never in any event want to see
their source code
Any ideas would be greatly appreciated.
TQ
** (See bug http://bugzilla.mozilla.org/show_bug.cgi?id=158592). This
bug caused problems when traversing call stack in Mozilla. I reported
this and made a reasonably good case to the Moz team and it was and
eventually fixed (Try that with Microsoft). Now Moz 1.3+ (Netscape
7+?) has had this patch included.
I have spent the last three years developing complex DHTML
applications that must work in IE 5.5sp2+ but I use Mozilla 1.3+** to
do all my development. I have build some cross browser debuggers so my
users can send me verbose debug dumps. I have some success but have
come to a roadblock with the basic underlying JavaScript models.
The only way to get a complete stack in IE is to use the
window.onerror handler. At this point by surfing the
arguments.callee.caller... you can navigate the call stack to the
originating point of the error. This works but it goes against the
first basic rule of debugging which is to handle the error as close to
the source as possible using try{...}catch(e){...} blocks.
Unfortunately in Mozilla, you cannot surf the stack by using
arguments.callee.caller from window.onerror handler :|
In Mozilla, they have error.stack which contains the full stack and
it works great but is only available if you use try/catch blocks.
However, in IE there is no stack property of error therefore if you
handle the error with a try/catch you will only know from the current
stack position (where it is handled) to the first level. All calls
after the current function/method are lost :[ ... Example - stack a(),
b(), c(), d(), e(), f() has error at e() and try/catch is at c(), in
IE you can only get a()-b()-c() and you will not know if the error
happened at c(), d(), e(), or f().
Here is some possible IE / Moz debugging solutions:
1) My current Production version- use try/catch blocks but put
them in as many error prone places and as close to error source
points. When error occurs store error state in global data structure.
Throw the error up and ultimately handle the error in window.onerror.
At window.onerror, read if global debug exists and use data and
possibly traverse call stack to originating call. ( In IE, you still
loose the stack from the point where it is handled :[. But in Mozilla
I get great debugging :] )
2) Possibility 1 - Structure code such that try/catches only
operate in Mozilla. This would need simple server side code to serve
up JavaScript with try/catch blocks if Mozilla and comment them out if
IE.
3) Possibility 2 - Find a way to get the error object in Mozilla
when handling error in window.onerror. Have not found any way to get
this yet and I am tempted to download the Mozilla source and write the
patch myself.
4) Possibility 3 - Find a way to get the stack from the source
error in IE when using try/catch. IE currently does not have a stack
property of error (Huge design flaw). I would never even dream of
suggesting this as a bug to Microsoft as I am morally against having
to pay to report bugs. Also I would never in any event want to see
their source code
Any ideas would be greatly appreciated.
TQ
** (See bug http://bugzilla.mozilla.org/show_bug.cgi?id=158592). This
bug caused problems when traversing call stack in Mozilla. I reported
this and made a reasonably good case to the Moz team and it was and
eventually fixed (Try that with Microsoft). Now Moz 1.3+ (Netscape
7+?) has had this patch included.