diff options
author | Chad Austin <chad@imvu.com> | 2014-05-02 16:17:55 -0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2014-05-21 22:57:28 +0700 |
commit | 95a583b28ac063c3e813e61ea938bb93de910d66 (patch) | |
tree | f46864326ca8460672e46de24332d559a747c35d | |
parent | 6ce9851175ef56f894bd537fbf871c363f8bd402 (diff) |
make optional methods work
-rw-r--r-- | src/embind/emval.js | 7 | ||||
-rw-r--r-- | system/include/emscripten/bind.h | 2 | ||||
-rw-r--r-- | system/include/emscripten/val.h | 9 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 7 |
4 files changed, 15 insertions, 10 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js index ebec3881..2b49fc83 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -281,10 +281,13 @@ function __emval_call_method(caller, handle, methodName, destructorsRef, args) { return caller(handle, methodName, allocateDestructors(destructorsRef), args); } -function __emval_has_function(handle, name) { +function __emval_has_function(handle, name, classType) { handle = requireHandle(handle); name = getStringOrSymbol(name); - return handle[name] instanceof Function; + classType = requireRegisteredType(classType, 'class wrapper filter'); + + var filter = classType.registeredClass.instancePrototype[name]; + return (handle[name] instanceof Function) && (filter === undefined || handle[name] !== filter); } function __emval_typeof(handle) { diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 3c2d7097..e03523c0 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -899,7 +899,7 @@ namespace emscripten { template<typename ReturnType, typename... Args, typename Default> ReturnType optional_call(const char* name, Default def, Args&&... args) const { - if (wrapped.has_function(name)) { + if (wrapped.has_implementation_defined_function<T>(name)) { return call<ReturnType>(name, std::forward<Args>(args)...); } else { return def(); diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 8bcc30c4..31f5923e 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -61,7 +61,8 @@ namespace emscripten { EM_VAR_ARGS argv); bool _emval_has_function( EM_VAL value, - const char* methodName); + const char* methodName, + internal::TYPEID filter); EM_VAL _emval_typeof(EM_VAL value); } @@ -392,8 +393,10 @@ namespace emscripten { return MethodCaller<ReturnValue, Args...>::call(handle, name, std::forward<Args>(args)...); } - bool has_function(const char* name) const { - return _emval_has_function(handle, name); + template<typename ClassType> + bool has_implementation_defined_function(const char* name) const { + using namespace internal; + return _emval_has_function(handle, name, TypeID<ClassType>::get()); } template<typename T> diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index d42e66d2..513ab1d4 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1693,8 +1693,6 @@ module({ assert.equal("concrete", result); }); -/* ENABLE THESE AS THEY PASS - test("optional methods are externally visible", function() { var instance = new Empty; var result = instance.optionalMethod("_123"); @@ -1702,16 +1700,17 @@ module({ assert.equal("optional_123", result); }); - test("optional methods", function() { + test("optional methods: not defined", function() { var instance = new Empty; var result = cm.callOptionalMethod(instance, "_123"); instance.delete(); assert.equal("optional_123", result); }); +/* ENABLE THESE AS THEY PASS test("can call parent implementation from within derived implementation", function() { var parent = cm.AbstractClass; - var ExtendsOptionalMethod = parent.extend({ + var ExtendsOptionalMethod = parent.extend("ExtendsOptionalMethod", { optionalMethod: function(s) { return "optionaljs_" + parent.prototype.optionalMethod.call(this, s); }, |