exception_propagation_2.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // the exception is not cleared before the next executeString call,
  16. // hence the next *exiting* executeString will throw.
  17. // In this case this is the executeString call in bar() function.
  18. $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print(e + " caught!\n"); }', 'trycatch1');
  19. $this->v8->executeString('try { PHP.foo.bar(); } catch (e) { print(e + " caught!\n"); }', 'trycatch2');
  20. }
  21. public function bar()
  22. {
  23. echo "To Bar!\n";
  24. // This executeString call throws a PHP exception, not propagated
  25. // to JS, hence immediately triggering the top-level catch handler.
  26. $this->v8->executeString('throw new Error();', 'throw_1');
  27. }
  28. }
  29. try {
  30. $foo = new Foo();
  31. } catch (V8JsScriptException $e) {
  32. echo "PHP Exception: ", $e->getMessage(), "\n"; //var_dump($e);
  33. }
  34. ?>
  35. ===EOF===
  36. --EXPECTF--
  37. object(V8JsScriptException)#%d (13) {
  38. ["message":protected]=>
  39. string(49) "throw_0:1: ReferenceError: fooobar is not defined"
  40. ["string":"Exception":private]=>
  41. string(0) ""
  42. ["code":protected]=>
  43. int(0)
  44. ["file":protected]=>
  45. string(%d) "%s"
  46. ["line":protected]=>
  47. int(10)
  48. ["trace":"Exception":private]=>
  49. array(2) {
  50. [0]=>
  51. array(6) {
  52. ["file"]=>
  53. string(%d) "%s"
  54. ["line"]=>
  55. int(10)
  56. ["function"]=>
  57. string(13) "executeString"
  58. ["class"]=>
  59. string(4) "V8Js"
  60. ["type"]=>
  61. string(2) "->"
  62. ["args"]=>
  63. array(2) {
  64. [0]=>
  65. string(7) "fooobar"
  66. [1]=>
  67. string(7) "throw_0"
  68. }
  69. }
  70. [1]=>
  71. array(6) {
  72. ["file"]=>
  73. string(%d) "%s"
  74. ["line"]=>
  75. int(29)
  76. ["function"]=>
  77. string(11) "__construct"
  78. ["class"]=>
  79. string(3) "Foo"
  80. ["type"]=>
  81. string(2) "->"
  82. ["args"]=>
  83. array(0) {
  84. }
  85. }
  86. }
  87. ["previous":"Exception":private]=>
  88. NULL
  89. ["JsFileName":protected]=>
  90. string(7) "throw_0"
  91. ["JsLineNumber":protected]=>
  92. int(1)
  93. ["JsStartColumn":protected]=>
  94. int(0)
  95. ["JsEndColumn":protected]=>
  96. int(1)
  97. ["JsSourceLine":protected]=>
  98. string(7) "fooobar"
  99. ["JsTrace":protected]=>
  100. string(57) "ReferenceError: fooobar is not defined
  101. at throw_0:1:1"
  102. }
  103. To Bar!
  104. PHP Exception: throw_0:1: ReferenceError: fooobar is not defined
  105. ===EOF===