mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 16:28:41 +00:00
Handle rewind on primed V8Generator
This commit is contained in:
parent
e686603b89
commit
da64b9f055
41
tests/generators_from_v8_003.phpt
Normal file
41
tests/generators_from_v8_003.phpt
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Generators V8 -> PHP (rewind)
|
||||||
|
--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();
|
||||||
|
$gen = $v8->executeString($js);
|
||||||
|
|
||||||
|
foreach($gen as $a) {
|
||||||
|
var_dump($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($gen as $a) {
|
||||||
|
var_dump($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECTF--
|
||||||
|
int(0)
|
||||||
|
int(1)
|
||||||
|
int(2)
|
||||||
|
int(3)
|
||||||
|
|
||||||
|
Fatal error: Uncaught V8JsException: V8Generator::rewind not supported by ES6 in %s
|
||||||
|
Stack trace:
|
||||||
|
#0 %s: V8Generator->rewind()
|
||||||
|
#1 {main}
|
||||||
|
thrown in %s on line 20
|
@ -616,6 +616,14 @@ PHP_METHOD(V8Generator, next)
|
|||||||
*/
|
*/
|
||||||
PHP_METHOD(V8Generator, rewind)
|
PHP_METHOD(V8Generator, rewind)
|
||||||
{
|
{
|
||||||
|
v8js_v8generator *g = Z_V8JS_V8GENERATOR_OBJ_P(getThis());
|
||||||
|
|
||||||
|
if(g->primed) {
|
||||||
|
zend_throw_exception(php_ce_v8js_exception,
|
||||||
|
"V8Generator::rewind not supported by ES6", 0 TSRMLS_CC);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
Loading…
Reference in New Issue
Block a user