@@ -1203,24 +1203,7 @@ Value prototypeFunctionForProperty(Runtime& runtime,
12031203 return Value::undefined ();
12041204 }
12051205
1206- Value classWrapperValue = bridge_->findObjectExpando (
1207- runtime, object_, " __nativeApiClassWrapper" );
1208- if (!classWrapperValue.isObject ()) {
1209- classWrapperValue = bridge_->findClassValue (runtime, object_getClass (object_));
1210- }
1211- if (!classWrapperValue.isObject ()) {
1212- if (const NativeApiSymbol* symbol =
1213- bridge_->findClassForRuntimeClass (object_getClass (object_))) {
1214- classWrapperValue = bridge_->findClassValue (
1215- runtime, objc_lookUpClass (symbol->runtimeName .c_str ()));
1216- }
1217- }
1218- if (!classWrapperValue.isObject ()) {
1219- return Value::undefined ();
1220- }
1221-
1222- Object classWrapper = classWrapperValue.asObject (runtime);
1223- Value prototypeValue = classWrapper.getProperty (runtime, " prototype" );
1206+ Value prototypeValue = enginePrototypeForObject (runtime);
12241207 if (!prototypeValue.isObject ()) {
12251208 return Value::undefined ();
12261209 }
@@ -1257,6 +1240,48 @@ Value prototypeFunctionForProperty(Runtime& runtime,
12571240 return Value::undefined ();
12581241 }
12591242
1243+ Value enginePrototypeForObject (Runtime& runtime) {
1244+ if (object_ == nil ) {
1245+ return Value::undefined ();
1246+ }
1247+
1248+ Value classWrapperValue = bridge_->findObjectExpando (
1249+ runtime, object_, " __nativeApiClassWrapper" );
1250+ if (!classWrapperValue.isObject ()) {
1251+ classWrapperValue = bridge_->findClassValue (runtime, object_getClass (object_));
1252+ }
1253+ if (!classWrapperValue.isObject ()) {
1254+ if (const NativeApiSymbol* symbol =
1255+ bridge_->findClassForRuntimeClass (object_getClass (object_))) {
1256+ classWrapperValue = bridge_->findClassValue (
1257+ runtime, objc_lookUpClass (symbol->runtimeName .c_str ()));
1258+ }
1259+ }
1260+ if (classWrapperValue.isObject ()) {
1261+ Object classWrapper = classWrapperValue.asObject (runtime);
1262+ Value prototypeValue = classWrapper.getProperty (runtime, " prototype" );
1263+ if (prototypeValue.isObject ()) {
1264+ return prototypeValue;
1265+ }
1266+ }
1267+
1268+ Value prototypeValue =
1269+ bridge_->findClassPrototype (runtime, object_getClass (object_));
1270+ if (prototypeValue.isObject ()) {
1271+ return prototypeValue;
1272+ }
1273+ if (const NativeApiSymbol* symbol =
1274+ bridge_->findClassForRuntimeClass (object_getClass (object_))) {
1275+ prototypeValue = bridge_->findClassPrototype (
1276+ runtime, objc_lookUpClass (symbol->runtimeName .c_str ()));
1277+ if (prototypeValue.isObject ()) {
1278+ return prototypeValue;
1279+ }
1280+ }
1281+
1282+ return Value::undefined ();
1283+ }
1284+
12601285 // Invoke a JS-prototype getter accessor with this instance as the receiver.
12611286 // Sets *found and returns the resolved value.
12621287 Value resolveEnginePrototypeGetter (Runtime& runtime,
@@ -1265,17 +1290,7 @@ Value resolveEnginePrototypeGetter(Runtime& runtime,
12651290 if (object_ == nil || property.empty ()) {
12661291 return Value::undefined ();
12671292 }
1268- Value classWrapperValue =
1269- bridge_->findObjectExpando (runtime, object_, " __nativeApiClassWrapper" );
1270- if (!classWrapperValue.isObject ()) {
1271- classWrapperValue =
1272- bridge_->findClassValue (runtime, object_getClass (object_));
1273- }
1274- if (!classWrapperValue.isObject ()) {
1275- return Value::undefined ();
1276- }
1277- Value prototypeValue =
1278- classWrapperValue.asObject (runtime).getProperty (runtime, " prototype" );
1293+ Value prototypeValue = enginePrototypeForObject (runtime);
12791294 if (!prototypeValue.isObject ()) {
12801295 return Value::undefined ();
12811296 }
@@ -1324,17 +1339,7 @@ bool invokeEnginePrototypeSetter(Runtime& runtime, const std::string& property,
13241339 if (object_ == nil || property.empty ()) {
13251340 return false ;
13261341 }
1327- Value classWrapperValue =
1328- bridge_->findObjectExpando (runtime, object_, " __nativeApiClassWrapper" );
1329- if (!classWrapperValue.isObject ()) {
1330- classWrapperValue =
1331- bridge_->findClassValue (runtime, object_getClass (object_));
1332- }
1333- if (!classWrapperValue.isObject ()) {
1334- return false ;
1335- }
1336- Value prototypeValue =
1337- classWrapperValue.asObject (runtime).getProperty (runtime, " prototype" );
1342+ Value prototypeValue = enginePrototypeForObject (runtime);
13381343 if (!prototypeValue.isObject ()) {
13391344 return false ;
13401345 }
@@ -1377,17 +1382,7 @@ bool enginePrototypeHasSetter(Runtime& runtime,
13771382 if (object_ == nil || property.empty ()) {
13781383 return false ;
13791384 }
1380- Value classWrapperValue =
1381- bridge_->findObjectExpando (runtime, object_, " __nativeApiClassWrapper" );
1382- if (!classWrapperValue.isObject ()) {
1383- classWrapperValue =
1384- bridge_->findClassValue (runtime, object_getClass (object_));
1385- }
1386- if (!classWrapperValue.isObject ()) {
1387- return false ;
1388- }
1389- Value prototypeValue =
1390- classWrapperValue.asObject (runtime).getProperty (runtime, " prototype" );
1385+ Value prototypeValue = enginePrototypeForObject (runtime);
13911386 if (!prototypeValue.isObject ()) {
13921387 return false ;
13931388 }
0 commit comments