Skip to content

Commit

Permalink
Remove getJSValue in favor of toJSValue
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed May 23, 2024
1 parent e661676 commit 02cd112
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void LayoutAnimationsManager::startLayoutAnimation(
jsi::Value(tag),
jsi::Value(static_cast<int>(type)),
values,
config->getJSValue(rt));
config->toJSValue(rt));
}

void LayoutAnimationsManager::cancelLayoutAnimation(
Expand Down
2 changes: 1 addition & 1 deletion Common/cpp/ReanimatedRuntime/WorkletRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jsi::Value WorkletRuntime::executeSync(
auto result = runGuarded(shareableWorklet);
auto shareableResult = extractShareableOrThrow(uiRuntime, result);
lock.unlock();
return shareableResult->getJSValue(rt);
return shareableResult->toJSValue(rt);
}

jsi::Value WorkletRuntime::get(
Expand Down
2 changes: 1 addition & 1 deletion Common/cpp/ReanimatedRuntime/WorkletRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WorkletRuntime : public jsi::HostObject,
Args &&...args) const {
jsi::Runtime &rt = *runtime_;
return runOnRuntimeGuarded(
rt, shareableWorklet->getJSValue(rt), std::forward<Args>(args)...);
rt, shareableWorklet->toJSValue(rt), std::forward<Args>(args)...);
}

void runAsyncGuarded(
Expand Down
4 changes: 2 additions & 2 deletions Common/cpp/ReanimatedRuntime/WorkletRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ void WorkletRuntimeDecorator::decorate(
: extractShareableOrThrow<ShareableArray>(
rt, argsValue, "[Reanimated] Args must be an array.");
jsScheduler->scheduleOnJS([=](jsi::Runtime &rt) {
auto remoteFun = shareableRemoteFun->getJSValue(rt);
auto remoteFun = shareableRemoteFun->toJSValue(rt);
if (shareableArgs == nullptr) {
// fast path for remote function w/o arguments
remoteFun.asObject(rt).asFunction(rt).call(rt);
} else {
auto argsArray =
shareableArgs->getJSValue(rt).asObject(rt).asArray(rt);
shareableArgs->toJSValue(rt).asObject(rt).asArray(rt);
auto argsSize = argsArray.size(rt);
// number of arguments is typically relatively small so it is ok to
// to use VLAs here, hence disabling the lint rule
Expand Down
8 changes: 4 additions & 4 deletions Common/cpp/SharedItems/Shareables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ std::shared_ptr<Shareable> Shareable::undefined() {
}

template <typename BaseClass>
jsi::Value RetainingShareable<BaseClass>::getJSValue(jsi::Runtime &rt) {
jsi::Value RetainingShareable<BaseClass>::toJSValue(jsi::Runtime &rt) {
if (&rt == primaryRuntime_) {
// TODO: it is suboptimal to generate new object every time getJS is
// called on host runtime – the objects we are generating already exists
Expand Down Expand Up @@ -172,7 +172,7 @@ jsi::Value ShareableArray::toJSValue(jsi::Runtime &rt) {
auto size = data_.size();
auto ary = jsi::Array(rt, size);
for (size_t i = 0; i < size; i++) {
ary.setValueAtIndex(rt, i, data_[i]->getJSValue(rt));
ary.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
}
return ary;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) {
auto obj = jsi::Object(rt);
for (size_t i = 0, size = data_.size(); i < size; i++) {
obj.setProperty(
rt, data_[i].first.c_str(), data_[i].second->getJSValue(rt));
rt, data_[i].first.c_str(), data_[i].second->toJSValue(rt));
}
if (nativeState_ != nullptr) {
obj.setNativeState(rt, nativeState_);
Expand Down Expand Up @@ -265,7 +265,7 @@ jsi::Value ShareableRemoteFunction::toJSValue(jsi::Runtime &rt) {

jsi::Value ShareableHandle::toJSValue(jsi::Runtime &rt) {
if (remoteValue_ == nullptr) {
auto initObj = initializer_->getJSValue(rt);
auto initObj = initializer_->toJSValue(rt);
auto value = std::make_unique<jsi::Value>(getValueUnpacker(rt).call(
rt, initObj, jsi::String::createFromAscii(rt, "Handle")));

Expand Down
9 changes: 2 additions & 7 deletions Common/cpp/SharedItems/Shareables.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ inline void cleanupIfRuntimeExists(
}

class Shareable {
protected:
public:
virtual jsi::Value toJSValue(jsi::Runtime &rt) = 0;

public:
virtual ~Shareable();

enum ValueType {
Expand All @@ -88,10 +87,6 @@ class Shareable {

explicit Shareable(ValueType valueType) : valueType_(valueType) {}

virtual jsi::Value getJSValue(jsi::Runtime &rt) {
return toJSValue(rt);
}

inline ValueType valueType() const {
return valueType_;
}
Expand All @@ -114,7 +109,7 @@ class RetainingShareable : virtual public BaseClass {
explicit RetainingShareable(jsi::Runtime &rt, Args &&...args)
: BaseClass(rt, std::forward<Args>(args)...), primaryRuntime_(&rt) {}

jsi::Value getJSValue(jsi::Runtime &rt);
jsi::Value toJSValue(jsi::Runtime &rt);

~RetainingShareable() {
cleanupIfRuntimeExists(secondaryRuntime_, secondaryValue_);
Expand Down

0 comments on commit 02cd112

Please sign in to comment.