mirror of
https://github.com/phpv8/v8js.git
synced 2025-03-22 02:17:02 +00:00
Test & implement PHP-side instantiation of JS generators
This commit is contained in:
parent
da64b9f055
commit
f97a25b69c
33
tests/generators_from_v8_004.phpt
Normal file
33
tests/generators_from_v8_004.phpt
Normal 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===
|
39
tests/generators_from_v8_005.phpt
Normal file
39
tests/generators_from_v8_005.phpt
Normal 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===
|
@ -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 */
|
/* 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);
|
v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(value);
|
||||||
|
|
||||||
if(isolate != c->ctx->isolate) {
|
if(isolate != c->ctx->isolate) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user