php_exceptions_004.phpt 778 B

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. Test V8::executeString() : PHP Exception handling (PHP->JS->PHP back 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. PHP.foo.throwException();
  16. // the exception should abort further execution,
  17. // hence the print must not pop up
  18. print("after throwException\\n");
  19. EOT;
  20. try {
  21. $v8->executeString($JS, 'php_exceptions_004', V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
  22. }
  23. catch(V8JsScriptException $e) {
  24. echo "Got V8JsScriptException\n";
  25. var_dump($e->getPrevious()->getMessage());
  26. }
  27. ?>
  28. ===EOF===
  29. --EXPECTF--
  30. Got V8JsScriptException
  31. string(14) "Test-Exception"
  32. ===EOF===