Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

patch v8 to support re.pack import()

Ammar Ahmed989b72de055c
diff --git a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
index 723e0d71a..e8ed42aeb8 100644
--- a/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
@@ -56,7 +56,6 @@ public class MainApplication extends MultiDexApplication implements ReactApplica
if (v8BundleAssetName != null) {
return v8BundleAssetName;
}
- Log.d("Notesnook:::", "LOADED" + v8BundleAssetName + super.getBundleAssetName());
return super.getBundleAssetName();
}
diff --git a/apps/mobile/patches/react-native-v8+1.4.5.patch b/apps/mobile/patches/react-native-v8+1.4.5.patch
index 589650d3d..8979ef839 100644
--- a/apps/mobile/patches/react-native-v8+1.4.5.patch
+++ b/apps/mobile/patches/react-native-v8+1.4.5.patch
@@ -1,5 +1,5 @@
diff --git a/node_modules/react-native-v8/android/CMakeLists.txt b/node_modules/react-native-v8/android/CMakeLists.txt
-index 66dae03..6933126 100644
+index 66dae03..e9c233f 100644
--- a/node_modules/react-native-v8/android/CMakeLists.txt
+++ b/node_modules/react-native-v8/android/CMakeLists.txt
@@ -20,9 +20,9 @@ set(CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HA
@@ -242,9 +242,8 @@ index 66dae03..6933126 100644
+ reactnative_internal_static
+ android
)
-\ No newline at end of file
diff --git a/node_modules/react-native-v8/android/build.gradle b/node_modules/react-native-v8/android/build.gradle
-index 4d78df9..d6e3d16 100644
+index 4d78df9..3d6e414 100644
--- a/node_modules/react-native-v8/android/build.gradle
+++ b/node_modules/react-native-v8/android/build.gradle
@@ -12,18 +12,18 @@ import org.apache.tools.ant.filters.ReplaceTokens
@@ -857,12 +856,65 @@ index 4d78df9..d6e3d16 100644
+ task.dependsOn(extractSOFiles)
+ }
}
-\ No newline at end of file
diff --git a/node_modules/react-native-v8/src/v8runtime/V8Runtime.cpp b/node_modules/react-native-v8/src/v8runtime/V8Runtime.cpp
-index 42af9c6..ad9d928 100644
+index 42af9c6..d0b427f 100644
--- a/node_modules/react-native-v8/src/v8runtime/V8Runtime.cpp
+++ b/node_modules/react-native-v8/src/v8runtime/V8Runtime.cpp
-@@ -572,6 +572,19 @@ jsi::PropNameID V8Runtime::createPropNameIDFromString(const jsi::String &str) {
+@@ -29,7 +29,8 @@ const char kHostFunctionProxyProp[] = "__hostFunctionProxy";
+ // static
+ std::unique_ptr<v8::Platform> V8Runtime::s_platform = nullptr;
+ std::mutex s_platform_mutex; // protects s_platform
+-
++bool isMainBundleLoaded = false;
++bool isMainBundleCached = false;
+ V8Runtime::V8Runtime(std::unique_ptr<V8RuntimeConfig> config,
+ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue)
+ : config_(std::move(config)) {
+@@ -43,7 +44,7 @@ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue)
+ v8::V8::Initialize();
+ }
+ }
+-
++ isMainBundleLoaded = false;
+ arrayBufferAllocator_.reset(
+ v8::ArrayBuffer::Allocator::NewDefaultAllocator());
+ v8::Isolate::CreateParams createParams;
+@@ -299,7 +300,8 @@ V8Runtime::LoadCodeCacheIfNeeded(const std::string &codecachePath) {
+ if (config_->codecacheMode == V8RuntimeConfig::CodecacheMode::kNone) {
+ return nullptr;
+ }
+-
++ if (isMainBundleLoaded) return nullptr;
++ isMainBundleLoaded = true;
+ if (config_->codecacheMode == V8RuntimeConfig::CodecacheMode::kPrebuilt) {
+ assert(config_->prebuiltCodecacheBlob);
+ return std::make_unique<v8::ScriptCompiler::CachedData>(
+@@ -314,6 +316,7 @@ V8Runtime::LoadCodeCacheIfNeeded(const std::string &codecachePath) {
+ LOG(INFO) << "Cannot load codecache file: " << codecachePath;
+ return nullptr;
+ }
++ isMainBundleCached = true;
+ fseek(file, 0, SEEK_END);
+ size_t size = ftell(file);
+ uint8_t *buffer = new uint8_t[size];
+@@ -346,6 +349,8 @@ bool V8Runtime::SaveCodeCacheIfNeeded(
+ return false;
+ }
+
++ if (isMainBundleCached) return false;
++
+ v8::HandleScope scopedHandle(isolate_);
+
+ v8::Local<v8::UnboundScript> unboundScript = script->GetUnboundScript();
+@@ -360,6 +365,7 @@ bool V8Runtime::SaveCodeCacheIfNeeded(
+ LOG(ERROR) << "Cannot save codecache file: " << codecachePath;
+ return false;
+ }
++ isMainBundleCached = true;
+ fwrite(newCachedData->data, 1, newCachedData->length, file);
+ fclose(file);
+ return true;
+@@ -572,6 +578,19 @@ jsi::PropNameID V8Runtime::createPropNameIDFromString(const jsi::String &str) {
reinterpret_cast<const uint8_t *>(*utf8), utf8.length());
}