parsing mozilla's Error stack property

  • Thread starter Java script Dude
  • Start date
J

Java script Dude

Has anybody hacked a stack parser for Mozilla Error stack property.

Some basic regular expressions would work well, but my time is a little
tight of late.

Basically I would like to parse out, function/method name, source path,
source name, line number.

Thanks,
JsD
 
T

Thomas 'PointedEars' Lahn

Java said:
Has anybody hacked a stack parser for Mozilla Error stack property.

Some basic regular expressions would work well, but my time is a little
tight of late.

Basically I would like to parse out, function/method name, source path,
source name, line number.

try
{
// don't declare x before
y = x;
}
catch (e)
{
var m, a = [];
while ((m = /^\s*(.*)@(.+):(\d+)\s*$/gm.exec(e.stack)))
{
a.push("Call: " + m[1] + "; source: " + m[2] + "; line: " + m[3]);
}
window.alert(e.stack + "\n__\n" + a.length + "\n__\n" + a.join("\n"));
}

Separating function identifier from argument list, and source path from
source name, is left as an exercise to the reader.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
try
{
// don't declare x before
y = x;
}
catch (e)
{
var m, a = [];
while ((m = /^\s*(.*)@(.+):(\d+)\s*$/gm.exec(e.stack)))

As I see that the source is also optional, this should be changed to

while ((m = /^\s*(.*)@(.*):(\d+)\s*$/gm.exec(e.stack)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top