1 #include "FrozenObject.h"
2 #include "RuntimeManager.h"
3 #include "ShareableValue.h"
4 #include "SharedParent.h"
5
6 namespace reanimated {
7
FrozenObject(jsi::Runtime & rt,const jsi::Object & object,RuntimeManager * runtimeManager)8 FrozenObject::FrozenObject(
9 jsi::Runtime &rt,
10 const jsi::Object &object,
11 RuntimeManager *runtimeManager) {
12 auto propertyNames = object.getPropertyNames(rt);
13 const size_t count = propertyNames.size(rt);
14 namesOrder.reserve(count);
15 for (size_t i = 0; i < count; i++) {
16 auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt);
17 namesOrder.push_back(propertyName.utf8(rt));
18 std::string nameStr = propertyName.utf8(rt);
19 map[nameStr] = ShareableValue::adapt(
20 rt, object.getProperty(rt, propertyName), runtimeManager);
21 this->containsHostFunction |= map[nameStr]->containsHostFunction;
22 }
23 }
24
shallowClone(jsi::Runtime & rt)25 jsi::Object FrozenObject::shallowClone(jsi::Runtime &rt) {
26 jsi::Object object(rt);
27 for (auto propName : namesOrder) {
28 auto value = map[propName];
29 object.setProperty(
30 rt, jsi::String::createFromUtf8(rt, propName), value->getValue(rt));
31 }
32 return object;
33 }
34
35 } // namespace reanimated
36