php_exceptions_001.phpt 942 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Test V8::executeString() : PHP Exception handling (repeated)
  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. // JS should not catch in default mode
  22. print("JS caught exception");
  23. }
  24. EOT;
  25. for($i = 0; $i < 5; $i ++) {
  26. var_dump($i);
  27. try {
  28. $v8->executeString($JS);
  29. } catch (Exception $e) {
  30. var_dump($e->getMessage());
  31. }
  32. }
  33. ?>
  34. ===EOF===
  35. --EXPECTF--
  36. int(0)
  37. string(14) "Test-Exception"
  38. int(1)
  39. string(14) "Test-Exception"
  40. int(2)
  41. string(14) "Test-Exception"
  42. int(3)
  43. string(14) "Test-Exception"
  44. int(4)
  45. string(14) "Test-Exception"
  46. ===EOF===