Skip to content

Commit 1828f4e

Browse files
authored
data_view_draft_UNCOMPILED
1 parent b1c9e1f commit 1828f4e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/xembind.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ namespace xeus
3939
// the typed array an be of any type
4040
ems::val js_array = buffers_vec[i];
4141

42+
// this might be a data-view..
43+
const std::string cls_name = js_array["constructor"]["name"].as<std::string>();
44+
const auto is_data_view = cls_name == std::string("DataView");
45+
46+
4247
// data we need to convert js_array into an js Uint8Arra
43-
ems::val js_array_buffer = js_array["buffer"].as<ems::val>();
48+
ems::val js_array_buffer = maybe_js_array["buffer"].as<ems::val>();
4449
ems::val byteOffset = js_array["byteOffset"].as<ems::val>();
4550
const unsigned length = js_array["length"].as<unsigned> ();
46-
const unsigned bytes_per_element = js_array["BYTES_PER_ELEMENT"].as<unsigned>();
47-
const unsigned length_uint8 = length * bytes_per_element;
51+
52+
// if its a data view we can/need to get the byteLength directly
53+
// because there is no "BYTES_PER_ELEMENT"
54+
const unsigned length_uint8 = is_data_view ? js_array["byteLength"].as<unsigned>() : length * js_array["BYTES_PER_ELEMENT"].as<unsigned>() ;
4855

4956
// convert js typed-array into an Uint8Array
5057
ems::val js_uint8array = ems::val::global("Uint8Array").new_(

0 commit comments

Comments
 (0)