MozPromiseHolder::operator=(MozPromiseHolder&&) shouldn't copy its mPromise member
Categories
(Core :: XPCOM, task)
Tracking
()
People
(Reporter: sg, Assigned: sg)
References
Details
Attachments
(1 file)
The move assignment operator should move the member instead.
Assignee | ||
Comment 1•6 years ago
•
|
||
NB: The assertions in the move assignment operator seem a bit odd, as they mean that it places custom preconditions on when an instance can be the target of a move. I am not sure if this is a good idea, as this makes the use error-prone and prevents the use of the class in generic templates (e.g. a nsTArray, which might move its elements in situations unaware of these assertions). It might be a better idea to provide a named member function instead, and delete the move operations altogether, if MozPromiseHolder
is not intended to be a general movable type.
Assignee | ||
Comment 2•6 years ago
|
||
![]() |
||
Comment 3•6 years ago
|
||
I don't know the exact rationale behind the assertions in MozPromiseHolder
. But looking at them, I would guess:
mMonitor
essentially makes another type ofMozPromiseHolder
, so themMonitor
assertions are making sure that you're not moving from a monitor-requiring instance to a non-monitor requiring instance -- that wouldn't make a lot of sense. (There are other combinations, but that seems like the easiest to explain.)- We're also ensuring that we don't overwrite an existing promise. Overwriting an existing promise here...what would that even mean?
I guess we could use a separately-named member function here, but it's going to be a weird class that supports move construction but not move assignment. We already have used MozPromiseHolder
in generic containers and it doesn't seem to have caused too many problems yet...
![]() |
||
Updated•6 years ago
|
Comment 5•6 years ago
|
||
bugherder |
Assignee | ||
Comment 6•6 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #3)
I don't know the exact rationale behind the assertions in
MozPromiseHolder
. But looking at them, I would guess:
mMonitor
essentially makes another type ofMozPromiseHolder
, so themMonitor
assertions are making sure that you're not moving from a monitor-requiring instance to a non-monitor requiring instance -- that wouldn't make a lot of sense. (There are other combinations, but that seems like the easiest to explain.)
This is only used at two places: https://searchfox.org/mozilla-central/search?q=symbol:_ZN7mozilla16MozPromiseHolder10SetMonitorEPNS_7MonitorE&redirect=false
Maybe this really should be a separate type (maybe via an additional template parameter), which is syntactically non-movable then. All the other uses don't need the mMonitor
member at all.
- We're also ensuring that we don't overwrite an existing promise. Overwriting an existing promise here...what would that even mean?
You mean, because, if Resolve
, Reject
or Steal
have been called, mPromise
will be set to nullptr
, and this ensures that a promise is not replaced without having dealt with it in either of these ways? Maybe that assertion is fine, still it looks a bit odd.
I guess we could use a separately-named member function here, but it's going to be a weird class that supports move construction but not move assignment.
Well, this would be odd, but less odd than. But never mind, the move assignment is probably needed due to:
We already have used
MozPromiseHolder
in generic containers and it doesn't seem to have caused too many problems yet...
Sorry, I didn't check before. Indeed, there are several uses of nsTArray<MozPromise>
. I checked a few of them, they make only a very limited use of nsTArray
. If they remove elements, they always move out the element first, which ensures that the precondition holds, given the current implementation of nsTArray
. Interestingly, there are also some uses of nsTArray<UniquePtr<MozPromise>>
, which don't make too much sense. They might be a workaround around issues due to the move preconditions though.
Assignee | ||
Updated•5 years ago
|
Description
•