comparison src/vim9execute.c @ 23921:a834f9c082e3 v8.2.2503

patch 8.2.2503: Vim9: a caught error may leave something on the stack Commit: https://github.com/vim/vim/commit/d9d7789b6fe5f2b4074375ee9f1c0bad3e4d3cfe Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 12 21:32:47 2021 +0100 patch 8.2.2503: Vim9: a caught error may leave something on the stack Problem: Vim9: a caught error may leave something on the stack. Solution: Drop items from the stack if needed. (closes https://github.com/vim/vim/issues/7826)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Feb 2021 21:45:04 +0100
parents 4b417b776b95
children 5e5780e3f75d
comparison
equal deleted inserted replaced
23920:80a01c446853 23921:a834f9c082e3
22 22
23 #include "vim9.h" 23 #include "vim9.h"
24 24
25 // Structure put on ec_trystack when ISN_TRY is encountered. 25 // Structure put on ec_trystack when ISN_TRY is encountered.
26 typedef struct { 26 typedef struct {
27 int tcd_frame_idx; // ec_frame_idx when ISN_TRY was encountered 27 int tcd_frame_idx; // ec_frame_idx at ISN_TRY
28 int tcd_stack_len; // size of ectx.ec_stack at ISN_TRY
28 int tcd_catch_idx; // instruction of the first catch 29 int tcd_catch_idx; // instruction of the first catch
29 int tcd_finally_idx; // instruction of the finally block 30 int tcd_finally_idx; // instruction of the finally block
30 int tcd_caught; // catch block entered 31 int tcd_caught; // catch block entered
31 int tcd_return; // when TRUE return from end of :finally 32 int tcd_return; // when TRUE return from end of :finally
32 } trycmd_T; 33 } trycmd_T;
2559 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data) 2560 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data)
2560 + ectx.ec_trystack.ga_len; 2561 + ectx.ec_trystack.ga_len;
2561 ++ectx.ec_trystack.ga_len; 2562 ++ectx.ec_trystack.ga_len;
2562 ++trylevel; 2563 ++trylevel;
2563 trycmd->tcd_frame_idx = ectx.ec_frame_idx; 2564 trycmd->tcd_frame_idx = ectx.ec_frame_idx;
2565 trycmd->tcd_stack_len = ectx.ec_stack.ga_len;
2564 trycmd->tcd_catch_idx = iptr->isn_arg.try.try_catch; 2566 trycmd->tcd_catch_idx = iptr->isn_arg.try.try_catch;
2565 trycmd->tcd_finally_idx = iptr->isn_arg.try.try_finally; 2567 trycmd->tcd_finally_idx = iptr->isn_arg.try.try_finally;
2566 trycmd->tcd_caught = FALSE; 2568 trycmd->tcd_caught = FALSE;
2567 trycmd->tcd_return = FALSE; 2569 trycmd->tcd_return = FALSE;
2568 } 2570 }
2630 discard_current_exception(); 2632 discard_current_exception();
2631 } 2633 }
2632 2634
2633 if (trycmd->tcd_return) 2635 if (trycmd->tcd_return)
2634 goto func_return; 2636 goto func_return;
2637
2638 while (ectx.ec_stack.ga_len > trycmd->tcd_stack_len)
2639 {
2640 --ectx.ec_stack.ga_len;
2641 clear_tv(STACK_TV_BOT(0));
2642 }
2635 } 2643 }
2636 } 2644 }
2637 break; 2645 break;
2638 2646
2639 case ISN_THROW: 2647 case ISN_THROW: