Skip to content

Commit 0227dc5

Browse files
committed
Add tests
1 parent 0cb3884 commit 0227dc5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/embind/embind.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,17 @@ module({
12771277
b.delete();
12781278
});
12791279

1280+
test("functions as class constructors", function() {
1281+
var a = new cm.ConstructFromFunction({optionA: true});
1282+
assert.equal(true, a.optionA);
1283+
1284+
var b = new cm.ConstructFromFunction();
1285+
assert.equal(false, b.optionA);
1286+
1287+
a.delete();
1288+
b.delete();
1289+
});
1290+
12801291
test("function objects as class methods", function() {
12811292
var b = cm.ValHolder.makeValHolder("foo");
12821293

tests/embind/embind_test.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,16 @@ ConstructFromFunctor<I> construct_from_functor_mixin(const val& v, int i)
17511751
return {v, i};
17521752
}
17531753

1754+
struct ConstructFromFunction {
1755+
bool optionA;
1756+
ConstructFromFunction(bool optionA_): optionA{optionA_} {};
1757+
};
1758+
1759+
auto ConstructFromFunctionConstructor(emscripten::val value) {
1760+
bool optionA = (value.as<bool>() && value["optionA"].as<bool>());
1761+
return new ConstructFromFunction(optionA);
1762+
}
1763+
17541764
EMSCRIPTEN_BINDINGS(tests) {
17551765
register_vector<int>("IntegerVector");
17561766
register_vector<char>("CharVector");
@@ -1873,6 +1883,10 @@ EMSCRIPTEN_BINDINGS(tests) {
18731883
.function("getA", &ConstructFromFunctor<2>::getA)
18741884
;
18751885

1886+
class_<ConstructFromFunction>("ConstructFromFunction")
1887+
.constructor<emscripten::val>(&ConstructFromFunctionConstructor)
1888+
;
1889+
18761890
class_<ValHolder>("ValHolder")
18771891
.smart_ptr<std::shared_ptr<ValHolder>>("std::shared_ptr<ValHolder>")
18781892
.constructor<val>()

0 commit comments

Comments
 (0)