On Fri, Apr 22, 2016 at 3:16 AM, Jan de Mooij <[email protected]> wrote:
>
> I think in 'ancient' SpiderMonkey, we used to deal with OOM by returning
> null/false. Other exceptions were reported to the JSContext.
>
> Then we changed this: ReportOutOfMemory now throws the "out of memory"
> string. This allowed scripts to catch OOMs, for instance when allocating
> large ArrayBuffers.

I fully admit to not doing much JS engine work these days and I don't
know about this ReportOutOfMemory behaviour. But isn't the "return
null/false" pattern still heavily used? Looking quickly through
jsapi.cpp it sure seems to be.

Assuming it is, one thing I've been thinking about is using
MOZ_WARN_UNUSED_RESULT more.
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 also think it's offputtingly verbose and I have thought about a
shorter synonym so you can do something like |MOZ_WARN_UNUSED(bool)|
or even |MOZ_CHECK(bool)| instead of |MOZ_WARN_UNUSED_RESULT bool|.

Nick
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to