From:  Steve Fink <>
Date:  10 May 2016 07:42:28 Hong Kong Time

Re: OOM exceptions


On 05/09/2016 04:32 PM, Nicholas Nethercote wrote:
> On Sat, Apr 23, 2016 at 9:29 AM, Nicholas Nethercote
>  wrote:
>> one thing I've been thinking about is using
>> It isn't useful for the "return null on failure" case, because the
>> result will always be used even if you forget the check. But it is
>> useful for the "return false on failure" case. I count 113 uses of it
>> currently in js/src/, the majority of which are for functions
>> returning bool. I suspect the number could/should be at least 10x
>> higher than that.
>> I would be happy to try to add more uses of it if people think it's worthwhile.
> I've started doing this in bug 1267551. (Taking over from bug 606349,
> where this idea was first suggested.)
> Having added quite a few MOZ_MUST_USE annotations now I can't help but
> wonder if it would be better to have some kind of result type
> (JSResult?), as an alternative to bool. A bit like nsresult but
> without the zillion different failure values.
> With that in place, bool would be used for the return type of
> functions to indicate true/false or yes/no, and JSResult would be used
> in fallible functions to indicate success/failure. And then we could
> use MOZ_MUST_USE_TYPE on JSResult, which would give us assurance (via
> static analysis) that all functions that return this type are checked,
> and then we wouldn't need all these MOZ_MUST_USE annotations
> everywhere.

JSBool is dead, long live JSBool!

> (We might also need a JSResultUnchecked variant, because for some
> fallible functions not checking the return value is reasonable.)

With JSBool, we could call this one 'bool'.