generators_from_v8_basic.phpt 841 B

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