static function trycatch($expr, $catch, $finally, $id = 0) { if (js_thrown(jsrt::$exception)) { #-- assert($expr == NULL); if ($expr != NULL) { echo "TRYCATCH ERROR: INCONSISTENT STATE.<hr><br>"; } /* evaluate catch */ if ($catch != NULL) { $obj = new js_object(); $obj->put($id, jsrt::$exception->value, array("dontdelete")); jsrt::$exception = NULL; jsrt::push_scope($obj); $ret = $catch(); jsrt::pop_scope(); if ($ret != NULL) { $expr = $ret; } } } if ($finally != NULL) { #-- XXX tentative workaround for the call_user_func + exception crash in 5.0.3 $ret = $finally(); if ($ret != NULL) { $expr = $ret; } } if (js_thrown(jsrt::$exception)) { throw jsrt::$exception; #-- pass it down. } return $expr; }