Skip to content

Commit 5162f65

Browse files
committed
feat: add a JSI conversion from OwningArrayBuffers to JS types
1 parent 6ab0df4 commit 5162f65

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • packages/react-native-executorch/common/rnexecutorch/host_objects

packages/react-native-executorch/common/rnexecutorch/host_objects/JsiConversions.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
88
#include <jsi/jsi.h>
9+
#include <rnexecutorch/Log.h>
10+
#include <rnexecutorch/jsi/OwningArrayBuffer.h>
911
#include <rnexecutorch/utils/JsiTensorView.h>
1012

1113
namespace rnexecutorch::jsiconversion {
@@ -105,7 +107,7 @@ inline JsiTensorView getValue<JsiTensorView>(const jsi::Value &val,
105107
throw jsi::JSError(runtime, "Data must be an ArrayBuffer or TypedArray");
106108
}
107109
}
108-
return std::move(tensorView);
110+
return tensorView;
109111
}
110112

111113
template <>
@@ -182,6 +184,17 @@ inline jsi::Value getJsiValue(int val, jsi::Runtime &runtime) {
182184
return jsi::Value(runtime, val);
183185
}
184186

187+
inline jsi::Value
188+
getJsiValue(const std::vector<std::shared_ptr<OwningArrayBuffer>> &vec,
189+
jsi::Runtime &runtime) {
190+
jsi::Array array(runtime, vec.size());
191+
for (size_t i = 0; i < vec.size(); i++) {
192+
jsi::ArrayBuffer arrayBuffer(runtime, vec[i]);
193+
array.setValueAtIndex(runtime, i, jsi::Value(runtime, arrayBuffer));
194+
}
195+
return jsi::Value(runtime, array);
196+
}
197+
185198
inline jsi::Value getJsiValue(const std::string &str, jsi::Runtime &runtime) {
186199
return jsi::String::createFromAscii(runtime, str);
187200
}

0 commit comments

Comments
 (0)