@@ -320,7 +320,7 @@ inline bool tryObjCNapiDispatch(napi_env env, Cif* cif, id self, bool classMetho
320320 *didInvoke = false ;
321321 }
322322
323- if (cif == nullptr || cif->signatureHash == 0 || cif-> skipGeneratedNapiDispatch ) {
323+ if (cif == nullptr || cif->signatureHash == 0 ) {
324324 return true ;
325325 }
326326
@@ -344,23 +344,36 @@ inline bool tryObjCNapiDispatch(napi_env env, Cif* cif, id self, bool classMetho
344344 reinterpret_cast <void *>(lookupObjCPreparedInvoker (descriptor->dispatchId ));
345345 descriptor->napiInvoker =
346346 reinterpret_cast <void *>(lookupObjCNapiInvoker (descriptor->dispatchId ));
347+ descriptor->engineDirectInvoker =
348+ reinterpret_cast <void *>(lookupObjCEngineDirectInvoker (descriptor->dispatchId ));
347349#ifdef TARGET_ENGINE_V8
348350 descriptor->v8Invoker = reinterpret_cast <void *>(lookupObjCV8Invoker (descriptor->dispatchId ));
349351#endif
350352 descriptor->dispatchLookupCached = true ;
351353 }
352354 }
353355
354- auto invoker = descriptor != nullptr
355- ? reinterpret_cast <ObjCNapiInvoker>(descriptor->napiInvoker )
356- : lookupObjCNapiInvoker (composeSignatureDispatchId (
357- cif->signatureHash , SignatureCallKind::ObjCMethod, dispatchFlags));
358- if (invoker == nullptr ) {
356+ ObjCEngineDirectInvoker engineInvoker =
357+ descriptor != nullptr
358+ ? reinterpret_cast <ObjCEngineDirectInvoker>(descriptor->engineDirectInvoker )
359+ : lookupObjCEngineDirectInvoker (composeSignatureDispatchId (
360+ cif->signatureHash , SignatureCallKind::ObjCMethod, dispatchFlags));
361+ ObjCNapiInvoker invoker =
362+ engineInvoker == nullptr && !cif->skipGeneratedNapiDispatch
363+ ? (descriptor != nullptr
364+ ? reinterpret_cast <ObjCNapiInvoker>(descriptor->napiInvoker )
365+ : lookupObjCNapiInvoker (composeSignatureDispatchId (
366+ cif->signatureHash , SignatureCallKind::ObjCMethod, dispatchFlags)))
367+ : nullptr ;
368+ if (engineInvoker == nullptr && invoker == nullptr ) {
359369 return true ;
360370 }
361371
362372 @try {
363- if (!invoker (env, cif, (void *)objc_msgSend, self, selector, argv, rvalue)) {
373+ bool invoked = engineInvoker != nullptr
374+ ? engineInvoker (env, cif, (void *)objc_msgSend, self, selector, argv, rvalue)
375+ : invoker (env, cif, (void *)objc_msgSend, self, selector, argv, rvalue);
376+ if (!invoked) {
364377 return false ;
365378 }
366379 } @catch (NSException * exception) {
@@ -419,6 +432,8 @@ inline bool objcNativeCall(napi_env env, Cif* cif, id self, bool classMethod,
419432 reinterpret_cast <void *>(lookupObjCPreparedInvoker (descriptor->dispatchId ));
420433 descriptor->napiInvoker =
421434 reinterpret_cast <void *>(lookupObjCNapiInvoker (descriptor->dispatchId ));
435+ descriptor->engineDirectInvoker =
436+ reinterpret_cast <void *>(lookupObjCEngineDirectInvoker (descriptor->dispatchId ));
422437#ifdef TARGET_ENGINE_V8
423438 descriptor->v8Invoker =
424439 reinterpret_cast <void *>(lookupObjCV8Invoker (descriptor->dispatchId ));
@@ -1675,7 +1690,13 @@ explicit CifReturnStorage(Cif* cif) {
16751690 }
16761691 }
16771692
1678- return cif->returnType ->toJS (env, nativeResult, method->returnOwned ? kReturnOwned : 0 );
1693+ napi_value fastResult = nullptr ;
1694+ if (TryFastConvertEngineReturnValue (env, cif->returnType ->kind ,
1695+ nativeResult, &fastResult)) {
1696+ return fastResult;
1697+ }
1698+ return cif->returnType ->toJS (env, nativeResult,
1699+ method->returnOwned ? kReturnOwned : 0 );
16791700 };
16801701
16811702 bool usesBlockFallback = false ;
@@ -1867,6 +1888,11 @@ NativeScriptException nativeScriptException(errorMessage != nullptr ? errorMessa
18671888 method->returnOwned ? kOwnedObject : kUnownedObject );
18681889 }
18691890
1891+ napi_value fastResult = nullptr ;
1892+ if (TryFastConvertEngineReturnValue (env, cif->returnType ->kind , rvalue,
1893+ &fastResult)) {
1894+ return fastResult;
1895+ }
18701896 return cif->returnType ->toJS (env, rvalue, 0 );
18711897}
18721898
0 commit comments