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