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