kripken/emscripten — pull request #247 by adetaylor (2012-02-12 17:03:44+00:00)
Title: Polymorphic exception handling.

Previously exception handling only worked if there were a 'catch' block which precisely matched
the type of the thrown exception.

That's not always the case if we're trying to catch subclasses.

This change enhances behaviour to match subclasses, and also covers some other cases where
we weren't catching the right thing.

You probably shouldn't pull this as-is, but I'd appreciate review comments.

In particular, I've added a lot to preamble.js, which seems wrong because pure C users don't need it. I would prefer to move the code into library.js, but I can't quite work out how to cause those functions to be pulled into the resulting code just because there's a C++ catch clause. Please help!

This will also enable me to simplify the code as I can then rely on the existing dynamic_cast function.

Arguably, we should also stick closer to the native C++ model of putting this functionality into __gxx_personality_v0. However, I don't think we need the same level of complexity because I think all the exception handling is done with the 'if' blocks that are already inserted by emscripten? -- could you confirm this? If so, I think a simple JavaScript routine to match the right catch block is simpler, and that's what I've done. Let me know what you prefer.

You'll probably note that my JavaScript is very rusty, so stylistic changes very welcome too.

Note that this enables the test 'test_typed_exceptions', which still fails due to a problem with the ordering of 'atexit' operations - I've a separate pull request for that change. Apart from that, it passes.