mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-08 18:58:41 +00:00
Handle exceptions thrown in JS generators well
This commit is contained in:
parent
6fa6f9316e
commit
479d14b5b0
33
tests/generators_from_v8_007.phpt
Normal file
33
tests/generators_from_v8_007.phpt
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Generators V8 -> PHP (throw JS)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$js = <<<EOJS
|
||||||
|
function* TheGen() {
|
||||||
|
yield 23;
|
||||||
|
throw new Error('blar');
|
||||||
|
}
|
||||||
|
|
||||||
|
TheGen();
|
||||||
|
EOJS;
|
||||||
|
|
||||||
|
$v8 = new V8Js();
|
||||||
|
$gen = $v8->executeString($js);
|
||||||
|
|
||||||
|
foreach($gen as $a) {
|
||||||
|
var_dump($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECTF--
|
||||||
|
int(23)
|
||||||
|
|
||||||
|
Fatal error: Uncaught V8JsScriptException: V8Js::compileString():3: Error: blar in %s
|
||||||
|
Stack trace:
|
||||||
|
#0 %s: V8Generator->next()
|
||||||
|
#1 {main}
|
||||||
|
thrown in %s
|
@ -510,6 +510,11 @@ static void v8js_v8generator_next(v8js_v8generator *g) /* {{{ */
|
|||||||
|
|
||||||
v8::Local<v8::Value> result = cb->Call(v8obj, 0, NULL);
|
v8::Local<v8::Value> result = cb->Call(v8obj, 0, NULL);
|
||||||
|
|
||||||
|
if(result.IsEmpty()) {
|
||||||
|
/* cb->Call probably threw (and already threw a zend exception), just return */
|
||||||
|
return V8JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(!result->IsObject()) {
|
if(!result->IsObject()) {
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
zend_throw_exception(php_ce_v8js_exception,
|
||||||
"V8Generator returned non-object on next()", 0);
|
"V8Generator returned non-object on next()", 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user