exception_filter_005.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test V8::setExceptionFilter() : Uninstall filter on NULL
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class myv8 extends V8Js
  8. {
  9. public function throwException(string $message) {
  10. throw new Exception($message);
  11. }
  12. }
  13. $v8 = new myv8();
  14. $v8->setExceptionFilter(function (Throwable $ex) {
  15. echo "exception filter called.\n";
  16. return "moep";
  17. });
  18. $v8->executeString('
  19. try {
  20. PHP.throwException("Oops");
  21. }
  22. catch (e) {
  23. var_dump(e);
  24. }
  25. ', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  26. $v8->setExceptionFilter(null);
  27. try {
  28. $v8->executeString('
  29. try {
  30. PHP.throwException("Oops");
  31. print("done\\n");
  32. }
  33. catch (e) {
  34. print("caught\\n");
  35. var_dump(e.getMessage());
  36. }
  37. ', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  38. } catch (Exception $ex) {
  39. echo "caught in php: " . $ex->getMessage() . PHP_EOL;
  40. }
  41. ?>
  42. ===EOF===
  43. --EXPECT--
  44. exception filter called.
  45. string(4) "moep"
  46. caught
  47. string(4) "Oops"
  48. ===EOF===