Skip to content

Commit

Permalink
Web.JSON: Throws exception when encode funcref, job or channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Nov 11, 2019
1 parent 3bf585e commit 7dcd77d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 1 addition & 5 deletions autoload/vital/__vital__/Web/JSON.vim
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ function! s:_encode(val, settings) abort
return 'false'
elseif s:const.null == a:val
return 'null'
else
" backward compatibility
return string(a:val)
endif
elseif t == 3
return s:_encode_list(a:val, a:settings)
Expand All @@ -200,9 +197,8 @@ function! s:_encode(val, settings) abort
return get(s:special_constants, a:val)
elseif t == 10
return s:_encode_list(s:bytes.from_blob(a:val), a:settings)
else
return string(a:val)
endif
throw 'vital: Web.JSON: Invalid argument: ' . string(a:val)
endfunction

" @vimlint(EVL102, 1, l:ns)
Expand Down
26 changes: 26 additions & 0 deletions test/Web/JSON.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,31 @@ Describe Web.JSON
Assert Equals(JSON.encode(0z), '[]')
Assert Equals(JSON.encode(0zFF.00.ED.01.5D.AF), '[255,0,237,1,93,175]')
End

It throws exception when encodes funcref
let Funcref = function('get')
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(Funcref)
End

It throws exception when encodes job
if !has('job')
Skip no available job type.
endif
if has('win32')
let job = job_start('cmd /c ""')
else
let job = job_start('true')
endif
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(job)
End

It throws exception when encodes channel
if !has('channel')
Skip no available channel type.
endif
let ch = ch_open('localhost:12345', {'waittime': 0})
silent! call ch_close(ch)
Throws /^vital: Web\.JSON: Invalid argument: / JSON.encode(ch)
End
End
End

0 comments on commit 7dcd77d

Please sign in to comment.