diff options
-rw-r--r-- | system/include/emscripten/bind.h | 2 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 24 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 12 |
3 files changed, 27 insertions, 11 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 681d79d0..13fa2008 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -1206,7 +1206,7 @@ namespace emscripten { _embind_register_constant( name, TypeID<const ConstantType&>::get(), - asGenericValue(BindingType<const ConstantType&>::toWireType(v))); + asGenericValue(BT::toWireType(v))); } } diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 2a14ccde..0976c597 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -55,7 +55,7 @@ module({ }); }); }); - + } BaseFixture.extend("access to base class members", function() { @@ -609,7 +609,7 @@ module({ assert.equal("0", cm.unsigned_int_to_string(0)); assert.equal("0", cm.long_to_string(0)); assert.equal("0", cm.unsigned_long_to_string(0)); - + // all types should have positive values. assert.equal("5", cm.char_to_string(5)); assert.equal("5", cm.signed_char_to_string(5)); @@ -650,7 +650,7 @@ module({ assert.equal("-32768", cm.short_to_string(-32768)); assert.equal("-2147483648", cm.int_to_string(-2147483648)); assert.equal("-2147483648", cm.long_to_string(-2147483648)); - + // passing out of range values should fail. assert.throws(TypeError, function() { cm.char_to_string(-129); }); assert.throws(TypeError, function() { cm.char_to_string(128); }); @@ -733,7 +733,7 @@ module({ test("overloading of derived class member functions", function() { var foo = new cm.MultipleOverloadsDerived(); - + // NOTE: In C++, default lookup rules will hide overloads from base class if derived class creates them. // In JS, we make the base class overloads implicitly available. In C++, they would need to be explicitly // invoked, like foo.MultipleOverloads::Func(10); @@ -748,7 +748,7 @@ module({ assert.equal(foo.WhichFuncCalled(), 4); foo.delete(); }); - + test("overloading of class static functions", function() { assert.equal(cm.MultipleOverloads.StaticFunc(10), 1); assert.equal(cm.MultipleOverloads.WhichStaticFuncCalled(), 1); @@ -1441,7 +1441,7 @@ module({ test("repr includes enum value", function() { assert.equal('<#Enum_ONE {}>', IMVU.repr(cm.Enum.ONE)); assert.equal('<#Enum_TWO {}>', IMVU.repr(cm.Enum.TWO)); - }); + }); } test("instanceof", function() { @@ -1644,7 +1644,7 @@ module({ }); if (typeof INVOKED_FROM_EMSCRIPTEN_TEST_RUNNER === "undefined") { // TODO: Enable this to work in Emscripten runner as well! - + BaseFixture.extend("unbound types", function() { function assertMessage(fn, message) { var e = assert.throws(cm.UnboundTypeError, fn); @@ -1689,7 +1689,7 @@ module({ }, 'Cannot construct HasConstructorUsingUnboundArgumentAndUnboundBase due to unbound types: 18SecondUnboundClass'); }); - + test('class function with unbound argument', function() { var x = new cm.BoundClass; assertMessage( @@ -1719,12 +1719,12 @@ module({ }, 'Cannot access BoundClass.property due to unbound types: 12UnboundClass'); x.delete(); }); - + // todo: tuple elements // todo: tuple element accessors // todo: struct fields }); - + } BaseFixture.extend("noncopyable", function() { @@ -1743,6 +1743,10 @@ module({ BaseFixture.extend("constants", function() { assert.equal(10, cm.INT_CONSTANT); + + assert.equal(1, cm.STATIC_CONST_INTEGER_VALUE_1); + assert.equal(1000, cm.STATIC_CONST_INTEGER_VALUE_1000); + assert.equal("some string", cm.STRING_CONSTANT); assert.deepEqual([1, 2, 3, 4], cm.VALUE_ARRAY_CONSTANT); assert.deepEqual({x:1,y:2,z:3,w:4}, cm.VALUE_OBJECT_CONSTANT); diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 4cf12615..508fe052 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -2215,8 +2215,20 @@ EMSCRIPTEN_BINDINGS(read_only_properties) { ; } +struct StaticConstIntStruct { + static const int STATIC_CONST_INTEGER_VALUE_1; + static const int STATIC_CONST_INTEGER_VALUE_1000; +}; + +const int StaticConstIntStruct::STATIC_CONST_INTEGER_VALUE_1 = 1; +const int StaticConstIntStruct::STATIC_CONST_INTEGER_VALUE_1000 = 1000; + EMSCRIPTEN_BINDINGS(constants) { constant("INT_CONSTANT", 10); + + constant("STATIC_CONST_INTEGER_VALUE_1", StaticConstIntStruct::STATIC_CONST_INTEGER_VALUE_1); + constant("STATIC_CONST_INTEGER_VALUE_1000", StaticConstIntStruct::STATIC_CONST_INTEGER_VALUE_1000); + constant("STRING_CONSTANT", std::string("some string")); TupleVector tv(1, 2, 3, 4); |