aboutsummaryrefslogtreecommitdiff
path: root/src/embind/embind.js
diff options
context:
space:
mode:
authorBill Welden <bwelden@imvu.com>2012-12-06 09:35:28 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:22:26 +0300
commit77dd6c9e8355041fe9363c25b2e30dbc9836b13f (patch)
tree0835a8a392a1d5db4aa076fa01ce7c73f85e09e8 /src/embind/embind.js
parent5fba40c9d81d8dc5ccb5fb9d12fa44eb884d96a6 (diff)
First fully functional automatic downcasting implementation.
Diffstat (limited to 'src/embind/embind.js')
-rwxr-xr-xsrc/embind/embind.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index e990c1a1..4ff84005 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -497,6 +497,7 @@ function __embind_register_class(
classType,
pointerType,
constPointerType,
+ isPolymorphic,
name,
destructor
) {
@@ -580,17 +581,31 @@ function __embind_register_class(
registerType(pointerType, pointerName, {
name: pointerName,
fromWireType: function(ptr) {
- var dynamicType = ___getDynamicPointerType(ptr); // !!! this won't work if pointer is not dynamic
- if (dynamicType === null || dynamicType === pointerType) {
- return new Handle(ptr);
- }
- try {
- dynamicType = requireRegisteredType(dynamicType);
- } catch (err) {
+ if (isPolymorphic) {
+ var toType = ___getDynamicPointerType(ptr);
+ var toTypeImpl = null;
+ if (toType === null || toType === pointerType) {
+ return new Handle(ptr);
+ }
+ var derivation = Module.__getDerivationPath(toType, classType);
+ var candidate = null;
+ for (var i = 0; i < derivation.size(); i++) {
+ candidate = derivation.at(i);
+ toTypeImpl = typeRegistry[candidate];
+ if (toTypeImpl) {
+ break;
+ }
+ }
+ derivation.delete();
+ if (toTypeImpl === null) {
+ return new Handle(ptr);
+ }
+ var toTypePointerImpl = requireRegisteredType(toTypeImpl.pointerType);
+ var castPtr = ___dynamicPointerCast(ptr, classType, candidate);
+ return toTypePointerImpl.fromWireTypeStatic(castPtr);
+ } else {
return new Handle(ptr);
}
- dynamicType = requireRegisteredType(dynamicType.pointerType);
- return dynamicType.fromWireTypeStatic(ptr);
},
fromWireTypeStatic: function(ptr) {
return new Handle(ptr);