@@ -74,34 +74,31 @@ inline JsiTensorView getValue<JsiTensorView>(const jsi::Value &val,
7474 size_t elementBytes =
7575 executorch::runtime::elementSize (tensorView.scalarType );
7676 tensorView.numel = arrayBytes / elementBytes;
77-
7877 } else {
7978 // Handle typed arrays (Float32Array, Int32Array, etc.)
80- if (dataObj.hasProperty (runtime, " buffer" ) &&
81- dataObj.hasProperty (runtime, " byteOffset" ) &&
82- dataObj.hasProperty (runtime, " byteLength" ) &&
79+ if (dataObj.hasProperty (runtime, " buffer" ) ||
80+ dataObj.hasProperty (runtime, " byteOffset" ) ||
81+ dataObj.hasProperty (runtime, " byteLength" ) ||
8382 dataObj.hasProperty (runtime, " length" )) {
84-
85- tensorView.numel =
86- getValue<int >(dataObj.getProperty (runtime, " length" ), runtime);
87-
88- jsi::Value bufferValue = dataObj.getProperty (runtime, " buffer" );
89- if (!bufferValue.isObject () ||
90- !bufferValue.asObject (runtime).isArrayBuffer (runtime)) {
91- throw jsi::JSError (runtime,
92- " TypedArray buffer property must be an ArrayBuffer" );
93- }
94-
95- jsi::ArrayBuffer arrayBuffer =
96- bufferValue.asObject (runtime).getArrayBuffer (runtime);
97- size_t byteOffset =
98- getValue<int >(dataObj.getProperty (runtime, " byteOffset" ), runtime);
99-
100- tensorView.dataPtr =
101- static_cast <uint8_t *>(arrayBuffer.data (runtime)) + byteOffset;
102- } else {
10383 throw jsi::JSError (runtime, " Data must be an ArrayBuffer or TypedArray" );
10484 }
85+ tensorView.numel =
86+ getValue<int >(dataObj.getProperty (runtime, " length" ), runtime);
87+
88+ jsi::Value bufferValue = dataObj.getProperty (runtime, " buffer" );
89+ if (!bufferValue.isObject () ||
90+ !bufferValue.asObject (runtime).isArrayBuffer (runtime)) {
91+ throw jsi::JSError (runtime,
92+ " TypedArray buffer property must be an ArrayBuffer" );
93+ }
94+
95+ jsi::ArrayBuffer arrayBuffer =
96+ bufferValue.asObject (runtime).getArrayBuffer (runtime);
97+ size_t byteOffset =
98+ getValue<int >(dataObj.getProperty (runtime, " byteOffset" ), runtime);
99+
100+ tensorView.dataPtr =
101+ static_cast <uint8_t *>(arrayBuffer.data (runtime)) + byteOffset;
105102 }
106103 return tensorView;
107104}
0 commit comments