diff options
-rw-r--r-- | src/embind/embind.js | 16 | ||||
-rw-r--r-- | system/include/emscripten/wire.h | 18 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index bbbeb96c..98d4b13e 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -60,7 +60,9 @@ function __embind_register_bool(boolType, name, trueValue, falseValue) { return o ? trueValue : falseValue; }, fromWireType: function(wt) { - return wt === trueValue; + // ambiguous emscripten ABI: sometimes return values are + // true or false, and sometimes integers (0 or 1) + return !!wt; }, }); } @@ -397,7 +399,7 @@ function __embind_register_smart_ptr( }; Handle.prototype['delete'] = function() { - if (!this.ptr && !this.smartPointer) { + if (!this.ptr) { throw new BindingError(pointeeType.name + ' instance already deleted'); } @@ -412,10 +414,18 @@ function __embind_register_smart_ptr( registerType(pointerType, name, { name: name, fromWireType: function(ptr) { + if (!getPointee(ptr)) { + destructor(ptr); + return null; + } return new Handle(ptr); }, toWireType: function(destructors, o) { - return o.smartPointer; + if (null === o) { + return 0; + } else { + return o.smartPointer; + } } }); } diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index 89e68c68..452628a0 100644 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -210,6 +210,24 @@ namespace emscripten { } }; + template<typename T> + struct BindingType<std::shared_ptr<T>> { + typedef std::shared_ptr<T> shared_ptr; + typedef std::shared_ptr<T>* WireType; + + static WireType toWireType(shared_ptr p) { + return new shared_ptr(p); + } + + static shared_ptr fromWireType(WireType wt) { + if (wt) { + return shared_ptr(*wt); + } else { + return shared_ptr(); + } + } + }; + template<typename Enum> struct EnumBindingType { typedef Enum WireType; |