Skip to content

Commit c0acd15

Browse files
committed
fix: cache unreadable runtime setter values
1 parent bd296cd commit c0acd15

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

NativeScript/ffi/shared/bridge/HostObjects.mm

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,31 @@ NativeApiSymbol nativeApiSymbolForRuntimeClass(
538538
return resolved;
539539
}
540540

541+
bool objectGetPathCanReadRuntimeProperty(id object,
542+
const std::string& property) {
543+
if (object == nil || property.empty()) {
544+
return false;
545+
}
546+
547+
if (class_conformsToProtocol(object_getClass(object),
548+
@protocol(NativeApiClassBuilderProtocol))) {
549+
return runtimeReadablePropertyGetter(object, property).has_value();
550+
}
551+
552+
if (objc_property_t prop =
553+
class_getProperty(object_getClass(object), property.c_str())) {
554+
std::string getter = property;
555+
if (char* customGetter = property_copyAttributeValue(prop, "G")) {
556+
getter = customGetter;
557+
free(customGetter);
558+
}
559+
return respondingPropertyGetterSelector(object, property, getter)
560+
.has_value();
561+
}
562+
563+
return false;
564+
}
565+
541566
class NativeApiSuperHostObject final : public HostObject {
542567
public:
543568
NativeApiSuperHostObject(std::shared_ptr<NativeApiBridge> bridge,
@@ -1700,7 +1725,7 @@ throw JSError(
17001725
Value args[] = {Value(runtime, value)};
17011726
callObjCSelector(runtime, bridge_, object_, false,
17021727
*setterSelectorName, nullptr, args, 1);
1703-
if (!runtimeReadablePropertyGetter(object_, property)) {
1728+
if (!objectGetPathCanReadRuntimeProperty(object_, property)) {
17041729
bridge_->setObjectExpando(runtime, object_, property, value);
17051730
}
17061731
NATIVE_API_SET_RETURN(true);

0 commit comments

Comments
 (0)