Skip to content

Commit

Permalink
add unit test for issue #221
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Slavchev committed Dec 12, 2015
1 parent c27e977 commit 08d3f04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/jni/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ Local<Object> ObjectManager::CreateJSWrapperHelper(jint javaObjectID, const stri

void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
{
int internalFieldCound = NativeScriptExtension::GetInternalFieldCount(object);
const int count = static_cast<int>(MetadataNodeKeys::END);
if (internalFieldCound != count)
{
string errMsg("Trying to link invalid 'this' to a Java object");
throw NativeScriptException(errMsg);
}

auto isolate = Isolate::GetCurrent();

DEBUG_WRITE("Linking js object: %d and java instance id: %d", object->GetIdentityHash(), javaObjectID);
Expand Down
25 changes: 25 additions & 0 deletions test-app/assets/app/tests/testAsserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,29 @@ describe("Tests that app does not crashes (no hard-fail asserts)", function () {
}
expect(exceptionThrown).toBe(true);
});

it("should throw an exception when trying to link invalid this to a Java object", function () {
var __extends = function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var MyObject = (function (_super) {
__extends(MyObject, _super);
function MyObject(name) {
_super.call(this);
return __native(this);
}
return MyObject;
})(java.lang.Object);

var exceptionThrown;
try {
var o = new MyObject();
exceptionThrown = false;
} catch (e) {
exceptionThrown = true;
}
expect(exceptionThrown).toBe(true);
});
});

0 comments on commit 08d3f04

Please sign in to comment.