Wrong stacktrace when using longjohn in nodejs

I am getting a wrong stacktrace using longjohn with the following code. It is showing setTimeout getting called from the firstfunction, but in real the program is crashing before firstfunction is getting executed.

I have created a ticket here https://github.com/mattinsler/longjohn/issues/16

var longjohn = require("longjohn");

setTimeout(function () {
    throw new Error();
}, 10);


setTimeout(function () {
    firstfunction();
}, 10000);


var firstfunction = function () {
    setTimeout(function () {
        console.log("First function");
    }, 10);
}

stacktrace

/home/jeevan/node_js/node_modules/longjohn/dist/longjohn.js:181
        throw e;
              ^
Error
    at firstfunction (/home/jeevan/node_js/longjohn.js:11:11)
    at listOnTimeout (timers.js:110:15)
---------------------------------------------
    at Object.<anonymous> (/home/jeevan/node_js/longjohn.js:10:1)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Module._load (module.js:312:12)
    at Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

My question is what can be the issue, How to fix it.

It happens without longjohn, too.

I don't exactly know why, but if you name your callbacks, it works better:

setTimeout(function MyFirstTimeoutCallback() {
  throw new Error();
}, 10);
...

This generates the following traceback:

/private/tmp/node_modules/longjohn/dist/longjohn.js:181
        throw e;
              ^
Error
    at MyFirstTimeoutCallback (/private/tmp/lj.js:4:9) <-- much better!
    at listOnTimeout (timers.js:110:15)
---------------------------------------------
    at Object.<anonymous> (/private/tmp/lj.js:3:1)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Module._load (module.js:312:12)
    at Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

EDIT: looks like this bug was introduced (somewhere) in Node 0.10. When I test with 0.8.23, it looks okay:

timers.js:103
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
Error
    at Object.<anonymous> (/private/tmp/lj.js:4:9) <-- correct
    at list.ontimeout (timers.js:101:19)
    ...

(bug report)

EDIT #2: it's a confirmed bug in V8 (see the linked bug report).