flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Javascript flexbuffers.toObject() small value change causes TypeError: Cannot mix BigInt

Open sketch34 opened this issue 2 years ago • 3 comments

Environment

flatbuffers v2.0.4 node v16.13.0 Debian GNU/Linux 11 (bullseye) tsc version 4.5.2

Repro

This is in Typescript:

const flex_in = {
  test_number: 72.6   // Change this to 72.5 and the error does not occur.
};
const flex_buf = flexbuffers.encode(flex_in, 1, false, false, false);
flexbuffers.toObject(flex_buf.buffer);    // *** Error ***
TypeError: Cannot mix BigInt and other types, use explicit conversions
    at keyForIndex (/home/Dev/test_proj/node_modules/flatbuffers/js/flexbuffers/reference-util.js:119:43)
    at Reference.toObject (/home/Dev/test_proj/node_modules/flatbuffers/js/flexbuffers/reference.js:166:60)
    at Proxy.toObject (/home/Dev/test_proj/node_modules/flatbuffers/js/flexbuffers.js:14:49)
    at Object.<anonymous> (/home/Dev/test_proj/src/test/test_buffers.js:73:13)
    at Generator.next (<anonymous>)

If I change test_number to 72.5 it works fine.

I'm not sure what the size (2nd) parameter to encode() should be, but the same thing happens if I call flexbuffers.encode(flex_in) with no other parameters.

sketch34 avatar Nov 19 '21 04:11 sketch34

@mzaks

aardappel avatar Nov 22 '21 19:11 aardappel

@mzaks Can you take a look?

dbaileychess avatar Aug 06 '22 18:08 dbaileychess

Bug is fixed in the PR #7434 Sorry for the delay. Seems like I missed the first mention in 2021.

mzaks avatar Aug 13 '22 10:08 mzaks