diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-21 19:09:09 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-21 19:09:09 +0200 |
commit | cd9172077bc8c0aafddf2e5367cc0ae2c00c8ff7 (patch) | |
tree | d460cabb1f58286f763089e7a9552be6c21059f3 /src/terminal.c | |
parent | 189663bdac1156237c49925f77bd197c1bdea12c (diff) | |
download | vim-git-cd9172077bc8c0aafddf2e5367cc0ae2c00c8ff7.tar.gz |
patch 8.2.3194: Vim9: argument types are not checked at compile timev8.2.3194
Problem: Vim9: argument types are not checked at compile time.
Solution: Add several more type checks, simplify some. (Yegappan
Lakshmanan, closes #8598)
Diffstat (limited to 'src/terminal.c')
-rw-r--r-- | src/terminal.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/terminal.c b/src/terminal.c index c758e4474..6c501ece5 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -5779,11 +5779,18 @@ get_row_number(typval_T *tv, term_T *term) void f_term_getline(typval_T *argvars, typval_T *rettv) { - buf_T *buf = term_get_buf(argvars, "term_getline()"); + buf_T *buf; term_T *term; int row; rettv->v_type = VAR_STRING; + + if (in_vim9script() + && (check_for_buffer_arg(argvars, 0) == FAIL + || check_for_lnum_arg(argvars, 1) == FAIL)) + return; + + buf = term_get_buf(argvars, "term_getline()"); if (buf == NULL) return; term = buf->b_term; @@ -5858,10 +5865,17 @@ f_term_getsize(typval_T *argvars, typval_T *rettv) void f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) { - buf_T *buf = term_get_buf(argvars, "term_setsize()"); + buf_T *buf; term_T *term; varnumber_T rows, cols; + if (in_vim9script() + && (check_for_buffer_arg(argvars, 0) == FAIL + || check_for_number_arg(argvars, 1) == FAIL + || check_for_number_arg(argvars, 2) == FAIL)) + return; + + buf = term_get_buf(argvars, "term_setsize()"); if (buf == NULL) { emsg(_("E955: Not a terminal buffer")); @@ -5933,7 +5947,7 @@ f_term_gettty(typval_T *argvars, typval_T *rettv) int num = 0; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_opt_bool_arg(argvars, 1) == FAIL)) return; @@ -5988,7 +6002,7 @@ f_term_list(typval_T *argvars UNUSED, typval_T *rettv) void f_term_scrape(typval_T *argvars, typval_T *rettv) { - buf_T *buf = term_get_buf(argvars, "term_scrape()"); + buf_T *buf; VTermScreen *screen = NULL; VTermPos pos; list_T *l; @@ -5998,6 +6012,13 @@ f_term_scrape(typval_T *argvars, typval_T *rettv) if (rettv_list_alloc(rettv) == FAIL) return; + + if (in_vim9script() + && (check_for_buffer_arg(argvars, 0) == FAIL + || check_for_lnum_arg(argvars, 1) == FAIL)) + return; + + buf = term_get_buf(argvars, "term_scrape()"); if (buf == NULL) return; term = buf->b_term; @@ -6104,7 +6125,7 @@ f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED) term_T *term; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_string_arg(argvars, 1) == FAIL)) return; @@ -6183,7 +6204,7 @@ f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED) term_T *term; if (in_vim9script() - && (check_for_opt_string_or_number_arg(argvars, 0) == FAIL + && (check_for_opt_buffer_arg(argvars, 0) == FAIL || (argvars[0].v_type != VAR_UNKNOWN && check_for_opt_list_arg(argvars, 1) == FAIL))) return; @@ -6217,7 +6238,7 @@ f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED) char_u *api; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_string_arg(argvars, 1) == FAIL)) return; @@ -6245,7 +6266,7 @@ f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED) char_u *cmd; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_string_arg(argvars, 1) == FAIL)) return; @@ -6273,7 +6294,7 @@ f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED) char_u *how; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_string_arg(argvars, 1) == FAIL)) return; @@ -6298,6 +6319,11 @@ f_term_start(typval_T *argvars, typval_T *rettv) jobopt_T opt; buf_T *buf; + if (in_vim9script() + && (check_for_string_or_list_arg(argvars, 0) == FAIL + || check_for_opt_dict_arg(argvars, 1) == FAIL)) + return; + init_job_options(&opt); if (argvars[1].v_type != VAR_UNKNOWN && get_job_options(&argvars[1], &opt, @@ -6326,7 +6352,7 @@ f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) buf_T *buf; if (in_vim9script() - && (check_for_string_or_number_arg(argvars, 0) == FAIL + && (check_for_buffer_arg(argvars, 0) == FAIL || check_for_opt_number_arg(argvars, 1) == FAIL)) return; |