Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getJSValue in favor of toJSValue #6042

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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
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
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
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
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
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
Loading