react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +176 -154
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +49 -33
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +14 -7
- package/Common/cpp/Registries/MapperRegistry.cpp +24 -20
- package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
- package/Common/cpp/SharedItems/FrozenObject.cpp +17 -8
- package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
- package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
- package/Common/cpp/SharedItems/ShareableValue.cpp +211 -160
- package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +25 -6
- package/Common/cpp/Tools/Mapper.cpp +30 -30
- package/Common/cpp/Tools/RuntimeDecorator.cpp +124 -86
- package/Common/cpp/Tools/Scheduler.cpp +6 -5
- package/Common/cpp/Tools/WorkletEventHandler.cpp +4 -2
- package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +50 -31
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +34 -16
- package/Common/cpp/headers/Registries/EventHandlerRegistry.h +15 -8
- package/Common/cpp/headers/Registries/MapperRegistry.h +5 -4
- package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
- package/Common/cpp/headers/SharedItems/FrozenObject.h +19 -11
- package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +8 -4
- package/Common/cpp/headers/SharedItems/MutableValue.h +23 -12
- package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +12 -7
- package/Common/cpp/headers/SharedItems/RemoteObject.h +19 -8
- package/Common/cpp/headers/SharedItems/RuntimeManager.h +26 -25
- package/Common/cpp/headers/SharedItems/ShareableValue.h +32 -27
- package/Common/cpp/headers/SharedItems/SharedParent.h +10 -7
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +95 -72
- package/Common/cpp/headers/SpecTools/ErrorHandler.h +18 -19
- package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
- package/Common/cpp/headers/Tools/JSIStoreValueUser.h +13 -16
- package/Common/cpp/headers/Tools/Mapper.h +19 -16
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +17 -7
- package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -11
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +36 -27
- package/Common/cpp/headers/Tools/Scheduler.h +30 -35
- package/Common/cpp/headers/Tools/WorkletEventHandler.h +11 -8
- package/Common/cpp/hidden_headers/Logger.h +14 -14
- package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
- package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
- package/README.md +1 -1
- package/RNReanimated.podspec +24 -6
- package/android/build.gradle +38 -29
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +10 -8
- package/ios/LayoutReanimation/REAAnimationsManager.m +91 -87
- package/ios/LayoutReanimation/REASnapshot.h +2 -2
- package/ios/LayoutReanimation/REASnapshot.m +8 -7
- package/ios/LayoutReanimation/REAUIManager.h +4 -4
- package/ios/LayoutReanimation/REAUIManager.mm +116 -70
- package/ios/Nodes/REAAlwaysNode.m +14 -15
- package/ios/Nodes/REABezierNode.m +8 -7
- package/ios/Nodes/REABlockNode.m +1 -1
- package/ios/Nodes/REACallFuncNode.h +0 -1
- package/ios/Nodes/REACallFuncNode.m +10 -8
- package/ios/Nodes/REAClockNodes.m +22 -20
- package/ios/Nodes/REAConcatNode.h +0 -1
- package/ios/Nodes/REAConcatNode.m +2 -2
- package/ios/Nodes/REACondNode.m +7 -5
- package/ios/Nodes/READebugNode.m +5 -4
- package/ios/Nodes/REAEventNode.m +1 -1
- package/ios/Nodes/REAFunctionNode.h +0 -1
- package/ios/Nodes/REAFunctionNode.m +2 -2
- package/ios/Nodes/REAJSCallNode.m +4 -5
- package/ios/Nodes/REANode.h +3 -4
- package/ios/Nodes/REANode.m +9 -11
- package/ios/Nodes/REAOperatorNode.m +68 -67
- package/ios/Nodes/REAParamNode.h +1 -3
- package/ios/Nodes/REAParamNode.m +15 -17
- package/ios/Nodes/REAPropsNode.h +1 -3
- package/ios/Nodes/REAPropsNode.m +19 -22
- package/ios/Nodes/REASetNode.h +0 -1
- package/ios/Nodes/REASetNode.m +7 -5
- package/ios/Nodes/REAStyleNode.h +0 -1
- package/ios/Nodes/REAStyleNode.m +2 -4
- package/ios/Nodes/REATransformNode.h +0 -1
- package/ios/Nodes/REATransformNode.m +3 -5
- package/ios/Nodes/REAValueNode.m +5 -7
- package/ios/REAEventDispatcher.m +4 -4
- package/ios/REAModule.h +0 -2
- package/ios/REAModule.m +29 -38
- package/ios/REANodesManager.h +11 -19
- package/ios/REANodesManager.m +106 -130
- package/ios/REAUtils.h +5 -3
- package/ios/RNGestureHandlerStateManager.h +5 -0
- package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
- package/ios/Transitioning/REAAllTransitions.h +2 -2
- package/ios/Transitioning/REAAllTransitions.m +14 -25
- package/ios/Transitioning/REATransition.h +8 -7
- package/ios/Transitioning/REATransition.m +19 -16
- package/ios/Transitioning/REATransitionAnimation.h +1 -1
- package/ios/Transitioning/REATransitionAnimation.m +2 -3
- package/ios/Transitioning/REATransitionManager.m +3 -3
- package/ios/native/NativeMethods.h +20 -5
- package/ios/native/NativeMethods.mm +14 -6
- package/ios/native/NativeProxy.h +4 -2
- package/ios/native/NativeProxy.mm +84 -63
- package/ios/native/REAIOSErrorHandler.h +13 -10
- package/ios/native/REAIOSErrorHandler.mm +19 -15
- package/ios/native/REAIOSLogger.h +8 -8
- package/ios/native/REAIOSLogger.mm +10 -6
- package/ios/native/REAIOSScheduler.h +5 -5
- package/ios/native/REAIOSScheduler.mm +17 -10
- package/ios/native/REAInitializer.h +5 -7
- package/ios/native/REAInitializer.mm +43 -31
- package/ios/native/UIResponder+Reanimated.mm +2 -2
- package/lib/Animated.js +9 -1
- package/lib/ConfigHelper.js +121 -138
- package/lib/ReanimatedEventEmitter.js +0 -1
- package/lib/ReanimatedModule.js +0 -1
- package/lib/ReanimatedModule.macos.js +0 -1
- package/lib/ReanimatedModule.native.js +5 -6
- package/lib/ReanimatedModule.windows.js +0 -1
- package/lib/ReanimatedModuleCompat.js +64 -35
- package/lib/createAnimatedComponent.js +468 -487
- package/lib/index.js +9 -1
- package/lib/reanimated2/NativeMethods.js +7 -12
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +37 -0
- package/lib/reanimated2/NativeReanimated/index.js +15 -0
- package/lib/reanimated2/PropAdapters.js +0 -1
- package/lib/reanimated2/UpdateProps.js +6 -7
- package/lib/reanimated2/ViewDescriptorsSet.js +4 -4
- package/lib/reanimated2/WorkletEventHandler.js +15 -13
- package/lib/reanimated2/animation/delay.js +8 -2
- package/lib/reanimated2/animation/spring.js +2 -0
- package/lib/reanimated2/animation/styleAnimation.js +7 -3
- package/lib/reanimated2/animation/util.js +25 -2
- package/lib/reanimated2/core.js +41 -17
- package/lib/reanimated2/globals.d.ts +21 -1
- package/lib/reanimated2/hook/useAnimatedRef.js +1 -1
- package/lib/reanimated2/hook/useAnimatedStyle.js +3 -3
- package/lib/reanimated2/index.js +1 -0
- package/lib/reanimated2/interpolation.js +95 -87
- package/lib/reanimated2/js-reanimated/JSReanimated.js +13 -10
- package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
- package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
- package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
- package/lib/reanimated2/js-reanimated/index.js +10 -8
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +33 -2
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +27 -124
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +1 -2
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +115 -45
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +7 -2
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +21 -21
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +25 -25
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +19 -17
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +5 -5
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +9 -9
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +17 -17
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +19 -19
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +9 -9
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +33 -33
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
- package/lib/reanimated2/layoutReanimation/index.js +1 -0
- package/lib/reanimated2/mock.js +3 -1
- package/lib/reanimated2/utils.js +9 -0
- package/lib/setAndForwardRef.js +14 -48
- package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
- package/mock.js +1 -1
- package/package.json +28 -17
- package/plugin.js +220 -39
- package/react-native-reanimated.d.ts +542 -547
- package/src/Animated.js +9 -1
- package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
- package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
- package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
- package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
- package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
- package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
- package/src/ReanimatedModuleCompat.ts +51 -0
- package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +285 -126
- package/src/reanimated2/NativeMethods.ts +34 -13
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +72 -0
- package/src/reanimated2/NativeReanimated/index.ts +18 -0
- package/src/reanimated2/PropAdapters.ts +0 -1
- package/src/reanimated2/UpdateProps.ts +31 -15
- package/src/reanimated2/ViewDescriptorsSet.ts +15 -12
- package/src/reanimated2/WorkletEventHandler.ts +41 -23
- package/src/reanimated2/animation/commonTypes.ts +4 -4
- package/src/reanimated2/animation/decay.ts +2 -2
- package/src/reanimated2/animation/delay.ts +11 -5
- package/src/reanimated2/animation/index.ts +7 -7
- package/src/reanimated2/animation/repeat.ts +4 -4
- package/src/reanimated2/animation/sequence.ts +2 -2
- package/src/reanimated2/animation/spring.ts +6 -5
- package/src/reanimated2/animation/styleAnimation.ts +27 -15
- package/src/reanimated2/animation/timing.ts +5 -5
- package/src/reanimated2/animation/util.ts +47 -8
- package/src/reanimated2/commonTypes.ts +3 -0
- package/src/reanimated2/core.ts +80 -34
- package/src/reanimated2/globals.d.ts +21 -1
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -1
- package/src/reanimated2/hook/useAnimatedRef.ts +13 -15
- package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -3
- package/src/reanimated2/hook/useAnimatedStyle.ts +7 -7
- package/src/reanimated2/hook/utils.ts +4 -3
- package/src/reanimated2/index.ts +1 -0
- package/src/reanimated2/interpolation.ts +170 -103
- package/src/reanimated2/js-reanimated/JSReanimated.ts +37 -23
- package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
- package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
- package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
- package/src/reanimated2/js-reanimated/index.ts +31 -14
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +75 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +29 -159
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -2
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -9
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -5
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +162 -82
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +7 -2
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +32 -32
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +38 -38
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +34 -32
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -8
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +14 -14
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +26 -26
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +28 -28
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +14 -14
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +50 -50
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
- package/src/reanimated2/layoutReanimation/index.ts +1 -0
- package/src/reanimated2/mock.ts +3 -1
- package/src/reanimated2/utils.ts +21 -0
- package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
- package/android/react-native-reanimated-62-hermes.aar +0 -0
- package/android/react-native-reanimated-62-jsc.aar +0 -0
- package/lib/reanimated2/NativeReanimated.js +0 -48
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.js +0 -55
- package/lib/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.js +0 -165
- package/src/ReanimatedModuleCompat.js +0 -37
- package/src/reanimated2/NativeReanimated.ts +0 -70
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +0 -41
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts +0 -82
- package/src/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.ts +0 -217
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
#include
|
|
2
|
-
#include "
|
|
3
|
-
#include "RuntimeManager.h"
|
|
1
|
+
#include <cxxabi.h>
|
|
2
|
+
#include "FrozenObject.h"
|
|
4
3
|
#include "MutableValue.h"
|
|
5
4
|
#include "MutableValueSetterProxy.h"
|
|
6
5
|
#include "RemoteObject.h"
|
|
7
|
-
#include "FrozenObject.h"
|
|
8
6
|
#include "RuntimeDecorator.h"
|
|
9
|
-
#include
|
|
7
|
+
#include "RuntimeManager.h"
|
|
8
|
+
#include "SharedParent.h"
|
|
10
9
|
|
|
11
10
|
namespace reanimated {
|
|
12
|
-
|
|
11
|
+
class ShareableValue;
|
|
13
12
|
const char *HIDDEN_HOST_OBJECT_PROP = "__reanimatedHostObjectRef";
|
|
14
|
-
const char *ALREADY_CONVERTED= "__alreadyConverted";
|
|
13
|
+
const char *ALREADY_CONVERTED = "__alreadyConverted";
|
|
15
14
|
const char *CALL_ASYNC = "__callAsync";
|
|
16
15
|
const char *PRIMAL_FUNCTION = "__primalFunction";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
const char *CALLBACK_ERROR_SUFFIX =
|
|
17
|
+
"\n\nPossible solutions are:\n"
|
|
18
|
+
"a) If you want to synchronously execute this method, mark it as a Worklet\n"
|
|
19
|
+
"b) If you want to execute this method on the JS thread, wrap it using runOnJS";
|
|
20
|
+
|
|
21
|
+
void addHiddenProperty(
|
|
22
|
+
jsi::Runtime &rt,
|
|
23
|
+
jsi::Value &&value,
|
|
24
|
+
const jsi::Object &obj,
|
|
25
|
+
const char *name) {
|
|
27
26
|
jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
|
|
28
|
-
jsi::Function defineProperty =
|
|
27
|
+
jsi::Function defineProperty =
|
|
28
|
+
globalObject.getPropertyAsFunction(rt, "defineProperty");
|
|
29
29
|
jsi::String internalPropName = jsi::String::createFromUtf8(rt, name);
|
|
30
30
|
jsi::Object paramForDefineProperty(rt);
|
|
31
31
|
paramForDefineProperty.setProperty(rt, "enumerable", false);
|
|
@@ -33,15 +33,16 @@ void addHiddenProperty(jsi::Runtime &rt,
|
|
|
33
33
|
defineProperty.call(rt, obj, internalPropName, paramForDefineProperty);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
void freeze(jsi::Runtime &rt, jsi::Object &obj) {
|
|
36
|
+
void freeze(jsi::Runtime &rt, const jsi::Object &obj) {
|
|
37
37
|
jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
|
|
38
38
|
jsi::Function freeze = globalObject.getPropertyAsFunction(rt, "freeze");
|
|
39
39
|
freeze.call(rt, obj);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
|
|
43
|
-
// when adapting from host object we can assign cached value immediately such
|
|
44
|
-
// running `toJSValue` in the future when given object is
|
|
43
|
+
// when adapting from host object we can assign cached value immediately such
|
|
44
|
+
// that we avoid running `toJSValue` in the future when given object is
|
|
45
|
+
// accessed
|
|
45
46
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
46
47
|
if (remoteValue.expired()) {
|
|
47
48
|
remoteValue = getWeakRef(rt);
|
|
@@ -52,7 +53,10 @@ void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
void ShareableValue::adapt(
|
|
56
|
+
void ShareableValue::adapt(
|
|
57
|
+
jsi::Runtime &rt,
|
|
58
|
+
const jsi::Value &value,
|
|
59
|
+
ValueType objectType) {
|
|
56
60
|
if (value.isObject()) {
|
|
57
61
|
jsi::Object object = value.asObject(rt);
|
|
58
62
|
jsi::Value hiddenValue = object.getProperty(rt, HIDDEN_HOST_OBJECT_PROP);
|
|
@@ -64,8 +68,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
64
68
|
type = ValueType::WorkletFunctionType;
|
|
65
69
|
}
|
|
66
70
|
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
67
|
-
|
|
68
|
-
);
|
|
71
|
+
hiddenProperty.getHostObject<FrozenObject>(rt));
|
|
69
72
|
if (object.hasProperty(rt, ALREADY_CONVERTED)) {
|
|
70
73
|
adaptCache(rt, value);
|
|
71
74
|
}
|
|
@@ -76,9 +79,9 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
76
79
|
|
|
77
80
|
if (objectType == ValueType::MutableValueType) {
|
|
78
81
|
type = ValueType::MutableValueType;
|
|
79
|
-
valueContainer =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
valueContainer =
|
|
83
|
+
std::make_unique<MutableValueWrapper>(std::make_shared<MutableValue>(
|
|
84
|
+
rt, value, runtimeManager, runtimeManager->scheduler));
|
|
82
85
|
} else if (value.isUndefined()) {
|
|
83
86
|
type = ValueType::UndefinedType;
|
|
84
87
|
} else if (value.isNull()) {
|
|
@@ -91,7 +94,8 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
91
94
|
valueContainer = std::make_unique<NumberValueWrapper>(value.asNumber());
|
|
92
95
|
} else if (value.isString()) {
|
|
93
96
|
type = ValueType::StringType;
|
|
94
|
-
valueContainer =
|
|
97
|
+
valueContainer =
|
|
98
|
+
std::make_unique<StringValueWrapper>(value.asString(rt).utf8(rt));
|
|
95
99
|
} else if (value.isObject()) {
|
|
96
100
|
auto object = value.asObject(rt);
|
|
97
101
|
if (object.isFunction(rt)) {
|
|
@@ -100,32 +104,39 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
100
104
|
type = ValueType::HostFunctionType;
|
|
101
105
|
containsHostFunction = true;
|
|
102
106
|
|
|
103
|
-
//Check if it's a hostFunction wrapper
|
|
107
|
+
// Check if it's a hostFunction wrapper
|
|
104
108
|
jsi::Value primalFunction = object.getProperty(rt, PRIMAL_FUNCTION);
|
|
105
109
|
if (!primalFunction.isUndefined()) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
jsi::Object handlerAsObject = primalFunction.asObject(rt);
|
|
111
|
+
std::shared_ptr<HostFunctionHandler> handler =
|
|
112
|
+
handlerAsObject.getHostObject<HostFunctionHandler>(rt);
|
|
113
|
+
valueContainer = std::make_unique<HostFunctionWrapper>(handler);
|
|
109
114
|
} else {
|
|
110
|
-
|
|
111
|
-
std::make_shared<HostFunctionHandler>(
|
|
115
|
+
valueContainer = std::make_unique<HostFunctionWrapper>(
|
|
116
|
+
std::make_shared<HostFunctionHandler>(
|
|
117
|
+
std::make_shared<jsi::Function>(object.asFunction(rt)), rt));
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
} else {
|
|
115
121
|
// a worklet
|
|
116
122
|
type = ValueType::WorkletFunctionType;
|
|
117
|
-
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
118
|
-
|
|
123
|
+
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
124
|
+
std::make_shared<FrozenObject>(rt, object, runtimeManager));
|
|
125
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
119
126
|
containsHostFunction |= frozenObject->containsHostFunction;
|
|
120
127
|
if (RuntimeDecorator::isReactRuntime(rt) && !containsHostFunction) {
|
|
121
|
-
addHiddenProperty(
|
|
128
|
+
addHiddenProperty(
|
|
129
|
+
rt,
|
|
130
|
+
createHost(rt, frozenObject),
|
|
131
|
+
object,
|
|
132
|
+
HIDDEN_HOST_OBJECT_PROP);
|
|
122
133
|
}
|
|
123
134
|
}
|
|
124
135
|
} else if (object.isArray(rt)) {
|
|
125
136
|
type = ValueType::FrozenArrayType;
|
|
126
137
|
auto array = object.asArray(rt);
|
|
127
138
|
valueContainer = std::make_unique<FrozenArrayWrapper>();
|
|
128
|
-
auto&
|
|
139
|
+
auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
|
|
129
140
|
for (size_t i = 0, size = array.size(rt); i < size; i++) {
|
|
130
141
|
auto sv = adapt(rt, array.getValueAtIndex(rt, i), runtimeManager);
|
|
131
142
|
containsHostFunction |= sv->containsHostFunction;
|
|
@@ -133,52 +144,63 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
133
144
|
}
|
|
134
145
|
} else if (object.isHostObject<MutableValue>(rt)) {
|
|
135
146
|
type = ValueType::MutableValueType;
|
|
136
|
-
valueContainer = std::make_unique<MutableValueWrapper>(
|
|
147
|
+
valueContainer = std::make_unique<MutableValueWrapper>(
|
|
148
|
+
object.getHostObject<MutableValue>(rt));
|
|
137
149
|
adaptCache(rt, value);
|
|
138
150
|
} else if (object.isHostObject<RemoteObject>(rt)) {
|
|
139
151
|
type = ValueType::RemoteObjectType;
|
|
140
152
|
valueContainer = std::make_unique<RemoteObjectWrapper>(
|
|
141
|
-
|
|
142
|
-
);
|
|
153
|
+
object.getHostObject<RemoteObject>(rt));
|
|
143
154
|
adaptCache(rt, value);
|
|
144
155
|
} else if (objectType == ValueType::RemoteObjectType) {
|
|
145
156
|
type = ValueType::RemoteObjectType;
|
|
146
|
-
valueContainer =
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
valueContainer =
|
|
158
|
+
std::make_unique<RemoteObjectWrapper>(std::make_shared<RemoteObject>(
|
|
159
|
+
rt, object, runtimeManager, runtimeManager->scheduler));
|
|
149
160
|
} else {
|
|
150
161
|
// create frozen object based on a copy of a given object
|
|
151
162
|
type = ValueType::FrozenObjectType;
|
|
152
163
|
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
164
|
+
std::make_shared<FrozenObject>(rt, object, runtimeManager));
|
|
165
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
156
166
|
containsHostFunction |= frozenObject->containsHostFunction;
|
|
157
167
|
if (RuntimeDecorator::isReactRuntime(rt)) {
|
|
158
168
|
if (!containsHostFunction) {
|
|
159
|
-
addHiddenProperty(
|
|
169
|
+
addHiddenProperty(
|
|
170
|
+
rt,
|
|
171
|
+
createHost(rt, frozenObject),
|
|
172
|
+
object,
|
|
173
|
+
HIDDEN_HOST_OBJECT_PROP);
|
|
160
174
|
}
|
|
161
175
|
freeze(rt, object);
|
|
162
176
|
}
|
|
163
177
|
}
|
|
164
178
|
} else if (value.isSymbol()) {
|
|
165
179
|
type = ValueType::StringType;
|
|
166
|
-
valueContainer =
|
|
180
|
+
valueContainer =
|
|
181
|
+
std::make_unique<StringValueWrapper>(value.asSymbol(rt).toString(rt));
|
|
167
182
|
} else {
|
|
168
183
|
throw "Invalid value type";
|
|
169
184
|
}
|
|
170
185
|
}
|
|
171
186
|
|
|
172
|
-
std::shared_ptr<ShareableValue> ShareableValue::adapt(
|
|
173
|
-
|
|
187
|
+
std::shared_ptr<ShareableValue> ShareableValue::adapt(
|
|
188
|
+
jsi::Runtime &rt,
|
|
189
|
+
const jsi::Value &value,
|
|
190
|
+
RuntimeManager *runtimeManager,
|
|
191
|
+
ValueType valueType) {
|
|
192
|
+
auto sv = std::shared_ptr<ShareableValue>(
|
|
193
|
+
new ShareableValue(runtimeManager, runtimeManager->scheduler));
|
|
174
194
|
sv->adapt(rt, value, valueType);
|
|
175
195
|
return sv;
|
|
176
196
|
}
|
|
177
197
|
|
|
178
198
|
jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
179
|
-
// TODO: maybe we can cache toJSValue results on a per-runtime basis, need to
|
|
199
|
+
// TODO: maybe we can cache toJSValue results on a per-runtime basis, need to
|
|
200
|
+
// avoid ref loops
|
|
180
201
|
if (&rt == runtimeManager->runtime.get()) {
|
|
181
|
-
// Getting value on the same runtime where it was created, prepare
|
|
202
|
+
// Getting value on the same runtime where it was created, prepare
|
|
203
|
+
// remoteValue
|
|
182
204
|
if (remoteValue.expired()) {
|
|
183
205
|
remoteValue = getWeakRef(rt);
|
|
184
206
|
}
|
|
@@ -188,7 +210,8 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
|
188
210
|
}
|
|
189
211
|
return jsi::Value(rt, *remoteValue.lock());
|
|
190
212
|
} else {
|
|
191
|
-
// Getting value on a different runtime than where it was created from,
|
|
213
|
+
// Getting value on a different runtime than where it was created from,
|
|
214
|
+
// prepare hostValue
|
|
192
215
|
if (hostValue.get() == nullptr) {
|
|
193
216
|
hostValue = std::make_unique<jsi::Value>(toJSValue(rt));
|
|
194
217
|
}
|
|
@@ -196,17 +219,23 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
|
196
219
|
}
|
|
197
220
|
}
|
|
198
221
|
|
|
199
|
-
jsi::Object ShareableValue::createHost(
|
|
222
|
+
jsi::Object ShareableValue::createHost(
|
|
223
|
+
jsi::Runtime &rt,
|
|
224
|
+
std::shared_ptr<jsi::HostObject> host) {
|
|
200
225
|
return jsi::Object::createFromHostObject(rt, host);
|
|
201
226
|
}
|
|
202
227
|
|
|
203
|
-
jsi::Value createFrozenWrapper(
|
|
204
|
-
|
|
228
|
+
jsi::Value createFrozenWrapper(
|
|
229
|
+
jsi::Runtime &rt,
|
|
230
|
+
std::shared_ptr<FrozenObject> frozenObject) {
|
|
231
|
+
jsi::Object __reanimatedHiddenHost =
|
|
232
|
+
jsi::Object::createFromHostObject(rt, frozenObject);
|
|
205
233
|
jsi::Object obj = frozenObject->shallowClone(rt);
|
|
206
234
|
jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
|
|
207
235
|
jsi::Function freeze = globalObject.getPropertyAsFunction(rt, "freeze");
|
|
208
236
|
if (!frozenObject->containsHostFunction) {
|
|
209
|
-
addHiddenProperty(
|
|
237
|
+
addHiddenProperty(
|
|
238
|
+
rt, std::move(__reanimatedHiddenHost), obj, HIDDEN_HOST_OBJECT_PROP);
|
|
210
239
|
addHiddenProperty(rt, true, obj, ALREADY_CONVERTED);
|
|
211
240
|
}
|
|
212
241
|
return freeze.call(rt, obj);
|
|
@@ -223,15 +252,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
223
252
|
case ValueType::NumberType:
|
|
224
253
|
return jsi::Value(ValueWrapper::asNumber(valueContainer));
|
|
225
254
|
case ValueType::StringType: {
|
|
226
|
-
auto&
|
|
255
|
+
auto &stringValue = ValueWrapper::asString(valueContainer);
|
|
227
256
|
return jsi::Value(rt, jsi::String::createFromUtf8(rt, stringValue));
|
|
228
257
|
}
|
|
229
258
|
case ValueType::FrozenObjectType: {
|
|
230
|
-
auto&
|
|
259
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
231
260
|
return createFrozenWrapper(rt, frozenObject);
|
|
232
261
|
}
|
|
233
262
|
case ValueType::FrozenArrayType: {
|
|
234
|
-
auto&
|
|
263
|
+
auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
|
|
235
264
|
jsi::Array array(rt, frozenArray.size());
|
|
236
265
|
for (size_t i = 0; i < frozenArray.size(); i++) {
|
|
237
266
|
array.setValueAtIndex(rt, i, frozenArray[i]->toJSValue(rt));
|
|
@@ -239,45 +268,50 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
239
268
|
return array;
|
|
240
269
|
}
|
|
241
270
|
case ValueType::RemoteObjectType: {
|
|
242
|
-
auto&
|
|
271
|
+
auto &remoteObject = ValueWrapper::asRemoteObject(valueContainer);
|
|
243
272
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
244
273
|
remoteObject->maybeInitializeOnWorkletRuntime(rt);
|
|
245
274
|
}
|
|
246
275
|
return createHost(rt, remoteObject);
|
|
247
276
|
}
|
|
248
277
|
case ValueType::MutableValueType: {
|
|
249
|
-
auto&
|
|
278
|
+
auto &mutableObject = ValueWrapper::asMutableValue(valueContainer);
|
|
250
279
|
return createHost(rt, mutableObject);
|
|
251
280
|
}
|
|
252
281
|
case ValueType::HostFunctionType: {
|
|
253
|
-
auto hostFunctionWrapper =
|
|
254
|
-
|
|
282
|
+
auto hostFunctionWrapper =
|
|
283
|
+
ValueWrapper::asHostFunctionWrapper(valueContainer);
|
|
284
|
+
auto &hostRuntime = hostFunctionWrapper->value->hostRuntime;
|
|
255
285
|
if (hostRuntime == &rt) {
|
|
256
|
-
// function is accessed from the same runtime it was crated, we just
|
|
257
|
-
return
|
|
286
|
+
// function is accessed from the same runtime it was crated, we just
|
|
287
|
+
// return same function obj
|
|
288
|
+
return jsi::Value(
|
|
289
|
+
rt, *hostFunctionWrapper->value->getPureFunction().get());
|
|
258
290
|
} else {
|
|
259
|
-
// function is accessed from a different runtime, we wrap function in
|
|
260
|
-
// call on an appropriate thread
|
|
291
|
+
// function is accessed from a different runtime, we wrap function in
|
|
292
|
+
// host func that'd enqueue call on an appropriate thread
|
|
261
293
|
|
|
262
294
|
auto runtimeManager = this->runtimeManager;
|
|
263
295
|
auto hostFunction = hostFunctionWrapper->value;
|
|
264
296
|
|
|
265
297
|
auto warnFunction = [runtimeManager, hostFunction](
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
) -> jsi::Value {
|
|
271
|
-
|
|
298
|
+
jsi::Runtime &rt,
|
|
299
|
+
const jsi::Value &thisValue,
|
|
300
|
+
const jsi::Value *args,
|
|
301
|
+
size_t count) -> jsi::Value {
|
|
272
302
|
jsi::Value jsThis = rt.global().getProperty(rt, "jsThis");
|
|
273
|
-
std::string workletLocation = jsThis.asObject(rt)
|
|
303
|
+
std::string workletLocation = jsThis.asObject(rt)
|
|
304
|
+
.getProperty(rt, "__location")
|
|
305
|
+
.toString(rt)
|
|
306
|
+
.utf8(rt);
|
|
274
307
|
std::string exceptionMessage = "Tried to synchronously call ";
|
|
275
|
-
if(hostFunction->functionName.empty()) {
|
|
308
|
+
if (hostFunction->functionName.empty()) {
|
|
276
309
|
exceptionMessage += "anonymous function";
|
|
277
310
|
} else {
|
|
278
311
|
exceptionMessage += "function {" + hostFunction->functionName + "}";
|
|
279
312
|
}
|
|
280
|
-
exceptionMessage +=
|
|
313
|
+
exceptionMessage +=
|
|
314
|
+
" from a different thread.\n\nOccurred in worklet location: ";
|
|
281
315
|
exceptionMessage += workletLocation;
|
|
282
316
|
exceptionMessage += CALLBACK_ERROR_SUFFIX;
|
|
283
317
|
runtimeManager->errorHandler->setError(exceptionMessage);
|
|
@@ -287,134 +321,149 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
287
321
|
};
|
|
288
322
|
|
|
289
323
|
auto clb = [runtimeManager, hostFunction, hostRuntime](
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
//
|
|
296
|
-
// from RN and not only RN methods from UI
|
|
324
|
+
jsi::Runtime &rt,
|
|
325
|
+
const jsi::Value &thisValue,
|
|
326
|
+
const jsi::Value *args,
|
|
327
|
+
size_t count) -> jsi::Value {
|
|
328
|
+
// TODO: we should find thread based on runtime such that we could
|
|
329
|
+
// also call UI methods from RN and not only RN methods from UI
|
|
297
330
|
|
|
298
331
|
std::vector<std::shared_ptr<ShareableValue>> params;
|
|
299
332
|
for (int i = 0; i < count; ++i) {
|
|
300
|
-
params.push_back(
|
|
333
|
+
params.push_back(
|
|
334
|
+
ShareableValue::adapt(rt, args[i], runtimeManager));
|
|
301
335
|
}
|
|
302
336
|
|
|
303
337
|
std::function<void()> job = [hostFunction, hostRuntime, params] {
|
|
304
|
-
jsi::Value *
|
|
338
|
+
jsi::Value *args = new jsi::Value[params.size()];
|
|
305
339
|
for (int i = 0; i < params.size(); ++i) {
|
|
306
340
|
args[i] = params[i]->getValue(*hostRuntime);
|
|
307
341
|
}
|
|
308
|
-
jsi::Value returnedValue =
|
|
309
|
-
|
|
310
|
-
|
|
342
|
+
jsi::Value returnedValue =
|
|
343
|
+
hostFunction->getPureFunction().get()->call(
|
|
344
|
+
*hostRuntime,
|
|
345
|
+
static_cast<const jsi::Value *>(args),
|
|
346
|
+
static_cast<size_t>(params.size()));
|
|
311
347
|
|
|
312
|
-
delete
|
|
348
|
+
delete[] args;
|
|
313
349
|
// ToDo use returned value to return promise
|
|
314
350
|
};
|
|
315
351
|
|
|
316
352
|
runtimeManager->scheduler->scheduleOnJS(job);
|
|
317
353
|
return jsi::Value::undefined();
|
|
318
354
|
};
|
|
319
|
-
jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(
|
|
320
|
-
|
|
355
|
+
jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(
|
|
356
|
+
rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, warnFunction);
|
|
357
|
+
jsi::Function res = jsi::Function::createFromHostFunction(
|
|
358
|
+
rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, clb);
|
|
321
359
|
addHiddenProperty(rt, std::move(res), wrapperFunction, CALL_ASYNC);
|
|
322
|
-
jsi::Object functionHandler =
|
|
323
|
-
|
|
360
|
+
jsi::Object functionHandler =
|
|
361
|
+
createHost(rt, hostFunctionWrapper->value);
|
|
362
|
+
addHiddenProperty(
|
|
363
|
+
rt, std::move(functionHandler), wrapperFunction, PRIMAL_FUNCTION);
|
|
324
364
|
return wrapperFunction;
|
|
325
365
|
}
|
|
326
366
|
}
|
|
327
367
|
case ValueType::WorkletFunctionType: {
|
|
328
368
|
auto runtimeManager = this->runtimeManager;
|
|
329
|
-
auto&
|
|
369
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(this->valueContainer);
|
|
330
370
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
331
371
|
// when running on worklet thread we prep a function
|
|
332
372
|
|
|
333
|
-
auto jsThis = std::make_shared<jsi::Object>(
|
|
334
|
-
|
|
373
|
+
auto jsThis = std::make_shared<jsi::Object>(
|
|
374
|
+
frozenObject->shallowClone(*runtimeManager->runtime));
|
|
375
|
+
std::shared_ptr<jsi::Function> funPtr(
|
|
376
|
+
runtimeManager->workletsCache->getFunction(rt, frozenObject));
|
|
335
377
|
auto name = funPtr->getProperty(rt, "name").asString(rt).utf8(rt);
|
|
336
378
|
|
|
337
|
-
auto clb = [=](
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
jsi::Value location = jsThis->getProperty(rt, "__location");
|
|
363
|
-
std::string str = "Javascript worklet error";
|
|
364
|
-
if (location.isString()) {
|
|
365
|
-
str += "\nIn file: " + location.asString(rt).utf8(rt);
|
|
366
|
-
}
|
|
367
|
-
runtimeManager->errorHandler->setError(str);
|
|
368
|
-
runtimeManager->errorHandler->raise();
|
|
379
|
+
auto clb = [=](jsi::Runtime &rt,
|
|
380
|
+
const jsi::Value &thisValue,
|
|
381
|
+
const jsi::Value *args,
|
|
382
|
+
size_t count) mutable -> jsi::Value {
|
|
383
|
+
const jsi::String jsThisName =
|
|
384
|
+
jsi::String::createFromAscii(rt, "jsThis");
|
|
385
|
+
jsi::Object global = rt.global();
|
|
386
|
+
jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
|
|
387
|
+
global.setProperty(rt, jsThisName, *jsThis); // set jsThis
|
|
388
|
+
|
|
389
|
+
jsi::Value res = jsi::Value::undefined();
|
|
390
|
+
try {
|
|
391
|
+
if (thisValue.isObject()) {
|
|
392
|
+
res =
|
|
393
|
+
funPtr->callWithThis(rt, thisValue.asObject(rt), args, count);
|
|
394
|
+
} else {
|
|
395
|
+
res = funPtr->call(rt, args, count);
|
|
396
|
+
}
|
|
397
|
+
} catch (jsi::JSError &e) {
|
|
398
|
+
throw e;
|
|
399
|
+
} catch (...) {
|
|
400
|
+
if (demangleExceptionName(
|
|
401
|
+
abi::__cxa_current_exception_type()->name()) ==
|
|
402
|
+
"facebook::jsi::JSError") {
|
|
403
|
+
throw jsi::JSError(rt, "Javascript worklet error");
|
|
369
404
|
}
|
|
370
|
-
|
|
371
|
-
|
|
405
|
+
// TODO find out a way to get the error's message on hermes
|
|
406
|
+
jsi::Value location = jsThis->getProperty(rt, "__location");
|
|
407
|
+
std::string str = "Javascript worklet error";
|
|
408
|
+
if (location.isString()) {
|
|
409
|
+
str += "\nIn file: " + location.asString(rt).utf8(rt);
|
|
410
|
+
}
|
|
411
|
+
runtimeManager->errorHandler->setError(str);
|
|
412
|
+
runtimeManager->errorHandler->raise();
|
|
413
|
+
}
|
|
414
|
+
global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
|
|
415
|
+
return res;
|
|
372
416
|
};
|
|
373
|
-
return jsi::Function::createFromHostFunction(
|
|
417
|
+
return jsi::Function::createFromHostFunction(
|
|
418
|
+
rt, jsi::PropNameID::forAscii(rt, name.c_str()), 0, clb);
|
|
374
419
|
} else {
|
|
375
420
|
// when run outside of UI thread we enqueue a call on the UI thread
|
|
376
|
-
auto clb = [=](
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
// TODO: we should find thread based on runtime such that we could also call UI methods
|
|
383
|
-
// from RN and not only RN methods from UI
|
|
421
|
+
auto clb = [=](jsi::Runtime &rt,
|
|
422
|
+
const jsi::Value &thisValue,
|
|
423
|
+
const jsi::Value *args,
|
|
424
|
+
size_t count) -> jsi::Value {
|
|
425
|
+
// TODO: we should find thread based on runtime such that we could
|
|
426
|
+
// also call UI methods from RN and not only RN methods from UI
|
|
384
427
|
|
|
385
428
|
std::vector<std::shared_ptr<ShareableValue>> params;
|
|
386
429
|
for (int i = 0; i < count; ++i) {
|
|
387
|
-
params.push_back(
|
|
430
|
+
params.push_back(
|
|
431
|
+
ShareableValue::adapt(rt, args[i], runtimeManager));
|
|
388
432
|
}
|
|
389
433
|
|
|
390
434
|
runtimeManager->scheduler->scheduleOnUI([=] {
|
|
391
435
|
jsi::Runtime &rt = *runtimeManager->runtime.get();
|
|
392
436
|
auto jsThis = createFrozenWrapper(rt, frozenObject).getObject(rt);
|
|
393
|
-
auto code =
|
|
394
|
-
|
|
437
|
+
auto code =
|
|
438
|
+
jsThis.getProperty(rt, "asString").asString(rt).utf8(rt);
|
|
439
|
+
std::shared_ptr<jsi::Function> funPtr(
|
|
440
|
+
runtimeManager->workletsCache->getFunction(rt, frozenObject));
|
|
395
441
|
|
|
396
|
-
jsi::Value *
|
|
442
|
+
jsi::Value *args = new jsi::Value[params.size()];
|
|
397
443
|
for (int i = 0; i < params.size(); ++i) {
|
|
398
444
|
args[i] = params[i]->getValue(rt);
|
|
399
445
|
}
|
|
400
446
|
|
|
401
447
|
jsi::Value returnedValue;
|
|
402
|
-
const jsi::String jsThisName =
|
|
448
|
+
const jsi::String jsThisName =
|
|
449
|
+
jsi::String::createFromAscii(rt, "jsThis");
|
|
403
450
|
jsi::Object global = rt.global();
|
|
404
451
|
jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
|
|
405
|
-
global.setProperty(rt, jsThisName, jsThis); //set jsThis
|
|
452
|
+
global.setProperty(rt, jsThisName, jsThis); // set jsThis
|
|
406
453
|
try {
|
|
407
|
-
returnedValue = funPtr->call(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
} catch(std::exception &e) {
|
|
454
|
+
returnedValue = funPtr->call(
|
|
455
|
+
rt,
|
|
456
|
+
static_cast<const jsi::Value *>(args),
|
|
457
|
+
static_cast<size_t>(params.size()));
|
|
458
|
+
} catch (std::exception &e) {
|
|
412
459
|
std::string str = e.what();
|
|
413
460
|
runtimeManager->errorHandler->setError(str);
|
|
414
461
|
runtimeManager->errorHandler->raise();
|
|
415
|
-
} catch(...) {
|
|
416
|
-
if(demangleExceptionName(
|
|
417
|
-
|
|
462
|
+
} catch (...) {
|
|
463
|
+
if (demangleExceptionName(
|
|
464
|
+
abi::__cxa_current_exception_type()->name()) ==
|
|
465
|
+
"facebook::jsi::JSError") {
|
|
466
|
+
throw jsi::JSError(rt, "Javascript worklet error");
|
|
418
467
|
}
|
|
419
468
|
// TODO find out a way to get the error's message on hermes
|
|
420
469
|
jsi::Value location = jsThis.getProperty(rt, "__location");
|
|
@@ -425,14 +474,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
425
474
|
runtimeManager->errorHandler->setError(str);
|
|
426
475
|
runtimeManager->errorHandler->raise();
|
|
427
476
|
}
|
|
428
|
-
global.setProperty(rt, jsThisName, oldJSThis); //clean jsThis
|
|
477
|
+
global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
|
|
429
478
|
|
|
430
|
-
delete
|
|
479
|
+
delete[] args;
|
|
431
480
|
// ToDo use returned value to return promise
|
|
432
481
|
});
|
|
433
482
|
return jsi::Value::undefined();
|
|
434
483
|
};
|
|
435
|
-
return jsi::Function::createFromHostFunction(
|
|
484
|
+
return jsi::Function::createFromHostFunction(
|
|
485
|
+
rt, jsi::PropNameID::forAscii(rt, "_workletFunction"), 0, clb);
|
|
436
486
|
}
|
|
437
487
|
}
|
|
438
488
|
default: {
|
|
@@ -444,7 +494,8 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
444
494
|
|
|
445
495
|
std::string ShareableValue::demangleExceptionName(std::string toDemangle) {
|
|
446
496
|
int status = 0;
|
|
447
|
-
char *
|
|
497
|
+
char *buff =
|
|
498
|
+
__cxxabiv1::__cxa_demangle(toDemangle.c_str(), nullptr, nullptr, &status);
|
|
448
499
|
if (!buff) {
|
|
449
500
|
return toDemangle;
|
|
450
501
|
}
|
|
@@ -453,4 +504,4 @@ std::string ShareableValue::demangleExceptionName(std::string toDemangle) {
|
|
|
453
504
|
return demangled;
|
|
454
505
|
}
|
|
455
506
|
|
|
456
|
-
}
|
|
507
|
+
} // namespace reanimated
|