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:
@@ -12,6 +12,11 @@
|
||||
#include "JSITypedArray.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace vision {
|
||||
|
||||
@@ -97,7 +102,7 @@ TypedArrayKind TypedArrayBase::getKind(jsi::Runtime &runtime) const {
|
||||
.asString(runtime)
|
||||
.utf8(runtime);
|
||||
return getTypedArrayKindForName(constructorName);
|
||||
};
|
||||
}
|
||||
|
||||
size_t TypedArrayBase::size(jsi::Runtime &runtime) const {
|
||||
return getProperty(runtime, propNameIDCache.get(runtime, Prop::Length)).asNumber();
|
||||
@@ -191,13 +196,13 @@ void arrayBufferUpdate(
|
||||
}
|
||||
|
||||
template <TypedArrayKind T>
|
||||
TypedArray<T>::TypedArray(jsi::Runtime &runtime, size_t size) : TypedArrayBase(runtime, size, T){};
|
||||
TypedArray<T>::TypedArray(jsi::Runtime &runtime, size_t size) : TypedArrayBase(runtime, size, T) {}
|
||||
|
||||
template <TypedArrayKind T>
|
||||
TypedArray<T>::TypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data)
|
||||
: TypedArrayBase(runtime, data.size(), T) {
|
||||
update(runtime, data);
|
||||
};
|
||||
}
|
||||
|
||||
template <TypedArrayKind T>
|
||||
TypedArray<T>::TypedArray(TypedArrayBase &&base) : TypedArrayBase(std::move(base)) {}
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <jsi/jsi.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace jsi = facebook::jsi;
|
||||
|
||||
@@ -77,7 +79,7 @@ struct typedArrayTypeMap<TypedArrayKind::Float64Array> {
|
||||
// the cache object is connected to the lifecycle of the js runtime
|
||||
class InvalidateCacheOnDestroy : public jsi::HostObject {
|
||||
public:
|
||||
InvalidateCacheOnDestroy(jsi::Runtime &runtime);
|
||||
explicit InvalidateCacheOnDestroy(jsi::Runtime &runtime);
|
||||
virtual ~InvalidateCacheOnDestroy();
|
||||
virtual jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) {
|
||||
return jsi::Value::null();
|
||||
@@ -139,9 +141,9 @@ void arrayBufferUpdate(
|
||||
template <TypedArrayKind T>
|
||||
class TypedArray : public TypedArrayBase {
|
||||
public:
|
||||
explicit TypedArray(TypedArrayBase &&base);
|
||||
TypedArray(jsi::Runtime &runtime, size_t size);
|
||||
TypedArray(jsi::Runtime &runtime, std::vector<ContentType<T>> data);
|
||||
TypedArray(TypedArrayBase &&base);
|
||||
TypedArray(TypedArray &&) = default;
|
||||
TypedArray &operator=(TypedArray &&) = default;
|
||||
|
||||
|
Reference in New Issue
Block a user