-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix runtime creation #1960
Closed
Closed
Fix runtime creation #1960
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ddf8bf
Connect to flipper
piaskowyk 7a8ae54
Separated runtimes
piaskowyk 4734871
Added runtime provider
piaskowyk 0675b8d
Clean up in C++
piaskowyk fdcdff3
Clean up in Java
piaskowyk a4a67a7
Universal runtime support
piaskowyk 0b07031
Clean up
piaskowyk a216e54
isDebuggable check
piaskowyk 01817f2
Remove unused lib import
piaskowyk 0b07f92
Fix typo
piaskowyk e2c7e2b
Merge with master
piaskowyk 5e586ee
Update cmake
piaskowyk ecf4ebe
Update lib order
piaskowyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "RuntimeProvider.h" | ||
|
||
#include <hermes/hermes.h> | ||
|
||
namespace reanimated | ||
{ | ||
|
||
std::shared_ptr<jsi::Runtime> RuntimeProvider::createRuntime( | ||
JavaScriptExecutorHolder* javaScriptExecutor, | ||
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread, | ||
bool isDebug, | ||
int runtimeType | ||
) { | ||
|
||
if(runtimeType == 1) { // JSC, V8 | ||
std::shared_ptr<ExecutorDelegate> delegate = std::shared_ptr<ExecutorDelegate>(); | ||
auto jsQueue = std::make_shared<JMessageQueueThread>(messageQueueThread); | ||
factory = javaScriptExecutor->getExecutorFactory(); | ||
executor = factory.get()->createJSExecutor(delegate, jsQueue); | ||
std::shared_ptr<jsi::Runtime> runtimeShared; | ||
runtimeShared.reset(static_cast<jsi::Runtime*>(executor.get()->getJavaScriptContext())); | ||
return runtimeShared; | ||
} | ||
|
||
// Hermes | ||
std::shared_ptr<jsi::Runtime> runtimeShared; | ||
std::unique_ptr<facebook::hermes::HermesRuntime> runtime = facebook::hermes::makeHermesRuntime(); | ||
if(isDebug) { | ||
auto jsQueue = std::make_shared<JMessageQueueThread>(messageQueueThread); | ||
SystraceSection s("RuntimeProvider::createRuntime"); | ||
facebook::hermes::HermesRuntime &hermesRuntimeRef = *runtime; | ||
auto adapter = std::make_unique<HermesExecutorRuntimeAdapter>(std::move(runtime), hermesRuntimeRef, jsQueue); | ||
runtimeShared = adapter->runtime_; | ||
facebook::hermes::inspector::chrome::enableDebugging(std::move(adapter), "Reanimated Runtime"); | ||
} | ||
else { | ||
runtimeShared = std::move(runtime); | ||
} | ||
return runtimeShared; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
android/src/main/cpp/headers/HermesExecutorRuntimeAdapter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <hermes/hermes.h> | ||
#include <hermes/inspector/RuntimeAdapter.h> | ||
#include <hermes/inspector/chrome/Registration.h> | ||
|
||
namespace reanimated { | ||
|
||
using namespace facebook; | ||
using namespace react; | ||
|
||
class HermesExecutorRuntimeAdapter : public facebook::hermes::inspector::RuntimeAdapter { | ||
public: | ||
HermesExecutorRuntimeAdapter( | ||
std::shared_ptr<facebook::jsi::Runtime> runtime, | ||
facebook::hermes::HermesRuntime &hermesRuntime, | ||
std::shared_ptr<MessageQueueThread> thread) | ||
: runtime_(runtime), | ||
hermesRuntime_(hermesRuntime), | ||
thread_(std::move(thread)) {} | ||
|
||
virtual ~HermesExecutorRuntimeAdapter() = default; | ||
|
||
facebook::jsi::Runtime &getRuntime() override { | ||
return *runtime_; | ||
} | ||
|
||
facebook::hermes::debugger::Debugger &getDebugger() override { | ||
return hermesRuntime_.getDebugger(); | ||
} | ||
|
||
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); | ||
}); | ||
} | ||
|
||
public: | ||
std::shared_ptr<facebook::jsi::Runtime> runtime_; | ||
facebook::hermes::HermesRuntime &hermesRuntime_; | ||
|
||
std::shared_ptr<MessageQueueThread> thread_; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <fbjni/fbjni.h> | ||
#include <jsi/jsi.h> | ||
#include <cxxreact/NativeToJsBridge.h> | ||
#include <cxxreact/MessageQueueThread.h> | ||
#include <cxxreact/SystraceSection.h> | ||
#include "NativeProxy.h" | ||
#include <hermes/inspector/RuntimeAdapter.h> | ||
#include <hermes/inspector/chrome/Registration.h> | ||
|
||
namespace reanimated | ||
{ | ||
|
||
class RuntimeProvider { | ||
public: | ||
RuntimeProvider() {} | ||
~RuntimeProvider() {} | ||
|
||
std::shared_ptr<JSExecutorFactory> factory; | ||
std::unique_ptr<JSExecutor> executor; | ||
|
||
std::shared_ptr<jsi::Runtime> createRuntime( | ||
JavaScriptExecutorHolder* javaScriptExecutor, | ||
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread, | ||
bool isDebug, | ||
int runtimeType | ||
); | ||
|
||
}; | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Hermes inspector is available only in debug build so we cannot merge this in the current shape.