From:  Nicholas Nethercote <n.nethercote@gmail.com>
Date:  10 May 2016 09:18:08 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.tech.js-engine.internals
Subject:  

Re: OOM exceptions

NNTP-Posting-Host:  63.245.214.181

On Tue, May 10, 2016 at 9:50 AM, Nick Fitzgerald
 wrote:
> Or, if we don't want to boil too many oceans and have something closer to
> our usage of bool and not worry about wrapping types:
>
> class Result
> {
>   public:
>     enum class Type : uint32_t
>     {
>         Ok,
>         Oom,
>         Exception,
>         // Etc...
>     };
>
>   private:
>     Type type_;
>
>   public:
>     // Helper methods here...
>
>     explicit operator bool () { return type_ == Type::Ok;}
>
>     // Etc...
> };

I was imagining something like this, though I wouldn't bother with
distinguishing between different kinds of failures, because that's not
something we've ever done so I don't see why we'd start now.

> If we are going to leave bool behind, I think we should use something
> Rustic:
>
> template 
> class MOZ_MUST_USE_TYPE Result : public mozilla::Variant
> {
>   public:
>     // Helper methods here...
>
>     explicit operator bool () { return is(); }
>
>     // Etc...
> };

That's total overkill for the bool case -- we don't need to
parameterize on either T or E. But if we wanted to be more principled
with fallible functions that return pointers, then a Result could
be useful.

Anyway, I'll stick with the MOZ_MUST_USE-on-bool changes for now.

Nick