generators_to_v8_004.phpt 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test V8::executeString() : Generators PHP -> V8 (yield from)
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . '/skipif.inc');
  6. // Actually this check is a bit bad as it tests import, but currently
  7. // there is no flag we can check for export
  8. if (!class_exists('V8Generator')) {
  9. die("skip Installed V8 version doesn't support generators");
  10. }
  11. ?>
  12. --FILE--
  13. <?php
  14. function FibonacciGenerator()
  15. {
  16. $i = 0;
  17. $j = 1;
  18. for(;;) {
  19. yield $j;
  20. list($i, $j) = array($j, $i + $j);
  21. }
  22. }
  23. $v8 = new V8Js();
  24. $v8->fibs = FibonacciGenerator();
  25. $JS = <<<EOJS
  26. function* prefixer() {
  27. yield* arguments;
  28. yield* PHP.fibs;
  29. }
  30. var gen = prefixer(23, 42);
  31. for(var i = 0; i < 10; i ++) {
  32. var_dump(gen.next().value);
  33. }
  34. EOJS;
  35. $v8->executeString($JS);
  36. ?>
  37. ===EOF===
  38. --EXPECT--
  39. int(23)
  40. int(42)
  41. int(1)
  42. int(1)
  43. int(2)
  44. int(3)
  45. int(5)
  46. int(8)
  47. int(13)
  48. int(21)
  49. ===EOF===