0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-09 15:18:41 +00:00

Test & implement PHP-side instantiation of JS generators

This commit is contained in:
Stefan Siegl 2016-01-07 22:57:50 +01:00
parent da64b9f055
commit f97a25b69c
3 changed files with 73 additions and 1 deletions

View File

@ -0,0 +1,33 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + foreach)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$js = <<<EOJS
function* TheGen() {
for(var i = 0; i < 4; i ++) {
yield i;
}
}
TheGen;
EOJS;
$v8 = new V8Js();
$TheGen = $v8->executeString($js);
$gen = $TheGen();
foreach($gen as $a) {
var_dump($a);
}
?>
===EOF===
--EXPECTF--
int(0)
int(1)
int(2)
int(3)
===EOF===

View File

@ -0,0 +1,39 @@
--TEST--
Test V8::executeString() : Generators V8 -> PHP (instantiate in PHP + iterate in JS)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$js = <<<EOJS
function* TheGen() {
for(var i = 0; i < 4; i ++) {
yield i;
}
}
TheGen;
EOJS;
$v8 = new V8Js();
$TheGen = $v8->executeString($js);
$gen = $TheGen();
$js = <<<EOJS
(function(gen) {
for(var i of gen) {
var_dump(i);
}
})
EOJS;
$fn = $v8->executeString($js);
$fn($gen);
?>
===EOF===
--EXPECTF--
int(0)
int(1)
int(2)
int(3)
===EOF===

View File

@ -938,7 +938,7 @@ v8::Handle<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate TSRML
}
/* Special case, passing back object originating from JS to JS */
if (ce == php_ce_v8function) {
if (ce == php_ce_v8function || ce == php_ce_v8generator) {
v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(value);
if(isolate != c->ctx->isolate) {