issue_116-v8function-injection.phpt 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test V8::executeString() : Issue #116 V8Function injection into other V8Js
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $a = new V8Js();
  8. $b = new V8Js();
  9. $a->name = 'A';
  10. $b->name = 'B';
  11. $a->b = $b;
  12. $a->executeString('PHP.b.test = function() { print("Hallo from within " + PHP.name + ".\\n"); };');
  13. // in PHP we see the property
  14. var_dump($b->test);
  15. // we see (and can call) the function object in instance A
  16. print("in A:\n");
  17. $a->executeString('PHP.b.test();');
  18. // in B the function object is not available
  19. print("in B:\n");
  20. $b->executeString('print(typeof PHP.b + "\\n");');
  21. try {
  22. $b->executeString('PHP.test();');
  23. }
  24. catch(Exception $e) {
  25. var_dump($e->getMessage());
  26. }
  27. unset($a);
  28. unset($b);
  29. ?>
  30. ===EOF===
  31. --EXPECTF--
  32. Warning: V8Js::executeString(): V8Function object passed to wrong V8Js instance in %s on line %d
  33. object(V8Function)#%d (0) {
  34. }
  35. in A:
  36. Hallo from within A.
  37. in B:
  38. undefined
  39. string(%d) "V8Js::compileString():1: TypeError: %s is not a function"
  40. ===EOF===