Fix use-after-move in console implementation #44297
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Changelog: [Internal]
In the new CDP backend, calling any
console
method a second time involves a call to a moved-fromstd::function
. This shouldn't work, but depending on the toolchain, sometimes it does - likely because moving from astd::function
leaves it in an unspecified state rather than a definitely empty state, andstd::function
s 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 ofdelegateExecutorSync
- only one copy of this function needs to exist at a time. But the correct way to avoid this copy is to capturebody
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 ofmutable
so the capturing is by const reference.Differential Revision: D56673529