generators_from_v8_008.phpt 658 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Test V8::executeString() : Generators V8 -> PHP (throw PHP)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $js = <<<EOJS
  8. function* TheGen() {
  9. yield 23;
  10. yield PHP.getValue();
  11. }
  12. TheGen();
  13. EOJS;
  14. $v8 = new V8Js();
  15. $v8->getValue = function() {
  16. throw new \Exception('this shall not work');
  17. };
  18. $gen = $v8->executeString($js);
  19. foreach($gen as $a) {
  20. var_dump($a);
  21. }
  22. ?>
  23. ===EOF===
  24. --EXPECTF--
  25. int(23)
  26. Fatal error: Uncaught Exception: this shall not work in %s
  27. Stack trace:
  28. #0 [internal function]: {closure}()
  29. #1 [internal function]: Closure->__invoke()
  30. #2 %s: V8Generator->next()
  31. #3 {main}
  32. thrown in %s