From 21a009de6370037dd6f26c42839894da25a2fee6 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Sat, 21 Nov 2026 17:00:09 -0300 Subject: [PATCH] refactor(runtime): canary wrapper templates by kind Canary handlers are now configured per CanaryKind: kPlain for objects outside JS-extended classes (native class constructors under scope "all", empty instances of such objects) and kExtended for instances of JS-extended classes. Wrappers take the kind of their object (WrapperLifetimeCanary:: KindOf), computed once per wrap; whether a class is JS-extended is cached per class and thread, since the superclass walk costs tens of nanoseconds a class. Adopt checks the kind it is given in debug builds only. ArgConverter::ConstructObject now gives a result whose kind differs from its constructor's template a new object of the result's kind, returned in place of `this`. Before, it did so only for a canary built from a template without handlers. The new cases are a plain template with a JS-extended result and the reverse, which constructing from a pointer (`new NativeClass(handle)`) or an initializer that returns another object reaches. `new` of a JS-extended subclass through a native base does not: ClassConstructorCallback takes the class from the native constructor's metadata, not from new.target. Both kinds install the same masking handlers at this commit, so the replacement object behaves as `this` would have; a later change gives plain canaries different handlers. --- NativeScript/runtime/ArgConverter.h | 23 ++--- NativeScript/runtime/ArgConverter.mm | 85 ++++++++++--------- NativeScript/runtime/ClassBuilder.mm | 4 +- NativeScript/runtime/MetadataBuilder.mm | 7 +- NativeScript/runtime/WrapperLifetime.h | 7 +- NativeScript/runtime/WrapperLifetime.mm | 9 +- NativeScript/runtime/WrapperLifetimeCanary.h | 43 ++++++---- NativeScript/runtime/WrapperLifetimeCanary.mm | 40 ++++++--- 8 files changed, 131 insertions(+), 87 deletions(-) diff --git a/NativeScript/runtime/ArgConverter.h b/NativeScript/runtime/ArgConverter.h index 30b2e7c72..7d06d7f99 100644 --- a/NativeScript/runtime/ArgConverter.h +++ b/NativeScript/runtime/ArgConverter.h @@ -7,6 +7,7 @@ #include "Common.h" #include "DataWrapper.h" #include "IsolateWrapper.h" +#include "WrapperLifetimeCanary.h" #include "libffi.h" namespace tns { @@ -64,14 +65,14 @@ class ArgConverter { v8::Local receiver, const std::vector& additionalProtocols = std::vector()); - // `intercepted`: the object carries the canary handlers - // (WrapperLifetimeCanary::Intercepts). + // `kind`: the canary handlers the object carries + // (WrapperLifetimeCanary::KindOf). static std::shared_ptr> CreateEmptyObject( - v8::Local context, bool intercepted); - // The constructor NewEmptyInstance takes: EmptyObjCtorFunc, or with - // `intercepted` its counterpart carrying the canary handlers. + v8::Local context, CanaryKind kind); + // The constructor NewEmptyInstance takes: EmptyObjCtorFunc for kNone, or its + // counterpart carrying `kind`'s canary handlers. static v8::Persistent* EmptyInstanceFunction( - v8::Isolate* isolate, bool intercepted); + v8::Isolate* isolate, CanaryKind kind); // CreateEmptyObject's object without the ObjectManager registration, for an // object whose collection has nothing to dispose. static v8::Local NewEmptyInstance( @@ -138,17 +139,17 @@ class ArgConverter { // caller returns its defined default. Resets `tc` in both cases. static id HandleBoundaryException(v8::Local context, v8::TryCatch& tc); - // `thisIntercepts`: the constructor's instance template carries the canary - // handlers (WrapperLifetimeCanary::ConfigureInstanceTemplate). Without them, - // a canary gets a new object, returned in place of `this`. + // `thisKind`: the canary handlers the constructor's instance template + // carries (WrapperLifetimeCanary::ConfigureInstanceTemplate). A canary whose + // kind differs gets a new object, returned in place of `this`. static void ConstructObject(v8::Local context, const v8::FunctionCallbackInfo& info, Class klass, const InterfaceMeta* interfaceMeta, - bool thisIntercepts); + CanaryKind thisKind); private: static v8::Local CreateEmptyInstanceFunction( - v8::Local context, bool intercepted); + v8::Local context, CanaryKind kind); static std::shared_ptr> CreateEmptyInstance( v8::Local context, v8::Persistent* ctorFunc); static void FindMethodOverloads(Class klass, std::string methodName, diff --git a/NativeScript/runtime/ArgConverter.mm b/NativeScript/runtime/ArgConverter.mm index f4bf13d31..41dd5f5af 100644 --- a/NativeScript/runtime/ArgConverter.mm +++ b/NativeScript/runtime/ArgConverter.mm @@ -57,13 +57,15 @@ bool IsKVOSubclassOf(Class klass, Class base) { strncmp(class_getName(klass), prefix, sizeof(prefix) - 1) == 0; } -// Canary mode: constructors of wrappers that carry the canary handlers. +// Canary mode: constructors of wrappers that carry the canary handlers, per +// CanaryKind (kNone has none). struct CanaryWrapperConstructors { + static constexpr size_t kKinds = 3; // The empty instance's, for canaries. - std::unique_ptr> emptyInstance; - // Shaped like a native class constructor's instances, which lack the - // handlers under scope "extended". - std::unique_ptr> constructedInstance; + std::unique_ptr> emptyInstance[kKinds]; + // Shaped like a native class constructor's instances, whose template is + // configured for one kind only (WrapperLifetimeCanary::NativeInstancesKind). + std::unique_ptr> constructedInstance[kKinds]; }; } // namespace @@ -98,7 +100,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { Isolate* isolate = v8::Isolate::GetCurrent(); auto cache = Caches::Get(isolate); cache->EmptyObjCtorFunc = std::make_unique>( - isolate, ArgConverter::CreateEmptyInstanceFunction(context, false)); + isolate, ArgConverter::CreateEmptyInstanceFunction(context, CanaryKind::kNone)); if (GetWrapperLifetimeMode() != WrapperLifetimeMode::kCanary) { return; } @@ -106,25 +108,29 @@ bool IsKVOSubclassOf(Class klass, Class base) { if (canary == nullptr) { return; } - canary->emptyInstance = std::make_unique>( - isolate, ArgConverter::CreateEmptyInstanceFunction(context, true)); - Local constructedTemplate = FunctionTemplate::New(isolate); - constructedTemplate->InstanceTemplate()->SetInternalFieldCount(1); - WrapperLifetimeCanary::ConfigureInstanceTemplate(constructedTemplate->InstanceTemplate()); - Local constructedFunc; - tns::Assert(constructedTemplate->GetFunction(context).ToLocal(&constructedFunc), isolate); - canary->constructedInstance = - std::make_unique>(isolate, constructedFunc); + for (CanaryKind kind : {CanaryKind::kPlain, CanaryKind::kExtended}) { + size_t index = static_cast(kind); + canary->emptyInstance[index] = std::make_unique>( + isolate, ArgConverter::CreateEmptyInstanceFunction(context, kind)); + Local constructedTemplate = FunctionTemplate::New(isolate); + constructedTemplate->InstanceTemplate()->SetInternalFieldCount(1); + WrapperLifetimeCanary::ConfigureInstanceTemplate(constructedTemplate->InstanceTemplate(), kind); + Local constructedFunc; + tns::Assert(constructedTemplate->GetFunction(context).ToLocal(&constructedFunc), isolate); + canary->constructedInstance[index] = + std::make_unique>(isolate, constructedFunc); + } } -Persistent* ArgConverter::EmptyInstanceFunction(Isolate* isolate, bool intercepted) { - if (intercepted) { +Persistent* ArgConverter::EmptyInstanceFunction(Isolate* isolate, CanaryKind kind) { + if (kind != CanaryKind::kNone) { // Teardown-safe: a -dealloc receiver can be built after InvalidateIsolate, // while deferred releases drain. CanaryWrapperConstructors* canary = Caches::ExistingStateFor(isolate); - tns::Assert(canary != nullptr && canary->emptyInstance != nullptr, isolate); - return canary->emptyInstance.get(); + size_t index = static_cast(kind); + tns::Assert(canary != nullptr && canary->emptyInstance[index] != nullptr, isolate); + return canary->emptyInstance[index].get(); } return Caches::Get(isolate)->EmptyObjCtorFunc.get(); } @@ -741,7 +747,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { void ArgConverter::ConstructObject(Local context, const FunctionCallbackInfo& info, Class klass, const InterfaceMeta* interfaceMeta, - bool thisIntercepts) { + CanaryKind thisKind) { Isolate* isolate = v8::Isolate::GetCurrent(); tns::Assert(klass != nullptr, isolate); WrapperLifetime::DrainAtCallEntry(isolate); @@ -805,20 +811,23 @@ bool IsKVOSubclassOf(Class klass, Class base) { ObjCDataWrapper* wrapper = new ObjCDataWrapper(result); Local thiz = info.This(); Local context = cache->GetContext(); - bool intercepted = thisIntercepts; - if (!intercepted && WrapperLifetimeCanary::Intercepts(result)) { - // A canary needs the handlers `this` was built without: returning - // another object makes it the result of `new`, and `this` after super(). + CanaryKind kind = thisKind; + CanaryKind resultKind = WrapperLifetimeCanary::KindOf(result); + if (resultKind != CanaryKind::kNone && resultKind != kind) { + // A canary needs handlers `this` was built without: returning another + // object makes it the result of `new`, and `this` after super(). CanaryWrapperConstructors* canary = Caches::StateFor(isolate); - tns::Assert(canary != nullptr && canary->constructedInstance != nullptr, isolate); - Local replacement = NewEmptyInstance(context, canary->constructedInstance.get()); + size_t index = static_cast(resultKind); + tns::Assert(canary != nullptr && canary->constructedInstance[index] != nullptr, isolate); + Local replacement = + NewEmptyInstance(context, canary->constructedInstance[index].get()); bool success; if (!replacement->SetPrototype(context, thiz->GetPrototype()).To(&success) || !success) { tns::Assert(false, isolate); } thiz = replacement; info.GetReturnValue().Set(thiz); - intercepted = true; + kind = resultKind; } tns::SetValue(isolate, thiz, wrapper); std::shared_ptr> poThiz = ObjectManager::Register(context, thiz); @@ -837,7 +846,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { wrapper->SetBornOnRuntimeThread(); ObjectManager::ProtectIfNativelyRetained(isolate, result, wrapper); } - WrapperLifetime::Adopt(isolate, wrapper, poThiz, result, intercepted); + WrapperLifetime::Adopt(isolate, wrapper, poThiz, result, kind); ExternalMemory::ChargeEstimatedSize(isolate, thiz); } } @@ -1058,7 +1067,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { ObjCAllocDataWrapper* allocDataWrapper = static_cast(wrapper); Class klass = allocDataWrapper->Klass(); - std::shared_ptr> poValue = CreateEmptyObject(context, false); + std::shared_ptr> poValue = CreateEmptyObject(context, CanaryKind::kNone); receiver = poValue->Get(isolate).As(); const Meta* meta = FindMeta(klass); @@ -1108,8 +1117,8 @@ bool IsKVOSubclassOf(Class klass, Class base) { receiver = it->second->Get(isolate).As(); WrapperLifetime::EscapeValue(isolate, receiver); } else { - bool intercepted = WrapperLifetimeCanary::Intercepts(target); - std::shared_ptr> poValue = CreateEmptyObject(context, intercepted); + CanaryKind kind = WrapperLifetimeCanary::KindOf(target); + std::shared_ptr> poValue = CreateEmptyObject(context, kind); receiver = poValue->Get(isolate).As(); tns::SetValue(isolate, receiver, wrapper); cache->Instances.emplace(target, poValue); @@ -1124,7 +1133,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { } if (wrapper->Type() == WrapperType::ObjCObject) { WrapperLifetime::Adopt(isolate, static_cast(wrapper), poValue, target, - intercepted); + kind); } } } else { @@ -1333,7 +1342,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { wrapper->MarkBorrowed(); // Its writes reach the object's JS state through the canary handlers. Local receiver = NewEmptyInstance( - context, EmptyInstanceFunction(isolate, WrapperLifetimeCanary::Intercepts(self))); + context, EmptyInstanceFunction(isolate, WrapperLifetimeCanary::KindOf(self))); CreateJsWrapper(context, wrapper, receiver); WrapperLifetimeCanary::Hydrate(isolate, receiver); *borrowed = wrapper; @@ -1364,9 +1373,9 @@ bool IsKVOSubclassOf(Class klass, Class base) { } std::shared_ptr> ArgConverter::CreateEmptyObject(Local context, - bool intercepted) { + CanaryKind kind) { Isolate* isolate = v8::Isolate::GetCurrent(); - Persistent* ctorFunc = EmptyInstanceFunction(isolate, intercepted); + Persistent* ctorFunc = EmptyInstanceFunction(isolate, kind); tns::Assert(ctorFunc != nullptr, isolate); return ArgConverter::CreateEmptyInstance(context, ctorFunc); } @@ -1390,7 +1399,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { } Local ArgConverter::CreateEmptyInstanceFunction(Local context, - bool intercepted) { + CanaryKind kind) { Isolate* isolate = v8::Isolate::GetCurrent(); Local emptyInstanceCtorFuncTemplate = FunctionTemplate::New(isolate, nullptr); Local instanceTemplate = emptyInstanceCtorFuncTemplate->InstanceTemplate(); @@ -1398,9 +1407,7 @@ bool IsKVOSubclassOf(Class klass, Class base) { instanceTemplate->SetHandler(IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback, IndexedPropertySetterCallback)); - if (intercepted) { - WrapperLifetimeCanary::ConfigureInstanceTemplate(instanceTemplate); - } + WrapperLifetimeCanary::ConfigureInstanceTemplate(instanceTemplate, kind); Local emptyInstanceCtorFunc; if (!emptyInstanceCtorFuncTemplate->GetFunction(context).ToLocal(&emptyInstanceCtorFunc)) { diff --git a/NativeScript/runtime/ClassBuilder.mm b/NativeScript/runtime/ClassBuilder.mm index 92fcd674a..a09e67c12 100644 --- a/NativeScript/runtime/ClassBuilder.mm +++ b/NativeScript/runtime/ClassBuilder.mm @@ -113,7 +113,7 @@ void ScopeClassNameToIsolate(std::string& name, int isolateId) { FunctionTemplate::New(isolate, ExtendedClassConstructorCallback, ext); extendedClassCtorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(1); WrapperLifetimeCanary::ConfigureInstanceTemplate( - extendedClassCtorFuncTemplate->InstanceTemplate()); + extendedClassCtorFuncTemplate->InstanceTemplate(), CanaryKind::kExtended); Local extendClassCtorFunc; if (!extendedClassCtorFuncTemplate->GetFunction(context).ToLocal(&extendClassCtorFunc)) { @@ -180,7 +180,7 @@ void ScopeClassNameToIsolate(std::string& name, int isolateId) { info.Data().As()->Value(v8::kExternalPointerTypeTagDefault)); Class klass = item->data_; - ArgConverter::ConstructObject(context, info, klass, nullptr, true); + ArgConverter::ConstructObject(context, info, klass, nullptr, CanaryKind::kExtended); } catch (NativeScriptException& ex) { ex.ReThrowToV8(isolate); } diff --git a/NativeScript/runtime/MetadataBuilder.mm b/NativeScript/runtime/MetadataBuilder.mm index d3cbb655a..94d85c3c5 100644 --- a/NativeScript/runtime/MetadataBuilder.mm +++ b/NativeScript/runtime/MetadataBuilder.mm @@ -847,9 +847,8 @@ throw NativeScriptException( ctorFuncTemplate = FunctionTemplate::New(isolate, ClassConstructorCallback, ext); ctorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(1); - if (WrapperLifetimeCanary::NativeInstancesIntercept()) { - WrapperLifetimeCanary::ConfigureInstanceTemplate(ctorFuncTemplate->InstanceTemplate()); - } + WrapperLifetimeCanary::ConfigureInstanceTemplate(ctorFuncTemplate->InstanceTemplate(), + WrapperLifetimeCanary::NativeInstancesKind()); ctorFuncTemplate->SetClassName(tns::ToV8String(isolate, meta->name())); Local baseCtorFunc; @@ -1410,7 +1409,7 @@ void CollectInstanceMemberNames(const BaseClassMeta* meta, Class klass, bool own const InterfaceMeta* interfaceMeta = static_cast(item->meta_); ArgConverter::ConstructObject(context, info, klass, interfaceMeta, - WrapperLifetimeCanary::NativeInstancesIntercept()); + WrapperLifetimeCanary::NativeInstancesKind()); } catch (NativeScriptException& ex) { ex.ReThrowToV8(isolate); } diff --git a/NativeScript/runtime/WrapperLifetime.h b/NativeScript/runtime/WrapperLifetime.h index 7df9791a6..6c8460114 100644 --- a/NativeScript/runtime/WrapperLifetime.h +++ b/NativeScript/runtime/WrapperLifetime.h @@ -7,6 +7,7 @@ #include "DataWrapper.h" #include "Helpers.h" #include "ObjectManager.h" +#include "WrapperLifetimeCanary.h" namespace tns { @@ -76,11 +77,11 @@ class WrapperLifetime { // A newly wrapped ObjC object: `handle` is its Instances entry, registered by // ObjectManager::Register and holding the entry's +1 on `target`. - // `intercepted`: the wrapper carries the canary handlers - // (WrapperLifetimeCanary::Intercepts). + // `kind`: the canary handlers the wrapper carries + // (WrapperLifetimeCanary::KindOf). static void Adopt(v8::Isolate* isolate, ObjCDataWrapper* wrapper, const std::shared_ptr>& handle, - id target, bool intercepted); + id target, CanaryKind kind); // The object crossed the JS/native boundary: native code returned it to JS, // or received it as a receiver, argument, return value of a JS-implemented diff --git a/NativeScript/runtime/WrapperLifetime.mm b/NativeScript/runtime/WrapperLifetime.mm index 294cd5e1f..f3d1a9052 100644 --- a/NativeScript/runtime/WrapperLifetime.mm +++ b/NativeScript/runtime/WrapperLifetime.mm @@ -351,7 +351,7 @@ void ReleaseAll(Isolate* isolate, RootedState* rooted) { void WrapperLifetime::Adopt(Isolate* isolate, ObjCDataWrapper* wrapper, const std::shared_ptr>& handle, id target, - bool intercepted) { + CanaryKind kind) { if (GetWrapperLifetimeMode() == WrapperLifetimeMode::kResurrecting || target == nil) { return; } @@ -372,8 +372,11 @@ void ReleaseAll(Isolate* isolate, RootedState* rooted) { wrapper->SetLifetimeState(state); if (GetWrapperLifetimeMode() == WrapperLifetimeMode::kCanary) { state->lifetimeCanary_ = IsInScope(target); - // A canary without the handlers would lose its JS properties when it dies. - tns::Assert(!state->lifetimeCanary_ || intercepted, isolate); +#ifdef DEBUG + // A canary without its kind's handlers would lose its JS properties when it + // dies. + tns::Assert(!state->lifetimeCanary_ || kind == WrapperLifetimeCanary::KindOf(target), isolate); +#endif if (state->lifetimeCanary_) { state->canaryRecord_ = WrapperLifetimeCanary::Find(isolate, target); if (state->canaryRecord_ != nullptr) { diff --git a/NativeScript/runtime/WrapperLifetimeCanary.h b/NativeScript/runtime/WrapperLifetimeCanary.h index 25ad85666..d98f2c391 100644 --- a/NativeScript/runtime/WrapperLifetimeCanary.h +++ b/NativeScript/runtime/WrapperLifetimeCanary.h @@ -3,6 +3,7 @@ #include +#include #include #include @@ -12,6 +13,18 @@ namespace tns { struct CanaryRecord; +// The handlers a wrapper's template carries in canary mode: none for a wrapper +// that is not a canary, and per kind for one that is. A canary must be built +// from a template configured for its object's kind (WrapperLifetimeCanary:: +// KindOf). +enum class CanaryKind : uint8_t { + kNone, + // A canary of an object outside JS-extended classes (scope "all"). + kPlain, + // A canary of an instance of a JS-extended class. + kExtended, +}; + // The canary wrapper lifetime mode (WrapperLifetimeMode::kCanary). // // An ObjC object's wrapper is a canary: a phantom-weak JS object that dies @@ -55,22 +68,22 @@ class WrapperLifetimeCanary { // `imp` unchanged for any other selector, or unless the mode is canary. static IMP WrapDealloc(SEL selector, IMP imp); - // Installs the forwarding handlers on an ObjC instance template. No-op unless - // the mode is canary. Only canaries need them: other wrappers would pay for - // every write and gain nothing. + // Installs `kind`'s handlers on an ObjC instance template. No-op for kNone, + // or unless the mode is canary. Only canaries need them: other wrappers would + // pay for every write and gain nothing. static void ConfigureInstanceTemplate( - v8::Local instanceTemplate); - - // Whether `object`'s wrapper is a canary, so must be built from a template - // ConfigureInstanceTemplate configured. - static bool Intercepts(id object); - - // Whether a native class constructor's instance template gets the handlers: - // under scope "all" its instances are canaries. Under "extended" they are - // canaries only when the constructor yields an instance of a JS-extended - // class (an existing object adopted from a pointer, or one an initializer - // returned instead), which ArgConverter::ConstructObject wraps anew. - static bool NativeInstancesIntercept(); + v8::Local instanceTemplate, CanaryKind kind); + + // The kind of canary `object`'s wrapper is, kNone when it is not one. + static CanaryKind KindOf(id object); + + // The kind a native class constructor's instance template is configured + // for: under scope "all" its instances are plain canaries. Under "extended" + // they are canaries only when the constructor yields an instance of a + // JS-extended class (an existing object adopted from a pointer, or one an + // initializer returned instead), which ArgConverter::ConstructObject wraps + // anew, as it does any result whose kind differs from the template's. + static CanaryKind NativeInstancesKind(); // Adds `unwrap` (a canary's native object -> its weak-collection key) and // `wrap` (key -> live or new canary, or undefined once the object is gone) diff --git a/NativeScript/runtime/WrapperLifetimeCanary.mm b/NativeScript/runtime/WrapperLifetimeCanary.mm index db2fb319a..2e5b34629 100644 --- a/NativeScript/runtime/WrapperLifetimeCanary.mm +++ b/NativeScript/runtime/WrapperLifetimeCanary.mm @@ -221,13 +221,27 @@ void ReportDyingRecordsDied(const DyingRecords& dying, void* object) { // Not a message: a root class without -conformsToProtocol: would crash under // scope "all". Walks the superclasses for key-value observing's subclass. +// Cached per class and thread, as every wrap under scope "all" asks and the +// walk costs tens of nanoseconds a class: the answer for a class is fixed +// before it has instances (ClassBuilder adds TNSDerivedClass to a class it +// creates first thing). A class disposed with objc_disposeClassPair and +// another allocated at its address would read the old answer. bool IsExtendedInstance(id object) { - for (Class cls = object_getClass(object); cls != nil; cls = class_getSuperclass(cls)) { + Class klass = object_getClass(object); + thread_local std::unordered_map extendedClasses; + auto cached = extendedClasses.find(klass); + if (cached != extendedClasses.end()) { + return cached->second; + } + bool extended = false; + for (Class cls = klass; cls != nil; cls = class_getSuperclass(cls)) { if (class_conformsToProtocol(cls, @protocol(TNSDerivedClass))) { - return true; + extended = true; + break; } } - return false; + extendedClasses.emplace(klass, extended); + return extended; } #if NS_CANARY_DEATH_SIGNAL == NS_CANARY_DEATH_ASSOCIATION @@ -950,8 +964,9 @@ void WrapCallback(const FunctionCallbackInfo& info) { }); } -void WrapperLifetimeCanary::ConfigureInstanceTemplate(Local instanceTemplate) { - if (GetWrapperLifetimeMode() != WrapperLifetimeMode::kCanary) { +void WrapperLifetimeCanary::ConfigureInstanceTemplate(Local instanceTemplate, + CanaryKind kind) { + if (kind == CanaryKind::kNone || GetWrapperLifetimeMode() != WrapperLifetimeMode::kCanary) { return; } instanceTemplate->SetHandler( @@ -959,14 +974,19 @@ void WrapCallback(const FunctionCallbackInfo& info) { nullptr, Local(), PropertyHandlerFlags::kNone)); } -bool WrapperLifetimeCanary::Intercepts(id object) { - return GetWrapperLifetimeMode() == WrapperLifetimeMode::kCanary && - WrapperLifetime::InScope(object); +CanaryKind WrapperLifetimeCanary::KindOf(id object) { + if (GetWrapperLifetimeMode() != WrapperLifetimeMode::kCanary || + !WrapperLifetime::InScope(object)) { + return CanaryKind::kNone; + } + return IsExtendedInstance(object) ? CanaryKind::kExtended : CanaryKind::kPlain; } -bool WrapperLifetimeCanary::NativeInstancesIntercept() { +CanaryKind WrapperLifetimeCanary::NativeInstancesKind() { return GetWrapperLifetimeMode() == WrapperLifetimeMode::kCanary && - GetWrapperLifetimeScope() == WrapperLifetimeScope::kAll; + GetWrapperLifetimeScope() == WrapperLifetimeScope::kAll + ? CanaryKind::kPlain + : CanaryKind::kNone; } void WrapperLifetimeCanary::Hydrate(Isolate* isolate, Local wrapper) {