Skip to content

Commit 2e0f581

Browse files
Merge pull request #817 from NativeScript/released-dangling-pointers
Clear pointers to deallocated memory. Add better marshaling error messages
2 parents 4bcdac8 + 3d43c1f commit 2e0f581

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

runtime/src/main/jni/CallbackHandlers.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ void CallbackHandlers::CallJavaMethod(const Local<Object>& caller, const string&
317317
callerJavaObject = objectManager->GetJavaObjectByJsObject(caller);
318318
if (callerJavaObject.IsNull()) {
319319
stringstream ss;
320-
ss << "No java object found on which to call \"" << methodName <<
321-
"\" method. It is possible your Javascript object is not linked with the corresponding Java class. Try passing context(this) to the constructor function.";
320+
if (args.IsConstructCall()) {
321+
ss << "No java object found on which to call \"" << methodName << "\" method. It is possible your Javascript object is not linked with the corresponding Java class. Try passing context(this) to the constructor function.";
322+
} else {
323+
ss << "Failed calling " << methodName << " on a " << className << " instance. The JavaScript instance no longer has available Java instance counterpart.";
324+
}
322325
throw NativeScriptException(ss.str());
323326
}
324327
}

runtime/src/main/jni/JsArgToArrayConverter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ bool JsArgToArrayConverter::ConvertArg(const Local<Value>& arg, int index) {
263263
if (success) {
264264
SetConvertedObject(env, index, obj.Move(), obj.IsGlobal());
265265
} else {
266-
s << "Cannot convert JavaScript object with id " << jsObj->GetIdentityHash() << " at index " << index;
266+
String::Utf8Value jsObjStr(jsObj);
267+
s << "Cannot marshal JavaScript argument " << (*jsObjStr ? *jsObjStr : "<failed-to-string>") << " at index " << index << " to Java type.";
267268
}
268269
break;
269270

@@ -274,7 +275,7 @@ bool JsArgToArrayConverter::ConvertArg(const Local<Value>& arg, int index) {
274275
SetConvertedObject(env, index, nullptr);
275276
success = true;
276277
} else {
277-
s << "Cannot convert JavaScript object at index " << index;
278+
s << "Cannot marshal JavaScript argument at index " << index << " to Java type.";
278279
success = false;
279280
}
280281

runtime/src/main/jni/ObjectManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void ObjectManager::ReleaseJSInstance(Persistent<Object>* po, JSInstanceInfo* js
329329
m_idToObject.erase(it);
330330
m_released.insert(po, javaObjectID);
331331
po->Reset();
332+
332333
delete po;
333334
delete jsInstanceInfo;
334335

0 commit comments

Comments
 (0)