mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1607634 - Part 2: Add a ParamTraits implementation for NotNull, r=ipc-reviewers,mccr8
For now, this implementation is based on the implementation of the underlying type, with extra checking that the value is not null before wrapping and returning. We may want to swap things around in the future so that types like RefPtr<T> are deserialized using NotNull<T*> or similar, so that the unnecessary serialization overhead of tracking nullness is unnecessary, however that is not implemented in this patch. Differential Revision: https://phabricator.services.mozilla.com/D168884
This commit is contained in:
parent
c821668d34
commit
7c9385cad1
@ -914,6 +914,25 @@ struct ParamTraitsMozilla<nsCOMPtr<T>> {
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ParamTraitsMozilla<mozilla::NotNull<T>> {
|
||||
static void Write(MessageWriter* writer, const mozilla::NotNull<T>& p) {
|
||||
ParamTraits<T>::Write(writer, p.get());
|
||||
}
|
||||
|
||||
static mozilla::Maybe<mozilla::NotNull<T>> Read(MessageReader* reader) {
|
||||
auto ptr = ReadParam<T>(reader);
|
||||
if (!ptr) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
if (!*ptr) {
|
||||
reader->FatalError("unexpected null value");
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
return mozilla::Some(mozilla::WrapNotNull(std::move(*ptr)));
|
||||
}
|
||||
};
|
||||
|
||||
// Finally, ParamTraits itself.
|
||||
|
||||
template <class P>
|
||||
|
Loading…
Reference in New Issue
Block a user