Skip to content

Commit aaa0a98

Browse files
committed
* fix bugs for onFinally logic
1 parent d2e6c4d commit aaa0a98

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

scope.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,16 +1335,17 @@ static zend_always_inline bool try_to_handle_exception(
13351335
ZVAL_OBJ(&parameters[1], &coroutine->std);
13361336
ZVAL_OBJ(&parameters[2], exception);
13371337

1338-
// We're trying to handle the exception using a callback function within the current Scope.
1339-
if (current_scope->exception_fci != NULL && current_scope->exception_fcc != NULL) {
1338+
// If the exception came from another child Scope,
1339+
// we first try to handle it using the child Scope exception handler.
1340+
if (from_scope != NULL && current_scope->child_exception_fci != NULL && current_scope->child_exception_fcc != NULL) {
13401341

1341-
zend_fcall_info *exception_fci = current_scope->exception_fci;
1342+
zend_fcall_info *exception_fci = current_scope->child_exception_fci;
13421343

13431344
exception_fci->retval = &retval;
13441345
exception_fci->param_count = 3;
13451346
exception_fci->params = &parameters[0];
13461347

1347-
zend_result result = zend_call_function(exception_fci, current_scope->exception_fcc);
1348+
zend_result result = zend_call_function(exception_fci, current_scope->child_exception_fcc);
13481349
Z_TRY_DELREF(retval);
13491350
exception_fci->retval = NULL;
13501351
exception_fci->param_count = 0;
@@ -1355,19 +1356,16 @@ static zend_always_inline bool try_to_handle_exception(
13551356
}
13561357
}
13571358

1358-
// If the previous attempt didn't work,
1359-
// we try to handle the error using the parent handler via setChildScopeExceptionHandler.
1360-
const async_scope_t * parent_scope = (async_scope_t *) current_scope->scope.parent_scope;
1361-
1362-
if (parent_scope != NULL && parent_scope->child_exception_fci != NULL && parent_scope->child_exception_fcc != NULL) {
1359+
// Second attempt is to handle the exception using the current Scope's exception handler.
1360+
if (current_scope->exception_fci != NULL && current_scope->exception_fcc != NULL) {
13631361

1364-
zend_fcall_info *exception_fci = parent_scope->exception_fci;
1362+
zend_fcall_info *exception_fci = current_scope->exception_fci;
13651363

13661364
exception_fci->retval = &retval;
13671365
exception_fci->param_count = 3;
13681366
exception_fci->params = &parameters[0];
13691367

1370-
zend_result result = zend_call_function(exception_fci, parent_scope->child_exception_fcc);
1368+
zend_result result = zend_call_function(exception_fci, current_scope->exception_fcc);
13711369
Z_TRY_DELREF(retval);
13721370
exception_fci->retval = NULL;
13731371
exception_fci->param_count = 0;

0 commit comments

Comments
 (0)