generators_from_v8_basic.phpt 945 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. Test V8::executeString() : Generators V8 -> PHP
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . '/skipif.inc');
  6. if (!class_exists('V8Generator')) {
  7. die("skip Installed V8 version doesn't support generators");
  8. }
  9. ?>
  10. --FILE--
  11. <?php
  12. $js = <<<EOJS
  13. function* TheGen() {
  14. for(var i = 0; i < 4; i ++) {
  15. yield i;
  16. }
  17. }
  18. TheGen.theValue = 23;
  19. EOJS;
  20. $v8 = new V8Js();
  21. $v8->executeString($js);
  22. // just get the Generator itself -- it's just a normal JS function to us,
  23. // i.e. V8Js should create a V8Function object.
  24. $gen = $v8->executeString('(TheGen)');
  25. var_dump($gen);
  26. // now instantiate the Generator and pass that back -- should become a
  27. // V8Generator object that implements the Iterator interface
  28. $gen = $v8->executeString('(TheGen())');
  29. var_dump($gen);
  30. var_dump($gen instanceof Iterator);
  31. ?>
  32. ===EOF===
  33. --EXPECTF--
  34. object(V8Function)#%d (1) {
  35. ["theValue"]=>
  36. int(23)
  37. }
  38. object(V8Generator)#%d (0) {
  39. }
  40. bool(true)
  41. ===EOF===