php_exceptions_002.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. Test V8::executeString() : PHP Exception handling (multi-level)
  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. function recurse($i) {
  12. echo "recurse[$i] ...\n";
  13. global $work;
  14. $work($i);
  15. }
  16. }
  17. $v8 = new V8Js();
  18. $v8->foo = new \Foo();
  19. $work = $v8->executeString(<<<EOT
  20. var work = function(level) {
  21. if(level--) {
  22. PHP.foo.recurse(level);
  23. }
  24. else {
  25. PHP.foo.throwException();
  26. }
  27. };
  28. work;
  29. EOT
  30. );
  31. for($i = 0; $i < 5; $i ++) {
  32. var_dump($i);
  33. try {
  34. $work($i);
  35. } catch (Exception $e) {
  36. var_dump($e->getMessage());
  37. }
  38. }
  39. ?>
  40. ===EOF===
  41. --EXPECT--
  42. int(0)
  43. string(14) "Test-Exception"
  44. int(1)
  45. recurse[0] ...
  46. string(14) "Test-Exception"
  47. int(2)
  48. recurse[1] ...
  49. recurse[0] ...
  50. string(14) "Test-Exception"
  51. int(3)
  52. recurse[2] ...
  53. recurse[1] ...
  54. recurse[0] ...
  55. string(14) "Test-Exception"
  56. int(4)
  57. recurse[3] ...
  58. recurse[2] ...
  59. recurse[1] ...
  60. recurse[0] ...
  61. string(14) "Test-Exception"
  62. ===EOF===