I had some difficulty understanding what `DetachSourceBuffer()` was trying to do. Its [parameter](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/MediaSourceDemuxer.cpp#179) is mutable `RefPtr<TrackBuffersManager>& aSourceBuffer`, but its caller [does not expect its `RefPtr<TrackBuffersManager> mTrackBuffersManager` argument to be stolen](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/SourceBuffer.cpp#449-451). I think `const RefPtr<TrackBuffersManager>& aSourceBuffer` was intended for the parameter. The parameter was simply `TrackBuffersManager*` prior to https://hg.mozilla.org/mozilla-central/rev/05b222ac8a540186f26caf7cfe514956399ecdfd#l2.12 The `Storages` template parameter for NewRunnableMethod<typename... Storages, > is the rvalue reference `RefPtr<TrackBuffersManager>&&` which [means](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1110) store as `RefPtr<TrackBuffersManager>` and is intended to be used with a `RefPtr<TrackBuffersManager>` argument passed with `std::move()`. Here instead the argument is the lvalue reference `RefPtr<TrackBuffersManager>& aSourceBuffer`. So what happens with the mutable reference argument? The corresponding `NewRunnableMethod()` parameter is `Args&&... aArgs`, which is `forward`ed to [construct](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1204) a `RunnableMethodArguments<Storages...> mArgs` member on the runnable, which resolves to `StoreCopyPassByLRef`, which [forwards](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#915) the rvalue reference, and so IIUC should be using the `RefPtr(const RefPtr<I>& aSmartPtr)` [copy constructor](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/mfbt/RefPtr.h#135) as intended.
Bug 1853201 Comment 6 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
I had some difficulty understanding what `DetachSourceBuffer()` was trying to do. Its [parameter](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/MediaSourceDemuxer.cpp#179) is mutable `RefPtr<TrackBuffersManager>& aSourceBuffer`, but its caller [does not expect its `RefPtr<TrackBuffersManager> mTrackBuffersManager` argument to be stolen](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/SourceBuffer.cpp#449-451). I think `const RefPtr<TrackBuffersManager>& aSourceBuffer` was intended for the parameter. The parameter was simply `TrackBuffersManager*` prior to https://hg.mozilla.org/mozilla-central/rev/05b222ac8a540186f26caf7cfe514956399ecdfd#l2.12 The `Storages` template parameter for NewRunnableMethod<typename... Storages, > is the rvalue reference `RefPtr<TrackBuffersManager>&&` which [means](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1110) store as `RefPtr<TrackBuffersManager>` and is intended to be used with a `RefPtr<TrackBuffersManager>` argument passed with `std::move()`. Here instead the argument is the lvalue reference `RefPtr<TrackBuffersManager>& aSourceBuffer`. So what happens with the mutable reference argument? The corresponding `NewRunnableMethod()` parameter is `Args&&... aArgs`, which is `forward`ed to [construct](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1204) a `RunnableMethodArguments<Storages...> mArgs` member on the runnable, which resolves to `StoreCopyPassByRRef`, which [forwards](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#928) the rvalue reference, and so IIUC should be using the `RefPtr(const RefPtr<I>& aSmartPtr)` [copy constructor](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/mfbt/RefPtr.h#135) as intended.
I had some difficulty understanding what `DetachSourceBuffer()` was trying to do. Its [parameter](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/MediaSourceDemuxer.cpp#179) is mutable `RefPtr<TrackBuffersManager>& aSourceBuffer`, but its caller [does not expect its `RefPtr<TrackBuffersManager> mTrackBuffersManager` argument to be stolen](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/dom/media/mediasource/SourceBuffer.cpp#449-451). I think `const RefPtr<TrackBuffersManager>& aSourceBuffer` was intended for the parameter. The parameter was simply `TrackBuffersManager*` prior to https://hg.mozilla.org/mozilla-central/rev/05b222ac8a540186f26caf7cfe514956399ecdfd#l2.12 The `Storages` template parameter for NewRunnableMethod<typename... Storages, > is the rvalue reference `RefPtr<TrackBuffersManager>&&` which [means](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1110) store as `RefPtr<TrackBuffersManager>` and is intended to be used with a `RefPtr<TrackBuffersManager>` argument passed with `std::move()`. Here instead the argument is the lvalue reference `RefPtr<TrackBuffersManager>& aSourceBuffer`. So what happens with the mutable reference argument? The corresponding `NewRunnableMethod()` parameter is `Args&&... aArgs`, which is `forward`ed to [construct](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#1204) a `RunnableMethodArguments<Storages...> mArgs` member on the runnable, which resolves to `StoreCopyPassByRRef`, which [forwards](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/xpcom/threads/nsThreadUtils.h#928) the lvalue reference, and so IIUC should be using the `RefPtr(const RefPtr<I>& aSmartPtr)` [copy constructor](https://searchfox.org/mozilla-central/rev/6602bdf9fff5020fbc8e248c963ddddf09a77b1b/mfbt/RefPtr.h#135) as intended.