Skip to content

Commit 8d6721a

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 0d23826 + 7823a3b commit 8d6721a

7 files changed

Lines changed: 218 additions & 199 deletions

File tree

runtime/doc/eval.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ delete( {fname} [, {flags}]) Number delete the file or directory {fname}
18461846
did_filetype() Number TRUE if FileType autocommand event used
18471847
diff_filler( {lnum}) Number diff filler lines about {lnum}
18481848
diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col}
1849+
disable_char_avail_for_testing({expr}) none test without typeahead
18491850
empty( {expr}) Number TRUE if {expr} is empty
18501851
escape( {string}, {chars}) String escape {chars} in {string} with '\'
18511852
eval( {string}) any evaluate {string} into its value
@@ -1952,14 +1953,14 @@ invert( {expr}) Number bitwise invert
19521953
isdirectory( {directory}) Number TRUE if {directory} is a directory
19531954
islocked( {expr}) Number TRUE if {expr} is locked
19541955
items( {dict}) List key-value pairs in {dict}
1955-
job_start({command} [, {options}]) Job start a job
1956-
job_status({job}) String get the status of a job
1957-
job_stop({job} [, {how}]) Number stop a job
1956+
job_start( {command} [, {options}]) Job start a job
1957+
job_status( {job}) String get the status of a job
1958+
job_stop( {job} [, {how}]) Number stop a job
19581959
join( {list} [, {sep}]) String join {list} items into one String
1959-
jsdecode( {string}) any decode JS style JSON
1960-
jsencode( {expr}) String encode JS style JSON
1961-
jsondecode( {string}) any decode JSON
1962-
jsonencode( {expr}) String encode JSON
1960+
js_decode( {string}) any decode JS style JSON
1961+
js_encode( {expr}) String encode JS style JSON
1962+
json_decode( {string}) any decode JSON
1963+
json_encode( {expr}) String encode JSON
19631964
keys( {dict}) List keys in {dict}
19641965
len( {expr}) Number the length of {expr}
19651966
libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
@@ -2733,8 +2734,9 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
27332734
When {expr} is a |List| a shallow copy is created. This means
27342735
that the original |List| can be changed without changing the
27352736
copy, and vice versa. But the items are identical, thus
2736-
changing an item changes the contents of both |Lists|. Also
2737-
see |deepcopy()|.
2737+
changing an item changes the contents of both |Lists|.
2738+
A |Dictionary| is copied in a similar way as a |List|.
2739+
Also see |deepcopy()|.
27382740

27392741
cos({expr}) *cos()*
27402742
Return the cosine of {expr}, measured in radians, as a |Float|.
@@ -4386,30 +4388,30 @@ join({list} [, {sep}]) *join()*
43864388
converted into a string like with |string()|.
43874389
The opposite function is |split()|.
43884390

4389-
jsdecode({string}) *jsdecode()*
4390-
This is similar to |jsondecode()| with these differences:
4391+
js_decode({string}) *js_decode()*
4392+
This is similar to |json_decode()| with these differences:
43914393
- Object key names do not have to be in quotes.
43924394
- Empty items in an array (between two commas) are allowed and
43934395
result in v:none items.
43944396

4395-
jsencode({expr}) *jsencode()*
4396-
This is similar to |jsonencode()| with these differences:
4397+
js_encode({expr}) *js_encode()*
4398+
This is similar to |json_encode()| with these differences:
43974399
- Object key names are not in quotes.
43984400
- v:none items in an array result in an empty item between
43994401
commas.
44004402
For example, the Vim object:
4401-
[1,v:none,{"one":1}],v:none ~
4403+
[1,v:none,{"one":1},v:none] ~
44024404
Will be encoded as:
44034405
[1,,{one:1},,] ~
4404-
While jsonencode() would produce:
4406+
While json_encode() would produce:
44054407
[1,null,{"one":1},null] ~
44064408
This encoding is valid for JavaScript. It is more efficient
44074409
than JSON, especially when using an array with optional items.
44084410

44094411

4410-
jsondecode({string}) *jsondecode()*
4412+
json_decode({string}) *json_decode()*
44114413
This parses a JSON formatted string and returns the equivalent
4412-
in Vim values. See |jsonencode()| for the relation between
4414+
in Vim values. See |json_encode()| for the relation between
44134415
JSON and Vim values.
44144416
The decoding is permissive:
44154417
- A trailing comma in an array and object is ignored.
@@ -4419,7 +4421,7 @@ jsondecode({string}) *jsondecode()*
44194421
- An empty object member name is not allowed.
44204422
- Duplicate object member names are not allowed.
44214423

4422-
jsonencode({expr}) *jsonencode()*
4424+
json_encode({expr}) *json_encode()*
44234425
Encode {expr} as JSON and return this as a string.
44244426
The encoding is specified in:
44254427
https://tools.ietf.org/html/rfc7159.html

src/eval.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ static void f_job_stop(typval_T *argvars, typval_T *rettv);
629629
static void f_job_status(typval_T *argvars, typval_T *rettv);
630630
#endif
631631
static void f_join(typval_T *argvars, typval_T *rettv);
632-
static void f_jsdecode(typval_T *argvars, typval_T *rettv);
633-
static void f_jsencode(typval_T *argvars, typval_T *rettv);
634-
static void f_jsondecode(typval_T *argvars, typval_T *rettv);
635-
static void f_jsonencode(typval_T *argvars, typval_T *rettv);
632+
static void f_js_decode(typval_T *argvars, typval_T *rettv);
633+
static void f_js_encode(typval_T *argvars, typval_T *rettv);
634+
static void f_json_decode(typval_T *argvars, typval_T *rettv);
635+
static void f_json_encode(typval_T *argvars, typval_T *rettv);
636636
static void f_keys(typval_T *argvars, typval_T *rettv);
637637
static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv);
638638
static void f_len(typval_T *argvars, typval_T *rettv);
@@ -8213,10 +8213,10 @@ static struct fst
82138213
{"job_stop", 1, 2, f_job_stop},
82148214
#endif
82158215
{"join", 1, 2, f_join},
8216-
{"jsdecode", 1, 1, f_jsdecode},
8217-
{"jsencode", 1, 1, f_jsencode},
8218-
{"jsondecode", 1, 1, f_jsondecode},
8219-
{"jsonencode", 1, 1, f_jsonencode},
8216+
{"js_decode", 1, 1, f_js_decode},
8217+
{"js_encode", 1, 1, f_js_encode},
8218+
{"json_decode", 1, 1, f_json_decode},
8219+
{"json_encode", 1, 1, f_json_encode},
82208220
{"keys", 1, 1, f_keys},
82218221
{"last_buffer_nr", 0, 0, f_last_buffer_nr},/* obsolete */
82228222
{"len", 1, 1, f_len},
@@ -9871,12 +9871,13 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98719871

98729872
if (argvars[1].v_type == VAR_DICT)
98739873
{
9874-
/* parse argdict */
9875-
dict_T *dict = argvars[1].vval.v_dict;
9874+
dict_T *dict = argvars[1].vval.v_dict;
9875+
dictitem_T *item;
98769876

9877-
if (dict_find(dict, (char_u *)"mode", -1) != NULL)
9877+
/* parse argdict */
9878+
if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL)
98789879
{
9879-
mode = get_dict_string(dict, (char_u *)"mode", FALSE);
9880+
mode = get_tv_string(&item->di_tv);
98809881
if (STRCMP(mode, "raw") == 0)
98819882
ch_mode = MODE_RAW;
98829883
else if (STRCMP(mode, "js") == 0)
@@ -9889,12 +9890,12 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98899890
return;
98909891
}
98919892
}
9892-
if (dict_find(dict, (char_u *)"waittime", -1) != NULL)
9893-
waittime = get_dict_number(dict, (char_u *)"waittime");
9894-
if (dict_find(dict, (char_u *)"timeout", -1) != NULL)
9895-
timeout = get_dict_number(dict, (char_u *)"timeout");
9896-
if (dict_find(dict, (char_u *)"callback", -1) != NULL)
9897-
callback = get_dict_string(dict, (char_u *)"callback", FALSE);
9893+
if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL)
9894+
waittime = get_tv_number(&item->di_tv);
9895+
if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL)
9896+
timeout = get_tv_number(&item->di_tv);
9897+
if ((item = dict_find(dict, (char_u *)"callback", -1)) != NULL)
9898+
callback = get_callback(&item->di_tv);
98989899
}
98999900
if (waittime < 0 || timeout < 0)
99009901
{
@@ -14506,10 +14507,10 @@ f_join(typval_T *argvars, typval_T *rettv)
1450614507
}
1450714508

1450814509
/*
14509-
* "jsdecode()" function
14510+
* "js_decode()" function
1451014511
*/
1451114512
static void
14512-
f_jsdecode(typval_T *argvars, typval_T *rettv)
14513+
f_js_decode(typval_T *argvars, typval_T *rettv)
1451314514
{
1451414515
js_read_T reader;
1451514516

@@ -14521,20 +14522,20 @@ f_jsdecode(typval_T *argvars, typval_T *rettv)
1452114522
}
1452214523

1452314524
/*
14524-
* "jsencode()" function
14525+
* "js_encode()" function
1452514526
*/
1452614527
static void
14527-
f_jsencode(typval_T *argvars, typval_T *rettv)
14528+
f_js_encode(typval_T *argvars, typval_T *rettv)
1452814529
{
1452914530
rettv->v_type = VAR_STRING;
1453014531
rettv->vval.v_string = json_encode(&argvars[0], JSON_JS);
1453114532
}
1453214533

1453314534
/*
14534-
* "jsondecode()" function
14535+
* "json_decode()" function
1453514536
*/
1453614537
static void
14537-
f_jsondecode(typval_T *argvars, typval_T *rettv)
14538+
f_json_decode(typval_T *argvars, typval_T *rettv)
1453814539
{
1453914540
js_read_T reader;
1454014541

@@ -14546,10 +14547,10 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
1454614547
}
1454714548

1454814549
/*
14549-
* "jsonencode()" function
14550+
* "json_encode()" function
1455014551
*/
1455114552
static void
14552-
f_jsonencode(typval_T *argvars, typval_T *rettv)
14553+
f_json_encode(typval_T *argvars, typval_T *rettv)
1455314554
{
1455414555
rettv->v_type = VAR_STRING;
1455514556
rettv->vval.v_string = json_encode(&argvars[0], 0);
@@ -21649,7 +21650,7 @@ get_tv_string_buf_chk(typval_T *varp, char_u *buf)
2164921650
"process %ld %s", (long)job->jv_pid, status);
2165021651
# elif defined(WIN32)
2165121652
vim_snprintf((char *)buf, NUMBUFLEN,
21652-
"process %ld %s", (long)job->jf_pi.dwProcessId,
21653+
"process %ld %s", (long)job->jv_pi.dwProcessId,
2165321654
status);
2165421655
# else
2165521656
/* fall-back */

src/os_win32.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,7 +5050,7 @@ mch_start_job(char *cmd, job_T *job)
50505050
job->jv_status = JOB_FAILED;
50515051
else
50525052
{
5053-
job->jf_pi = pi;
5053+
job->jv_pi = pi;
50545054
job->jv_status = JOB_STARTED;
50555055
}
50565056
}
@@ -5060,12 +5060,12 @@ mch_job_status(job_T *job)
50605060
{
50615061
DWORD dwExitCode = 0;
50625062

5063-
if (!GetExitCodeProcess(job->jf_pi.hProcess, &dwExitCode))
5063+
if (!GetExitCodeProcess(job->jv_pi.hProcess, &dwExitCode))
50645064
return "dead";
50655065
if (dwExitCode != STILL_ACTIVE)
50665066
{
5067-
CloseHandle(job->jf_pi.hProcess);
5068-
CloseHandle(job->jf_pi.hThread);
5067+
CloseHandle(job->jv_pi.hProcess);
5068+
CloseHandle(job->jv_pi.hThread);
50695069
return "dead";
50705070
}
50715071
return "run";
@@ -5075,12 +5075,12 @@ mch_job_status(job_T *job)
50755075
mch_stop_job(job_T *job, char_u *how)
50765076
{
50775077
if (STRCMP(how, "kill") == 0)
5078-
TerminateProcess(job->jf_pi.hProcess, 0);
5078+
TerminateProcess(job->jv_pi.hProcess, 0);
50795079
else
50805080
return GenerateConsoleCtrlEvent(
50815081
STRCMP(how, "hup") == 0 ?
50825082
CTRL_BREAK_EVENT : CTRL_C_EVENT,
5083-
job->jf_pi.dwProcessId) ? OK : FAIL;
5083+
job->jv_pi.dwProcessId) ? OK : FAIL;
50845084
return OK;
50855085
}
50865086
#endif

src/structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ struct jobvar_S
12491249
int jv_exitval;
12501250
#endif
12511251
#ifdef WIN32
1252-
PROCESS_INFORMATION jf_pi;
1252+
PROCESS_INFORMATION jv_pi;
12531253
#endif
12541254
jobstatus_T jv_status;
12551255

src/testdir/test_channel.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ func s:communicate(port)
118118
call assert_equal(handle, s:responseHandle)
119119
call assert_equal('got it', s:responseMsg)
120120

121+
let s:responseHandle = -1
122+
let s:responseMsg = ''
123+
call ch_sendexpr(handle, 'hello!', function('s:RequestHandler'))
124+
sleep 10m
125+
call assert_equal(handle, s:responseHandle)
126+
call assert_equal('got it', s:responseMsg)
127+
121128
" Send an eval request that works.
122129
call assert_equal('ok', ch_sendexpr(handle, 'eval-works'))
123130
sleep 10m
@@ -206,13 +213,12 @@ endfunc
206213

207214
let s:reply = ""
208215
func s:Handler(chan, msg)
216+
unlet s:reply
209217
let s:reply = a:msg
210218
endfunc
211219

212220
func s:channel_handler(port)
213-
let chopt = copy(s:chopt)
214-
let chopt['callback'] = 's:Handler'
215-
let handle = ch_open('localhost:' . a:port, chopt)
221+
let handle = ch_open('localhost:' . a:port, s:chopt)
216222
if handle < 0
217223
call assert_false(1, "Can't open channel")
218224
return
@@ -230,7 +236,11 @@ func s:channel_handler(port)
230236
endfunc
231237

232238
func Test_channel_handler()
239+
let s:chopt.callback = 's:Handler'
240+
call s:run_server('s:channel_handler')
241+
let s:chopt.callback = function('s:Handler')
233242
call s:run_server('s:channel_handler')
243+
unlet s:chopt.callback
234244
endfunc
235245

236246
" Test that trying to connect to a non-existing port fails quickly.

0 commit comments

Comments
 (0)