react-native-macos/ReactCommon
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
..
butter Fixed typo in ReactCommon/buffer/map.h (#34631) 2022-11-30 06:55:21 -08:00
callinvoker Add ability to schedule JS functions as tasks from turbo modules (#35525) 2022-12-01 09:49:44 -08:00
cxxreact Unify native performanceNow implementation across platforms 2022-12-28 11:03:14 -08:00
hermes Fix Hermes warnings/errors from stricter compiler settings in Horizon 2023-01-09 09:58:55 -08:00
jsc Clarify const-ness of JSI references 2022-12-15 19:18:15 -08:00
jsengineinstance The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jserrorhandler Revert D42369492: Add basic tests for JsErrorHandler 2023-01-05 13:25:50 -08:00
jsi Only intercept JSIExceptions when constructing JSError 2023-01-22 00:25:49 -08:00
jsiexecutor Unify native performanceNow implementation across platforms 2022-12-28 11:03:14 -08:00
jsinspector Enable C++17 for cxxreact and jsiexecutor/inspector and ... (#35435) 2022-11-23 18:48:47 -08:00
libraries/fbcore/src/test/java/com/facebook/powermock Explicitly set language to JAVA where it is missing [xplat] (round 1) 2022-07-06 09:07:07 -07:00
logger Update .podspec license information (#35245) 2022-11-07 09:52:52 -08:00
react internalize Slider module (#35825) 2023-01-16 02:42:18 -08:00
reactperflogger Update .podspec license information (#35245) 2022-11-07 09:52:52 -08:00
runtimeexecutor Update .podspec license information (#35245) 2022-11-07 09:52:52 -08:00
yoga Remove legacy layout diffing 2023-01-19 06:38:45 -08:00
React-Fabric.podspec internalize Slider module (#35825) 2023-01-16 02:42:18 -08:00
React-rncore.podspec Update .podspec license information (#35245) 2022-11-07 09:52:52 -08:00
ReactCommon.podspec Properly support both libraries and use_frameworks (#35624) (#35637) 2022-12-14 02:24:07 -08:00