preillyme/v8js — pull request #91 by stesie (2014-04-13 21:09:00+00:00)
Title: Handle PHP Fatal Errors inside JS->PHP callbacks

Hi there,

this fixes #87

As pointed out there, a fatal error caused within a JS->PHP callback resulted in a segfault during shutdown of V8. This was obviously due to PHP's setjmp/longjmp behaviour when handling fatal errors; which just discarded V8's stack frames.

This patch changes the behaviour to catch the fatal error via overwriting `zend_error_cb`; now leaving only stack frames down to `php_v8js_call_php_func`. There the original error handler is restored, the isolate is re-entered, V8 signaled to terminate execution and the code flow just falls back into V8.
As soon as V8 terminated execution, the fatal error is re-thrown, this time triggering the normal error handler which logs the error and shuts down the engine

cheers
~stesie