@@ -628,6 +628,8 @@ static void f_job_stop(typval_T *argvars, typval_T *rettv);
628628static void f_job_status(typval_T *argvars, typval_T *rettv);
629629#endif
630630static void f_join(typval_T *argvars, typval_T *rettv);
631+ static void f_jsdecode(typval_T *argvars, typval_T *rettv);
632+ static void f_jsencode(typval_T *argvars, typval_T *rettv);
631633static void f_jsondecode(typval_T *argvars, typval_T *rettv);
632634static void f_jsonencode(typval_T *argvars, typval_T *rettv);
633635static void f_keys(typval_T *argvars, typval_T *rettv);
@@ -8206,6 +8208,8 @@ static struct fst
82068208 {"job_stop", 1, 1, f_job_stop},
82078209#endif
82088210 {"join", 1, 2, f_join},
8211+ {"jsdecode", 1, 1, f_jsdecode},
8212+ {"jsencode", 1, 1, f_jsencode},
82098213 {"jsondecode", 1, 1, f_jsondecode},
82108214 {"jsonencode", 1, 1, f_jsonencode},
82118215 {"keys", 1, 1, f_keys},
@@ -9829,7 +9833,7 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98299833 int port;
98309834 int waittime = 0;
98319835 int timeout = 2000;
9832- int json_mode = TRUE ;
9836+ ch_mode_T ch_mode = MODE_JSON ;
98339837 int ch_idx;
98349838
98359839 /* default: fail */
@@ -9868,8 +9872,12 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98689872 {
98699873 mode = get_dict_string(dict, (char_u *)"mode", FALSE);
98709874 if (STRCMP(mode, "raw") == 0)
9871- json_mode = FALSE;
9872- else if (STRCMP(mode, "json") != 0)
9875+ ch_mode = MODE_RAW;
9876+ else if (STRCMP(mode, "js") == 0)
9877+ ch_mode = MODE_JS;
9878+ else if (STRCMP(mode, "json") == 0)
9879+ ch_mode = MODE_JSON;
9880+ else
98739881 {
98749882 EMSG2(_(e_invarg2), mode);
98759883 return;
@@ -9891,7 +9899,7 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
98919899 ch_idx = channel_open((char *)address, port, waittime, NULL);
98929900 if (ch_idx >= 0)
98939901 {
9894- channel_set_json_mode(ch_idx, json_mode );
9902+ channel_set_json_mode(ch_idx, ch_mode );
98959903 channel_set_timeout(ch_idx, timeout);
98969904 if (callback != NULL && *callback != NUL)
98979905 channel_set_callback(ch_idx, callback);
@@ -9946,7 +9954,7 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
99469954 rettv->vval.v_string = NULL;
99479955
99489956 id = channel_get_id();
9949- text = json_encode_nr_expr(id, &argvars[1]);
9957+ text = json_encode_nr_expr(id, &argvars[1], 0 );
99509958 if (text == NULL)
99519959 return;
99529960
@@ -14442,6 +14450,31 @@ f_join(typval_T *argvars, typval_T *rettv)
1444214450 rettv->vval.v_string = NULL;
1444314451}
1444414452
14453+ /*
14454+ * "jsdecode()" function
14455+ */
14456+ static void
14457+ f_jsdecode(typval_T *argvars, typval_T *rettv)
14458+ {
14459+ js_read_T reader;
14460+
14461+ reader.js_buf = get_tv_string(&argvars[0]);
14462+ reader.js_fill = NULL;
14463+ reader.js_used = 0;
14464+ if (json_decode_all(&reader, rettv, JSON_JS) != OK)
14465+ EMSG(_(e_invarg));
14466+ }
14467+
14468+ /*
14469+ * "jsencode()" function
14470+ */
14471+ static void
14472+ f_jsencode(typval_T *argvars, typval_T *rettv)
14473+ {
14474+ rettv->v_type = VAR_STRING;
14475+ rettv->vval.v_string = json_encode(&argvars[0], JSON_JS);
14476+ }
14477+
1444514478/*
1444614479 * "jsondecode()" function
1444714480 */
@@ -14453,7 +14486,7 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
1445314486 reader.js_buf = get_tv_string(&argvars[0]);
1445414487 reader.js_fill = NULL;
1445514488 reader.js_used = 0;
14456- if (json_decode_all(&reader, rettv) != OK)
14489+ if (json_decode_all(&reader, rettv, 0 ) != OK)
1445714490 EMSG(_(e_invarg));
1445814491}
1445914492
@@ -14464,7 +14497,7 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
1446414497f_jsonencode(typval_T *argvars, typval_T *rettv)
1446514498{
1446614499 rettv->v_type = VAR_STRING;
14467- rettv->vval.v_string = json_encode(&argvars[0]);
14500+ rettv->vval.v_string = json_encode(&argvars[0], 0 );
1446814501}
1446914502
1447014503/*
0 commit comments