summaryrefslogtreecommitdiff
path: root/tests/embind/embind.test.js
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2014-05-13 01:06:05 -0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-05-21 23:07:56 +0700
commit121cb8f58671140441eec21780f97fef4f8cb667 (patch)
tree8ceeb480041782a9af00b33893eb3f90bee639dc /tests/embind/embind.test.js
parenta33f6e69daf7428ae03dc7a024644e0ba944f70a (diff)
Passing an argument from C++ into JavaScript has 'borrow' semantics rather than ownership semantics. That is, to keep a reference beyond the function call, you must call .clone(). This is necessary to avoid special-casing non-overridden virtual functions. (I don't know if this change will stick. It's possible it will have some problems.)
Diffstat (limited to 'tests/embind/embind.test.js')
-rw-r--r--tests/embind/embind.test.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index ae421f27..a6b2e98c 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1953,6 +1953,53 @@ module({
rv.delete();
cm.flushPendingDeletes();
});
+
+ test("method arguments with pointer ownership semantics are cleaned up after call", function() {
+ var parent = cm.AbstractClass;
+ var C = parent.extend("C", {
+ abstractMethod: function() {
+ },
+ });
+ var impl = new C;
+ cm.passShared(impl);
+ impl.delete();
+ });
+
+ test("method arguments with pointer ownership semantics can be cloned", function() {
+ var parent = cm.AbstractClass;
+ var owned;
+ var C = parent.extend("C", {
+ abstractMethod: function() {
+ },
+ passShared: function(p) {
+ owned = p.clone();
+ }
+ });
+ var impl = new C;
+ cm.passShared(impl);
+ impl.delete();
+
+ assert.equal("Derived", owned.getClassName());
+ owned.delete();
+ });
+
+ test("emscripten::val method arguments don't leak", function() {
+ var parent = cm.AbstractClass;
+ var got;
+ var C = parent.extend("C", {
+ abstractMethod: function() {
+ },
+ passVal: function(g) {
+ got = g;
+ }
+ });
+ var impl = new C;
+ var v = {};
+ cm.passVal(impl, v);
+ impl.delete();
+
+ assert.equal(v, got);
+ });
});
BaseFixture.extend("registration order", function() {