diff options
-rw-r--r-- | src/embind/embind.js | 3 | ||||
-rw-r--r-- | system/include/emscripten/bind.h | 5 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 18 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 3aa9fef7..ef16e952 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -1773,6 +1773,9 @@ function __embind_create_inheriting_constructor(constructorName, wrapperType, pr }); }; + wrapperPrototype.__destruct = function __destruct() { + }; + ctor.prototype = Object.create(wrapperPrototype); for (var p in properties) { ctor.prototype[p] = properties[p]; diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 57d8f476..f6debae1 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -917,7 +917,10 @@ namespace emscripten { template<typename... Args> \ T(::emscripten::val&& v, Args&&... args) \ : wrapper(std::forward<::emscripten::val>(v), std::forward<Args>(args)...) \ - {} + {} \ + ~T() { \ + call<void>("__destruct"); \ + } namespace internal { struct NoBaseClass { diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index a1d54a09..e77a8a43 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1768,6 +1768,24 @@ module({ assert.equal("hi", rv); }); + test("__destruct is called when object is destroyed", function() { + var parent = cm.HeldAbstractClass; + var calls = []; + var C = parent.extend("C", { + method: function() { + }, + __destruct: function() { + calls.push("__destruct"); + } + }); + var impl = new C; + var copy = impl.clone(); + impl.delete(); + assert.deepEqual([], calls); + copy.delete(); + assert.deepEqual(["__destruct"], calls); + }); + /* does not pass yet test("if JavaScript implementation of interface is returned, don't wrap in new handle", function() { var parent = cm.HeldAbstractClass; |