aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-03-14 00:22:27 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:25:51 +0300
commitc8cdc3f73c486cc4ac2ac5da0de01f6072a092af (patch)
treea4f0434cfdd6ab660e83c4ca769816b086f37bf8 /src
parent0badaf9b00289ffd204b88c8875f442822b1b704 (diff)
Support the smart_ptr policy BY_EMVAL and pass the original smart pointer if the parameter has an identical type.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/embind/embind.js43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index de6826aa..89669172 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -508,7 +508,6 @@ RegisteredPointer.prototype.isPolymorphic = function() {
};
RegisteredPointer.prototype.toWireType = function(destructors, handle) {
- var fromRawType;
if (handle === null) {
if (this.isReference) {
throwBindingError('null is not a valid ' + this.name);
@@ -531,20 +530,17 @@ RegisteredPointer.prototype.toWireType = function(destructors, handle) {
if (!this.isConst && handle.$$.registeredPointer.isConst) {
throwBindingError('Cannot pass argument of type ' + handle.$$.registeredPointer.name + ' to parameter of type ' + this.name);
}
- var pointeeType = handle.$$.pointeeType;
- if (pointeeType.isPolymorphic()) {
- fromRawType = pointeeType.getDynamicRawPointerType(handle.$$.ptr);
- } else {
- fromRawType = pointeeType.rawType;
- }
- if (fromRawType === this.pointeeType.rawType) {
- return this.isSmartPointer ? handle.$$.smartPtr : handle.$$.ptr;
- }
- var ptr = staticPointerCast(handle.$$.ptr, fromRawType, this.pointeeType.rawType);
+ var handleClass = handle.$$.registeredPointer.registeredClass;
+ var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
if (this.isSmartPointer) {
switch (this.sharingPolicy) {
case 0: // NONE
- throwBindingError('NONE sharing policy not yet supported');
+ // no upcasting
+ if (handle.$$.registeredPointer === this) {
+ ptr = handle.$$.smartPtr;
+ } else {
+ throwBindingError('NONE sharing policy not yet supported');
+ }
break;
case 1: // INTRUSIVE
@@ -552,19 +548,22 @@ RegisteredPointer.prototype.toWireType = function(destructors, handle) {
break;
case 2: // BY_EMVAL
- var clonedHandle = handle.clone();
- ptr = this.rawShare(
- ptr,
- __emval_register(function() {
- clonedHandle.delete();
- })
- );
- destructors.push(this.rawDestructor, ptr);
- break;
+ if (handle.$$.registeredPointer === this) {
+ ptr = handle.$$.smartPtr;
+ } else {
+ var clonedHandle = handle.clone();
+ ptr = this.rawShare(
+ ptr,
+ __emval_register(function() {
+ clonedHandle.delete();
+ })
+ );
+ destructors.push(this.rawDestructor, ptr);
+ }
+ break;
default:
throwBindingError('Unsupporting sharing policy');
-
}
}
return ptr;