Search code examples
duktape

Any way to get proper C++ stack unwinding when duktape throws an error?


Is there currently any way to get duktape to properly unwind the C++ stack (calling all appropriate destructors, etc.) when an error is encountered in duktape?

I know that Lua (for example) has the capability to do this by switching from the use of longjmp to C++ exceptions when Lua is compiled by a C++ compiler, but at first glance I'm not seeing anything similar in duktape, and I'm definitely winding up with C++ destructors not getting called. If that capability doesn't exist yet in duktape, are there any plans for it? (If the longjmp destinations are set and used in a strictly LIFO fashion, I'm guessing it'd be doable. If not, then maybe not so doable...)

I've been playing with duktape a bit and so far I've been impressed...I'm mostly done with a C++ template-based metaprogramming library that lets you automatically create duktape bindings to C++ functions. This stack-unwinding thing may be a complete deal-breaker, though...don't think I can use duktape if I can't trust my C++ destructors to get called.

EDIT: actually, on further reflection, I can probably make things work without the stack unwinding, although of course everything will be significantly more complex and error-prone. It'd still be a great feature to have.


Solution

  • As of Duktape 1.2 there isn't yet support for replacing setjmp/longjmp (which are used for error handling inside Duktape) with a C++ exception friendly try-catch mechanism. Support for that is planned for future versions though.