You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
If a native module spec declares a custom type:
https://www.internalfb.com/code/fbsource/[f6aeb413dbc3]/xplat/js/RKJSModules/Libraries/hsr/tm/code/editable_object/NativeEditableObjectModule.js?lines=151-154
The codegen will generate a c++ struct for that type, like so:
```
template <typename P0, typename P1>
struct NativeEditableObjectModuleChangedProperty {
P0 propertyPath;
P1 value;
bool operator==(const NativeEditableObjectModuleChangedProperty &other) const {
return propertyPath == other.propertyPath && value == other.value;
}
};
```
## Problem
People can sometimes forget to default initialize this struct:
- **Report:** [post](https://fb.workplace.com/groups/rn.support/permalink/28506993098922601/)
- **Diff #1:** D74868762
- **Diff #2:** D77182083
In this scenario, all the members contain garbage data.
## Changes
This diff ensures that all the members are always default initialized, like so:
```
template <typename P0, typename P1>
struct NativeEditableObjectModuleChangedProperty {
P0 propertyPath{};
P1 value{};
bool operator==(const NativeEditableObjectModuleChangedProperty &other) const {
return propertyPath == other.propertyPath && value == other.value;
}
};
```
This way, even if you forget to default initailize the struct, the members will still be default initialized.
## Concerns/Risks
This could cause compilation issues in some of our existing native modules. (if one of the member types doesn't have a default constructor).
Code could start behaving differently, now that all the members are default initialized. (my hunch is that the risk from this causing a problem is low).
Changelog: [General][Changed] c++ tm codegen: Default initialize properties in custom structs
Reviewed By: christophpurrer
Differential Revision: D77315742
Copy file name to clipboardExpand all lines: packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap
0 commit comments