diff options
-rwxr-xr-x | src/embind/embind.js | 27 | ||||
-rwxr-xr-x | tests/embind/embind.test.js | 4 |
2 files changed, 13 insertions, 18 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 2a484dea..b41137e7 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -820,12 +820,8 @@ var genericPointerToWireType = function(destructors, handle) { } } - if (!(handle instanceof this.registeredClass.constructor)) { - throwBindingError('Expected null or instance of ' + this.name + ', got ' + _embind_repr(handle)); - } - - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object'); + if (!handle.$$ || !handle.$$.ptr) { + throwBindingError('Cannot pass deleted or null object'); } // TODO: this is not strictly true @@ -884,11 +880,9 @@ var nonConstNoSmartPtrRawPointerToWireType = function(destructors, handle) { } return 0; } - if (!(handle instanceof this.registeredClass.constructor)) { - throwBindingError('Expected null or instance of ' + this.name + ', got ' + _embind_repr(handle)); - } - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object'); + + if (!handle.$$ || !handle.$$.ptr) { + throwBindingError('Cannot pass deleted or null object'); } if (handle.$$.ptrType.isConst) { throwBindingError('Cannot convert argument of type ' + handle.$$.ptrType.name + ' to parameter type ' + this.name); @@ -905,11 +899,9 @@ var constNoSmartPtrRawPointerToWireType = function(destructors, handle) { } return 0; } - if (!(handle instanceof this.registeredClass.constructor)) { - throwBindingError('Expected null or instance of ' + this.name + ', got ' + _embind_repr(handle)); - } - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object'); + + if (!handle.$$ || !handle.$$.ptr) { + throwBindingError('Cannot pass deleted or null object'); } var handleClass = handle.$$.ptrType.registeredClass; var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass); @@ -1283,6 +1275,9 @@ function downcastPointer(ptr, ptrClass, desiredClass) { function upcastPointer(ptr, ptrClass, desiredClass) { while (ptrClass !== desiredClass) { + if (!ptrClass.upcast) { + throwBindingError("Expected null or instance of " + desiredClass.name + ", got an instance of " + ptrClass.name); + } ptr = ptrClass.upcast(ptr); ptrClass = ptrClass.baseClass; } diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 0763f09a..efb5ae84 100755 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -143,7 +143,7 @@ module({ var e = assert.throws(cm.BindingError, function() { cm.Derived.prototype.setMember.call(a, "foo"); }); - assert.equal('Expected null or instance of Derived*, got [object Object]', e.message); + assert.equal('Expected null or instance of Derived, got an instance of Base2', e.message); a.delete(); }); @@ -154,7 +154,7 @@ module({ var e = assert.throws(cm.BindingError, function() { cm.Base2.prototype.getField.call(a); }); - assert.equal('Expected null or instance of Base2 const*, got [object Object]', e.message); + assert.equal('Expected null or instance of Base2, got an instance of Base1', e.message); a.delete(); }); |