Skip to content

Commit 20107e6

Browse files
committed
perf(ffi/v8): fix constructor/superclass resolution with kNonMasking
Improve constructor handler to try cached class value and global lookup before falling back to makeNativeClassValue. Also skip className from prototype installation. Tests: 712/713 (1 Swift class name edge case remaining) Benchmark: ~773ms
1 parent a6413ef commit 20107e6

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

NativeScript/ffi/shared/bridge/HostObjects.mm

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,40 @@ Value get(Runtime& runtime, const PropNameID& name) override {
974974
if (object_ == nil) {
975975
return Value::undefined();
976976
}
977+
// Check class wrapper expando first (set during class setup).
977978
Value classWrapper = bridge_->findObjectExpando(
978979
runtime, object_, "__nativeApiClassWrapper");
979980
if (classWrapper.isObject()) {
980981
return classWrapper;
981982
}
983+
// Try cached class value.
984+
Class objClass = object_getClass(object_);
985+
Value cached = bridge_->findClassValue(runtime, objClass);
986+
if (!cached.isUndefined()) {
987+
return cached;
988+
}
989+
// Resolve through metadata and global.
982990
NativeApiSymbol symbol =
983-
nativeApiSymbolForRuntimeClass(bridge_, object_getClass(object_));
991+
nativeApiSymbolForRuntimeClass(bridge_, objClass);
992+
// Try the global by the symbol's name (which may be the JS-friendly name
993+
// from metadata, different from the ObjC runtime name for Swift classes).
994+
if (!symbol.name.empty()) {
995+
Object global = runtime.global();
996+
if (global.hasProperty(runtime, symbol.name.c_str())) {
997+
Value globalClass = global.getProperty(runtime, symbol.name.c_str());
998+
if (!globalClass.isUndefined() && !globalClass.isNull()) {
999+
return globalClass;
1000+
}
1001+
}
1002+
// Also try the runtime name if different.
1003+
if (symbol.runtimeName != symbol.name &&
1004+
global.hasProperty(runtime, symbol.runtimeName.c_str())) {
1005+
Value globalClass = global.getProperty(runtime, symbol.runtimeName.c_str());
1006+
if (!globalClass.isUndefined() && !globalClass.isNull()) {
1007+
return globalClass;
1008+
}
1009+
}
1010+
}
9841011
return makeNativeClassValue(runtime, bridge_, std::move(symbol));
9851012
}
9861013
if (property == "superclass") {

0 commit comments

Comments
 (0)