Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Emscripten 3.1.47 additions #15

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add checks for Emscripten version
jerbob92 committed Nov 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 88b6a8f592924a8d949a45bacff38a65ace9c589
28 changes: 27 additions & 1 deletion embind_test.go
Original file line number Diff line number Diff line change
@@ -841,6 +841,26 @@ type ICreateOscillator interface {
CreateOscillator() *webkitAudioContextOscillator
}

func isSupportedByEmscriptenVersion(version []any, major, minor, tiny int32) bool {
currentMajor := version[0].(int32)
currentMinor := version[1].(int32)
currentTiny := version[2].(int32)

if currentMajor > major {
return true
}

if currentMajor == major && currentMinor > minor {
return true
}

if currentMajor == major && currentMinor == minor && currentTiny >= tiny {
return true
}

return false
}

var _ = Describe("Using embind emval", Label("library"), func() {
When("using the Go struct mapping", func() {
It("fails when no struct is mapped", func() {
@@ -880,7 +900,13 @@ All done!
Expect(array).To(Equal([]any{}))
})

It("can create an iterator on an array and loop over it", func() {
It("can create an iterator on an array and loop over it (from version 3.1.47)", func() {
version, err := engine.CallPublicSymbol(ctx, "emscripten_version")
Expect(err).To(BeNil())
if !isSupportedByEmscriptenVersion(version.([]any), 3, 1, 47) {
return
}

res, err := engine.CallPublicSymbol(ctx, "emval_iterator")
Expect(err).To(BeNil())
Expect(res).To(Not(BeNil()))
15 changes: 15 additions & 0 deletions testdata/wasm/emval.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <emscripten/version.h>
#include <stdio.h>
#include <math.h>

@@ -81,6 +82,15 @@ val emval_array() {
return val::array();
}

val emscripten_version() {
std::vector<int> version_vec;
version_vec.push_back(__EMSCRIPTEN_major__);
version_vec.push_back(__EMSCRIPTEN_minor__);
version_vec.push_back(__EMSCRIPTEN_tiny__);
return val::array(version_vec);
}

#if __EMSCRIPTEN_major__ > 3 || (__EMSCRIPTEN_major__ == 3 && __EMSCRIPTEN_minor__ > 1) || (__EMSCRIPTEN_major__ == 3 && __EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 47)
std::vector<int> emval_iterator() {
std::vector<int> vec2;
vec2.push_back(0);
@@ -93,6 +103,7 @@ std::vector<int> emval_iterator() {
}
return vec2_from_iter;
}
#endif

EMSCRIPTEN_BINDINGS(emval) {
function("doEmval", &doEmval);
@@ -109,5 +120,9 @@ EMSCRIPTEN_BINDINGS(emval) {
function("emval_u16_string", &emval_u16_string, allow_raw_pointers());
function("emval_u8_string", &emval_u8_string, allow_raw_pointers());
function("emval_array", &emval_array);
function("emscripten_version", &emscripten_version);

#if __EMSCRIPTEN_major__ > 3 || (__EMSCRIPTEN_major__ == 3 && __EMSCRIPTEN_minor__ > 1) || (__EMSCRIPTEN_major__ == 3 && __EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 47)
function("emval_iterator", &emval_iterator);
#endif
}
Binary file modified testdata/wasm/tests.wasm
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/generated/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.