react-native-macos/ReactCommon/jsi
Neil Dhar cd5a8c48c5 Only intercept JSIExceptions when constructing JSError
Summary:
Constructing a `JSError` currently catches all exceptions that occur,
regardless of their type, and embeds the information from them in the
newly created `JSError`. This means that the type of exceptions can be
silently changed.

This results in a bug if Hermes is built with
`HERMESVM_EXCEPTION_ON_OOM` enabled. The OOM exception will get
converted to a `JSError`, which in turn can get converted into a
regular JS exception. The regular JS exception can then be caught by JS
and ignored. This leads to the VM continuing to execute in a bad
state.

I considered three ways to fix this:
1. Add a new type of exception to JSI that is intentionally meant to be
ignored, and the Hermes OOM exception then subclasses it.
2. Propagate all exceptions that happen when constructing `JSError`.
3. Propagate all exceptions except `JSIException`s when constructing
`JSError`.

The first is technically the most surgical, but it adds complexity to
JSI, and will require some extra machinery to implement since we
wouldn't be able to throw it directly from inside the VM. I'm also not
comfortable with the idea of JSI suppressing exceptions that are
completely unrelated to JSI.

The second is the simplest, and seems to match what JS would do if
`throw new Error()` itself threw, but there is some possibility that it
is a change in behaviour for existing code.

So the third approach, which is implemented in this diff, tries to
compromise between the two. Hermes can only ever throw `JSIException`s
from regular JS operations, so there should be no change for existing
code (except code that uses exceptions on OOM, which is what we're
trying to fix). Any other exception gets passed through to the caller.

Changelog:
[Internal][Fixed] - Fixed handling of Hermes OOM exceptions in JSI.

Reviewed By: jpporto

Differential Revision: D41831616

fbshipit-source-id: 42e0dde1c4acc016ab19533941c58fc1797ba1c2
2023-01-22 00:25:49 -08:00
..
jsi Only intercept JSIExceptions when constructing JSError 2023-01-22 00:25:49 -08:00
.clang-tidy The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
BUCK Move JSCRuntime into its own folder (#35482) 2022-11-28 04:13:55 -08:00
CMakeLists.txt Expose `jscruntime` to be consumed via Prefab 2022-11-28 04:13:55 -08:00
React-jsi.podspec Bring back JSIDynamic and JSI together 2022-11-29 08:53:50 -08:00