#include "WorkletsCache.h" #include "FrozenObject.h" #include "ShareableValue.h" #include #include using namespace facebook; namespace reanimated { jsi::Value eval(jsi::Runtime &rt, const char *code) { return rt.global().getPropertyAsFunction(rt, "eval").call(rt, code); } jsi::Function function(jsi::Runtime &rt, const std::string &code) { return eval(rt, ("(" + code + ")").c_str()).getObject(rt).getFunction(rt); } std::shared_ptr WorkletsCache::getFunction( jsi::Runtime &rt, std::shared_ptr frozenObj) { long long workletHash = ValueWrapper::asNumber(frozenObj->map["__workletHash"]->valueContainer); if (worklets.count(workletHash) == 0) { auto codeBuffer = std::make_shared( "(" + ValueWrapper::asString(frozenObj->map["asString"]->valueContainer) + ")"); auto func = rt.evaluateJavaScript( codeBuffer, ValueWrapper::asString( frozenObj->map["__location"]->valueContainer)) .asObject(rt) .asFunction(rt); worklets[workletHash] = std::make_shared(std::move(func)); } return worklets[workletHash]; } } // namespace reanimated