@react-native-ohos/react-native-reanimated 3.18.1-rc.5 → 3.18.2-rc.2
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/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +10 -10
- package/harmony/reanimated/BuildProfile.ets +16 -16
- package/harmony/reanimated/build-profile.json5 +11 -11
- package/harmony/reanimated/oh-package.json5 +11 -11
- package/harmony/reanimated/src/main/cpp/CMakeLists.txt +1 -1
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -68
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -87
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -252
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
- package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -155
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -182
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
- package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
- package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
- package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +7 -0
- package/harmony/reanimated/src/main/module.json5 +12 -12
- package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
- package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
- package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/reanimated/ts.ts +6 -6
- package/harmony/reanimated.har +0 -0
- package/package.json +50 -50
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
#include <worklets/WorkletRuntime/ReanimatedHermesRuntime.h>
|
|
2
|
-
|
|
3
|
-
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
4
|
-
// don't support hermes and it causes the compilation to fail.
|
|
5
|
-
#if JS_RUNTIME_HERMES
|
|
6
|
-
|
|
7
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
8
|
-
#include <jsi/decorator.h>
|
|
9
|
-
#include <jsi/jsi.h>
|
|
10
|
-
|
|
11
|
-
#include <memory>
|
|
12
|
-
#include <string>
|
|
13
|
-
#include <utility>
|
|
14
|
-
|
|
15
|
-
namespace worklets {
|
|
16
|
-
|
|
17
|
-
using namespace facebook;
|
|
18
|
-
using namespace react;
|
|
19
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
20
|
-
using namespace facebook::hermes::inspector_modern;
|
|
21
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
22
|
-
|
|
23
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
24
|
-
|
|
25
|
-
class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
|
|
26
|
-
public:
|
|
27
|
-
explicit HermesExecutorRuntimeAdapter(
|
|
28
|
-
facebook::hermes::HermesRuntime &hermesRuntime,
|
|
29
|
-
const std::shared_ptr<MessageQueueThread> &thread)
|
|
30
|
-
: hermesRuntime_(hermesRuntime), thread_(std::move(thread)) {}
|
|
31
|
-
|
|
32
|
-
virtual ~HermesExecutorRuntimeAdapter() {
|
|
33
|
-
// This is required by iOS, because there is an assertion in the destructor
|
|
34
|
-
// that the thread was indeed `quit` before
|
|
35
|
-
thread_->quitSynchronous();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
facebook::hermes::HermesRuntime &getRuntime() override {
|
|
39
|
-
return hermesRuntime_;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// This is not empty in the original implementation, but we decided to tickle
|
|
43
|
-
// the runtime by running a small piece of code on every frame as using this
|
|
44
|
-
// required us to hold a refernce to the runtime inside this adapter which
|
|
45
|
-
// caused issues while reloading the app.
|
|
46
|
-
void tickleJs() override {}
|
|
47
|
-
|
|
48
|
-
public:
|
|
49
|
-
facebook::hermes::HermesRuntime &hermesRuntime_;
|
|
50
|
-
std::shared_ptr<MessageQueueThread> thread_;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
54
|
-
|
|
55
|
-
ReanimatedHermesRuntime::ReanimatedHermesRuntime(
|
|
56
|
-
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
57
|
-
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
58
|
-
const std::string &name)
|
|
59
|
-
: jsi::WithRuntimeDecorator<ReanimatedReentrancyCheck>(
|
|
60
|
-
*runtime,
|
|
61
|
-
reentrancyCheck_),
|
|
62
|
-
runtime_(std::move(runtime)) {
|
|
63
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
64
|
-
auto adapter =
|
|
65
|
-
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
|
|
66
|
-
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
|
|
67
|
-
#else
|
|
68
|
-
// This is required by iOS, because there is an assertion in the destructor
|
|
69
|
-
// that the thread was indeed `quit` before
|
|
70
|
-
jsQueue->quitSynchronous();
|
|
71
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
72
|
-
|
|
73
|
-
#ifndef NDEBUG
|
|
74
|
-
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
|
|
75
|
-
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
|
|
76
|
-
*runtime_,
|
|
77
|
-
jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
|
|
78
|
-
3,
|
|
79
|
-
[wrappedRuntime](
|
|
80
|
-
jsi::Runtime &rt,
|
|
81
|
-
const jsi::Value &thisValue,
|
|
82
|
-
const jsi::Value *args,
|
|
83
|
-
size_t count) -> jsi::Value {
|
|
84
|
-
auto code = std::make_shared<const jsi::StringBuffer>(
|
|
85
|
-
args[0].asString(rt).utf8(rt));
|
|
86
|
-
std::string sourceURL;
|
|
87
|
-
if (count > 1 && args[1].isString()) {
|
|
88
|
-
sourceURL = args[1].asString(rt).utf8(rt);
|
|
89
|
-
}
|
|
90
|
-
std::shared_ptr<const jsi::Buffer> sourceMap;
|
|
91
|
-
if (count > 2 && args[2].isString()) {
|
|
92
|
-
sourceMap = std::make_shared<const jsi::StringBuffer>(
|
|
93
|
-
args[2].asString(rt).utf8(rt));
|
|
94
|
-
}
|
|
95
|
-
return wrappedRuntime->evaluateJavaScriptWithSourceMap(
|
|
96
|
-
code, sourceMap, sourceURL);
|
|
97
|
-
});
|
|
98
|
-
runtime_->global().setProperty(
|
|
99
|
-
*runtime_, "evalWithSourceMap", evalWithSourceMap);
|
|
100
|
-
#endif // NDEBUG
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
|
|
104
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
105
|
-
// We have to disable debugging before the runtime is destroyed.
|
|
106
|
-
chrome::disableDebugging(debugToken_);
|
|
107
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
} // namespace worklets
|
|
111
|
-
|
|
112
|
-
#endif // JS_RUNTIME_HERMES
|
|
1
|
+
#include <worklets/WorkletRuntime/ReanimatedHermesRuntime.h>
|
|
2
|
+
|
|
3
|
+
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
4
|
+
// don't support hermes and it causes the compilation to fail.
|
|
5
|
+
#if JS_RUNTIME_HERMES
|
|
6
|
+
|
|
7
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
8
|
+
#include <jsi/decorator.h>
|
|
9
|
+
#include <jsi/jsi.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <utility>
|
|
14
|
+
|
|
15
|
+
namespace worklets {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
using namespace react;
|
|
19
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
20
|
+
using namespace facebook::hermes::inspector_modern;
|
|
21
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
22
|
+
|
|
23
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
24
|
+
|
|
25
|
+
class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
|
|
26
|
+
public:
|
|
27
|
+
explicit HermesExecutorRuntimeAdapter(
|
|
28
|
+
facebook::hermes::HermesRuntime &hermesRuntime,
|
|
29
|
+
const std::shared_ptr<MessageQueueThread> &thread)
|
|
30
|
+
: hermesRuntime_(hermesRuntime), thread_(std::move(thread)) {}
|
|
31
|
+
|
|
32
|
+
virtual ~HermesExecutorRuntimeAdapter() {
|
|
33
|
+
// This is required by iOS, because there is an assertion in the destructor
|
|
34
|
+
// that the thread was indeed `quit` before
|
|
35
|
+
thread_->quitSynchronous();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
facebook::hermes::HermesRuntime &getRuntime() override {
|
|
39
|
+
return hermesRuntime_;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// This is not empty in the original implementation, but we decided to tickle
|
|
43
|
+
// the runtime by running a small piece of code on every frame as using this
|
|
44
|
+
// required us to hold a refernce to the runtime inside this adapter which
|
|
45
|
+
// caused issues while reloading the app.
|
|
46
|
+
void tickleJs() override {}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
facebook::hermes::HermesRuntime &hermesRuntime_;
|
|
50
|
+
std::shared_ptr<MessageQueueThread> thread_;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
54
|
+
|
|
55
|
+
ReanimatedHermesRuntime::ReanimatedHermesRuntime(
|
|
56
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
57
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
58
|
+
const std::string &name)
|
|
59
|
+
: jsi::WithRuntimeDecorator<ReanimatedReentrancyCheck>(
|
|
60
|
+
*runtime,
|
|
61
|
+
reentrancyCheck_),
|
|
62
|
+
runtime_(std::move(runtime)) {
|
|
63
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
64
|
+
auto adapter =
|
|
65
|
+
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
|
|
66
|
+
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
|
|
67
|
+
#else
|
|
68
|
+
// This is required by iOS, because there is an assertion in the destructor
|
|
69
|
+
// that the thread was indeed `quit` before
|
|
70
|
+
jsQueue->quitSynchronous();
|
|
71
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
72
|
+
|
|
73
|
+
#ifndef NDEBUG
|
|
74
|
+
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
|
|
75
|
+
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
|
|
76
|
+
*runtime_,
|
|
77
|
+
jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
|
|
78
|
+
3,
|
|
79
|
+
[wrappedRuntime](
|
|
80
|
+
jsi::Runtime &rt,
|
|
81
|
+
const jsi::Value &thisValue,
|
|
82
|
+
const jsi::Value *args,
|
|
83
|
+
size_t count) -> jsi::Value {
|
|
84
|
+
auto code = std::make_shared<const jsi::StringBuffer>(
|
|
85
|
+
args[0].asString(rt).utf8(rt));
|
|
86
|
+
std::string sourceURL;
|
|
87
|
+
if (count > 1 && args[1].isString()) {
|
|
88
|
+
sourceURL = args[1].asString(rt).utf8(rt);
|
|
89
|
+
}
|
|
90
|
+
std::shared_ptr<const jsi::Buffer> sourceMap;
|
|
91
|
+
if (count > 2 && args[2].isString()) {
|
|
92
|
+
sourceMap = std::make_shared<const jsi::StringBuffer>(
|
|
93
|
+
args[2].asString(rt).utf8(rt));
|
|
94
|
+
}
|
|
95
|
+
return wrappedRuntime->evaluateJavaScriptWithSourceMap(
|
|
96
|
+
code, sourceMap, sourceURL);
|
|
97
|
+
});
|
|
98
|
+
runtime_->global().setProperty(
|
|
99
|
+
*runtime_, "evalWithSourceMap", evalWithSourceMap);
|
|
100
|
+
#endif // NDEBUG
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
|
|
104
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
105
|
+
// We have to disable debugging before the runtime is destroyed.
|
|
106
|
+
chrome::disableDebugging(debugToken_);
|
|
107
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
} // namespace worklets
|
|
111
|
+
|
|
112
|
+
#endif // JS_RUNTIME_HERMES
|
package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <worklets/Tools/Defs.h>
|
|
4
|
-
|
|
5
|
-
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
6
|
-
// don't support hermes and it causes the compilation to fail.
|
|
7
|
-
#if JS_RUNTIME_HERMES
|
|
8
|
-
|
|
9
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
10
|
-
#include <hermes/hermes.h>
|
|
11
|
-
#include <jsi/decorator.h>
|
|
12
|
-
#include <jsi/jsi.h>
|
|
13
|
-
|
|
14
|
-
#include <atomic>
|
|
15
|
-
#include <memory>
|
|
16
|
-
#include <string>
|
|
17
|
-
#include <thread>
|
|
18
|
-
|
|
19
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
20
|
-
#include <hermes/inspector-modern/chrome/Registration.h>
|
|
21
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
22
|
-
|
|
23
|
-
namespace worklets {
|
|
24
|
-
|
|
25
|
-
using namespace facebook;
|
|
26
|
-
using namespace react;
|
|
27
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
28
|
-
using namespace facebook::hermes::inspector_modern;
|
|
29
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
30
|
-
|
|
31
|
-
// ReentrancyCheck is copied from React Native
|
|
32
|
-
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
33
|
-
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
34
|
-
struct ReanimatedReentrancyCheck {
|
|
35
|
-
// This is effectively a very subtle and complex assert, so only
|
|
36
|
-
// include it in builds which would include asserts.
|
|
37
|
-
#ifndef NDEBUG
|
|
38
|
-
ReanimatedReentrancyCheck() : tid(std::thread::id()), depth(0) {}
|
|
39
|
-
|
|
40
|
-
void before() {
|
|
41
|
-
std::thread::id this_id = std::this_thread::get_id();
|
|
42
|
-
std::thread::id expected = std::thread::id();
|
|
43
|
-
|
|
44
|
-
// A note on memory ordering: the main purpose of these checks is
|
|
45
|
-
// to observe a before/before race, without an intervening after.
|
|
46
|
-
// This will be detected by the compare_exchange_strong atomicity
|
|
47
|
-
// properties, regardless of memory order.
|
|
48
|
-
//
|
|
49
|
-
// For everything else, it is easiest to think of 'depth' as a
|
|
50
|
-
// proxy for any access made inside the VM. If access to depth
|
|
51
|
-
// are reordered incorrectly, the same could be true of any other
|
|
52
|
-
// operation made by the VM. In fact, using acquire/release
|
|
53
|
-
// memory ordering could create barriers which mask a programmer
|
|
54
|
-
// error. So, we use relaxed memory order, to avoid masking
|
|
55
|
-
// actual ordering errors. Although, in practice, ordering errors
|
|
56
|
-
// of this sort would be surprising, because the decorator would
|
|
57
|
-
// need to call after() without before().
|
|
58
|
-
|
|
59
|
-
if (tid.compare_exchange_strong(
|
|
60
|
-
expected, this_id, std::memory_order_relaxed)) {
|
|
61
|
-
// Returns true if tid and expected were the same. If they
|
|
62
|
-
// were, then the stored tid referred to no thread, and we
|
|
63
|
-
// atomically saved this thread's tid. Now increment depth.
|
|
64
|
-
assert(depth == 0 && "[Reanimated] No thread id, but depth != 0");
|
|
65
|
-
++depth;
|
|
66
|
-
} else if (expected == this_id) {
|
|
67
|
-
// If the stored tid referred to a thread, expected was set to
|
|
68
|
-
// that value. If that value is this thread's tid, that's ok,
|
|
69
|
-
// just increment depth again.
|
|
70
|
-
assert(depth != 0 && "[Reanimated] Thread id was set, but depth == 0");
|
|
71
|
-
++depth;
|
|
72
|
-
} else {
|
|
73
|
-
// The stored tid was some other thread. This indicates a bad
|
|
74
|
-
// programmer error, where VM methods were called on two
|
|
75
|
-
// different threads unsafely. Fail fast (and hard) so the
|
|
76
|
-
// crash can be analyzed.
|
|
77
|
-
__builtin_trap();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
void after() {
|
|
82
|
-
assert(
|
|
83
|
-
tid.load(std::memory_order_relaxed) == std::this_thread::get_id() &&
|
|
84
|
-
"[Reanimated] No thread id in after()");
|
|
85
|
-
if (--depth == 0) {
|
|
86
|
-
// If we decremented depth to zero, store no-thread into tid.
|
|
87
|
-
std::thread::id expected = std::this_thread::get_id();
|
|
88
|
-
bool didWrite = tid.compare_exchange_strong(
|
|
89
|
-
expected, std::thread::id(), std::memory_order_relaxed);
|
|
90
|
-
assert(didWrite && "[Reanimated] Decremented to zero, but no tid write");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
std::atomic<std::thread::id> tid;
|
|
95
|
-
// This is not atomic, as it is only written or read from the owning
|
|
96
|
-
// thread.
|
|
97
|
-
unsigned int depth;
|
|
98
|
-
#endif // NDEBUG
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// This is in fact a subclass of jsi::Runtime! WithRuntimeDecorator is a
|
|
102
|
-
// template class that is a subclass of DecoratedRuntime which is also a
|
|
103
|
-
// template class that then inherits its template, which in this case is
|
|
104
|
-
// jsi::Runtime. So the inheritance is: ReanimatedHermesRuntime ->
|
|
105
|
-
// WithRuntimeDecorator -> DecoratedRuntime -> jsi::Runtime You can find out
|
|
106
|
-
// more about this in ReactCommon/jsi/jsi/Decorator.h or by following this link:
|
|
107
|
-
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/jsi/jsi/decorator.h
|
|
108
|
-
class ReanimatedHermesRuntime
|
|
109
|
-
: public jsi::WithRuntimeDecorator<ReanimatedReentrancyCheck> {
|
|
110
|
-
public:
|
|
111
|
-
ReanimatedHermesRuntime(
|
|
112
|
-
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
113
|
-
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
114
|
-
const std::string &name);
|
|
115
|
-
~ReanimatedHermesRuntime();
|
|
116
|
-
|
|
117
|
-
private:
|
|
118
|
-
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
|
|
119
|
-
ReanimatedReentrancyCheck reentrancyCheck_;
|
|
120
|
-
#if HERMES_ENABLE_DEBUGGER
|
|
121
|
-
chrome::DebugSessionToken debugToken_;
|
|
122
|
-
#endif // HERMES_ENABLE_DEBUGGER
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
} // namespace worklets
|
|
126
|
-
|
|
127
|
-
#endif // JS_RUNTIME_HERMES
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <worklets/Tools/Defs.h>
|
|
4
|
+
|
|
5
|
+
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
6
|
+
// don't support hermes and it causes the compilation to fail.
|
|
7
|
+
#if JS_RUNTIME_HERMES
|
|
8
|
+
|
|
9
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
10
|
+
#include <hermes/hermes.h>
|
|
11
|
+
#include <jsi/decorator.h>
|
|
12
|
+
#include <jsi/jsi.h>
|
|
13
|
+
|
|
14
|
+
#include <atomic>
|
|
15
|
+
#include <memory>
|
|
16
|
+
#include <string>
|
|
17
|
+
#include <thread>
|
|
18
|
+
|
|
19
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
20
|
+
#include <hermes/inspector-modern/chrome/Registration.h>
|
|
21
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
22
|
+
|
|
23
|
+
namespace worklets {
|
|
24
|
+
|
|
25
|
+
using namespace facebook;
|
|
26
|
+
using namespace react;
|
|
27
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
28
|
+
using namespace facebook::hermes::inspector_modern;
|
|
29
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
30
|
+
|
|
31
|
+
// ReentrancyCheck is copied from React Native
|
|
32
|
+
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
33
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
34
|
+
struct ReanimatedReentrancyCheck {
|
|
35
|
+
// This is effectively a very subtle and complex assert, so only
|
|
36
|
+
// include it in builds which would include asserts.
|
|
37
|
+
#ifndef NDEBUG
|
|
38
|
+
ReanimatedReentrancyCheck() : tid(std::thread::id()), depth(0) {}
|
|
39
|
+
|
|
40
|
+
void before() {
|
|
41
|
+
std::thread::id this_id = std::this_thread::get_id();
|
|
42
|
+
std::thread::id expected = std::thread::id();
|
|
43
|
+
|
|
44
|
+
// A note on memory ordering: the main purpose of these checks is
|
|
45
|
+
// to observe a before/before race, without an intervening after.
|
|
46
|
+
// This will be detected by the compare_exchange_strong atomicity
|
|
47
|
+
// properties, regardless of memory order.
|
|
48
|
+
//
|
|
49
|
+
// For everything else, it is easiest to think of 'depth' as a
|
|
50
|
+
// proxy for any access made inside the VM. If access to depth
|
|
51
|
+
// are reordered incorrectly, the same could be true of any other
|
|
52
|
+
// operation made by the VM. In fact, using acquire/release
|
|
53
|
+
// memory ordering could create barriers which mask a programmer
|
|
54
|
+
// error. So, we use relaxed memory order, to avoid masking
|
|
55
|
+
// actual ordering errors. Although, in practice, ordering errors
|
|
56
|
+
// of this sort would be surprising, because the decorator would
|
|
57
|
+
// need to call after() without before().
|
|
58
|
+
|
|
59
|
+
if (tid.compare_exchange_strong(
|
|
60
|
+
expected, this_id, std::memory_order_relaxed)) {
|
|
61
|
+
// Returns true if tid and expected were the same. If they
|
|
62
|
+
// were, then the stored tid referred to no thread, and we
|
|
63
|
+
// atomically saved this thread's tid. Now increment depth.
|
|
64
|
+
assert(depth == 0 && "[Reanimated] No thread id, but depth != 0");
|
|
65
|
+
++depth;
|
|
66
|
+
} else if (expected == this_id) {
|
|
67
|
+
// If the stored tid referred to a thread, expected was set to
|
|
68
|
+
// that value. If that value is this thread's tid, that's ok,
|
|
69
|
+
// just increment depth again.
|
|
70
|
+
assert(depth != 0 && "[Reanimated] Thread id was set, but depth == 0");
|
|
71
|
+
++depth;
|
|
72
|
+
} else {
|
|
73
|
+
// The stored tid was some other thread. This indicates a bad
|
|
74
|
+
// programmer error, where VM methods were called on two
|
|
75
|
+
// different threads unsafely. Fail fast (and hard) so the
|
|
76
|
+
// crash can be analyzed.
|
|
77
|
+
__builtin_trap();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void after() {
|
|
82
|
+
assert(
|
|
83
|
+
tid.load(std::memory_order_relaxed) == std::this_thread::get_id() &&
|
|
84
|
+
"[Reanimated] No thread id in after()");
|
|
85
|
+
if (--depth == 0) {
|
|
86
|
+
// If we decremented depth to zero, store no-thread into tid.
|
|
87
|
+
std::thread::id expected = std::this_thread::get_id();
|
|
88
|
+
bool didWrite = tid.compare_exchange_strong(
|
|
89
|
+
expected, std::thread::id(), std::memory_order_relaxed);
|
|
90
|
+
assert(didWrite && "[Reanimated] Decremented to zero, but no tid write");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
std::atomic<std::thread::id> tid;
|
|
95
|
+
// This is not atomic, as it is only written or read from the owning
|
|
96
|
+
// thread.
|
|
97
|
+
unsigned int depth;
|
|
98
|
+
#endif // NDEBUG
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// This is in fact a subclass of jsi::Runtime! WithRuntimeDecorator is a
|
|
102
|
+
// template class that is a subclass of DecoratedRuntime which is also a
|
|
103
|
+
// template class that then inherits its template, which in this case is
|
|
104
|
+
// jsi::Runtime. So the inheritance is: ReanimatedHermesRuntime ->
|
|
105
|
+
// WithRuntimeDecorator -> DecoratedRuntime -> jsi::Runtime You can find out
|
|
106
|
+
// more about this in ReactCommon/jsi/jsi/Decorator.h or by following this link:
|
|
107
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/jsi/jsi/decorator.h
|
|
108
|
+
class ReanimatedHermesRuntime
|
|
109
|
+
: public jsi::WithRuntimeDecorator<ReanimatedReentrancyCheck> {
|
|
110
|
+
public:
|
|
111
|
+
ReanimatedHermesRuntime(
|
|
112
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
113
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
114
|
+
const std::string &name);
|
|
115
|
+
~ReanimatedHermesRuntime();
|
|
116
|
+
|
|
117
|
+
private:
|
|
118
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
|
|
119
|
+
ReanimatedReentrancyCheck reentrancyCheck_;
|
|
120
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
121
|
+
chrome::DebugSessionToken debugToken_;
|
|
122
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
} // namespace worklets
|
|
126
|
+
|
|
127
|
+
#endif // JS_RUNTIME_HERMES
|
package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
#include <worklets/Tools/Defs.h>
|
|
2
|
-
#include <worklets/WorkletRuntime/ReanimatedRuntime.h>
|
|
3
|
-
|
|
4
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
5
|
-
#include <jsi/jsi.h>
|
|
6
|
-
|
|
7
|
-
#include <memory>
|
|
8
|
-
#include <utility>
|
|
9
|
-
|
|
10
|
-
#if JS_RUNTIME_HERMES
|
|
11
|
-
#include <worklets/WorkletRuntime/ReanimatedHermesRuntime.h>
|
|
12
|
-
#elif JS_RUNTIME_V8
|
|
13
|
-
#include <v8runtime/V8RuntimeFactory.h>
|
|
14
|
-
#else
|
|
15
|
-
#include <jsc/JSCRuntime.h>
|
|
16
|
-
#endif // JS_RUNTIME
|
|
17
|
-
|
|
18
|
-
namespace worklets {
|
|
19
|
-
|
|
20
|
-
using namespace facebook;
|
|
21
|
-
using namespace react;
|
|
22
|
-
|
|
23
|
-
std::shared_ptr<jsi::Runtime> ReanimatedRuntime::make(
|
|
24
|
-
jsi::Runtime &rnRuntime,
|
|
25
|
-
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
26
|
-
const std::string &name) {
|
|
27
|
-
(void)rnRuntime; // used only for V8
|
|
28
|
-
#if JS_RUNTIME_HERMES
|
|
29
|
-
// We don't call `jsQueue->quitSynchronous()` here, since it will be done
|
|
30
|
-
// later in ReanimatedHermesRuntime
|
|
31
|
-
|
|
32
|
-
auto runtime = facebook::hermes::makeHermesRuntime();
|
|
33
|
-
return std::make_shared<ReanimatedHermesRuntime>(
|
|
34
|
-
std::move(runtime), jsQueue, name);
|
|
35
|
-
#elif JS_RUNTIME_V8
|
|
36
|
-
// This is required by iOS, because there is an assertion in the destructor
|
|
37
|
-
// that the thread was indeed `quit` before.
|
|
38
|
-
jsQueue->quitSynchronous();
|
|
39
|
-
|
|
40
|
-
auto config = std::make_unique<rnv8::V8RuntimeConfig>();
|
|
41
|
-
config->enableInspector = false;
|
|
42
|
-
config->appName = name;
|
|
43
|
-
return rnv8::createSharedV8Runtime(&rnRuntime, std::move(config));
|
|
44
|
-
#else
|
|
45
|
-
// This is required by iOS, because there is an assertion in the destructor
|
|
46
|
-
// that the thread was indeed `quit` before
|
|
47
|
-
jsQueue->quitSynchronous();
|
|
48
|
-
|
|
49
|
-
return facebook::jsc::makeJSCRuntime();
|
|
50
|
-
#endif
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
} // namespace worklets
|
|
1
|
+
#include <worklets/Tools/Defs.h>
|
|
2
|
+
#include <worklets/WorkletRuntime/ReanimatedRuntime.h>
|
|
3
|
+
|
|
4
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
#if JS_RUNTIME_HERMES
|
|
11
|
+
#include <worklets/WorkletRuntime/ReanimatedHermesRuntime.h>
|
|
12
|
+
#elif JS_RUNTIME_V8
|
|
13
|
+
#include <v8runtime/V8RuntimeFactory.h>
|
|
14
|
+
#else
|
|
15
|
+
#include <jsc/JSCRuntime.h>
|
|
16
|
+
#endif // JS_RUNTIME
|
|
17
|
+
|
|
18
|
+
namespace worklets {
|
|
19
|
+
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
using namespace react;
|
|
22
|
+
|
|
23
|
+
std::shared_ptr<jsi::Runtime> ReanimatedRuntime::make(
|
|
24
|
+
jsi::Runtime &rnRuntime,
|
|
25
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
26
|
+
const std::string &name) {
|
|
27
|
+
(void)rnRuntime; // used only for V8
|
|
28
|
+
#if JS_RUNTIME_HERMES
|
|
29
|
+
// We don't call `jsQueue->quitSynchronous()` here, since it will be done
|
|
30
|
+
// later in ReanimatedHermesRuntime
|
|
31
|
+
|
|
32
|
+
auto runtime = facebook::hermes::makeHermesRuntime();
|
|
33
|
+
return std::make_shared<ReanimatedHermesRuntime>(
|
|
34
|
+
std::move(runtime), jsQueue, name);
|
|
35
|
+
#elif JS_RUNTIME_V8
|
|
36
|
+
// This is required by iOS, because there is an assertion in the destructor
|
|
37
|
+
// that the thread was indeed `quit` before.
|
|
38
|
+
jsQueue->quitSynchronous();
|
|
39
|
+
|
|
40
|
+
auto config = std::make_unique<rnv8::V8RuntimeConfig>();
|
|
41
|
+
config->enableInspector = false;
|
|
42
|
+
config->appName = name;
|
|
43
|
+
return rnv8::createSharedV8Runtime(&rnRuntime, std::move(config));
|
|
44
|
+
#else
|
|
45
|
+
// This is required by iOS, because there is an assertion in the destructor
|
|
46
|
+
// that the thread was indeed `quit` before
|
|
47
|
+
jsQueue->quitSynchronous();
|
|
48
|
+
|
|
49
|
+
return facebook::jsc::makeJSCRuntime();
|
|
50
|
+
#endif
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} // namespace worklets
|
package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
4
|
-
#include <jsi/jsi.h>
|
|
5
|
-
|
|
6
|
-
#include <memory>
|
|
7
|
-
#include <string>
|
|
8
|
-
|
|
9
|
-
namespace worklets {
|
|
10
|
-
|
|
11
|
-
using namespace facebook;
|
|
12
|
-
using namespace react;
|
|
13
|
-
|
|
14
|
-
class ReanimatedRuntime {
|
|
15
|
-
public:
|
|
16
|
-
static std::shared_ptr<jsi::Runtime> make(
|
|
17
|
-
jsi::Runtime &rnRuntime,
|
|
18
|
-
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
19
|
-
const std::string &name);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
} // namespace worklets
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
4
|
+
#include <jsi/jsi.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
using namespace react;
|
|
13
|
+
|
|
14
|
+
class ReanimatedRuntime {
|
|
15
|
+
public:
|
|
16
|
+
static std::shared_ptr<jsi::Runtime> make(
|
|
17
|
+
jsi::Runtime &rnRuntime,
|
|
18
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
19
|
+
const std::string &name);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
} // namespace worklets
|