exception_propagation_2.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --TEST--
  2. Test V8::executeString() : Exception propagation test 2
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo {
  8. private $v8 = NULL;
  9. public function __construct()
  10. {
  11. $this->v8 = new V8Js(null, array(), array(), false);
  12. $this->v8->foo = $this;
  13. $this->v8->executeString('fooobar', 'throw_0');
  14. var_dump($this->v8->getPendingException());
  15. $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print(e + " caught!\n"); }', 'trycatch1');
  16. $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print(e + " caught!\n"); }', 'trycatch2');
  17. }
  18. public function bar()
  19. {
  20. echo "To Bar!\n";
  21. $this->v8->executeString('throw new Error();', 'throw_1');
  22. }
  23. }
  24. try {
  25. $foo = new Foo();
  26. } catch (V8JsException $e) {
  27. echo "PHP Exception: ", $e->getMessage(), "\n"; //var_dump($e);
  28. }
  29. ?>
  30. ===EOF===
  31. --EXPECTF--
  32. object(V8JsException)#3 (11) {
  33. ["message":protected]=>
  34. string(49) "throw_0:1: ReferenceError: fooobar is not defined"
  35. ["string":"Exception":private]=>
  36. string(0) ""
  37. ["code":protected]=>
  38. int(0)
  39. ["file":protected]=>
  40. string(%d) "%s"
  41. ["line":protected]=>
  42. int(10)
  43. ["trace":"Exception":private]=>
  44. array(2) {
  45. [0]=>
  46. array(6) {
  47. ["file"]=>
  48. string(%d) "%s"
  49. ["line"]=>
  50. int(10)
  51. ["function"]=>
  52. string(13) "executeString"
  53. ["class"]=>
  54. string(4) "V8Js"
  55. ["type"]=>
  56. string(2) "->"
  57. ["args"]=>
  58. array(2) {
  59. [0]=>
  60. string(7) "fooobar"
  61. [1]=>
  62. string(7) "throw_0"
  63. }
  64. }
  65. [1]=>
  66. array(6) {
  67. ["file"]=>
  68. string(%d) "%s"
  69. ["line"]=>
  70. int(24)
  71. ["function"]=>
  72. string(11) "__construct"
  73. ["class"]=>
  74. string(3) "Foo"
  75. ["type"]=>
  76. string(2) "->"
  77. ["args"]=>
  78. array(0) {
  79. }
  80. }
  81. }
  82. ["previous":"Exception":private]=>
  83. NULL
  84. ["JsFileName":protected]=>
  85. string(7) "throw_0"
  86. ["JsLineNumber":protected]=>
  87. int(1)
  88. ["JsSourceLine":protected]=>
  89. string(7) "fooobar"
  90. ["JsTrace":protected]=>
  91. string(57) "ReferenceError: fooobar is not defined
  92. at throw_0:1:1"
  93. }
  94. To Bar!
  95. Error caught!
  96. PHP Exception: throw_0:1: ReferenceError: fooobar is not defined
  97. ===EOF===