Skip to content

Commit f8b38f7

Browse files
Treat nulls as NaNs on floating point input.
Added a log hook to allow logging generally in emscripten environments.
1 parent 8b1b11f commit f8b38f7

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Diff for: RESTProcess_base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ namespace classdesc
12721272

12731273
template <class T>
12741274
typename enable_if<is_floating_point<T>, bool>::T partiallyMatchable(const REST_PROCESS_BUFFER& x)
1275-
{return x.type()==RESTProcessType::float_number||x.type()==RESTProcessType::int_number;}
1275+
{return x.type()==RESTProcessType::float_number||x.type()==RESTProcessType::int_number||x.type()==RESTProcessType::null;}
12761276

12771277
template <class T>
12781278
typename enable_if<

Diff for: classdesc.h

+3
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ namespace classdesc
11221122
template <> int enumKey<RESTProcessType::Type >(const string& x){return int(enum_keysData<RESTProcessType::Type >::keys(x));}
11231123
template <> string enumKey<RESTProcessType::Type >(int x){return enum_keysData<RESTProcessType::Type >::keys(x);}
11241124
}
1125+
1126+
/// and undefined hook to allow logging to console in an emscripten environment.
1127+
void log(const std::string&);
11251128
}
11261129

11271130

Diff for: json_pack_base.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stdarg.h>
1919
#include <vector>
2020
#include <map>
21+
#include <cmath>
2122

2223
namespace classdesc
2324
{
@@ -296,8 +297,20 @@ namespace classdesc
296297

297298
inline json5_parser::mValue valueof(float a)
298299
{return json5_parser::mValue(double(a));}
300+
299301
template <> inline float getValue(const json5_parser::mValue& x)
300-
{return x.get_value<double>();}
302+
{
303+
// treat nulls as nans - JSON.stringify of special values returns "null"
304+
if (x.type()==json5_parser::null_type) return std::nan("");
305+
return x.get_value<double>();
306+
}
307+
308+
template <> inline double getValue(const json5_parser::mValue& x)
309+
{
310+
// treat nulls as nans - JSON.stringify of special values returns "null"
311+
if (x.type()==json5_parser::null_type) return std::nan("");
312+
return x.get_value<double>();
313+
}
301314

302315
// basic types
303316
template <class T> typename

0 commit comments

Comments
 (0)