@@ -7,7 +7,6 @@ using Observables: @map
7
7
export showtable
8
8
9
9
const ag_grid_imports = []
10
- const js_max_safe_int = Int128 (2 ^ 53 - 1 )
11
10
12
11
function __init__ ()
13
12
version = readchomp (joinpath (@__DIR__ , " .." , " ag-grid.version" ))
@@ -259,6 +258,18 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength,
259
258
onimport (w, handler)
260
259
end
261
260
261
+ function _is_javascript_safe (x:: Integer )
262
+ min_safe_int = - (Int64 (2 )^ 53 - 1 )
263
+ max_safe_int = Int64 (2 )^ 53 - 1
264
+ min_safe_int < x < max_safe_int
265
+ end
266
+
267
+ function _is_javascript_safe (x:: AbstractFloat )
268
+ min_safe_float = - (Float64 (2 )^ 53 - 1 )
269
+ max_safe_float = Float64 (2 )^ 53 - 1
270
+ min_safe_float < x < max_safe_float
271
+ end
272
+
262
273
# directly write JSON instead of allocating temporary dicts etc
263
274
function table2json (schema, rows, types; requested = nothing )
264
275
io = IOBuffer ()
@@ -273,7 +284,7 @@ function table2json(schema, rows, types; requested = nothing)
273
284
columnwriter = JSON. Writer. CompactContext (io)
274
285
JSON. begin_object (columnwriter)
275
286
Tables. eachcolumn (schema, row) do val, ind, name
276
- if val isa Real && isfinite (val) && - js_max_safe_int < trunc (Int128, val) < js_max_safe_int
287
+ if val isa Real && isfinite (val) && _is_javascript_safe ( val)
277
288
JSON. show_pair (columnwriter, ser, name, val)
278
289
elseif val === nothing || val === missing
279
290
JSON. show_pair (columnwriter, ser, name, repr (val))
0 commit comments