Closed tjzel closed 2 weeks ago
@tomekzaw It's for performance. Why would we surround it with the try-catch on every call, since we will know everything after the first call.
@tjzel I wouldn't worry much about performance in this case, C++ try/catch
blocks are quite fast.
SInce we know that some versions react-native-macos don't support jsi::NativeState
when using JSC, why can't we just use #ifdef
s instead?
Also, the names nativeStateAccess
, AccessProbe
, Safe
and Unsafe
are a bit overwhelming, how about simply supportsNativeState
with Yes
and No
instead?
Finally, I don't like the fact that some unrelated files have been formatted, can we move them to a separate PR?
Sorry about that, I added jsi::NativeState
here.. I didn't test on MacOS / JSC.
@mrousavy No worries
@tomekzaw I read an interesting article about try/catch blocks performance from which it seems that try blocks are fast but the catch ones are expensive. Since these calls would constantly throw when nativeState
is not implemented, I'd rather keep the current approach.
Regarding #ifdef
I don't know how would we do that. I don't think there's any flag that would tell us if nativeState
is implemented on a given engine.
I'll revert formatting and make the names more approachable.
Well I guess we can do it that way for now, if the problem persists we will resort to runtime checks.
Superseded by #6137
Summary
In some implementations of JSC, at least
react-native-macos
here native state methods are not implemented and they are throwing errors. This PR adds logic that will go around this issue, by probing thehasNativeState
method to determine whether it should use that.Fixes #5974
Test plan