@@ -127,9 +127,16 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric(struct DecoderState *ds) {
127127
128128 JSUINT64 overflowLimit = LLONG_MAX ;
129129
130- if (* (offset ) == '-' ) {
130+ if (* (offset ) == 'I' ) {
131+ goto DECODE_INF ;
132+ } else if (* (offset ) == 'N' ) {
133+ goto DECODE_NAN ;
134+ } else if (* (offset ) == '-' ) {
131135 offset ++ ;
132136 intNeg = -1 ;
137+ if (* (offset ) == 'I' ) {
138+ goto DECODE_INF ;
139+ }
133140 overflowLimit = LLONG_MIN ;
134141 }
135142
@@ -281,6 +288,48 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric(struct DecoderState *ds) {
281288 }
282289 }
283290
291+ DECODE_NAN :
292+ offset ++ ;
293+ if (* (offset ++ ) != 'a' ) goto SET_NAN_ERROR ;
294+ if (* (offset ++ ) != 'N' ) goto SET_NAN_ERROR ;
295+
296+ ds -> lastType = JT_NULL ;
297+ ds -> start = offset ;
298+ return ds -> dec -> newNull (ds -> prv );
299+
300+ SET_NAN_ERROR :
301+ return SetError (ds , -1 , "Unexpected character found when decoding 'NaN'" );
302+
303+ DECODE_INF :
304+ offset ++ ;
305+ if (* (offset ++ ) != 'n' ) goto SET_INF_ERROR ;
306+ if (* (offset ++ ) != 'f' ) goto SET_INF_ERROR ;
307+ if (* (offset ++ ) != 'i' ) goto SET_INF_ERROR ;
308+ if (* (offset ++ ) != 'n' ) goto SET_INF_ERROR ;
309+ if (* (offset ++ ) != 'i' ) goto SET_INF_ERROR ;
310+ if (* (offset ++ ) != 't' ) goto SET_INF_ERROR ;
311+ if (* (offset ++ ) != 'y' ) goto SET_INF_ERROR ;
312+
313+ ds -> start = offset ;
314+
315+ if (intNeg == 1 ) {
316+ ds -> lastType = JT_POS_INF ;
317+ return ds -> dec -> newPosInf (ds -> prv );
318+ } else {
319+ ds -> lastType = JT_NEG_INF ;
320+ return ds -> dec -> newNegInf (ds -> prv );
321+ }
322+
323+ SET_INF_ERROR :
324+ if (intNeg == 1 ) {
325+ const char * msg = "Unexpected character found when decoding 'Infinity'" ;
326+ return SetError (ds , -1 , msg );
327+ } else {
328+ const char * msg = "Unexpected character found when decoding '-Infinity'" ;
329+ return SetError (ds , -1 , msg );
330+ }
331+
332+
284333BREAK_EXP_LOOP :
285334 // FIXME: Check for arithmetic overflow here
286335 ds -> lastType = JT_DOUBLE ;
@@ -1070,6 +1119,8 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_any(struct DecoderState *ds) {
10701119 case '7' :
10711120 case '8' :
10721121 case '9' :
1122+ case 'I' :
1123+ case 'N' :
10731124 case '-' :
10741125 return decode_numeric (ds );
10751126
0 commit comments