aboutsummaryrefslogtreecommitdiff
path: root/tests/embind/embind_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/embind/embind_test.cpp')
-rw-r--r--tests/embind/embind_test.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 23761efc..e8ca0338 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1148,6 +1148,25 @@ EMSCRIPTEN_BINDINGS(interface_tests) {
function("callDifferentArguments", &callDifferentArguments);
}
+template<typename T, size_t sizeOfArray>
+constexpr size_t getElementCount(T (&)[sizeOfArray]) {
+ return sizeOfArray;
+}
+
+static void callWithMemoryView(val v) {
+ // static so the JS test can read the memory after callTakeMemoryView runs
+ static unsigned char data[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+ v(memory_view(getElementCount(data), data));
+ static float f[] = { 1.5f, 2.5f, 3.5f, 4.5f };
+ v(typed_memory_view(getElementCount(f), f));
+ static short s[] = { 1000, 100, 10, 1 };
+ v(typed_memory_view(getElementCount(s), s));
+}
+
+EMSCRIPTEN_BINDINGS(memory_view_tests) {
+ function("callWithMemoryView", &callWithMemoryView);
+}
+
class HasExternalConstructor {
public:
HasExternalConstructor(const std::string& str)