Skip to content

Commit 77fedf7

Browse files
committed
fix(runtime): canary receivers of JS methods native code calls stay canaries
WrapperLifetime::Relinquish handed a canary back to ObjectManager like any other unrooted wrapper. A canary keeps the canary mode's lifetime, so only wrappers outside the canary scope get ownership tracking.
1 parent 9d83bd0 commit 77fedf7

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎NativeScript/runtime/ArgConverter.mm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,8 @@ bool IsKVOSubclassOf(Class klass, Class base) {
13441344
// Native code usually still holds the object (it is mid-initialization or
13451345
// owned by whoever called in), and its JS state must outlive this call: the
13461346
// handle stays strong until the Instances entry is the object's only owner.
1347-
// A wrapper a lifetime mode roots keeps the mode's own lifetime instead.
1347+
// A wrapper a lifetime mode roots or makes a canary keeps the mode's own
1348+
// lifetime instead.
13481349
if (wrapper->LifetimeState() != nullptr) {
13491350
if (ObjectWeakCallbackState* state = WrapperLifetime::Relinquish(wrapper)) {
13501351
ObjectManager::ManageOwnership(isolate, wrapper, state);

‎NativeScript/runtime/WrapperLifetime.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class WrapperLifetime {
103103
}
104104
}
105105

106-
// Gives an adopted wrapper that is not rooted back to ObjectManager: returns
107-
// its registration with the handle strong, for
106+
// Gives an adopted wrapper that is neither rooted nor a canary back to
107+
// ObjectManager: returns its registration with the handle strong, for
108108
// ObjectManager::ManageOwnership. Null when the mode keeps the wrapper.
109109
static ObjectWeakCallbackState* Relinquish(ObjCDataWrapper* wrapper);
110110

‎NativeScript/runtime/WrapperLifetime.mm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ void ReleaseAll(Isolate* isolate, RootedState* rooted) {
382382

383383
ObjectWeakCallbackState* WrapperLifetime::Relinquish(ObjCDataWrapper* wrapper) {
384384
ObjectWeakCallbackState* state = wrapper->LifetimeState();
385-
if (state == nullptr || state->lifetimeTracked_ || state->target_->IsEmpty()) {
385+
if (state == nullptr || state->lifetimeTracked_ || state->lifetimeCanary_ ||
386+
state->target_->IsEmpty()) {
386387
return nullptr;
387388
}
388389
if (state->target_->IsWeak()) {

0 commit comments

Comments
 (0)