Fix use-after-move in console implementation
Summary: Changelog: [Internal]
In the new CDP backend, calling any console method a second time involves a call to a moved-from std::function. This shouldn't work, but depending on the toolchain, sometimes it does - likely because moving from a std::function leaves it in an unspecified state rather than a definitely empty state, and std::functions are always copyable so falling back to a copy is technically legal.
In the code in question, we're right to want to avoid a copy of the body function into the argument of delegateExecutorSync - only one copy of this function needs to exist at a time. But the correct way to avoid this copy is to capture body by reference, as we can do that repeatedly with no ill effects. (delegateExecutorSync is, as its name suggests, synchronous, so there are no lifetime issues.) Doing this also allows us to remove the use of mutable so the capturing is by const reference.
Differential Revision: D56673529
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 19,461,330 | -1 |
| android | hermes | armeabi-v7a | n/a | -- |
| android | hermes | x86 | n/a | -- |
| android | hermes | x86_64 | n/a | -- |
| android | jsc | arm64-v8a | 22,834,242 | +8 |
| android | jsc | armeabi-v7a | n/a | -- |
| android | jsc | x86 | n/a | -- |
| android | jsc | x86_64 | n/a | -- |
Base commit: e2ad6696d872447608a26fcf499e573280fb43a8 Branch: main
Merged as https://github.com/facebook/react-native/commit/fb0c856cf298c6f9310423fb443a6d2c8f3b6252