Lift extensions to MOZ_TRY and related macros from dom/quota/QuotaCommon.h (QM_TRY_*)
Categories
(Core :: MFBT, task, P3)
Tracking
()
People
(Reporter: sg, Assigned: janv)
References
Details
Attachments
(1 file)
For the quota manager and its clients, several extensions to the mechanism provided by MOZ_TRY and MOZ_TRY_VAR are introduced, including:
- Split
MOZ_TRY_VARintoMOZ_TRY_INSPECTandMOZ_TRY_UNWRAP, so that unwrapping can be avoided where not necessary. - Allow variables to be declared by
MOZ_TRY_INSPECTandMOZ_TRY_UNWRAP(which allows declaringconstreferences/variables!) - Report failures in a customizable way, e.g. via
NS_DebugBreak/NS_WARNING. - Allow the use in functions not returning an error, but having void return type or, e.g., where a nullptr should be returned to indicate an error.
- Allow customization of cleanup in case of a failure before returning.
- Allow asserting on failure.
- Add
MOZ_TRY_RETURNto propagate both the result and a failure (including the customization options and reporting mentioned above).
These extensions could benefit the whole codebase by lifting them to mfbt/Result.h.
The original motivation for providing custom macros was the need to include extended error reporting. There is some challenge to make this general and customizable for the whole codebase, the default might be using NS_DebugBreak/NS_WARNING as mentioned above.
Parts of the macros in dom/quota/QuotaCommon.h might currently be specific to Result<T, nsresult>, but this limitation should be liftable.
When adding more extensions to control-flow-hiding macros, https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/xpcom/base/nsDebug.h#34-35 should be considered.
| Assignee | ||
Comment 2•5 years ago
|
||
I was opposed to using "control-flow-hiding" macros for long time, but after introduction of mozilla::Result and MOZ_TRY I changed my mind.
There's a documentation for QM_TRY* macros, including a comparison of typical usage:
https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/dom/quota/QuotaCommon.h#96
(In reply to Jan Varga [:janv] from comment #2)
I was opposed to using "control-flow-hiding" macros for long time, but after introduction of mozilla::Result and MOZ_TRY I changed my mind.
There's a documentation for QM_TRY* macros, including a comparison of typical usage:
https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/dom/quota/QuotaCommon.h#96
If there's consensus about this among the ones owning the style guide (are there actually owners?), the recommendation to use MOZ_TRY etc. should presumably be added to https://searchfox.org/mozilla-central/rev/e1d1f043957191616721b9e8bf811c0aab8a203a/xpcom/base/nsDebug.h#34-35.
| Reporter | ||
Comment 4•5 years ago
|
||
It's worth to note that currently MOZ_TRY_VAR cannot be used at all with a non-default-constructible success type, but QM_TRY_UNWRAP/QM_TRY_INSPECT can. I came across this limitation when trying to use it with Result<std::reference_wrapper<T>, nsresult>.
Updated•4 years ago
|
Updated•4 years ago
|
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 6•2 years ago
|
||
| Assignee | ||
Updated•2 years ago
|
Updated•10 months ago
|
Description
•