mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-08 15:48:40 +00:00
48 lines
661 B
Plaintext
48 lines
661 B
Plaintext
|
--TEST--
|
||
|
Test V8::executeString() : Generators PHP -> V8 (instantiate in JS, iterate in PHP)
|
||
|
--SKIPIF--
|
||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||
|
--FILE--
|
||
|
<?php
|
||
|
|
||
|
$v8 = new V8Js();
|
||
|
$v8->Gen = function() {
|
||
|
for($i = 0; $i < 6; $i ++) {
|
||
|
yield $i;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
$JS = <<<EOJS
|
||
|
var g = PHP.Gen();
|
||
|
var_dump(g.next());
|
||
|
var_dump(g.next());
|
||
|
(g);
|
||
|
EOJS;
|
||
|
|
||
|
$gen = $v8->executeString($JS);
|
||
|
|
||
|
foreach($gen as $i) {
|
||
|
var_dump($i);
|
||
|
}
|
||
|
|
||
|
?>
|
||
|
===EOF===
|
||
|
--EXPECTF--
|
||
|
object(Object)#%d (2) {
|
||
|
["value"] =>
|
||
|
int(0)
|
||
|
["done"] =>
|
||
|
bool(false)
|
||
|
}
|
||
|
object(Object)#%d (2) {
|
||
|
["value"] =>
|
||
|
int(1)
|
||
|
["done"] =>
|
||
|
bool(false)
|
||
|
}
|
||
|
int(2)
|
||
|
int(3)
|
||
|
int(4)
|
||
|
int(5)
|
||
|
===EOF===
|