Browse Source
Restored proper generators behaviour in conjunction with "finally". (Nikita)
pull/242/merge
Restored proper generators behaviour in conjunction with "finally". (Nikita)
pull/242/merge
13 changed files with 171 additions and 102 deletions
-
0Zend/tests/generators/finally/finally_ran_on_close.phpt
-
2Zend/tests/generators/finally/return_return.phpt
-
18Zend/tests/generators/finally/return_yield.phpt
-
24Zend/tests/generators/finally/throw_yield.phpt
-
18Zend/tests/generators/finally/yield_return.phpt
-
24Zend/tests/generators/finally/yield_throw.phpt
-
22Zend/tests/generators/finally/yield_yield.phpt
-
28Zend/tests/generators/finally_uninterrupted.phpt
-
38Zend/zend_generators.c
-
22Zend/zend_opcode.c
-
13Zend/zend_vm_def.h
-
63Zend/zend_vm_execute.h
-
1Zend/zend_vm_opcodes.h
@ -1,5 +1,5 @@ |
|||
--TEST-- |
|||
Use of finally in generator with return |
|||
try { return } finally { return } in generator |
|||
--FILE-- |
|||
<?php |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
try { return } finally { yield } |
|||
--FILE-- |
|||
<?php |
|||
function foo($f, $t) { |
|||
for ($i = $f; $i <= $t; $i++) { |
|||
try { |
|||
return; |
|||
} finally { |
|||
yield $i; |
|||
} |
|||
} |
|||
} |
|||
foreach (foo(1, 5) as $x) { |
|||
echo $x, "\n"; |
|||
} |
|||
--EXPECT-- |
|||
1 |
|||
@ -0,0 +1,24 @@ |
|||
--TEST-- |
|||
try { throw } finally { yield } |
|||
--FILE-- |
|||
<?php |
|||
function foo($f, $t) { |
|||
for ($i = $f; $i <= $t; $i++) { |
|||
try { |
|||
throw new Exception; |
|||
} finally { |
|||
yield $i; |
|||
} |
|||
} |
|||
} |
|||
foreach (foo(1, 5) as $x) { |
|||
echo $x, "\n"; |
|||
} |
|||
--EXPECTF-- |
|||
1 |
|||
|
|||
Fatal error: Uncaught exception 'Exception' in %s:%d |
|||
Stack trace: |
|||
#0 %s(%d): foo(1, 5) |
|||
#1 {main} |
|||
thrown in %s on line %d |
|||
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
try { yield } finally { return } |
|||
--FILE-- |
|||
<?php |
|||
function foo($f, $t) { |
|||
for ($i = $f; $i <= $t; $i++) { |
|||
try { |
|||
yield $i; |
|||
} finally { |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
foreach (foo(1, 5) as $x) { |
|||
echo $x, "\n"; |
|||
} |
|||
--EXPECT-- |
|||
1 |
|||
@ -0,0 +1,24 @@ |
|||
--TEST-- |
|||
try { yield } finally { throw } |
|||
--FILE-- |
|||
<?php |
|||
function foo($f, $t) { |
|||
for ($i = $f; $i <= $t; $i++) { |
|||
try { |
|||
yield $i; |
|||
} finally { |
|||
throw new Exception; |
|||
} |
|||
} |
|||
} |
|||
foreach (foo(1, 5) as $x) { |
|||
echo $x, "\n"; |
|||
} |
|||
--EXPECTF-- |
|||
1 |
|||
|
|||
Fatal error: Uncaught exception 'Exception' in %s:%d |
|||
Stack trace: |
|||
#0 %s(%d): foo(1, 5) |
|||
#1 {main} |
|||
thrown in %s on line %d |
|||
@ -0,0 +1,22 @@ |
|||
--TEST-- |
|||
Try { yield } finally { yield } |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function foo() { |
|||
try { |
|||
echo "1"; |
|||
yield "2"; |
|||
echo "3"; |
|||
} finally { |
|||
echo "4"; |
|||
yield "5"; |
|||
echo "6"; |
|||
} |
|||
echo "7"; |
|||
} |
|||
foreach (foo() as $x) { |
|||
echo $x; |
|||
} |
|||
--EXPECT-- |
|||
1234567 |
|||
@ -1,28 +0,0 @@ |
|||
--TEST-- |
|||
Use of finally in generator without interrupt |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function gen() { |
|||
try { |
|||
throw new Exception; |
|||
} finally { |
|||
echo "finally run\n"; |
|||
} |
|||
|
|||
yield; // force generator |
|||
} |
|||
|
|||
$gen = gen(); |
|||
$gen->rewind(); // force run |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
finally run |
|||
|
|||
Fatal error: Uncaught exception 'Exception' in %s:%d |
|||
Stack trace: |
|||
#0 [internal function]: gen() |
|||
#1 %s(%d): Generator->rewind() |
|||
#2 {main} |
|||
thrown in %s on line %d |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue