There has been a JavaScript stack trace API in V8 for some time now, but it have not been well documented. However this has now been fixed and the nice documentation by christian.plesner.hansen can be found at http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi.There is also a C++ counterpart for which the documentation is in the C++ header file. Look for class StackTrace and friends in http://code.google.com/p/v8/source/browse/branches/bleeding_edge/include/v8.h.Regards,Søren--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
Yes. Here is my plan:
I will split the EventEmitter class/concept into two things. One will
be C++ a base class (deriving from ObjectWrap) for all "watchers" (a
libev term), call it (for now) a Hard Event Emitter. The other will be
JS only for now call it a Soft Event Emitter.
Hard Event Emitters get callbacks directly off the event loop (or at
least almost directly off the event loop - maybe via libpq) they make
the first call into JS. Hard Emitters are where "the buck stops" when
an exception is thrown in somewhere in the stack - Soft Emitters will
allow the exception to propagate up, but Hard Emitters must deal with
it - there is no where eles to go. Dealing with it means either
1) Calling the 'uncaughtException' event
or
2) Exiting the process and printing the stack trace associated with
the exception.
What we can do is every time a Hard Emitter is created, record the
stack and store it in the Hard Emitter. Then if that Emitter ever hits
an exception, it will print the stack associated with the exception
plus the stack it recorded when it was created.
This will give a lot more context into where errors are created.
You could take it a step further: When Hard Emitters are created, in
addition to recording the stack they could record a link to the Hard
Emitter whose callback they are currently in. This would allow you to
walk backwards arbitrarily far to see where an exception originated.
Recording a link to another Hard Emitter doesn't cost much - it's
likely this can be done even in very busy servers. However it's
unknown how expensive recording a stack trace is (specifically
v8::StackTrace::CurrentStackTrace(),
http://github.com/ry/node/blob/242161bef2e3631d315f8da8a62c088bdc100c87/deps/v8/include/v8.h#L778-787)
- likely slow enough that it will show up in benchmarks if we're doing
it for every single Hard Emitter construction. Thus we should plan to
have this be an optional feature, enabled by a command line flag
(--debug enables it?).
Soft Emitters will be just sugar. Actually they will be exactly what
exists in lib/events.js currently:
http://github.com/ry/node/blob/242161bef2e3631d315f8da8a62c088bdc100c87/lib/events.js
Example: in a TCP socket, the Hard Emitter would the be the IOWatcher
which emits a "readable" event for the associated file descriptor. The
net.js code does some stuff (reads data from the fd into a Buffer) and
eventually emits a "data" event from it's user-facing Soft Emitter
interface.
Two random notes about this refactor:
1) It lends to a good infrastructure for sticking in dtrace probes. We
can do probes on Hard Emitters completely in C++.
2) (I'm not suggesting this API, just pointing out that this refactor
will allow for such things.) There is also the possibly of having an
interface for recovering from errors. Imagine:
t = setTimeout(function () {
throw new Error('xxx');
}, 1000);
t.onException = function (e) { /* ... */ };
Ryan
However, if it causes any relevant performance impact (which I suspect
it will), I think it should be disabled by default, unless you
./configure --debug, since it's an advanced debugging option.
It might be nice to have a ./configure --with-event-trace so that you
could enable this feature without adding the overhead of the other
debug() function calls.
--i
2010/6/30 Felix Geisendörfer <fe...@debuggable.com>:
Yeah.
The "--for-pure-speed" option should be implied by the fact that
you're using NodeJS in the first place.
--i
> ./configure --for-pure-speed
The "--for-pure-speed" option should be implied by the fact that
you're using NodeJS in the first place.