exception_propagation_2.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_propagation_2.php on line 11
  38. object(V8JsScriptException)#%d (13) {
  39. ["message":protected]=>
  40. string(49) "throw_0:1: ReferenceError: fooobar is not defined"
  41. ["string":"Exception":private]=>
  42. string(0) ""
  43. ["code":protected]=>
  44. int(0)
  45. ["file":protected]=>
  46. string(%d) "%s"
  47. ["line":protected]=>
  48. int(10)
  49. ["trace":"Exception":private]=>
  50. array(2) {
  51. [0]=>
  52. array(6) {
  53. ["file"]=>
  54. string(%d) "%s"
  55. ["line"]=>
  56. int(10)
  57. ["function"]=>
  58. string(13) "executeString"
  59. ["class"]=>
  60. string(4) "V8Js"
  61. ["type"]=>
  62. string(2) "->"
  63. ["args"]=>
  64. array(2) {
  65. [0]=>
  66. string(7) "fooobar"
  67. [1]=>
  68. string(7) "throw_0"
  69. }
  70. }
  71. [1]=>
  72. array(6) {
  73. ["file"]=>
  74. string(%d) "%s"
  75. ["line"]=>
  76. int(29)
  77. ["function"]=>
  78. string(11) "__construct"
  79. ["class"]=>
  80. string(3) "Foo"
  81. ["type"]=>
  82. string(2) "->"
  83. ["args"]=>
  84. array(0) {
  85. }
  86. }
  87. }
  88. ["previous":"Exception":private]=>
  89. NULL
  90. ["JsFileName":protected]=>
  91. string(7) "throw_0"
  92. ["JsLineNumber":protected]=>
  93. int(1)
  94. ["JsStartColumn":protected]=>
  95. int(0)
  96. ["JsEndColumn":protected]=>
  97. int(1)
  98. ["JsSourceLine":protected]=>
  99. string(7) "fooobar"
  100. ["JsTrace":protected]=>
  101. string(57) "ReferenceError: fooobar is not defined
  102. at throw_0:1:1"
  103. }
  104. To Bar!
  105. PHP Exception: throw_0:1: ReferenceError: fooobar is not defined
  106. ===EOF===