json.writer: add an explicit error when serializing fp-specials
parent
5ed3aef603
commit
5c23f10e50
|
@ -1,10 +1,13 @@
|
||||||
USING: kernel vocabs ;
|
USING: kernel vocabs summary debugger io ;
|
||||||
IN: json
|
IN: json
|
||||||
|
|
||||||
SINGLETON: json-null
|
SINGLETON: json-null
|
||||||
|
|
||||||
ERROR: json-error ;
|
ERROR: json-error ;
|
||||||
|
|
||||||
|
ERROR: json-fp-special-error value ;
|
||||||
|
M: json-fp-special-error summary drop "JSON serialization: illegal float:" ;
|
||||||
|
|
||||||
: if-json-null ( x if-null else -- )
|
: if-json-null ( x if-null else -- )
|
||||||
[ dup json-null? ]
|
[ dup json-null? ]
|
||||||
[ [ drop ] prepose ]
|
[ [ drop ] prepose ]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2006 Chris Double.
|
! Copyright (C) 2006 Chris Double.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: help.markup help.syntax kernel ;
|
USING: json help.markup help.syntax kernel ;
|
||||||
IN: json.writer
|
IN: json.writer
|
||||||
|
|
||||||
HELP: >json
|
HELP: >json
|
||||||
|
@ -23,6 +23,11 @@ $nl
|
||||||
}
|
}
|
||||||
{ $see-also >json } ;
|
{ $see-also >json } ;
|
||||||
|
|
||||||
|
{ json-fp-special-error json-allow-fp-special? } related-words
|
||||||
|
|
||||||
|
HELP: json-fp-special-error
|
||||||
|
{ $error-description "Thrown by " { $link "json.writer" } " when attempting to serialize -1/0. or +1/0. or NaN when " { $link json-allow-fp-special? } " is not enabled." } ;
|
||||||
|
|
||||||
ARTICLE: "json.writer" "JSON writer"
|
ARTICLE: "json.writer" "JSON writer"
|
||||||
"The " { $vocab-link "json.writer" } " vocabulary defines words for converting objects to JSON format."
|
"The " { $vocab-link "json.writer" } " vocabulary defines words for converting objects to JSON format."
|
||||||
{ $subsections
|
{ $subsections
|
||||||
|
|
|
@ -94,7 +94,7 @@ M: integer stream-json-print
|
||||||
|
|
||||||
: float>json ( float -- string )
|
: float>json ( float -- string )
|
||||||
dup fp-special? [
|
dup fp-special? [
|
||||||
json-allow-fp-special? get [ json-error ] unless
|
json-allow-fp-special? get [ json-fp-special-error ] unless
|
||||||
{
|
{
|
||||||
{ [ dup fp-nan? ] [ drop "NaN" ] }
|
{ [ dup fp-nan? ] [ drop "NaN" ] }
|
||||||
{ [ dup 1/0. = ] [ drop "Infinity" ] }
|
{ [ dup 1/0. = ] [ drop "Infinity" ] }
|
||||||
|
|
Loading…
Reference in New Issue