Skip to content

Commit

Permalink
make runtime reference thread safe on tickleJs call
Browse files Browse the repository at this point in the history
Summary:
The reference to runtime assumes the queue will ensure references to runtime are valid when invoked. This
isn't the case if you create a breakpoint, Hermes hit that breakpoint and your refresh the app. This consistently
will crash the app.

The fix is to not assument this, similar to ReactCommon/react/runtime/hermes/HermesInstance.cpp

Reviewed By: javache

Differential Revision: D50225678

fbshipit-source-id: b45cae1f5f687bc8c699fd74b187376a547012c5
  • Loading branch information
blakef authored and facebook-github-bot committed Oct 12, 2023
1 parent 11d9b9c commit 067c989
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ class HermesExecutorRuntimeAdapter
}

void tickleJs() override {
// The queue will ensure that runtime_ is still valid when this
// gets invoked.
thread_->runOnQueue([&runtime = runtime_]() {
auto func =
runtime->global().getPropertyAsFunction(*runtime, "__tickleJs");
func.call(*runtime);
});
thread_->runOnQueue(
[weakRuntime = std::weak_ptr<HermesRuntime>(runtime_)]() {
auto runtime = weakRuntime.lock();
if (!runtime) {
return;
}
jsi::Function func =
runtime->global().getPropertyAsFunction(*runtime, "__tickleJs");
func.call(*runtime);
});
}

private:
Expand Down

0 comments on commit 067c989

Please sign in to comment.