fix: Improve C++ safety by attaching Cache Invalidator to jsi::Runtime's lifecycle (#1488)

* fix: fix C++ lint

* fix: attach `InvalidateCacheOnDestroy` to `jsi::Runtime`
This commit is contained in:
Marc Rousavy
2023-02-21 15:44:43 +01:00
committed by GitHub
parent 1ddea178ae
commit 0c3cd66016
8 changed files with 31 additions and 9 deletions

View File

@@ -15,6 +15,7 @@
#include "JSIJNIConversion.h"
#include "java-bindings/JImageProxy.h"
#include "java-bindings/JFrameProcessorPlugin.h"
#include "JSITypedArray.h"
namespace vision {
@@ -151,6 +152,12 @@ void FrameProcessorRuntimeManager::installJSIBindings() {
auto& jsiRuntime = *_jsRuntime;
// HostObject that attaches the cache to the lifecycle of the Runtime. On Runtime destroy, we destroy the cache.
auto propNameCacheObject = std::make_shared<vision::InvalidateCacheOnDestroy>(jsiRuntime);
jsiRuntime.global().setProperty(jsiRuntime,
"__visionCameraPropNameCache",
jsi::Object::createFromHostObject(jsiRuntime, propNameCacheObject));
auto setFrameProcessor = JSI_HOST_FUNCTION_LAMBDA {
__android_log_write(ANDROID_LOG_INFO, TAG, "Setting new Frame Processor...");

View File

@@ -45,7 +45,7 @@ class FrameProcessorRuntimeManager : public jni::HybridClass<FrameProcessorRunti
void registerPlugin(alias_ref<JFrameProcessorPlugin::javaobject> plugin);
void logErrorToJS(const std::string& message);
void setFrameProcessor(jsi::Runtime& runtime, // NOLINT(runtime/references)
void setFrameProcessor(jsi::Runtime& runtime,
int viewTag,
const jsi::Value& frameProcessor);
void unsetFrameProcessor(int viewTag);

View File

@@ -14,9 +14,9 @@ namespace JSIJNIConversion {
using namespace facebook;
jobject convertJSIValueToJNIObject(jsi::Runtime& runtime, const jsi::Value& value); // NOLINT(runtime/references)
jobject convertJSIValueToJNIObject(jsi::Runtime& runtime, const jsi::Value& value);
jsi::Value convertJNIObjectToJSIValue(jsi::Runtime& runtime, const jni::local_ref<jobject>& object); // NOLINT(runtime/references)
jsi::Value convertJNIObjectToJSIValue(jsi::Runtime& runtime, const jni::local_ref<jobject>& object);
} // namespace JSIJNIConversion