exception_propagation_2.phpt 2.3 KB

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