-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching UWP react native instance to use JSI (#2485)
* Switching UWP SampleApplication to use JSI * Update ChakraJsiRuntime.h * Integration ChakraJsiRuntime with desktop integration tests and fixing the logging
- Loading branch information
1 parent
a366955
commit 761e2e7
Showing
15 changed files
with
270 additions
and
22 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "pch.h" | ||
|
||
#include "ChakraJSIRuntimeHolder.h" | ||
|
||
#include <Chakra/ChakraJsiRuntimeFactory.h> | ||
|
||
using namespace facebook; | ||
using namespace facebook::react; | ||
using namespace facebook::jsi::chakraruntime; | ||
|
||
namespace facebook { | ||
namespace react { | ||
namespace test { | ||
|
||
std::shared_ptr<facebook::jsi::Runtime> ChakraJSIRuntimeHolder::getRuntime() noexcept { | ||
std::call_once(once_flag_, [this]() { initRuntime(); }); | ||
|
||
if (!runtime_) std::terminate(); | ||
|
||
// ChakraJsiRuntime is not thread safe as of now. | ||
if (own_thread_id_ != std::this_thread::get_id()) std::terminate(); | ||
|
||
return runtime_; | ||
} | ||
|
||
void ChakraJSIRuntimeHolder::initRuntime() noexcept { | ||
runtime_ = facebook::jsi::chakraruntime::makeChakraJsiRuntime(std::move(args_)); | ||
own_thread_id_ = std::this_thread::get_id(); | ||
} | ||
|
||
Logger ChakraJSIRuntimeHolder::ChakraRuntimeLoggerFromReactLogger(facebook::react::NativeLoggingHook loggingCallback) noexcept | ||
{ | ||
return[loggingCallback = std::move(loggingCallback)](const char* message, LogLevel logLevel) -> void | ||
{ | ||
loggingCallback(static_cast<facebook::react::RCTLogLevel>(logLevel), message); | ||
}; | ||
} | ||
|
||
ChakraJsiRuntimeArgs ChakraJSIRuntimeHolder::RuntimeArgsFromDevSettings(std::shared_ptr<facebook::react::DevSettings> devSettings) noexcept | ||
{ | ||
ChakraJsiRuntimeArgs runtimeArgs; | ||
|
||
runtimeArgs.debuggerBreakOnNextLine = devSettings->debuggerBreakOnNextLine; | ||
runtimeArgs.debuggerPort = devSettings->debuggerPort; | ||
runtimeArgs.debuggerRuntimeName = devSettings->debuggerRuntimeName; | ||
|
||
runtimeArgs.enableDebugging = devSettings->useDirectDebugger; | ||
|
||
if (devSettings->loggingCallback) { | ||
runtimeArgs.loggingCallback = ChakraRuntimeLoggerFromReactLogger(devSettings->loggingCallback); | ||
} | ||
|
||
runtimeArgs.enableNativePerformanceNow = devSettings->enableNativePerformanceNow; | ||
|
||
runtimeArgs.enableJITCompilation = devSettings->useJITCompilation; | ||
|
||
runtimeArgs.memoryTracker = devSettings->memoryTracker; | ||
|
||
return runtimeArgs; | ||
} | ||
|
||
}}} |
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,44 @@ | ||
#pragma once | ||
|
||
#include <DevSettings.h> | ||
|
||
#include <jsi/ScriptStore.h> | ||
#include <jsi/RuntimeHolder.h> | ||
|
||
#include <Chakra/ChakraJsiRuntimeArgs.h> | ||
|
||
#include <Logging.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
namespace test { | ||
|
||
class ChakraJSIRuntimeHolder : public facebook::jsi::RuntimeHolderLazyInit { | ||
public: | ||
std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override; | ||
|
||
ChakraJSIRuntimeHolder(std::shared_ptr<facebook::react::DevSettings> devSettings, | ||
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue, | ||
std::unique_ptr<facebook::jsi::ScriptStore>&& scriptStore, | ||
std::unique_ptr<facebook::jsi::PreparedScriptStore>&& preparedScriptStore) noexcept | ||
: args_(RuntimeArgsFromDevSettings(devSettings)) { | ||
args_.jsQueue = std::move(jsQueue); | ||
args_.scriptStore = std::move(scriptStore); | ||
args_.preparedScriptStore = std::move(preparedScriptStore); | ||
} | ||
|
||
private: | ||
facebook::jsi::chakraruntime::ChakraJsiRuntimeArgs RuntimeArgsFromDevSettings(std::shared_ptr<facebook::react::DevSettings> devSettings) noexcept; | ||
facebook::jsi::chakraruntime::Logger ChakraRuntimeLoggerFromReactLogger(facebook::react::NativeLoggingHook loggingCallback) noexcept; | ||
|
||
void initRuntime() noexcept; | ||
|
||
facebook::jsi::chakraruntime::ChakraJsiRuntimeArgs args_; | ||
std::shared_ptr<facebook::jsi::Runtime> runtime_; | ||
|
||
std::once_flag once_flag_; | ||
std::thread::id own_thread_id_; | ||
|
||
}; | ||
|
||
}}} |
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,61 @@ | ||
#include "pch.h" | ||
|
||
#include "ChakraJSIRuntimeHolder.h" | ||
|
||
#include <Chakra/ChakraJsiRuntimeFactory.h> | ||
|
||
using namespace facebook; | ||
using namespace facebook::react; | ||
using namespace facebook::jsi::chakraruntime; | ||
|
||
namespace react { | ||
namespace uwp { | ||
|
||
std::shared_ptr<facebook::jsi::Runtime> ChakraJSIRuntimeHolder::getRuntime() noexcept { | ||
std::call_once(once_flag_, [this]() { initRuntime(); }); | ||
|
||
if (!runtime_) std::terminate(); | ||
|
||
// ChakraJsiRuntime is not thread safe as of now. | ||
if (own_thread_id_ != std::this_thread::get_id()) std::terminate(); | ||
|
||
return runtime_; | ||
} | ||
|
||
void ChakraJSIRuntimeHolder::initRuntime() noexcept { | ||
runtime_ = facebook::jsi::chakraruntime::makeChakraJsiRuntime(std::move(args_)); | ||
own_thread_id_ = std::this_thread::get_id(); | ||
} | ||
|
||
Logger ChakraJSIRuntimeHolder::ChakraRuntimeLoggerFromReactLogger(facebook::react::NativeLoggingHook loggingCallback) noexcept | ||
{ | ||
return[loggingCallback = std::move(loggingCallback)](const char* message, LogLevel logLevel) -> void | ||
{ | ||
loggingCallback(static_cast<facebook::react::RCTLogLevel>(logLevel), message); | ||
}; | ||
} | ||
|
||
ChakraJsiRuntimeArgs ChakraJSIRuntimeHolder::RuntimeArgsFromDevSettings(std::shared_ptr<facebook::react::DevSettings> devSettings) noexcept | ||
{ | ||
ChakraJsiRuntimeArgs runtimeArgs; | ||
|
||
runtimeArgs.debuggerBreakOnNextLine = devSettings->debuggerBreakOnNextLine; | ||
runtimeArgs.debuggerPort = devSettings->debuggerPort; | ||
runtimeArgs.debuggerRuntimeName = devSettings->debuggerRuntimeName; | ||
|
||
runtimeArgs.enableDebugging = devSettings->useDirectDebugger; | ||
|
||
if (devSettings->loggingCallback) { | ||
runtimeArgs.loggingCallback = ChakraRuntimeLoggerFromReactLogger(devSettings->loggingCallback); | ||
} | ||
|
||
runtimeArgs.enableNativePerformanceNow = devSettings->enableNativePerformanceNow; | ||
|
||
runtimeArgs.enableJITCompilation = devSettings->useJITCompilation; | ||
|
||
runtimeArgs.memoryTracker = devSettings->memoryTracker; | ||
|
||
return runtimeArgs; | ||
} | ||
|
||
}} |
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,43 @@ | ||
#pragma once | ||
|
||
#include <DevSettings.h> | ||
|
||
#include <jsi/ScriptStore.h> | ||
#include <jsi/RuntimeHolder.h> | ||
|
||
#include <Chakra/ChakraJsiRuntimeArgs.h> | ||
|
||
#include <Logging.h> | ||
|
||
namespace react { | ||
namespace uwp { | ||
|
||
class ChakraJSIRuntimeHolder : public facebook::jsi::RuntimeHolderLazyInit { | ||
public: | ||
std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override; | ||
|
||
ChakraJSIRuntimeHolder(std::shared_ptr<facebook::react::DevSettings> devSettings, | ||
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue, | ||
std::unique_ptr<facebook::jsi::ScriptStore>&& scriptStore, | ||
std::unique_ptr<facebook::jsi::PreparedScriptStore>&& preparedScriptStore) noexcept | ||
: args_(RuntimeArgsFromDevSettings(devSettings)) { | ||
args_.jsQueue = std::move(jsQueue); | ||
args_.scriptStore = std::move(scriptStore); | ||
args_.preparedScriptStore = std::move(preparedScriptStore); | ||
} | ||
|
||
private: | ||
facebook::jsi::chakraruntime::ChakraJsiRuntimeArgs RuntimeArgsFromDevSettings(std::shared_ptr<facebook::react::DevSettings> devSettings) noexcept; | ||
facebook::jsi::chakraruntime::Logger ChakraRuntimeLoggerFromReactLogger(facebook::react::NativeLoggingHook loggingCallback) noexcept; | ||
|
||
void initRuntime() noexcept; | ||
|
||
facebook::jsi::chakraruntime::ChakraJsiRuntimeArgs args_; | ||
std::shared_ptr<facebook::jsi::Runtime> runtime_; | ||
|
||
std::once_flag once_flag_; | ||
std::thread::id own_thread_id_; | ||
|
||
}; | ||
|
||
}} |
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
Oops, something went wrong.