microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.37k stars 1.14k forks source link

JS integer literals are parsed into folly::dynamic ints on debug, doubles on release #4225

Open ddalp opened 4 years ago

ddalp commented 4 years ago

This bug was found while writing the Camera Native Module. For example: Method TakePicture() below: REACT_METHOD(takePicture) void takePicture( std::map<std::wstring, winrt::Microsoft::ReactNative::JSValue>&& options, int viewTag, winrt::Microsoft::ReactNative::ReactPromise&& result) noexcept);

Options can contain a value pair such as {"target", 2}, when parsing the JSValue, 2 is Int64 in debug build but Double in Release build. I have to write a utility function to parse both types as a workaround.

namrog84 commented 4 years ago

Related int64 vs double issues #4181

jonthysell commented 4 years ago

This is happening even deeper in RN - numeric literals are coming into folly::dynamic objetcs as ints on Debug and doubles on Release. The JSValues are forwarding exactly what they received from folly

jonthysell commented 4 years ago

The JSValue APIs for native modules now include better functions for getting numerical values (doing the casting for you). As for why folly differs in the first place, that's still a lower level problem.

NickGerleman commented 3 years ago

This is likely a JSI (in release_ vs non-JSI (Using WebSocketJSExecutor) thing. My understanding is that RN core has the same sort of behavior, where types have been different in legacy vs JSI.

Not sure there is much we can do though, and eventually everything will be on JSI.