Skip to content

Event emitter in native module corrupts double arguments #11322

@birdofpreyru

Description

@birdofpreyru

Problem Description

When developing a native module, I use event emitter, and I found that if I pass a large double argument (both directly as the event argument, or when making event argument JSValue and passing in a JSValueObject with double field), the double value I receive on JS side is corrupt, if it was large originally. Say, 75535 (a bit larger than 2bit unsigned integer) passes to the JS side unchanged; but say 2147483647 (the maximum value of signed 4bit integer) turns up as 2147480000 on the JS side; and other large values show the same pattern: least significant digits are lost and turned into zeros on JS side. My naive guess, somewhere in data passing between native and JS side the RN windows fails to respect the correct byte-order, or something else like that.

Steps To Reproduce

Just try what happens when you declare on native module:

REACT_EVENT(EmitEvent);
std::function<void(double)> EmitEvent;

trigger it with a large number passed in, and what you get on the JS side when capture this event.

Expected Results

Expect RN Windows not screwing double arguments of events.

CLI version

10.1.3

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 2.90 GB / 11.90 GB
  Binaries:
    Node: 18.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 9.3.1 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.19041.0, 10.0.22000.0, 10.0.22621.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 17.4.33403.182 (Visual Studio Community 2022)
  Languages:
    Java: 11.0.12 - C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: ^0.71.2 => 0.71.3
    react-native-windows: 0.71.1 => 0.71.1
  npmGlobalPackages:
    *react-native*: Not Found

Target Platform Version

10.0.19041

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

No response

Metadata

Metadata

Assignees

Labels

Area: Native ModulesWorkstream: Module SupportModule developers have the requisite tooling and clear path for adding windows support to modules.bug

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions