Skip to content

Commit 9cc697a

Browse files
committed
fix(runtime): count an object constructed from JS under its class
RegisterInstance links the wrapper before the class is known to the link, then records the class with SetJavaClass. That set only the instance info, so getWrapperClassCounts(), which reads the weak-callback state, counted every JS-constructed object under <unknown>, and a dead canary's record never got the class either. SetJavaClass now updates the state too.
1 parent 30ff362 commit 9cc697a

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎test-app/app/src/main/assets/app/tests/testWrapperLifetimeModes.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,14 @@ describe("Wrapper lifetime modes", function () {
757757
}
758758
});
759759

760+
it("counts an object constructed from JS under its own class", function () {
761+
var Counted = com.tns.tests.DummyClass.extend({});
762+
var made = new Counted();
763+
var entry = runtime.getWrapperClassCounts()[made.getClass().getName()];
764+
expect(entry).toBeDefined();
765+
expect(entry.wrappers).toBe(1);
766+
});
767+
760768
it("counts canary activity", function () {
761769
var before = stats();
762770
var runnable = new java.lang.Runnable({ run: function () {} });

‎test-app/runtime/src/main/cpp/ObjectManager.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ jclass ObjectManager::GetJavaClass(const Local<Object>& instance) {
362362
void ObjectManager::SetJavaClass(const Local<Object>& instance, jclass clazz) {
363363
JSInstanceInfo* jsInfo = GetJSInstanceInfo(instance);
364364
jsInfo->objectClazz = clazz;
365+
if (ObjectWeakCallbackState* state = m_idToObject.Find(jsInfo->javaObjectID)) {
366+
state->objectClazz = clazz;
367+
}
365368
}
366369

367370
int ObjectManager::GetOrCreateObjectId(jobject object) {

0 commit comments

Comments
 (0)