Skip to content

Commit 0667c20

Browse files
committed
feat: add a JSI conversion from OwningArrayBuffers to JS types
1 parent 36f3fdb commit 0667c20

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
@@ -5,6 +5,8 @@
55

66
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
77
#include <jsi/jsi.h>
8+
#include <rnexecutorch/Log.h>
9+
#include <rnexecutorch/jsi/OwningArrayBuffer.h>
810
#include <rnexecutorch/utils/JsiTensorView.h>
911

1012
namespace rnexecutorch::jsiconversion {
@@ -104,7 +106,7 @@ inline JsiTensorView getValue<JsiTensorView>(const jsi::Value &val,
104106
throw jsi::JSError(runtime, "Data must be an ArrayBuffer or TypedArray");
105107
}
106108
}
107-
return std::move(tensorView);
109+
return tensorView;
108110
}
109111

110112
template <>
@@ -181,6 +183,17 @@ inline jsi::Value getJsiValue(int val, jsi::Runtime &runtime) {
181183
return jsi::Value(runtime, val);
182184
}
183185

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

0 commit comments

Comments
 (0)