diff options
-rw-r--r-- | src/embind/embind.js | 8 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 29 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 27dfa928..6f905d55 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -1823,6 +1823,10 @@ function __embind_create_inheriting_constructor(constructorName, wrapperType, pr // It's a little nasty that we're modifying the wrapper prototype here. wrapperPrototype.__construct = function __construct() { + if (this === wrapperPrototype) { + throwBindingError("Pass correct 'this' to __construct"); + } + var inner = baseConstructor.__$implement.apply( undefined, [this].concat(arraySlice.call(arguments))); @@ -1835,6 +1839,10 @@ function __embind_create_inheriting_constructor(constructorName, wrapperType, pr }; wrapperPrototype.__destruct = function __destruct() { + if (this === wrapperPrototype) { + throwBindingError("Pass correct 'this' to __destruct"); + } + unregisterInheritedInstance(registeredClass, this.$$.ptr); }; diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index bc0a6154..067b3f60 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1800,6 +1800,35 @@ module({ rv.delete(); }); + test("can instantiate two wrappers with constructors", function() { + var parent = cm.HeldAbstractClass; + var C = parent.extend("C", { + __construct: function() { + this.__parent.__construct.call(this); + }, + method: function() { + } + }); + var a = new C; + var b = new C; + a.delete(); + b.delete(); + }); + + test("incorrectly calling parent is an error", function() { + var parent = cm.HeldAbstractClass; + var C = parent.extend("C", { + __construct: function() { + this.__parent.__construct(); + }, + method: function() { + } + }); + assert.throws(cm.BindingError, function() { + new C; + }); + }); + test("deleteLater() works for JavaScript implementations", function() { var parent = cm.HeldAbstractClass; var C = parent.extend("C", { |