react-native-worklets 0.8.0-rc.0 → 0.8.1
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/worklets/Compat/StableApi.cpp +121 -0
- package/Common/cpp/worklets/Compat/StableApi.h +109 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +14 -14
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -7
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +5 -14
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +3 -5
- package/Common/cpp/worklets/SharedItems/Serializable.h +1 -43
- package/Common/cpp/worklets/Tools/Defs.h +2 -7
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +1 -1
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +73 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +20 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +2 -2
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +0 -4
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +0 -3
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +27 -17
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +12 -3
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +74 -2
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +0 -4
- package/RNWorklets.podspec +1 -2
- package/android/CMakeLists.txt +1 -4
- package/android/build.gradle +0 -3
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +1 -1
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +2 -2
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +2 -2
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +28 -18
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +6 -5
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -2
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.java +4 -2
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.java +4 -2
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +5 -2
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +3 -2
- package/apple/worklets/apple/WorkletsModule.mm +40 -26
- package/compatibility.json +2 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js +3 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/debug/jsVersion.js.map +1 -1
- package/lib/module/featureFlags/staticFlags.json +0 -1
- package/lib/module/featureFlags/types.js +0 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/memory/serializable.native.js +13 -5
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/shareable.js +15 -0
- package/lib/module/memory/shareable.js.map +1 -1
- package/lib/module/memory/shareable.native.js +15 -0
- package/lib/module/memory/shareable.native.js.map +1 -1
- package/lib/module/runtimeKind.js +2 -0
- package/lib/module/runtimeKind.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -1
- package/lib/typescript/featureFlags/types.d.ts +0 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
- package/lib/typescript/memory/shareable.d.ts +16 -2
- package/lib/typescript/memory/shareable.d.ts.map +1 -1
- package/lib/typescript/memory/shareable.native.d.ts +16 -2
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -1
- package/lib/typescript/memory/types.d.ts +42 -0
- package/lib/typescript/memory/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/package.json +16 -15
- package/scripts/worklets_utils.rb +0 -2
- package/src/WorkletsModule/NativeWorklets.native.ts +3 -2
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +0 -1
- package/src/featureFlags/types.ts +0 -1
- package/src/memory/serializable.native.ts +15 -10
- package/src/memory/shareable.native.ts +16 -2
- package/src/memory/shareable.ts +16 -2
- package/src/memory/types.ts +42 -0
- package/src/privateGlobals.d.ts +4 -0
- package/src/runtimeKind.ts +1 -0
- package/src/specs/NativeWorkletsModule.ts +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#include <jsi/jsi.h>
|
|
2
|
+
#include <worklets/Compat/Holders.h>
|
|
3
|
+
#include <worklets/Compat/StableApi.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
#include <worklets/SharedItems/Synchronizable.h>
|
|
6
|
+
#include <worklets/Tools/JSISerializer.h>
|
|
7
|
+
#include <worklets/WorkletRuntime/RuntimeHolder.h>
|
|
8
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
9
|
+
|
|
10
|
+
#include <memory>
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
|
|
14
|
+
std::string JSIValueToStdString(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value) {
|
|
15
|
+
return worklets::stringifyJSIValue(rt, value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void scheduleOnUI(const std::shared_ptr<UIScheduler> &uiScheduler, const std::function<void()> &job) {
|
|
19
|
+
uiScheduler->scheduleOnUI(job);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
facebook::jsi::Runtime &getJSIRuntimeFromWorkletRuntime(const std::shared_ptr<WorkletRuntime> &workletRuntime) {
|
|
23
|
+
return workletRuntime->getJSIRuntime();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
std::weak_ptr<WorkletRuntime> getWeakRuntimeFromJSIRuntime(jsi::Runtime &rt) {
|
|
27
|
+
return WorkletRuntime::getWeakRuntimeFromJSIRuntime(rt);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
std::shared_ptr<Serializable>
|
|
31
|
+
extractSerializable(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value, const std::string &errorMessage) {
|
|
32
|
+
return extractSerializableOrThrow(rt, value, errorMessage);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
std::shared_ptr<Serializable> extractSerializable(
|
|
36
|
+
facebook::jsi::Runtime &rt,
|
|
37
|
+
const facebook::jsi::Value &value,
|
|
38
|
+
const std::string &errorMessage,
|
|
39
|
+
const Serializable::ValueType expectedType) {
|
|
40
|
+
switch (expectedType) {
|
|
41
|
+
case Serializable::ValueType::WorkletType:
|
|
42
|
+
return extractSerializableOrThrow<SerializableWorklet>(rt, value, errorMessage);
|
|
43
|
+
case Serializable::ValueType::UndefinedType:
|
|
44
|
+
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
|
|
45
|
+
case Serializable::ValueType::NullType:
|
|
46
|
+
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
|
|
47
|
+
case Serializable::ValueType::BooleanType:
|
|
48
|
+
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
|
|
49
|
+
case Serializable::ValueType::NumberType:
|
|
50
|
+
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
|
|
51
|
+
case Serializable::ValueType::BigIntType:
|
|
52
|
+
return extractSerializableOrThrow<SerializableBigInt>(rt, value, errorMessage);
|
|
53
|
+
case Serializable::ValueType::StringType:
|
|
54
|
+
return extractSerializableOrThrow<SerializableString>(rt, value, errorMessage);
|
|
55
|
+
case Serializable::ValueType::ObjectType:
|
|
56
|
+
return extractSerializableOrThrow<SerializableObject>(rt, value, errorMessage);
|
|
57
|
+
case Serializable::ValueType::ArrayType:
|
|
58
|
+
return extractSerializableOrThrow<SerializableArray>(rt, value, errorMessage);
|
|
59
|
+
case Serializable::ValueType::MapType:
|
|
60
|
+
return extractSerializableOrThrow<SerializableMap>(rt, value, errorMessage);
|
|
61
|
+
case Serializable::ValueType::SetType:
|
|
62
|
+
return extractSerializableOrThrow<SerializableSet>(rt, value, errorMessage);
|
|
63
|
+
case Serializable::ValueType::RemoteFunctionType:
|
|
64
|
+
return extractSerializableOrThrow<SerializableRemoteFunction>(rt, value, errorMessage);
|
|
65
|
+
case Serializable::ValueType::HandleType:
|
|
66
|
+
return extractSerializableOrThrow<SerializableInitializer>(rt, value, errorMessage);
|
|
67
|
+
case Serializable::ValueType::HostObjectType:
|
|
68
|
+
return extractSerializableOrThrow<SerializableHostObject>(rt, value, errorMessage);
|
|
69
|
+
case Serializable::ValueType::HostFunctionType:
|
|
70
|
+
return extractSerializableOrThrow<SerializableHostFunction>(rt, value, errorMessage);
|
|
71
|
+
case Serializable::ValueType::ArrayBufferType:
|
|
72
|
+
return extractSerializableOrThrow<SerializableArrayBuffer>(rt, value, errorMessage);
|
|
73
|
+
case Serializable::ValueType::TurboModuleLikeType:
|
|
74
|
+
return extractSerializableOrThrow<SerializableTurboModuleLike>(rt, value, errorMessage);
|
|
75
|
+
case Serializable::ValueType::ImportType:
|
|
76
|
+
return extractSerializableOrThrow<SerializableImport>(rt, value, errorMessage);
|
|
77
|
+
case Serializable::ValueType::SynchronizableType:
|
|
78
|
+
return extractSerializableOrThrow<Synchronizable>(rt, value, errorMessage);
|
|
79
|
+
case Serializable::ValueType::CustomType:
|
|
80
|
+
return extractSerializableOrThrow<CustomSerializable>(rt, value, errorMessage);
|
|
81
|
+
case Serializable::ValueType::SymbolType:
|
|
82
|
+
throw std::runtime_error("[Worklets] Not implemented.");
|
|
83
|
+
case Serializable::ValueType::ShareableType:
|
|
84
|
+
throw std::runtime_error("[Worklets] Not implemented.");
|
|
85
|
+
default:
|
|
86
|
+
throw std::runtime_error("[Worklets] Invalid expected type provided to extractSerializable.");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void runSyncOnRuntime(
|
|
91
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
92
|
+
const std::shared_ptr<Serializable> &worklet) {
|
|
93
|
+
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void runSyncOnRuntime(
|
|
97
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
98
|
+
const std::shared_ptr<Serializable> &worklet,
|
|
99
|
+
const facebook::jsi::Value &arg0) {
|
|
100
|
+
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet), arg0);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void runSyncOnRuntime(
|
|
104
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
105
|
+
const std::shared_ptr<Serializable> &worklet,
|
|
106
|
+
const facebook::jsi::Value &arg0,
|
|
107
|
+
const facebook::jsi::Value &arg1) {
|
|
108
|
+
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet), arg0, arg1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
std::shared_ptr<WorkletRuntime> getWorkletRuntimeFromHolder(
|
|
112
|
+
facebook::jsi::Runtime &rt,
|
|
113
|
+
const facebook::jsi::Object &object) {
|
|
114
|
+
return object.getNativeState<WorkletRuntimeHolder>(rt)->runtime_;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
std::shared_ptr<UIScheduler> getUISchedulerFromHolder(facebook::jsi::Runtime &rt, const facebook::jsi::Object &object) {
|
|
118
|
+
return object.getNativeState<UISchedulerHolder>(rt)->scheduler_;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
} // namespace worklets
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Version of `react-native-worklets` which introduced current stable API.
|
|
5
|
+
* It can be used by libraries to verify they use a compatible version
|
|
6
|
+
* of `react-native-worklets` installed when integrating in C++.
|
|
7
|
+
*/
|
|
8
|
+
#define WORKLETS_STABLE_API_VERSION "0.8.0"
|
|
9
|
+
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace facebook::jsi {
|
|
16
|
+
class Runtime;
|
|
17
|
+
class Value;
|
|
18
|
+
class Object;
|
|
19
|
+
} // namespace facebook::jsi
|
|
20
|
+
|
|
21
|
+
namespace worklets {
|
|
22
|
+
|
|
23
|
+
class WorkletRuntime;
|
|
24
|
+
class UIScheduler;
|
|
25
|
+
|
|
26
|
+
class Serializable {
|
|
27
|
+
public:
|
|
28
|
+
virtual facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) = 0;
|
|
29
|
+
|
|
30
|
+
virtual ~Serializable();
|
|
31
|
+
|
|
32
|
+
enum class ValueType : std::uint8_t {
|
|
33
|
+
UndefinedType,
|
|
34
|
+
NullType,
|
|
35
|
+
BooleanType,
|
|
36
|
+
NumberType,
|
|
37
|
+
BigIntType,
|
|
38
|
+
StringType,
|
|
39
|
+
ObjectType,
|
|
40
|
+
ArrayType,
|
|
41
|
+
MapType,
|
|
42
|
+
SetType,
|
|
43
|
+
WorkletType,
|
|
44
|
+
RemoteFunctionType,
|
|
45
|
+
HandleType,
|
|
46
|
+
HostObjectType,
|
|
47
|
+
HostFunctionType,
|
|
48
|
+
ArrayBufferType,
|
|
49
|
+
TurboModuleLikeType,
|
|
50
|
+
ImportType,
|
|
51
|
+
SynchronizableType,
|
|
52
|
+
CustomType,
|
|
53
|
+
SymbolType, /* unused */
|
|
54
|
+
ShareableType
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
explicit Serializable(ValueType valueType) : valueType_(valueType) {}
|
|
58
|
+
|
|
59
|
+
inline ValueType valueType() const {
|
|
60
|
+
return valueType_;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static std::shared_ptr<Serializable> undefined();
|
|
64
|
+
|
|
65
|
+
protected:
|
|
66
|
+
ValueType valueType_;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
extern std::shared_ptr<WorkletRuntime> getWorkletRuntimeFromHolder(
|
|
70
|
+
facebook::jsi::Runtime &rt,
|
|
71
|
+
const facebook::jsi::Object &object);
|
|
72
|
+
|
|
73
|
+
extern std::shared_ptr<UIScheduler> getUISchedulerFromHolder(
|
|
74
|
+
facebook::jsi::Runtime &rt,
|
|
75
|
+
const facebook::jsi::Object &object);
|
|
76
|
+
|
|
77
|
+
extern facebook::jsi::Runtime &getJSIRuntimeFromWorkletRuntime(const std::shared_ptr<WorkletRuntime> &workletRuntime);
|
|
78
|
+
|
|
79
|
+
extern std::weak_ptr<WorkletRuntime> getWeakRuntimeFromJSIRuntime(facebook::jsi::Runtime &rt);
|
|
80
|
+
|
|
81
|
+
extern void scheduleOnUI(const std::shared_ptr<UIScheduler> &uiScheduler, const std::function<void()> &job);
|
|
82
|
+
|
|
83
|
+
extern std::string JSIValueToStdString(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value);
|
|
84
|
+
|
|
85
|
+
extern std::shared_ptr<Serializable>
|
|
86
|
+
extractSerializable(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value, const std::string &errorMessage);
|
|
87
|
+
|
|
88
|
+
extern std::shared_ptr<Serializable> extractSerializable(
|
|
89
|
+
facebook::jsi::Runtime &rt,
|
|
90
|
+
const facebook::jsi::Value &value,
|
|
91
|
+
const std::string &errorMessage,
|
|
92
|
+
const Serializable::ValueType expectedType);
|
|
93
|
+
|
|
94
|
+
extern void runSyncOnRuntime(
|
|
95
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
96
|
+
const std::shared_ptr<Serializable> &worklet);
|
|
97
|
+
|
|
98
|
+
extern void runSyncOnRuntime(
|
|
99
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
100
|
+
const std::shared_ptr<Serializable> &worklet,
|
|
101
|
+
const facebook::jsi::Value &arg0);
|
|
102
|
+
|
|
103
|
+
extern void runSyncOnRuntime(
|
|
104
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
105
|
+
const std::shared_ptr<Serializable> &worklet,
|
|
106
|
+
const facebook::jsi::Value &arg0,
|
|
107
|
+
const facebook::jsi::Value &arg1);
|
|
108
|
+
|
|
109
|
+
} // namespace worklets
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include <react/renderer/uimanager/UIManagerBinding.h>
|
|
3
3
|
#include <react/renderer/uimanager/primitives.h>
|
|
4
4
|
#include <worklets/Compat/Holders.h>
|
|
5
|
+
#include <worklets/Compat/StableApi.h>
|
|
5
6
|
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
6
7
|
#include <worklets/NativeModules/WorkletsModuleProxy.h>
|
|
7
8
|
#include <worklets/SharedItems/Serializable.h>
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
#include <worklets/Tools/Defs.h>
|
|
12
13
|
#include <worklets/Tools/FeatureFlags.h>
|
|
13
14
|
#include <worklets/Tools/JSLogger.h>
|
|
15
|
+
#include <worklets/WorkletRuntime/BundleModeConfig.h>
|
|
14
16
|
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
15
17
|
|
|
16
18
|
#include <memory>
|
|
@@ -86,14 +88,13 @@ inline jsi::Value createWorkletRuntime(
|
|
|
86
88
|
return jsi::Object::createFromHostObject(originRuntime, workletRuntime);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
#ifdef WORKLETS_BUNDLE_MODE_ENABLED
|
|
90
91
|
inline jsi::Value propagateModuleUpdate(
|
|
91
92
|
const std::shared_ptr<RuntimeManager> &runtimeManager,
|
|
92
93
|
const std::string &code,
|
|
93
94
|
const std::string &sourceUrl) {
|
|
94
95
|
const auto runtimes = runtimeManager->getAllRuntimes();
|
|
95
96
|
|
|
96
|
-
for (auto runtime : runtimes) {
|
|
97
|
+
for (const auto &runtime : runtimes) {
|
|
97
98
|
runtime->runSync([code, sourceUrl](jsi::Runtime &rt) -> void {
|
|
98
99
|
const auto buffer = std::make_shared<jsi::StringBuffer>(code);
|
|
99
100
|
rt.evaluateJavaScript(buffer, sourceUrl);
|
|
@@ -101,7 +102,6 @@ inline jsi::Value propagateModuleUpdate(
|
|
|
101
102
|
}
|
|
102
103
|
return jsi::Value::undefined();
|
|
103
104
|
}
|
|
104
|
-
#endif // WORKLETS_BUNDLE_MODE_ENABLED
|
|
105
105
|
|
|
106
106
|
inline jsi::Value reportFatalErrorOnJS(
|
|
107
107
|
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
@@ -151,19 +151,17 @@ inline void registerCustomSerializable(
|
|
|
151
151
|
|
|
152
152
|
JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
|
|
153
153
|
const bool isDevBundle,
|
|
154
|
-
const std::shared_ptr<const ScriptBuffer> &script,
|
|
155
|
-
const std::string &sourceUrl,
|
|
156
154
|
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
157
155
|
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
158
156
|
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
159
157
|
const std::shared_ptr<MemoryManager> &memoryManager,
|
|
160
158
|
const std::shared_ptr<RuntimeManager> &runtimeManager,
|
|
161
159
|
const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime,
|
|
162
|
-
const std::shared_ptr<RuntimeBindings> &runtimeBindings
|
|
160
|
+
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
161
|
+
const BundleModeConfig &bundleModeConfig)
|
|
163
162
|
: jsi::HostObject(),
|
|
164
163
|
isDevBundle_(isDevBundle),
|
|
165
|
-
|
|
166
|
-
sourceUrl_(sourceUrl),
|
|
164
|
+
bundleModeConfig_(bundleModeConfig),
|
|
167
165
|
jsQueue_(jsQueue),
|
|
168
166
|
jsScheduler_(jsScheduler),
|
|
169
167
|
uiScheduler_(uiScheduler),
|
|
@@ -218,9 +216,7 @@ std::vector<jsi::PropNameID> JSIWorkletsModuleProxy::getPropertyNames(jsi::Runti
|
|
|
218
216
|
|
|
219
217
|
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "createShareable"));
|
|
220
218
|
|
|
221
|
-
#ifdef WORKLETS_BUNDLE_MODE_ENABLED
|
|
222
219
|
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "propagateModuleUpdate"));
|
|
223
|
-
#endif // WORKLETS_BUNDLE_MODE_ENABLED
|
|
224
220
|
|
|
225
221
|
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUIRuntimeHolder"));
|
|
226
222
|
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUISchedulerHolder"));
|
|
@@ -578,7 +574,6 @@ jsi::Value JSIWorkletsModuleProxy::get(jsi::Runtime &rt, const jsi::PropNameID &
|
|
|
578
574
|
});
|
|
579
575
|
}
|
|
580
576
|
|
|
581
|
-
#ifdef WORKLETS_BUNDLE_MODE_ENABLED
|
|
582
577
|
if (name == "propagateModuleUpdate") {
|
|
583
578
|
return jsi::Function::createFromHostFunction(
|
|
584
579
|
rt,
|
|
@@ -592,7 +587,6 @@ jsi::Value JSIWorkletsModuleProxy::get(jsi::Runtime &rt, const jsi::PropNameID &
|
|
|
592
587
|
/* sourceURL */ args[1].asString(rt).utf8(rt));
|
|
593
588
|
});
|
|
594
589
|
}
|
|
595
|
-
#endif // WORKLETS_BUNDLE_MODE_ENABLED
|
|
596
590
|
|
|
597
591
|
if (name == "getStaticFeatureFlag") {
|
|
598
592
|
return jsi::Function::createFromHostFunction(
|
|
@@ -619,8 +613,13 @@ jsi::Value JSIWorkletsModuleProxy::get(jsi::Runtime &rt, const jsi::PropNameID &
|
|
|
619
613
|
0,
|
|
620
614
|
[uiWorkletRuntime = uiWorkletRuntime_](
|
|
621
615
|
jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
616
|
+
const auto strongUIWorkletRuntime = uiWorkletRuntime.lock();
|
|
617
|
+
if (!strongUIWorkletRuntime) {
|
|
618
|
+
throw jsi::JSError(rt, "[Worklets] UI Worklet Runtime is not available.");
|
|
619
|
+
}
|
|
620
|
+
auto nativeState = std::make_shared<WorkletRuntimeHolder>(strongUIWorkletRuntime);
|
|
622
621
|
auto obj = jsi::Object(rt);
|
|
623
|
-
obj.setNativeState(rt, std::
|
|
622
|
+
obj.setNativeState(rt, std::move(nativeState));
|
|
624
623
|
return obj;
|
|
625
624
|
});
|
|
626
625
|
}
|
|
@@ -632,8 +631,9 @@ jsi::Value JSIWorkletsModuleProxy::get(jsi::Runtime &rt, const jsi::PropNameID &
|
|
|
632
631
|
0,
|
|
633
632
|
[uiScheduler = uiScheduler_](
|
|
634
633
|
jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
634
|
+
auto nativeState = std::make_shared<UISchedulerHolder>(uiScheduler);
|
|
635
635
|
auto obj = jsi::Object(rt);
|
|
636
|
-
obj.setNativeState(rt, std::
|
|
636
|
+
obj.setNativeState(rt, std::move(nativeState));
|
|
637
637
|
return obj;
|
|
638
638
|
});
|
|
639
639
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#include <worklets/SharedItems/Serializable.h>
|
|
9
9
|
#include <worklets/Tools/Defs.h>
|
|
10
10
|
#include <worklets/Tools/ScriptBuffer.h>
|
|
11
|
+
#include <worklets/WorkletRuntime/BundleModeConfig.h>
|
|
11
12
|
#include <worklets/WorkletRuntime/RuntimeBindings.h>
|
|
12
13
|
#include <worklets/WorkletRuntime/RuntimeManager.h>
|
|
13
14
|
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
@@ -26,15 +27,14 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
|
|
|
26
27
|
public:
|
|
27
28
|
explicit JSIWorkletsModuleProxy(
|
|
28
29
|
const bool isDevBundle,
|
|
29
|
-
const std::shared_ptr<const ScriptBuffer> &script,
|
|
30
|
-
const std::string &sourceUrl,
|
|
31
30
|
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
32
31
|
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
33
32
|
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
34
33
|
const std::shared_ptr<MemoryManager> &memoryManager,
|
|
35
34
|
const std::shared_ptr<RuntimeManager> &runtimeManager,
|
|
36
35
|
const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime,
|
|
37
|
-
const std::shared_ptr<RuntimeBindings> &runtimeBindings
|
|
36
|
+
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
37
|
+
const BundleModeConfig &bundleModeConfig);
|
|
38
38
|
|
|
39
39
|
JSIWorkletsModuleProxy(const JSIWorkletsModuleProxy &other) = default;
|
|
40
40
|
|
|
@@ -56,16 +56,20 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
|
|
|
56
56
|
return uiScheduler_;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
[[nodiscard]] bool isBundleModeEnabled() const {
|
|
60
|
+
return bundleModeConfig_.enabled;
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
[[nodiscard]] bool isDevBundle() const {
|
|
60
64
|
return isDevBundle_;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
[[nodiscard]] std::shared_ptr<const ScriptBuffer> getScript() const {
|
|
64
|
-
return
|
|
68
|
+
return bundleModeConfig_.script;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
[[nodiscard]] std::string getSourceUrl() const {
|
|
68
|
-
return
|
|
72
|
+
return bundleModeConfig_.sourceURL;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
[[nodiscard]] std::shared_ptr<MemoryManager> getMemoryManager() const {
|
|
@@ -82,8 +86,7 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
|
|
|
82
86
|
|
|
83
87
|
private:
|
|
84
88
|
const bool isDevBundle_;
|
|
85
|
-
const
|
|
86
|
-
const std::string sourceUrl_;
|
|
89
|
+
const BundleModeConfig bundleModeConfig_;
|
|
87
90
|
const std::shared_ptr<MessageQueueThread> jsQueue_;
|
|
88
91
|
const std::shared_ptr<JSScheduler> jsScheduler_;
|
|
89
92
|
const std::shared_ptr<UIScheduler> uiScheduler_;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include <react/renderer/uimanager/UIManagerBinding.h>
|
|
2
2
|
#include <react/renderer/uimanager/primitives.h>
|
|
3
|
-
|
|
4
3
|
#include <worklets/NativeModules/WorkletsModuleProxy.h>
|
|
5
4
|
#include <worklets/RunLoop/AsyncQueueImpl.h>
|
|
6
5
|
#include <worklets/SharedItems/Serializable.h>
|
|
@@ -9,19 +8,14 @@
|
|
|
9
8
|
#include <worklets/WorkletRuntime/RuntimeBindings.h>
|
|
10
9
|
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
11
10
|
|
|
12
|
-
#ifdef __ANDROID__
|
|
13
|
-
#include <fbjni/fbjni.h>
|
|
14
|
-
#endif // __ANDROID__
|
|
15
|
-
|
|
16
11
|
#include <memory>
|
|
17
|
-
#include <string>
|
|
18
12
|
#include <utility>
|
|
19
13
|
|
|
20
14
|
using namespace facebook;
|
|
21
15
|
|
|
22
16
|
namespace worklets {
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
bool isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime);
|
|
25
19
|
|
|
26
20
|
WorkletsModuleProxy::WorkletsModuleProxy(
|
|
27
21
|
jsi::Runtime &rnRuntime,
|
|
@@ -30,16 +24,14 @@ WorkletsModuleProxy::WorkletsModuleProxy(
|
|
|
30
24
|
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
31
25
|
std::function<bool()> &&isJavaScriptThread,
|
|
32
26
|
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
33
|
-
const
|
|
34
|
-
const std::string &sourceUrl)
|
|
27
|
+
const BundleModeConfig &bundleModeConfig)
|
|
35
28
|
: isDevBundle_(isDevBundleFromRNRuntime(rnRuntime)),
|
|
36
29
|
jsQueue_(jsQueue),
|
|
37
30
|
jsScheduler_(std::make_shared<JSScheduler>(rnRuntime, jsCallInvoker, std::move(isJavaScriptThread))),
|
|
38
31
|
uiScheduler_(uiScheduler),
|
|
39
32
|
jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
|
|
40
33
|
runtimeBindings_(runtimeBindings),
|
|
41
|
-
|
|
42
|
-
sourceUrl_(sourceUrl),
|
|
34
|
+
bundleModeConfig_(bundleModeConfig),
|
|
43
35
|
memoryManager_(std::make_shared<MemoryManager>()),
|
|
44
36
|
runtimeManager_(std::make_shared<RuntimeManager>()),
|
|
45
37
|
uiWorkletRuntime_(
|
|
@@ -61,15 +53,14 @@ std::shared_ptr<JSIWorkletsModuleProxy> WorkletsModuleProxy::createJSIWorkletsMo
|
|
|
61
53
|
assert(uiWorkletRuntime_ && "UI Worklet Runtime must be initialized before creating JSI proxy.");
|
|
62
54
|
return std::make_shared<JSIWorkletsModuleProxy>(
|
|
63
55
|
isDevBundle_,
|
|
64
|
-
script_,
|
|
65
|
-
sourceUrl_,
|
|
66
56
|
jsQueue_,
|
|
67
57
|
jsScheduler_,
|
|
68
58
|
uiScheduler_,
|
|
69
59
|
memoryManager_,
|
|
70
60
|
runtimeManager_,
|
|
71
61
|
uiWorkletRuntime_,
|
|
72
|
-
runtimeBindings_
|
|
62
|
+
runtimeBindings_,
|
|
63
|
+
bundleModeConfig_);
|
|
73
64
|
}
|
|
74
65
|
|
|
75
66
|
WorkletsModuleProxy::~WorkletsModuleProxy() {
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
#include <worklets/Tools/ScriptBuffer.h>
|
|
13
13
|
#include <worklets/Tools/SingleInstanceChecker.h>
|
|
14
14
|
#include <worklets/Tools/UIScheduler.h>
|
|
15
|
+
#include <worklets/WorkletRuntime/BundleModeConfig.h>
|
|
15
16
|
#include <worklets/WorkletRuntime/RuntimeManager.h>
|
|
16
17
|
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
17
18
|
|
|
18
19
|
#include <memory>
|
|
19
|
-
#include <string>
|
|
20
20
|
|
|
21
21
|
namespace worklets {
|
|
22
22
|
|
|
@@ -29,8 +29,7 @@ class WorkletsModuleProxy : public std::enable_shared_from_this<WorkletsModulePr
|
|
|
29
29
|
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
30
30
|
std::function<bool()> &&isJavaScriptQueue,
|
|
31
31
|
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
32
|
-
const
|
|
33
|
-
const std::string &sourceUrl);
|
|
32
|
+
const BundleModeConfig &bundleModeConfig);
|
|
34
33
|
|
|
35
34
|
~WorkletsModuleProxy();
|
|
36
35
|
|
|
@@ -67,8 +66,7 @@ class WorkletsModuleProxy : public std::enable_shared_from_this<WorkletsModulePr
|
|
|
67
66
|
const std::shared_ptr<UIScheduler> uiScheduler_;
|
|
68
67
|
const std::shared_ptr<JSLogger> jsLogger_;
|
|
69
68
|
const std::shared_ptr<RuntimeBindings> runtimeBindings_;
|
|
70
|
-
const
|
|
71
|
-
const std::string sourceUrl_;
|
|
69
|
+
const BundleModeConfig bundleModeConfig_;
|
|
72
70
|
const std::shared_ptr<MemoryManager> memoryManager_;
|
|
73
71
|
const std::shared_ptr<RuntimeManager> runtimeManager_;
|
|
74
72
|
std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <worklets/Compat/StableApi.h>
|
|
3
4
|
#include <worklets/Registries/WorkletRuntimeRegistry.h>
|
|
4
5
|
|
|
5
6
|
#include <jsi/jsi.h>
|
|
@@ -39,49 +40,6 @@ inline void cleanupIfRuntimeExists(jsi::Runtime *rt, std::unique_ptr<jsi::Value>
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
class Serializable {
|
|
43
|
-
public:
|
|
44
|
-
virtual jsi::Value toJSValue(jsi::Runtime &rt) = 0;
|
|
45
|
-
|
|
46
|
-
virtual ~Serializable();
|
|
47
|
-
|
|
48
|
-
enum class ValueType : std::uint8_t {
|
|
49
|
-
UndefinedType,
|
|
50
|
-
NullType,
|
|
51
|
-
BooleanType,
|
|
52
|
-
NumberType,
|
|
53
|
-
BigIntType,
|
|
54
|
-
StringType,
|
|
55
|
-
ObjectType,
|
|
56
|
-
ArrayType,
|
|
57
|
-
MapType,
|
|
58
|
-
SetType,
|
|
59
|
-
WorkletType,
|
|
60
|
-
RemoteFunctionType,
|
|
61
|
-
HandleType,
|
|
62
|
-
HostObjectType,
|
|
63
|
-
HostFunctionType,
|
|
64
|
-
ArrayBufferType,
|
|
65
|
-
TurboModuleLikeType,
|
|
66
|
-
ImportType,
|
|
67
|
-
SynchronizableType,
|
|
68
|
-
CustomType,
|
|
69
|
-
SymbolType, /* unused */
|
|
70
|
-
ShareableType,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
explicit Serializable(ValueType valueType) : valueType_(valueType) {}
|
|
74
|
-
|
|
75
|
-
inline ValueType valueType() const {
|
|
76
|
-
return valueType_;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static std::shared_ptr<Serializable> undefined();
|
|
80
|
-
|
|
81
|
-
protected:
|
|
82
|
-
ValueType valueType_;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
43
|
template <typename BaseClass>
|
|
86
44
|
class RetainingSerializable : virtual public BaseClass {
|
|
87
45
|
private:
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
/*
|
|
4
|
-
On Android JS_RUNTIME_HERMES is set in CMakeList.txt,
|
|
5
|
-
but on iOS there is no simple way to defect if Hermes exists
|
|
6
|
-
so we have to check if headers are available.
|
|
7
|
-
*/
|
|
8
3
|
#if __APPLE__ && __has_include(<hermes/hermes.h>)
|
|
9
4
|
#define JS_RUNTIME_HERMES 1
|
|
10
5
|
#endif
|
|
11
6
|
|
|
12
|
-
#if REACT_NATIVE_MINOR_VERSION >= 84
|
|
7
|
+
#if REACT_NATIVE_MINOR_VERSION >= 84
|
|
13
8
|
#include <cxxreact/JSBigString.h>
|
|
14
9
|
namespace worklets {
|
|
15
10
|
using JSBigStringBuffer = facebook::react::JSBigString;
|
|
@@ -19,4 +14,4 @@ using JSBigStringBuffer = facebook::react::JSBigString;
|
|
|
19
14
|
namespace worklets {
|
|
20
15
|
using JSBigStringBuffer = facebook::react::BigStringBuffer;
|
|
21
16
|
}
|
|
22
|
-
#endif // REACT_NATIVE_MINOR_VERSION >= 84
|
|
17
|
+
#endif // REACT_NATIVE_MINOR_VERSION >= 84
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/Tools/ScriptBuffer.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
struct BundleModeConfig {
|
|
12
|
+
bool enabled;
|
|
13
|
+
std::shared_ptr<const ScriptBuffer> script;
|
|
14
|
+
std::string sourceURL;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
} // namespace worklets
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#include <worklets/Tools/Defs.h>
|
|
2
|
+
#include <worklets/WorkletRuntime/HermesProfiling.h>
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#if JS_RUNTIME_HERMES
|
|
7
|
+
#include <hermes/hermes.h>
|
|
8
|
+
|
|
9
|
+
#include <chrono>
|
|
10
|
+
#include <filesystem>
|
|
11
|
+
#include <sstream>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
namespace worklets {
|
|
15
|
+
|
|
16
|
+
#if JS_RUNTIME_HERMES
|
|
17
|
+
static std::string generateUniqueProfilePath() {
|
|
18
|
+
auto now = std::chrono::steady_clock::now().time_since_epoch().count();
|
|
19
|
+
std::ostringstream oss;
|
|
20
|
+
oss << "profile-" << now << ".cpuprofile";
|
|
21
|
+
std::filesystem::path dir = std::filesystem::temp_directory_path();
|
|
22
|
+
return (dir / oss.str()).string();
|
|
23
|
+
}
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
void startProfiling(facebook::jsi::Runtime &rt, double meanHzFreq) {
|
|
27
|
+
#if JS_RUNTIME_HERMES
|
|
28
|
+
#if REACT_NATIVE_MINOR_VERSION >= 81
|
|
29
|
+
auto *ihermes = facebook::jsi::castInterface<facebook::hermes::IHermes>(&rt);
|
|
30
|
+
if (ihermes) {
|
|
31
|
+
ihermes->registerForProfiling();
|
|
32
|
+
}
|
|
33
|
+
auto *api = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(facebook::hermes::makeHermesRootAPI());
|
|
34
|
+
if (api) {
|
|
35
|
+
api->enableSamplingProfiler(meanHzFreq);
|
|
36
|
+
}
|
|
37
|
+
#else
|
|
38
|
+
(void)rt;
|
|
39
|
+
(void)meanHzFreq;
|
|
40
|
+
facebook::hermes::HermesRuntime::enableSamplingProfiler();
|
|
41
|
+
#endif
|
|
42
|
+
#else
|
|
43
|
+
(void)rt;
|
|
44
|
+
(void)meanHzFreq;
|
|
45
|
+
#endif
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::string stopProfiling(facebook::jsi::Runtime &rt) {
|
|
49
|
+
#if JS_RUNTIME_HERMES
|
|
50
|
+
std::string path = generateUniqueProfilePath();
|
|
51
|
+
#if REACT_NATIVE_MINOR_VERSION >= 81
|
|
52
|
+
auto *api = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(facebook::hermes::makeHermesRootAPI());
|
|
53
|
+
if (api) {
|
|
54
|
+
api->dumpSampledTraceToFile(path);
|
|
55
|
+
api->disableSamplingProfiler();
|
|
56
|
+
}
|
|
57
|
+
auto *ihermes = facebook::jsi::castInterface<facebook::hermes::IHermes>(&rt);
|
|
58
|
+
if (ihermes) {
|
|
59
|
+
ihermes->unregisterForProfiling();
|
|
60
|
+
}
|
|
61
|
+
#else
|
|
62
|
+
(void)rt;
|
|
63
|
+
facebook::hermes::HermesRuntime::dumpSampledTraceToFile(path);
|
|
64
|
+
facebook::hermes::HermesRuntime::disableSamplingProfiler();
|
|
65
|
+
#endif
|
|
66
|
+
return path;
|
|
67
|
+
#else
|
|
68
|
+
(void)rt;
|
|
69
|
+
return {};
|
|
70
|
+
#endif
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
} // namespace worklets
|