php_exceptions_005.phpt 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test V8::executeString() : PHP Exception handling (JS throw PHP-exception)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo {
  8. function getException() {
  9. return new \Exception("Test-Exception");
  10. }
  11. }
  12. $v8 = new V8Js();
  13. $v8->foo = new \Foo();
  14. $JS = <<< EOT
  15. var ex = PHP.foo.getException();
  16. print("after getException\\n");
  17. throw ex;
  18. print("after throw\\n");
  19. EOT;
  20. try {
  21. $v8->executeString($JS, 'php_exceptions_005');
  22. }
  23. catch(V8JsScriptException $e) {
  24. echo "Got V8JsScriptException\n";
  25. var_dump($e->getMessage());
  26. var_dump($e->getPrevious()->getMessage());
  27. }
  28. ?>
  29. ===EOF===
  30. --EXPECTF--
  31. after getException
  32. Got V8JsScriptException
  33. string(%d) "php_exceptions_005:3: Exception: Test-Exception in %s
  34. Stack trace:
  35. #0 [internal function]: Foo->getException()
  36. #1 %s: V8Js->executeString('var ex = PHP.fo...', 'php_exceptions_...')
  37. #2 {main}"
  38. string(14) "Test-Exception"
  39. ===EOF===