ctx_lifetime.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. Test V8::executeString() : Testing lifespan of V8Js context objects
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo
  8. {
  9. function hello() {
  10. echo "Hello!\n";
  11. }
  12. }
  13. class Testing
  14. {
  15. function onectx()
  16. {
  17. $v8js = new V8Js();
  18. $v8js->foo = new Foo;
  19. return $v8js->executeString("({ bar: 23, hello: function() { PHP.foo.__call('hello',[]); } })");
  20. // $v8js will be dereferenced here, but the result escapes.
  21. }
  22. }
  23. $t = new Testing();
  24. $a = $t->onectx();
  25. /* $a is no longer valid, since the associated V8Js() object has been
  26. * destroyed. Instead the property access will throw. */
  27. var_dump($a);
  28. try {
  29. var_dump($a->bar);
  30. }
  31. catch(Exception $e) {
  32. var_dump($e->getMessage());
  33. }
  34. $a->hello();
  35. ?>
  36. ===EOF===
  37. --EXPECTF--
  38. object(V8Object)#%d (0) {
  39. }
  40. string(55) "Can't access V8Object after V8Js instance is destroyed!"
  41. Fatal error: Uncaught V8JsException: Can't access V8Object after V8Js instance is destroyed! in %s%etests%ectx_lifetime.php:35
  42. Stack trace:
  43. #0 {main}
  44. thrown in %s%etests%ectx_lifetime.php on line 35