generators_from_v8_008.phpt 762 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test V8::executeString() : Generators V8 -> PHP (throw 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. yield 23;
  15. yield PHP.getValue();
  16. }
  17. TheGen();
  18. EOJS;
  19. $v8 = new V8Js();
  20. $v8->getValue = function() {
  21. throw new \Exception('this shall not work');
  22. };
  23. $gen = $v8->executeString($js);
  24. foreach($gen as $a) {
  25. var_dump($a);
  26. }
  27. ?>
  28. ===EOF===
  29. --EXPECTF--
  30. int(23)
  31. Fatal error: Uncaught Exception: this shall not work in %s
  32. Stack trace:
  33. #0 [internal function]: {closure}()
  34. #1 [internal function]: Closure->__invoke()
  35. #2 %s: V8Generator->next()
  36. #3 {main}
  37. thrown in %s