aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-04-16 22:03:13 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-18 20:08:34 +0300
commit496b38f13f74e04af233d5ad7307be4f099b07e5 (patch)
tree0fbf8e63e4bb8c1b84044d32d6b5609ff64911be
parent3734028036e309fa13c8b4b9956666285ebaf94d (diff)
Add a new unit test that explicitly checks for the case when two different classes happen to have member functions with the same name and signature - a reason why the 'instanceof' check exists in embind.js.
-rwxr-xr-xtests/embind/embind.test.js11
-rw-r--r--tests/embind/embind_test.cpp5
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index ff20791d..0763f09a 100755
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -147,6 +147,17 @@ module({
a.delete();
});
+ test("calling method on unrelated class throws error (2)", function() {
+ // Base1 and Base2 both have the method 'getField()' exposed - make sure
+ // that calling the Base2 function with a 'this' instance of Base1 doesn't accidentally work!
+ var a = new cm.Base1;
+ var e = assert.throws(cm.BindingError, function() {
+ cm.Base2.prototype.getField.call(a);
+ });
+ assert.equal('Expected null or instance of Base2 const*, got [object Object]', e.message);
+ a.delete();
+ });
+
test("calling method with invalid this throws error", function() {
var e = assert.throws(cm.BindingError, function() {
cm.Derived.prototype.setMember.call(undefined, "foo");
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 04771dbe..0439c832 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1814,6 +1814,11 @@ EMSCRIPTEN_BINDINGS(tests) {
function("embind_attempt_to_modify_smart_pointer_when_passed_by_value", embind_attempt_to_modify_smart_pointer_when_passed_by_value);
function("embind_save_smart_base_pointer", embind_save_smart_base_pointer);
+ class_<Base1>("Base1")
+ .constructor()
+ .function("getField", &Base1::getField)
+ ;
+
class_<Base2>("Base2")
.function("getField", &Base2::getField)
.property("field", &Base2::field2)