exception_filter_001.phpt 662 B

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. Test V8::setExceptionFilter() : String conversion
  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 $ex->getMessage();
  17. });
  18. $v8->executeString('
  19. try {
  20. PHP.throwException("Oops");
  21. }
  22. catch (e) {
  23. var_dump(typeof e); // string
  24. var_dump(e);
  25. }
  26. ', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  27. ?>
  28. ===EOF===
  29. --EXPECT--
  30. exception filter called.
  31. string(6) "string"
  32. string(4) "Oops"
  33. ===EOF===