Skip to content

Commit 3044278

Browse files
committed
Web.JSON: Throws exception when encode funcref, job or channel.
1 parent 04349a9 commit 3044278

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

autoload/vital/__vital__/Web/JSON.vim

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ function! s:_encode(val, settings) abort
183183
return 'false'
184184
elseif s:const.null == a:val
185185
return 'null'
186-
else
187-
" backward compatibility
188-
return string(a:val)
189186
endif
190187
elseif t == 3
191188
return s:_encode_list(a:val, a:settings)
@@ -203,9 +200,8 @@ function! s:_encode(val, settings) abort
203200
return get(s:special_constants, a:val)
204201
elseif t == 10
205202
return s:_encode_list(s:bytes.from_blob(a:val), a:settings)
206-
else
207-
return string(a:val)
208203
endif
204+
throw 'vital: Web.JSON: Invalid argument: ' . string(a:val)
209205
endfunction
210206

211207
" @vimlint(EVL102, 1, l:ns)

test/Web/JSON.vimspec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,26 @@ Describe Web.JSON
308308
Assert Equals(JSON.encode(0z), '[]')
309309
Assert Equals(JSON.encode(0zFF.00.ED.01.5D.AF), '[255,0,237,1,93,175]')
310310
End
311+
312+
It throws exception when encodes funcref
313+
let Funcref = function('get')
314+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(Funcref)
315+
End
316+
317+
It throws exception when encodes job
318+
if !exists('*test_null_job')
319+
Skip no available job type.
320+
endif
321+
let job = test_null_job()
322+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(job)
323+
End
324+
325+
It throws exception when encodes channel
326+
if !exists('*test_null_channel')
327+
Skip no available channel type.
328+
endif
329+
let ch = test_null_channel()
330+
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(ch)
331+
End
311332
End
312333
End

0 commit comments

Comments
 (0)