php_exceptions_003.phpt 741 B

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. Test V8::executeString() : PHP Exception handling (basic JS propagation)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo {
  8. function throwException() {
  9. throw new \Exception("Test-Exception");
  10. }
  11. }
  12. $v8 = new V8Js();
  13. $v8->foo = new \Foo();
  14. $JS = <<< EOT
  15. try {
  16. PHP.foo.throwException();
  17. // the exception should abort further execution,
  18. // hence the print must not pop up
  19. print("after throwException\\n");
  20. } catch(e) {
  21. print("JS caught exception!\\n");
  22. var_dump(e.getMessage());
  23. }
  24. EOT;
  25. $v8->executeString($JS, 'php_exceptions_003', V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  26. ?>
  27. ===EOF===
  28. --EXPECTF--
  29. JS caught exception!
  30. string(14) "Test-Exception"
  31. ===EOF===