diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/embind/embind.test.js | 9 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 31 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 0976c597..a36c8b08 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1916,6 +1916,15 @@ module({ sh1.delete(); }); }); + + BaseFixture.extend("mixin", function() { + test("can call mixin method", function() { + var a = new cm.DerivedWithMixin(); + assert.instanceof(a, cm.Base); + assert.equal(10, a.get10()); + a.delete(); + }); + }); }); /* global run_all_tests */ diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 508fe052..4efc4bd8 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -2273,3 +2273,34 @@ EMSCRIPTEN_BINDINGS(return_values) { function("return_StringHolder_copy", &return_StringHolder_copy); function("call_StringHolder_func", &call_StringHolder_func); } + + +struct Mixin { + int get10() const { + return 10; + } +}; + +template<typename ClassBinding> +const ClassBinding& registerMixin(const ClassBinding& binding) { + // need a wrapper for implicit conversion from DerivedWithMixin to Mixin + struct Local { + static int get10(const typename ClassBinding::class_type& self) { + return self.get10(); + } + }; + + return binding + .function("get10", &Local::get10) + ; +} + +class DerivedWithMixin : public Base, public Mixin { +}; + +EMSCRIPTEN_BINDINGS(mixins) { + registerMixin( + class_<DerivedWithMixin, base<Base>>("DerivedWithMixin") + .constructor<>() + ); +} |