@react-native-ohos/react-native-reanimated 3.18.2-rc.2 → 3.18.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 +1 -1
- package/harmony/reanimated/build-profile.json5 +11 -11
- package/harmony/reanimated/oh-package.json5 +11 -11
- 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 -96
- 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 +254 -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 -173
- 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 -189
- package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
- package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +3 -0
- 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/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +4 -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,342 +1,342 @@
|
|
|
1
|
-
#include <worklets/Tools/JSISerializer.h>
|
|
2
|
-
|
|
3
|
-
#include <cxxabi.h>
|
|
4
|
-
#include <iostream>
|
|
5
|
-
#include <sstream>
|
|
6
|
-
|
|
7
|
-
namespace worklets {
|
|
8
|
-
|
|
9
|
-
const std::vector<std::string> SUPPORTED_ERROR_TYPES = {
|
|
10
|
-
"Error",
|
|
11
|
-
"AggregateError",
|
|
12
|
-
"EvalError",
|
|
13
|
-
"RangeError",
|
|
14
|
-
"ReferenceError",
|
|
15
|
-
"SyntaxError",
|
|
16
|
-
"TypeError",
|
|
17
|
-
"URIError",
|
|
18
|
-
"InternalError"};
|
|
19
|
-
|
|
20
|
-
const std::vector<std::string> SUPPORTED_INDEXED_COLLECTION_TYPES = {
|
|
21
|
-
"Int8Array",
|
|
22
|
-
"Uint8Array",
|
|
23
|
-
"Uint8ClampedArray",
|
|
24
|
-
"Int16Array",
|
|
25
|
-
"Uint16Array",
|
|
26
|
-
"Int32Array",
|
|
27
|
-
"Uint32Array",
|
|
28
|
-
"BigInt64Array",
|
|
29
|
-
"BigUint64Array",
|
|
30
|
-
"Float32Array",
|
|
31
|
-
"Float64Array",
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const std::vector<std::string> SUPPORTED_STRUCTURED_DATA_TYPES = {
|
|
35
|
-
"ArrayBuffer",
|
|
36
|
-
"SharedArrayBuffer",
|
|
37
|
-
"DataView",
|
|
38
|
-
"Atomics",
|
|
39
|
-
"JSON",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const std::vector<std::string> SUPPORTED_MANAGING_MEMORY_TYPES = {
|
|
43
|
-
"WeakRef",
|
|
44
|
-
"FinalizationRegistry",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const std::vector<std::string> SUPPORTED_ABSTRACTION_OBJECT_TYPES = {
|
|
48
|
-
"Iterator",
|
|
49
|
-
"AsyncIterator",
|
|
50
|
-
"Promise",
|
|
51
|
-
"GeneratorFunction",
|
|
52
|
-
"AsyncGeneratorFunction",
|
|
53
|
-
"Generator",
|
|
54
|
-
"AsyncGenerator",
|
|
55
|
-
"AsyncFunction",
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const std::vector<std::string> SUPPORTED_REFLECTION_TYPES = {
|
|
59
|
-
"Reflect",
|
|
60
|
-
"Proxy",
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
static inline std::string getObjectTypeName(
|
|
64
|
-
jsi::Runtime &rt,
|
|
65
|
-
const jsi::Object &object) {
|
|
66
|
-
return object.getPropertyAsObject(rt, "constructor")
|
|
67
|
-
.getProperty(rt, "name")
|
|
68
|
-
.toString(rt)
|
|
69
|
-
.utf8(rt);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static inline bool isInstanceOf(
|
|
73
|
-
jsi::Runtime &rt,
|
|
74
|
-
const jsi::Object &object,
|
|
75
|
-
const std::string &type) {
|
|
76
|
-
return getObjectTypeName(rt, object) == type;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static inline bool isInstanceOfAny(
|
|
80
|
-
jsi::Runtime &rt,
|
|
81
|
-
const jsi::Object &object,
|
|
82
|
-
const std::vector<std::string> &supportedTypes) {
|
|
83
|
-
auto instanceType = getObjectTypeName(rt, object);
|
|
84
|
-
|
|
85
|
-
return std::find(
|
|
86
|
-
supportedTypes.begin(), supportedTypes.end(), instanceType) !=
|
|
87
|
-
supportedTypes.end();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
JSISerializer::JSISerializer(jsi::Runtime &rt)
|
|
91
|
-
: rt_(rt),
|
|
92
|
-
visitedNodes_(rt_.global()
|
|
93
|
-
.getPropertyAsFunction(rt_, "Set")
|
|
94
|
-
.callAsConstructor(rt_)
|
|
95
|
-
.asObject(rt_)) {}
|
|
96
|
-
|
|
97
|
-
std::string JSISerializer::stringifyWithName(const jsi::Object &object) {
|
|
98
|
-
std::stringstream ss;
|
|
99
|
-
ss << '[' << getObjectTypeName(rt_, object) << ']';
|
|
100
|
-
|
|
101
|
-
return ss.str();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
std::string JSISerializer::stringifyArray(const jsi::Array &arr) {
|
|
105
|
-
std::stringstream ss;
|
|
106
|
-
ss << '[';
|
|
107
|
-
|
|
108
|
-
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
109
|
-
jsi::Value element = arr.getValueAtIndex(rt_, i);
|
|
110
|
-
ss << stringifyJSIValueRecursively(element);
|
|
111
|
-
if (i != length - 1) {
|
|
112
|
-
ss << ", ";
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
ss << ']';
|
|
117
|
-
|
|
118
|
-
return ss.str();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
std::string JSISerializer::stringifyFunction(const jsi::Function &func) {
|
|
122
|
-
std::stringstream ss;
|
|
123
|
-
auto kind = (func.isHostFunction(rt_) ? "jsi::HostFunction" : "Function");
|
|
124
|
-
auto name = func.getProperty(rt_, "name").toString(rt_).utf8(rt_);
|
|
125
|
-
name = name.empty() ? "anonymous" : name;
|
|
126
|
-
|
|
127
|
-
ss << '[' << kind << ' ' << name << ']';
|
|
128
|
-
return ss.str();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
std::string JSISerializer::stringifyHostObject(jsi::HostObject &hostObject) {
|
|
132
|
-
int status = -1;
|
|
133
|
-
char *hostObjClassName =
|
|
134
|
-
abi::__cxa_demangle(typeid(hostObject).name(), NULL, NULL, &status);
|
|
135
|
-
if (status != 0) {
|
|
136
|
-
return "[jsi::HostObject]";
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
std::stringstream ss;
|
|
140
|
-
ss << "[jsi::HostObject(" << hostObjClassName << ")";
|
|
141
|
-
std::free(hostObjClassName);
|
|
142
|
-
|
|
143
|
-
auto props = hostObject.getPropertyNames(rt_);
|
|
144
|
-
auto propsCount = props.size();
|
|
145
|
-
|
|
146
|
-
if (propsCount > 0) {
|
|
147
|
-
ss << " {";
|
|
148
|
-
auto lastKey = props.back().utf8(rt_);
|
|
149
|
-
for (const auto &key : props) {
|
|
150
|
-
auto formattedKey = key.utf8(rt_);
|
|
151
|
-
auto value = hostObject.get(rt_, key);
|
|
152
|
-
ss << '"' << formattedKey << '"' << ": "
|
|
153
|
-
<< stringifyJSIValueRecursively(value);
|
|
154
|
-
if (formattedKey != lastKey) {
|
|
155
|
-
ss << ", ";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
ss << '}';
|
|
159
|
-
}
|
|
160
|
-
ss << ']';
|
|
161
|
-
|
|
162
|
-
return ss.str();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
std::string JSISerializer::stringifyObject(const jsi::Object &object) {
|
|
166
|
-
std::stringstream ss;
|
|
167
|
-
ss << '{';
|
|
168
|
-
|
|
169
|
-
auto props = object.getPropertyNames(rt_);
|
|
170
|
-
|
|
171
|
-
for (size_t i = 0, propsCount = props.size(rt_); i < propsCount; i++) {
|
|
172
|
-
jsi::String propName = props.getValueAtIndex(rt_, i).toString(rt_);
|
|
173
|
-
ss << '"' << propName.utf8(rt_) << '"' << ": "
|
|
174
|
-
<< stringifyJSIValueRecursively(object.getProperty(rt_, propName));
|
|
175
|
-
if (i != propsCount - 1) {
|
|
176
|
-
ss << ", ";
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
ss << '}';
|
|
181
|
-
|
|
182
|
-
return ss.str();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
std::string JSISerializer::stringifyError(const jsi::Object &object) {
|
|
186
|
-
std::stringstream ss;
|
|
187
|
-
ss << '[' << object.getProperty(rt_, "name").toString(rt_).utf8(rt_) << ": "
|
|
188
|
-
<< object.getProperty(rt_, "message").toString(rt_).utf8(rt_) << ']';
|
|
189
|
-
return ss.str();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
std::string JSISerializer::stringifySet(const jsi::Object &object) {
|
|
193
|
-
std::stringstream ss;
|
|
194
|
-
jsi::Function arrayFrom = rt_.global()
|
|
195
|
-
.getPropertyAsObject(rt_, "Array")
|
|
196
|
-
.getPropertyAsFunction(rt_, "from");
|
|
197
|
-
jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
|
|
198
|
-
|
|
199
|
-
if (!result.isArray(rt_)) {
|
|
200
|
-
return "[Set]";
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
auto arr = result.asArray(rt_);
|
|
204
|
-
ss << "Set {";
|
|
205
|
-
|
|
206
|
-
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
207
|
-
ss << stringifyJSIValueRecursively(arr.getValueAtIndex(rt_, i));
|
|
208
|
-
if (i != length - 1) {
|
|
209
|
-
ss << ", ";
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
ss << '}';
|
|
214
|
-
|
|
215
|
-
return ss.str();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
std::string JSISerializer::stringifyMap(const jsi::Object &object) {
|
|
219
|
-
std::stringstream ss;
|
|
220
|
-
jsi::Function arrayFrom = rt_.global()
|
|
221
|
-
.getPropertyAsObject(rt_, "Array")
|
|
222
|
-
.getPropertyAsFunction(rt_, "from");
|
|
223
|
-
jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
|
|
224
|
-
|
|
225
|
-
if (!result.isArray(rt_)) {
|
|
226
|
-
return "[Map]";
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
auto arr = result.asArray(rt_);
|
|
230
|
-
ss << "Map {";
|
|
231
|
-
|
|
232
|
-
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
233
|
-
auto pair = arr.getValueAtIndex(rt_, i).asObject(rt_).getArray(rt_);
|
|
234
|
-
auto key = pair.getValueAtIndex(rt_, 0);
|
|
235
|
-
auto value = pair.getValueAtIndex(rt_, 1);
|
|
236
|
-
ss << stringifyJSIValueRecursively(key) << ": "
|
|
237
|
-
<< stringifyJSIValueRecursively(value);
|
|
238
|
-
if (i != length - 1) {
|
|
239
|
-
ss << ", ";
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
ss << '}';
|
|
244
|
-
|
|
245
|
-
return ss.str();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
std::string JSISerializer::stringifyRecursiveType(const jsi::Object &object) {
|
|
249
|
-
auto type = getObjectTypeName(rt_, object);
|
|
250
|
-
|
|
251
|
-
if (type == "Array") {
|
|
252
|
-
return "[...]";
|
|
253
|
-
}
|
|
254
|
-
if (type == "Object") {
|
|
255
|
-
return "{...}";
|
|
256
|
-
}
|
|
257
|
-
return "...";
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
std::string JSISerializer::stringifyWithToString(const jsi::Object &object) {
|
|
261
|
-
return object.getPropertyAsFunction(rt_, "toString")
|
|
262
|
-
.callWithThis(rt_, object)
|
|
263
|
-
.toString(rt_)
|
|
264
|
-
.utf8(rt_);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
std::string JSISerializer::stringifyJSIValueRecursively(
|
|
268
|
-
const jsi::Value &value,
|
|
269
|
-
bool isTopLevel) {
|
|
270
|
-
if (value.isBool() || value.isNumber()) {
|
|
271
|
-
return value.toString(rt_).utf8(rt_);
|
|
272
|
-
}
|
|
273
|
-
if (value.isString()) {
|
|
274
|
-
return isTopLevel ? value.getString(rt_).utf8(rt_)
|
|
275
|
-
: '"' + value.getString(rt_).utf8(rt_) + '"';
|
|
276
|
-
}
|
|
277
|
-
if (value.isSymbol()) {
|
|
278
|
-
return value.getSymbol(rt_).toString(rt_);
|
|
279
|
-
}
|
|
280
|
-
if (value.isBigInt()) {
|
|
281
|
-
return value.getBigInt(rt_).toString(rt_).utf8(rt_) + 'n';
|
|
282
|
-
}
|
|
283
|
-
if (value.isUndefined()) {
|
|
284
|
-
return "undefined";
|
|
285
|
-
}
|
|
286
|
-
if (value.isNull()) {
|
|
287
|
-
return "null";
|
|
288
|
-
}
|
|
289
|
-
if (value.isObject()) {
|
|
290
|
-
jsi::Object object = value.asObject(rt_);
|
|
291
|
-
|
|
292
|
-
if (hasBeenVisited(object)) {
|
|
293
|
-
return stringifyRecursiveType(object);
|
|
294
|
-
}
|
|
295
|
-
markAsVisited(object);
|
|
296
|
-
|
|
297
|
-
if (object.isArray(rt_)) {
|
|
298
|
-
return stringifyArray(object.getArray(rt_));
|
|
299
|
-
}
|
|
300
|
-
if (object.isFunction(rt_)) {
|
|
301
|
-
return stringifyFunction(object.getFunction(rt_));
|
|
302
|
-
}
|
|
303
|
-
if (object.isHostObject(rt_)) {
|
|
304
|
-
return stringifyHostObject(*object.getHostObject(rt_));
|
|
305
|
-
}
|
|
306
|
-
if (isInstanceOfAny(rt_, object, SUPPORTED_ERROR_TYPES)) {
|
|
307
|
-
return stringifyError(object);
|
|
308
|
-
}
|
|
309
|
-
if (isInstanceOfAny(rt_, object, SUPPORTED_INDEXED_COLLECTION_TYPES) ||
|
|
310
|
-
isInstanceOfAny(rt_, object, SUPPORTED_STRUCTURED_DATA_TYPES) ||
|
|
311
|
-
isInstanceOfAny(rt_, object, SUPPORTED_MANAGING_MEMORY_TYPES) ||
|
|
312
|
-
isInstanceOfAny(rt_, object, SUPPORTED_ABSTRACTION_OBJECT_TYPES) ||
|
|
313
|
-
isInstanceOfAny(rt_, object, SUPPORTED_REFLECTION_TYPES) ||
|
|
314
|
-
isInstanceOf(rt_, object, "Intl") ||
|
|
315
|
-
isInstanceOf(rt_, object, "WeakMap") ||
|
|
316
|
-
isInstanceOf(rt_, object, "WeakSet")) {
|
|
317
|
-
// TODO: Consider extending this log info
|
|
318
|
-
return stringifyWithName(object);
|
|
319
|
-
}
|
|
320
|
-
if (isInstanceOf(rt_, object, "Date") ||
|
|
321
|
-
isInstanceOf(rt_, object, "RegExp")) {
|
|
322
|
-
return stringifyWithToString(object);
|
|
323
|
-
}
|
|
324
|
-
if (isInstanceOf(rt_, object, "Map")) {
|
|
325
|
-
return stringifyMap(object);
|
|
326
|
-
}
|
|
327
|
-
if (isInstanceOf(rt_, object, "Set")) {
|
|
328
|
-
return stringifySet(object);
|
|
329
|
-
}
|
|
330
|
-
return stringifyObject(object);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
throw std::runtime_error("[Reanimated] Unsupported value type.");
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
std::string stringifyJSIValue(jsi::Runtime &rt, const jsi::Value &value) {
|
|
337
|
-
JSISerializer serializer(rt);
|
|
338
|
-
|
|
339
|
-
return serializer.stringifyJSIValueRecursively(value, true);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
} // namespace worklets
|
|
1
|
+
#include <worklets/Tools/JSISerializer.h>
|
|
2
|
+
|
|
3
|
+
#include <cxxabi.h>
|
|
4
|
+
#include <iostream>
|
|
5
|
+
#include <sstream>
|
|
6
|
+
|
|
7
|
+
namespace worklets {
|
|
8
|
+
|
|
9
|
+
const std::vector<std::string> SUPPORTED_ERROR_TYPES = {
|
|
10
|
+
"Error",
|
|
11
|
+
"AggregateError",
|
|
12
|
+
"EvalError",
|
|
13
|
+
"RangeError",
|
|
14
|
+
"ReferenceError",
|
|
15
|
+
"SyntaxError",
|
|
16
|
+
"TypeError",
|
|
17
|
+
"URIError",
|
|
18
|
+
"InternalError"};
|
|
19
|
+
|
|
20
|
+
const std::vector<std::string> SUPPORTED_INDEXED_COLLECTION_TYPES = {
|
|
21
|
+
"Int8Array",
|
|
22
|
+
"Uint8Array",
|
|
23
|
+
"Uint8ClampedArray",
|
|
24
|
+
"Int16Array",
|
|
25
|
+
"Uint16Array",
|
|
26
|
+
"Int32Array",
|
|
27
|
+
"Uint32Array",
|
|
28
|
+
"BigInt64Array",
|
|
29
|
+
"BigUint64Array",
|
|
30
|
+
"Float32Array",
|
|
31
|
+
"Float64Array",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const std::vector<std::string> SUPPORTED_STRUCTURED_DATA_TYPES = {
|
|
35
|
+
"ArrayBuffer",
|
|
36
|
+
"SharedArrayBuffer",
|
|
37
|
+
"DataView",
|
|
38
|
+
"Atomics",
|
|
39
|
+
"JSON",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const std::vector<std::string> SUPPORTED_MANAGING_MEMORY_TYPES = {
|
|
43
|
+
"WeakRef",
|
|
44
|
+
"FinalizationRegistry",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const std::vector<std::string> SUPPORTED_ABSTRACTION_OBJECT_TYPES = {
|
|
48
|
+
"Iterator",
|
|
49
|
+
"AsyncIterator",
|
|
50
|
+
"Promise",
|
|
51
|
+
"GeneratorFunction",
|
|
52
|
+
"AsyncGeneratorFunction",
|
|
53
|
+
"Generator",
|
|
54
|
+
"AsyncGenerator",
|
|
55
|
+
"AsyncFunction",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const std::vector<std::string> SUPPORTED_REFLECTION_TYPES = {
|
|
59
|
+
"Reflect",
|
|
60
|
+
"Proxy",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
static inline std::string getObjectTypeName(
|
|
64
|
+
jsi::Runtime &rt,
|
|
65
|
+
const jsi::Object &object) {
|
|
66
|
+
return object.getPropertyAsObject(rt, "constructor")
|
|
67
|
+
.getProperty(rt, "name")
|
|
68
|
+
.toString(rt)
|
|
69
|
+
.utf8(rt);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static inline bool isInstanceOf(
|
|
73
|
+
jsi::Runtime &rt,
|
|
74
|
+
const jsi::Object &object,
|
|
75
|
+
const std::string &type) {
|
|
76
|
+
return getObjectTypeName(rt, object) == type;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static inline bool isInstanceOfAny(
|
|
80
|
+
jsi::Runtime &rt,
|
|
81
|
+
const jsi::Object &object,
|
|
82
|
+
const std::vector<std::string> &supportedTypes) {
|
|
83
|
+
auto instanceType = getObjectTypeName(rt, object);
|
|
84
|
+
|
|
85
|
+
return std::find(
|
|
86
|
+
supportedTypes.begin(), supportedTypes.end(), instanceType) !=
|
|
87
|
+
supportedTypes.end();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
JSISerializer::JSISerializer(jsi::Runtime &rt)
|
|
91
|
+
: rt_(rt),
|
|
92
|
+
visitedNodes_(rt_.global()
|
|
93
|
+
.getPropertyAsFunction(rt_, "Set")
|
|
94
|
+
.callAsConstructor(rt_)
|
|
95
|
+
.asObject(rt_)) {}
|
|
96
|
+
|
|
97
|
+
std::string JSISerializer::stringifyWithName(const jsi::Object &object) {
|
|
98
|
+
std::stringstream ss;
|
|
99
|
+
ss << '[' << getObjectTypeName(rt_, object) << ']';
|
|
100
|
+
|
|
101
|
+
return ss.str();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
std::string JSISerializer::stringifyArray(const jsi::Array &arr) {
|
|
105
|
+
std::stringstream ss;
|
|
106
|
+
ss << '[';
|
|
107
|
+
|
|
108
|
+
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
109
|
+
jsi::Value element = arr.getValueAtIndex(rt_, i);
|
|
110
|
+
ss << stringifyJSIValueRecursively(element);
|
|
111
|
+
if (i != length - 1) {
|
|
112
|
+
ss << ", ";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
ss << ']';
|
|
117
|
+
|
|
118
|
+
return ss.str();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
std::string JSISerializer::stringifyFunction(const jsi::Function &func) {
|
|
122
|
+
std::stringstream ss;
|
|
123
|
+
auto kind = (func.isHostFunction(rt_) ? "jsi::HostFunction" : "Function");
|
|
124
|
+
auto name = func.getProperty(rt_, "name").toString(rt_).utf8(rt_);
|
|
125
|
+
name = name.empty() ? "anonymous" : name;
|
|
126
|
+
|
|
127
|
+
ss << '[' << kind << ' ' << name << ']';
|
|
128
|
+
return ss.str();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
std::string JSISerializer::stringifyHostObject(jsi::HostObject &hostObject) {
|
|
132
|
+
int status = -1;
|
|
133
|
+
char *hostObjClassName =
|
|
134
|
+
abi::__cxa_demangle(typeid(hostObject).name(), NULL, NULL, &status);
|
|
135
|
+
if (status != 0) {
|
|
136
|
+
return "[jsi::HostObject]";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
std::stringstream ss;
|
|
140
|
+
ss << "[jsi::HostObject(" << hostObjClassName << ")";
|
|
141
|
+
std::free(hostObjClassName);
|
|
142
|
+
|
|
143
|
+
auto props = hostObject.getPropertyNames(rt_);
|
|
144
|
+
auto propsCount = props.size();
|
|
145
|
+
|
|
146
|
+
if (propsCount > 0) {
|
|
147
|
+
ss << " {";
|
|
148
|
+
auto lastKey = props.back().utf8(rt_);
|
|
149
|
+
for (const auto &key : props) {
|
|
150
|
+
auto formattedKey = key.utf8(rt_);
|
|
151
|
+
auto value = hostObject.get(rt_, key);
|
|
152
|
+
ss << '"' << formattedKey << '"' << ": "
|
|
153
|
+
<< stringifyJSIValueRecursively(value);
|
|
154
|
+
if (formattedKey != lastKey) {
|
|
155
|
+
ss << ", ";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
ss << '}';
|
|
159
|
+
}
|
|
160
|
+
ss << ']';
|
|
161
|
+
|
|
162
|
+
return ss.str();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
std::string JSISerializer::stringifyObject(const jsi::Object &object) {
|
|
166
|
+
std::stringstream ss;
|
|
167
|
+
ss << '{';
|
|
168
|
+
|
|
169
|
+
auto props = object.getPropertyNames(rt_);
|
|
170
|
+
|
|
171
|
+
for (size_t i = 0, propsCount = props.size(rt_); i < propsCount; i++) {
|
|
172
|
+
jsi::String propName = props.getValueAtIndex(rt_, i).toString(rt_);
|
|
173
|
+
ss << '"' << propName.utf8(rt_) << '"' << ": "
|
|
174
|
+
<< stringifyJSIValueRecursively(object.getProperty(rt_, propName));
|
|
175
|
+
if (i != propsCount - 1) {
|
|
176
|
+
ss << ", ";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
ss << '}';
|
|
181
|
+
|
|
182
|
+
return ss.str();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
std::string JSISerializer::stringifyError(const jsi::Object &object) {
|
|
186
|
+
std::stringstream ss;
|
|
187
|
+
ss << '[' << object.getProperty(rt_, "name").toString(rt_).utf8(rt_) << ": "
|
|
188
|
+
<< object.getProperty(rt_, "message").toString(rt_).utf8(rt_) << ']';
|
|
189
|
+
return ss.str();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
std::string JSISerializer::stringifySet(const jsi::Object &object) {
|
|
193
|
+
std::stringstream ss;
|
|
194
|
+
jsi::Function arrayFrom = rt_.global()
|
|
195
|
+
.getPropertyAsObject(rt_, "Array")
|
|
196
|
+
.getPropertyAsFunction(rt_, "from");
|
|
197
|
+
jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
|
|
198
|
+
|
|
199
|
+
if (!result.isArray(rt_)) {
|
|
200
|
+
return "[Set]";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
auto arr = result.asArray(rt_);
|
|
204
|
+
ss << "Set {";
|
|
205
|
+
|
|
206
|
+
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
207
|
+
ss << stringifyJSIValueRecursively(arr.getValueAtIndex(rt_, i));
|
|
208
|
+
if (i != length - 1) {
|
|
209
|
+
ss << ", ";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
ss << '}';
|
|
214
|
+
|
|
215
|
+
return ss.str();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
std::string JSISerializer::stringifyMap(const jsi::Object &object) {
|
|
219
|
+
std::stringstream ss;
|
|
220
|
+
jsi::Function arrayFrom = rt_.global()
|
|
221
|
+
.getPropertyAsObject(rt_, "Array")
|
|
222
|
+
.getPropertyAsFunction(rt_, "from");
|
|
223
|
+
jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
|
|
224
|
+
|
|
225
|
+
if (!result.isArray(rt_)) {
|
|
226
|
+
return "[Map]";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
auto arr = result.asArray(rt_);
|
|
230
|
+
ss << "Map {";
|
|
231
|
+
|
|
232
|
+
for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
|
|
233
|
+
auto pair = arr.getValueAtIndex(rt_, i).asObject(rt_).getArray(rt_);
|
|
234
|
+
auto key = pair.getValueAtIndex(rt_, 0);
|
|
235
|
+
auto value = pair.getValueAtIndex(rt_, 1);
|
|
236
|
+
ss << stringifyJSIValueRecursively(key) << ": "
|
|
237
|
+
<< stringifyJSIValueRecursively(value);
|
|
238
|
+
if (i != length - 1) {
|
|
239
|
+
ss << ", ";
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ss << '}';
|
|
244
|
+
|
|
245
|
+
return ss.str();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
std::string JSISerializer::stringifyRecursiveType(const jsi::Object &object) {
|
|
249
|
+
auto type = getObjectTypeName(rt_, object);
|
|
250
|
+
|
|
251
|
+
if (type == "Array") {
|
|
252
|
+
return "[...]";
|
|
253
|
+
}
|
|
254
|
+
if (type == "Object") {
|
|
255
|
+
return "{...}";
|
|
256
|
+
}
|
|
257
|
+
return "...";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
std::string JSISerializer::stringifyWithToString(const jsi::Object &object) {
|
|
261
|
+
return object.getPropertyAsFunction(rt_, "toString")
|
|
262
|
+
.callWithThis(rt_, object)
|
|
263
|
+
.toString(rt_)
|
|
264
|
+
.utf8(rt_);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
std::string JSISerializer::stringifyJSIValueRecursively(
|
|
268
|
+
const jsi::Value &value,
|
|
269
|
+
bool isTopLevel) {
|
|
270
|
+
if (value.isBool() || value.isNumber()) {
|
|
271
|
+
return value.toString(rt_).utf8(rt_);
|
|
272
|
+
}
|
|
273
|
+
if (value.isString()) {
|
|
274
|
+
return isTopLevel ? value.getString(rt_).utf8(rt_)
|
|
275
|
+
: '"' + value.getString(rt_).utf8(rt_) + '"';
|
|
276
|
+
}
|
|
277
|
+
if (value.isSymbol()) {
|
|
278
|
+
return value.getSymbol(rt_).toString(rt_);
|
|
279
|
+
}
|
|
280
|
+
if (value.isBigInt()) {
|
|
281
|
+
return value.getBigInt(rt_).toString(rt_).utf8(rt_) + 'n';
|
|
282
|
+
}
|
|
283
|
+
if (value.isUndefined()) {
|
|
284
|
+
return "undefined";
|
|
285
|
+
}
|
|
286
|
+
if (value.isNull()) {
|
|
287
|
+
return "null";
|
|
288
|
+
}
|
|
289
|
+
if (value.isObject()) {
|
|
290
|
+
jsi::Object object = value.asObject(rt_);
|
|
291
|
+
|
|
292
|
+
if (hasBeenVisited(object)) {
|
|
293
|
+
return stringifyRecursiveType(object);
|
|
294
|
+
}
|
|
295
|
+
markAsVisited(object);
|
|
296
|
+
|
|
297
|
+
if (object.isArray(rt_)) {
|
|
298
|
+
return stringifyArray(object.getArray(rt_));
|
|
299
|
+
}
|
|
300
|
+
if (object.isFunction(rt_)) {
|
|
301
|
+
return stringifyFunction(object.getFunction(rt_));
|
|
302
|
+
}
|
|
303
|
+
if (object.isHostObject(rt_)) {
|
|
304
|
+
return stringifyHostObject(*object.getHostObject(rt_));
|
|
305
|
+
}
|
|
306
|
+
if (isInstanceOfAny(rt_, object, SUPPORTED_ERROR_TYPES)) {
|
|
307
|
+
return stringifyError(object);
|
|
308
|
+
}
|
|
309
|
+
if (isInstanceOfAny(rt_, object, SUPPORTED_INDEXED_COLLECTION_TYPES) ||
|
|
310
|
+
isInstanceOfAny(rt_, object, SUPPORTED_STRUCTURED_DATA_TYPES) ||
|
|
311
|
+
isInstanceOfAny(rt_, object, SUPPORTED_MANAGING_MEMORY_TYPES) ||
|
|
312
|
+
isInstanceOfAny(rt_, object, SUPPORTED_ABSTRACTION_OBJECT_TYPES) ||
|
|
313
|
+
isInstanceOfAny(rt_, object, SUPPORTED_REFLECTION_TYPES) ||
|
|
314
|
+
isInstanceOf(rt_, object, "Intl") ||
|
|
315
|
+
isInstanceOf(rt_, object, "WeakMap") ||
|
|
316
|
+
isInstanceOf(rt_, object, "WeakSet")) {
|
|
317
|
+
// TODO: Consider extending this log info
|
|
318
|
+
return stringifyWithName(object);
|
|
319
|
+
}
|
|
320
|
+
if (isInstanceOf(rt_, object, "Date") ||
|
|
321
|
+
isInstanceOf(rt_, object, "RegExp")) {
|
|
322
|
+
return stringifyWithToString(object);
|
|
323
|
+
}
|
|
324
|
+
if (isInstanceOf(rt_, object, "Map")) {
|
|
325
|
+
return stringifyMap(object);
|
|
326
|
+
}
|
|
327
|
+
if (isInstanceOf(rt_, object, "Set")) {
|
|
328
|
+
return stringifySet(object);
|
|
329
|
+
}
|
|
330
|
+
return stringifyObject(object);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
throw std::runtime_error("[Reanimated] Unsupported value type.");
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
std::string stringifyJSIValue(jsi::Runtime &rt, const jsi::Value &value) {
|
|
337
|
+
JSISerializer serializer(rt);
|
|
338
|
+
|
|
339
|
+
return serializer.stringifyJSIValueRecursively(value, true);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
} // namespace worklets
|