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

add react-native 0.70 support #139

Merged
merged 4 commits into from
Sep 11, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:
runs-on: macos-10.15
strategy:
matrix:
rn-version: [0.69, 0.68]
rn-version: ['0.70', '0.69']
v8-android-variant:
[v8-android-jit, v8-android-jit-nointl, v8-android, v8-android-nointl]
include:
- rn-version: '0.68'
v8-android-variant: v8-android-jit

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/cpp/V8ExecutorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace rnv8 {
namespace {

std::unique_ptr<jsi::Runtime> makeV8RuntimeSystraced(
std::unique_ptr<V8RuntimeConfig> config,
std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<react::MessageQueueThread> jsQueue) {
react::SystraceSection s("V8ExecutorFactory::makeV8RuntimeSystraced");
return createV8Runtime(std::move(config), jsQueue);
Expand Down
1 change: 1 addition & 0 deletions scripts/lib/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _patch_app_gradle(self):
with io.open(app_gradle_path, "r", encoding="utf8") as f:
content = str(f.read())
new_content = self._get_patched_packging_option(content)
new_content = new_content.replace("enableHermes: true", "enableHermes: false")
with io.open(app_gradle_path, "w", encoding="utf8") as f:
f.write(new_content)

Expand Down
17 changes: 9 additions & 8 deletions src/v8runtime/V8Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ InspectorClient::InspectorClient(
v8::Local<v8::Context> context,
const std::string &appName,
const std::string &deviceName) {
jsQueue_ = jsQueue;
jsQueue_ = jsQueue;
isolate_ = context->GetIsolate();
v8::HandleScope scopedHandle(isolate_);
channel_.reset(new InspectorFrontend(this, context));
Expand Down Expand Up @@ -246,15 +246,16 @@ void InspectorClient::DispatchProxy(const std::string &message) {
auto messageObj = folly::parseJson(message);
auto method = messageObj["method"].asString();

// For `v8::CpuProfiler` or some other modules with thread local storage, we should dispatch messages in the js thread.
// For `v8::CpuProfiler` or some other modules with thread local storage, we
// should dispatch messages in the js thread.
if (method == "Profiler.start" || method == "Profiler.stop") {
jsQueue_->runOnQueue([this, normalizedString]() {
v8::Isolate *isolate = GetIsolate();
v8::Locker locker(isolate);
v8::Isolate::Scope scopedIsolate(isolate);
v8::HandleScope scopedHandle(isolate);
v8::Context::Scope scopedContext(GetContext().Get(isolate));
session_->dispatchProtocolMessage(ToStringView(normalizedString));
v8::Isolate *isolate = GetIsolate();
v8::Locker locker(isolate);
v8::Isolate::Scope scopedIsolate(isolate);
v8::HandleScope scopedHandle(isolate);
v8::Context::Scope scopedContext(GetContext().Get(isolate));
session_->dispatchProtocolMessage(ToStringView(normalizedString));
});
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/v8runtime/V8Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include <condition_variable>
#include <cxxreact/MessageQueueThread.h>
#include <condition_variable>
#include "jsinspector/InspectorInterfaces.h"
#include "v8-inspector.h"

Expand Down
55 changes: 51 additions & 4 deletions src/v8runtime/V8Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const char kHostFunctionProxyProp[] = "__hostFunctionProxy";
std::unique_ptr<v8::Platform> V8Runtime::s_platform = nullptr;
std::mutex s_platform_mutex; // protects s_platform

V8Runtime::V8Runtime(std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue)
V8Runtime::V8Runtime(
std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue)
: config_(std::move(config)) {
{
const std::lock_guard<std::mutex> lock(s_platform_mutex);
Expand Down Expand Up @@ -70,7 +71,10 @@ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue)
jsQueue_ = jsQueue;
if (config_->enableInspector) {
inspectorClient_ = std::make_shared<InspectorClient>(
jsQueue_, context_.Get(isolate_), config_->appName, config_->deviceName);
jsQueue_,
context_.Get(isolate_),
config_->appName,
config_->deviceName);
inspectorClient_->ConnectToReactFrontend();
}
}
Expand Down Expand Up @@ -108,7 +112,10 @@ V8Runtime::V8Runtime(

if (config_->enableInspector) {
inspectorClient_ = std::make_shared<InspectorClient>(
jsQueue_, context_.Get(isolate_), config_->appName, config_->deviceName);
jsQueue_,
context_.Get(isolate_),
config_->appName,
config_->deviceName);
inspectorClient_->ConnectToReactFrontend();
}
}
Expand Down Expand Up @@ -486,6 +493,25 @@ jsi::Runtime::PointerValue *V8Runtime::cloneSymbol(
return new V8PointerValue(isolate_, v8PointerValue->Get(isolate_));
}

#if REACT_NATIVE_TARGET_VERSION >= 70
jsi::Runtime::PointerValue *V8Runtime::cloneBigInt(
const Runtime::PointerValue *pv) {
if (!pv) {
return nullptr;
}

v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
v8::HandleScope scopedHandle(isolate_);
v8::Context::Scope scopedContext(context_.Get(isolate_));

const V8PointerValue *v8PointerValue =
static_cast<const V8PointerValue *>(pv);
assert(v8PointerValue->Get(isolate_)->IsBigInt());
return new V8PointerValue(isolate_, v8PointerValue->Get(isolate_));
}
#endif

jsi::Runtime::PointerValue *V8Runtime::cloneString(
const Runtime::PointerValue *pv) {
if (!pv) {
Expand Down Expand Up @@ -1244,6 +1270,27 @@ bool V8Runtime::strictEquals(const jsi::Symbol &a, const jsi::Symbol &b) const {
return result;
}

#if REACT_NATIVE_TARGET_VERSION >= 70
bool V8Runtime::strictEquals(const jsi::BigInt &a, const jsi::BigInt &b) const {
v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
v8::HandleScope scopedHandle(isolate_);
v8::Context::Scope scopedContext(context_.Get(isolate_));

v8::TryCatch tryCatch(isolate_);
v8::Local<v8::Value> v8ValueA =
(static_cast<const V8PointerValue *>(getPointerValue(a)))->Get(isolate_);
v8::Local<v8::Value> v8ValueB =
(static_cast<const V8PointerValue *>(getPointerValue(b)))->Get(isolate_);
bool result = v8ValueA->StrictEquals(v8ValueB);

if (tryCatch.HasCaught()) {
ReportException(isolate_, &tryCatch);
}
return result;
}
#endif

bool V8Runtime::strictEquals(const jsi::String &a, const jsi::String &b) const {
v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
Expand Down
13 changes: 11 additions & 2 deletions src/v8runtime/V8Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class InspectorClient;

class V8Runtime : public facebook::jsi::Runtime {
public:
V8Runtime(std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue);
V8Runtime(
std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue);
V8Runtime(
const V8Runtime *v8Runtime,
std::unique_ptr<V8RuntimeConfig> config);
Expand Down Expand Up @@ -73,6 +74,9 @@ class V8Runtime : public facebook::jsi::Runtime {

protected:
PointerValue *cloneSymbol(const Runtime::PointerValue *pv) override;
#if REACT_NATIVE_TARGET_VERSION >= 70
PointerValue *cloneBigInt(const Runtime::PointerValue *pv) override;
#endif
PointerValue *cloneString(const Runtime::PointerValue *pv) override;
PointerValue *cloneObject(const Runtime::PointerValue *pv) override;
PointerValue *clonePropNameID(const Runtime::PointerValue *pv) override;
Expand Down Expand Up @@ -170,6 +174,11 @@ class V8Runtime : public facebook::jsi::Runtime {
bool strictEquals(
const facebook::jsi::Symbol &a,
const facebook::jsi::Symbol &b) const override;
#if REACT_NATIVE_TARGET_VERSION >= 70
bool strictEquals(
const facebook::jsi::BigInt &a,
const facebook::jsi::BigInt &b) const override;
#endif
bool strictEquals(
const facebook::jsi::String &a,
const facebook::jsi::String &b) const override;
Expand Down
5 changes: 3 additions & 2 deletions src/v8runtime/V8RuntimeFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

#pragma once

#include <cxxreact/MessageQueueThread.h>
#include <memory.h>
#include "V8RuntimeConfig.h"
#include "jsi/jsi.h"
#include <cxxreact/MessageQueueThread.h>

namespace rnv8 {

std::unique_ptr<facebook::jsi::Runtime> createV8Runtime(
std::unique_ptr<V8RuntimeConfig> config, std::shared_ptr<facebook::react::MessageQueueThread> jsQueue);
std::unique_ptr<V8RuntimeConfig> config,
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue);

std::unique_ptr<facebook::jsi::Runtime> createSharedV8Runtime(
const facebook::jsi::Runtime *sharedRuntime,
Expand Down