-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathStableApi.cpp
More file actions
145 lines (128 loc) · 6.56 KB
/
Copy pathStableApi.cpp
File metadata and controls
145 lines (128 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <jsi/jsi.h>
#include <worklets/Compat/Holders.h>
#include <worklets/Compat/StableApi.h>
#include <worklets/SharedItems/Serializable.h>
#include <worklets/SharedItems/SerializableRemoteFunction.h>
#include <worklets/SharedItems/Shareable.h>
#include <worklets/SharedItems/Synchronizable.h>
#include <worklets/Tools/JSISerializer.h>
#include <worklets/Tools/WorkletsJSIUtils.h>
#include <worklets/WorkletRuntime/RuntimeHolder.h>
#include <worklets/WorkletRuntime/WorkletRuntime.h>
#include <memory>
namespace worklets {
std::string JSIValueToStdString(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value) {
return worklets::stringifyJSIValue(rt, value);
}
void scheduleOnUI(const std::shared_ptr<UIScheduler> &uiScheduler, const std::function<void()> &job) {
uiScheduler->scheduleOnUI(job);
}
facebook::jsi::Runtime &getJSIRuntimeFromWorkletRuntime(const std::shared_ptr<WorkletRuntime> &workletRuntime) {
return workletRuntime->getJSIRuntime();
}
std::weak_ptr<WorkletRuntime> getWeakRuntimeFromJSIRuntime(jsi::Runtime &rt) {
return WorkletRuntime::getWeakRuntimeFromJSIRuntime(rt);
}
std::shared_ptr<Serializable>
extractSerializable(facebook::jsi::Runtime &rt, const facebook::jsi::Value &value, const std::string &errorMessage) {
return extractSerializableOrThrow(rt, value, errorMessage);
}
std::shared_ptr<Serializable> extractSerializable(
facebook::jsi::Runtime &rt,
const facebook::jsi::Value &value,
const std::string &errorMessage,
const Serializable::ValueType expectedType) {
switch (expectedType) {
case Serializable::ValueType::WorkletType:
return extractSerializableOrThrow<SerializableWorklet>(rt, value, errorMessage);
case Serializable::ValueType::UndefinedType:
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
case Serializable::ValueType::NullType:
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
case Serializable::ValueType::BooleanType:
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
case Serializable::ValueType::NumberType:
return extractSerializableOrThrow<SerializableScalar>(rt, value, errorMessage);
case Serializable::ValueType::BigIntType:
return extractSerializableOrThrow<SerializableBigInt>(rt, value, errorMessage);
case Serializable::ValueType::StringType:
return extractSerializableOrThrow<SerializableString>(rt, value, errorMessage);
case Serializable::ValueType::ObjectType:
return extractSerializableOrThrow<SerializableObject>(rt, value, errorMessage);
case Serializable::ValueType::ArrayType:
return extractSerializableOrThrow<SerializableArray>(rt, value, errorMessage);
case Serializable::ValueType::MapType:
return extractSerializableOrThrow<SerializableMap>(rt, value, errorMessage);
case Serializable::ValueType::SetType:
return extractSerializableOrThrow<SerializableSet>(rt, value, errorMessage);
case Serializable::ValueType::RemoteFunctionType:
return extractSerializableOrThrow<SerializableRemoteFunction>(rt, value, errorMessage);
case Serializable::ValueType::HandleType:
return extractSerializableOrThrow<SerializableInitializer>(rt, value, errorMessage);
case Serializable::ValueType::HostObjectType:
return extractSerializableOrThrow<SerializableHostObject>(rt, value, errorMessage);
case Serializable::ValueType::HostFunctionType:
return extractSerializableOrThrow<SerializableHostFunction>(rt, value, errorMessage);
case Serializable::ValueType::ArrayBufferType:
return extractSerializableOrThrow<SerializableArrayBuffer>(rt, value, errorMessage);
case Serializable::ValueType::TurboModuleLikeType:
return extractSerializableOrThrow<SerializableTurboModuleLike>(rt, value, errorMessage);
case Serializable::ValueType::ImportType:
return extractSerializableOrThrow<SerializableImport>(rt, value, errorMessage);
case Serializable::ValueType::SynchronizableType:
return extractSerializableOrThrow<Synchronizable>(rt, value, errorMessage);
case Serializable::ValueType::CustomType:
return extractSerializableOrThrow<CustomSerializable>(rt, value, errorMessage);
case Serializable::ValueType::SymbolType:
throw std::runtime_error("[Worklets] Not implemented.");
case Serializable::ValueType::ShareableType:
return extractSerializableOrThrow<Shareable>(rt, value, errorMessage);
case Serializable::ValueType::ErrorType:
return extractSerializableOrThrow<SerializableError>(rt, value, errorMessage);
case Serializable::ValueType::RegExpType:
return extractSerializableOrThrow<SerializableRegExp>(rt, value, errorMessage);
default:
throw std::runtime_error("[Worklets] Invalid expected type provided to extractSerializable.");
}
}
void runSyncOnRuntime(
const std::shared_ptr<WorkletRuntime> &workletRuntime,
const std::shared_ptr<Serializable> &worklet) {
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet));
}
void runSyncOnRuntime(
const std::shared_ptr<WorkletRuntime> &workletRuntime,
const std::shared_ptr<Serializable> &worklet,
const facebook::jsi::Value &arg0) {
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet), arg0);
}
void runSyncOnRuntime(
const std::shared_ptr<WorkletRuntime> &workletRuntime,
const std::shared_ptr<Serializable> &worklet,
const facebook::jsi::Value &arg0,
const facebook::jsi::Value &arg1) {
workletRuntime->runSync(std::static_pointer_cast<SerializableWorklet>(worklet), arg0, arg1);
}
void runSyncOnRuntime(const std::shared_ptr<WorkletRuntime> &workletRuntime, const facebook::jsi::Function &function) {
workletRuntime->runSync(function);
}
void runSyncOnRuntime(
const std::shared_ptr<WorkletRuntime> &workletRuntime,
const facebook::jsi::Function &function,
const facebook::jsi::Value &arg0) {
workletRuntime->runSync(function, arg0);
}
std::shared_ptr<WorkletRuntime> getWorkletRuntimeFromHolder(
facebook::jsi::Runtime &rt,
const facebook::jsi::Object &object) {
return object.getNativeState<WorkletRuntimeHolder>(rt)->runtime_;
}
std::shared_ptr<UIScheduler> getUISchedulerFromHolder(facebook::jsi::Runtime &rt, const facebook::jsi::Object &object) {
return object.getNativeState<UISchedulerHolder>(rt)->scheduler_;
}
void installRequestAnimationFrame(
facebook::jsi::Runtime &uiRuntime,
const RequestAnimationFrameHostFunction &requestAnimationFrame) {
jsi_utils::installJsiFunction(uiRuntime, "__nativeRequestAnimationFrame", requestAnimationFrame);
}
} // namespace worklets