@@ -49,22 +49,40 @@ public void executeVoid(VirtualFrame frame) {
4949 if (finalbody == null ) {
5050 body .executeVoid (frame );
5151 } else {
52- try {
53- body .executeVoid (frame );
54- } catch (PException handledException ) {
55- handleException (frame , handledException );
56- } catch (AbstractTruffleException | ControlFlowException e ) {
57- finalbody .executeVoid (frame );
52+ executeImpl (frame , false );
53+ }
54+ }
55+
56+ @ Override
57+ public Object returnExecute (VirtualFrame frame ) {
58+ if (finalbody == null ) {
59+ return body .returnExecute (frame );
60+ } else {
61+ return executeImpl (frame , true );
62+ }
63+ }
64+
65+ public Object executeImpl (VirtualFrame frame , boolean isReturn ) {
66+ assert finalbody != null ;
67+ Object result = null ;
68+ try {
69+ // The assumption is that finally blocks usually do not return, we execute those in
70+ // control flow exceptions mode to be able to execute the body with 'returnExecute'
71+ result = body .genericExecute (frame , isReturn );
72+ } catch (PException handledException ) {
73+ handleException (frame , handledException );
74+ } catch (AbstractTruffleException | ControlFlowException e ) {
75+ finalbody .executeVoid (frame );
76+ throw e ;
77+ } catch (Throwable e ) {
78+ PException pe = wrapJavaExceptionIfApplicable (e );
79+ if (pe == null ) {
5880 throw e ;
59- } catch (Throwable e ) {
60- PException pe = wrapJavaExceptionIfApplicable (e );
61- if (pe == null ) {
62- throw e ;
63- }
64- handleException (frame , pe );
6581 }
66- finalbody . executeVoid (frame );
82+ handleException (frame , pe );
6783 }
84+ finalbody .executeVoid (frame );
85+ return result ;
6886 }
6987
7088 private void handleException (VirtualFrame frame , PException handledException ) {
0 commit comments