patch 9.1.0481: Vim9: term_getjob() throws an exception on error

Commit: 
https://github.com/vim/vim/commit/a78eb25db3089b864dab8a9cc6c9e5270bf09644
Author: Ernie Rael <err...@raelity.com>
Date:   Thu Jun 13 17:24:54 2024 +0200

    patch 9.1.0481: Vim9: term_getjob() throws an exception on error
    
    Problem:  Vim9: term_getjob() throws an exception on error
    Solution: Return null_job instead, when there is no job
              (Ernie Rael)
    
    closes: #14984
    
    Signed-off-by: Ernie Rael <err...@raelity.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 0f0b42a64..f509ea979 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
-*terminal.txt* For Vim version 9.1.  Last change: 2024 Jun 08
+*terminal.txt* For Vim version 9.1.  Last change: 2024 Jun 13
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -647,7 +647,8 @@ term_getcursor({buf})                                       
*term_getcursor()*
 term_getjob({buf})                                     *term_getjob()*
                Get the Job associated with terminal window {buf}.
                {buf} is used as with |term_getsize()|.
-               Returns |v:null| when there is no job.
+               Returns |v:null| when there is no job. In Vim9 script, return
+               null_job when there is no job.
 
                Can also be used as a |method|: >
                        GetBufnr()->term_getjob()
diff --git a/src/terminal.c b/src/terminal.c
index 07b69c6a7..648fc7872 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -6171,8 +6171,16 @@ f_term_getjob(typval_T *argvars, typval_T *rettv)
     buf = term_get_buf(argvars, "term_getjob()");
     if (buf == NULL)
     {
-       rettv->v_type = VAR_SPECIAL;
-       rettv->vval.v_number = VVAL_NULL;
+       if (in_vim9script())
+       {
+           rettv->v_type = VAR_JOB;
+           rettv->vval.v_job = NULL;
+       }
+       else
+       {
+           rettv->v_type = VAR_SPECIAL;
+           rettv->vval.v_number = VVAL_NULL;
+       }
        return;
     }
 
diff --git a/src/testdir/test_vim9_builtin.vim 
b/src/testdir/test_vim9_builtin.vim
index 3200b7335..6b1a50d41 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -4557,6 +4557,7 @@ enddef
 def Test_term_getjob()
   CheckRunVimInTerminal
   v9.CheckSourceDefAndScriptFailure(['term_getjob(0z10)'], ['E1013: Argument 
1: type mismatch, expected string but got blob', 'E1220: String or Number 
required for argument 1'])
+  v9.CheckSourceDefAndScriptSuccess(['assert_true(term_getjob(0) == 
null_job)'])
 enddef
 
 def Test_term_getline()
diff --git a/src/version.c b/src/version.c
index 89ba9fc39..1360d1cfc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    481,
 /**/
     480,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sHmOs-00Aee3-QX%40256bit.org.

Raspunde prin e-mail lui