diff --git a/ReactCommon/turbomodule/core/TurboCxxModule.h b/ReactCommon/turbomodule/core/TurboCxxModule.h index c44ba2a9d..8cd06fcd8 100644 --- a/ReactCommon/turbomodule/core/TurboCxxModule.h +++ b/ReactCommon/turbomodule/core/TurboCxxModule.h @@ -28,12 +28,12 @@ public: virtual facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override; - virtual jsi::Value invokeMethod( + jsi::Value invokeMethod( jsi::Runtime &runtime, TurboModuleMethodValueKind valueKind, const std::string &methodName, const jsi::Value *args, - size_t count) override; + size_t count); private: std::vector cxxMethods_; diff --git a/ReactCommon/turbomodule/core/TurboModule.cpp b/ReactCommon/turbomodule/core/TurboModule.cpp index 916c2b60d..352bb7a8b 100644 --- a/ReactCommon/turbomodule/core/TurboModule.cpp +++ b/ReactCommon/turbomodule/core/TurboModule.cpp @@ -16,11 +16,7 @@ TurboModule::TurboModule(const std::string &name, std::shared_ptr : name_(name), jsInvoker_(jsInvoker) {} -TurboModule::~TurboModule() { - invalidate(); -} - -void TurboModule::invalidate() {} +TurboModule::~TurboModule() {} jsi::Value TurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) { std::string propNameUtf8 = propName.utf8(runtime); @@ -39,14 +35,5 @@ jsi::Value TurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propNa }); } -jsi::Value TurboModule::invokeMethod( - jsi::Runtime &runtime, - TurboModuleMethodValueKind valueKind, - const std::string &methodName, - const jsi::Value *args, - size_t count) { - return jsi::Value::undefined(); -} - } // namespace react } // namespace facebook diff --git a/ReactCommon/turbomodule/core/TurboModule.h b/ReactCommon/turbomodule/core/TurboModule.h index d1691edfd..4bb398a0c 100644 --- a/ReactCommon/turbomodule/core/TurboModule.h +++ b/ReactCommon/turbomodule/core/TurboModule.h @@ -40,24 +40,8 @@ public: TurboModule(const std::string &name, std::shared_ptr jsInvoker); virtual ~TurboModule(); - /** - * Instruct this module to invalidate itself. - */ - virtual void invalidate(); - virtual facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override; - /** - * General method invocation mechanism. - * Each subclass decides how the invocation should be, and whether it should be platform-specific. - */ - virtual jsi::Value invokeMethod( - jsi::Runtime &runtime, - TurboModuleMethodValueKind valueKind, - const std::string &methodName, - const jsi::Value *args, - size_t count); - const std::string name_; std::shared_ptr jsInvoker_; diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h index 6cbc3a42e..ab0464ac8 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h @@ -33,13 +33,6 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { public: ObjCTurboModule(const std::string &name, id instance, std::shared_ptr jsInvoker); - virtual jsi::Value invokeMethod( - jsi::Runtime &runtime, - TurboModuleMethodValueKind valueKind, - const std::string &methodName, - const jsi::Value *args, - size_t count) override; - jsi::Value invokeObjCMethod( jsi::Runtime &runtime, TurboModuleMethodValueKind valueKind, diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.mm index 6b594ef03..a66058537 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.mm @@ -278,53 +278,6 @@ namespace react { namespace { -SEL resolveMethodSelector( - TurboModuleMethodValueKind valueKind, - id module, - std::string moduleName, - std::string methodName, - size_t argCount) { - // Assume the instance is properly bound to the right class at this point. - SEL selector = nil; - - // PromiseKind expects 2 additional function args for resolve() and reject() - size_t adjustedCount = valueKind == PromiseKind ? argCount + 2 : argCount; - - // Notes: - // - This may be expensive lookup. The codegen output should specify the exact selector name. - if (adjustedCount == 0) { - selector = NSSelectorFromString([NSString stringWithUTF8String:methodName.c_str()]); - if (![module respondsToSelector:selector]) { - throw std::runtime_error("Unable to find method: " + methodName + " for module: " + moduleName + ". Make sure the module is installed correctly."); - } - } else if (adjustedCount == 1) { - selector = NSSelectorFromString([NSString stringWithFormat:@"%s:", methodName.c_str()]); - if (![module respondsToSelector:selector]) { - throw std::runtime_error("Unable to find method: " + methodName + " for module: " + moduleName + ". Make sure the module is installed correctly."); - } - } else { - unsigned int numberOfMethods; - Method *methods = class_copyMethodList([module class], &numberOfMethods); - if (methods) { - NSString *methodPrefix = [NSString stringWithFormat:@"%s:", methodName.c_str()]; - for (unsigned int i = 0; i < numberOfMethods; i++) { - SEL s = method_getName(methods[i]); - NSString *objcMethodName = NSStringFromSelector(s); - if ([objcMethodName hasPrefix:methodPrefix]) { - selector = s; - break; - } - } - free(methods); - } - if (!selector) { - throw std::runtime_error("Unable to find method: " + methodName + " for module: " + moduleName + ". Make sure the module is installed correctly."); - } - } - - return selector; -} - /** * Perform method invocation on a specific queue as configured by the module class. * This serves as a backward-compatible support for RCTBridgeModule's methodQueue API. @@ -474,16 +427,16 @@ NSInvocation *ObjCTurboModule::getMethodInvocation( NSMutableArray *retainedObjectsForInvocation) { NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[module class] instanceMethodSignatureForSelector:selector]]; [inv setSelector:selector]; - + NSMethodSignature *methodSignature = [[module class] instanceMethodSignatureForSelector:selector]; - + for (size_t i = 0; i < count; i++) { const jsi::Value *arg = &args[i]; const char *objCArgType = [methodSignature getArgumentTypeAtIndex:i + 2]; - + if (arg->isBool()) { bool v = arg->getBool(); - + /** * JS type checking ensures the Objective C argument here is either a BOOL or NSNumber*. */ @@ -494,13 +447,13 @@ NSInvocation *ObjCTurboModule::getMethodInvocation( } else { [inv setArgument:(void *)&v atIndex:i + 2]; } - + continue; } - + if (arg->isNumber()) { double v = arg->getNumber(); - + /** * JS type checking ensures the Objective C argument here is either a double or NSNumber*. */ @@ -511,18 +464,18 @@ NSInvocation *ObjCTurboModule::getMethodInvocation( } else { [inv setArgument:(void *)&v atIndex:i + 2]; } - + continue; } - + /** * Convert arg to ObjC objects. */ id objCArg = convertJSIValueToObjCObject(runtime, *arg, jsInvoker); - + if (objCArg) { NSString *methodNameNSString = @(methodName.c_str()); - + /** * Convert objects using RCTConvert. */ @@ -562,7 +515,7 @@ NSInvocation *ObjCTurboModule::getMethodInvocation( continue; } } - + /** * Insert converted args unmodified. */ @@ -571,7 +524,7 @@ NSInvocation *ObjCTurboModule::getMethodInvocation( [retainedObjectsForInvocation addObject:objCArg]; } } - + /** * TODO(rsnara): * If you remove this call, then synchronous calls that return NSDictionary's break. @@ -589,16 +542,6 @@ ObjCTurboModule::ObjCTurboModule( : TurboModule(name, jsInvoker), instance_(instance) {} -jsi::Value ObjCTurboModule::invokeMethod( - jsi::Runtime &runtime, - TurboModuleMethodValueKind valueKind, - const std::string &methodName, - const jsi::Value *args, - size_t count) { - SEL selector = resolveMethodSelector(valueKind, instance_, name_, methodName, count); - return invokeObjCMethod(runtime, valueKind, methodName, selector, args, count); -} - jsi::Value ObjCTurboModule::invokeObjCMethod( jsi::Runtime &runtime, TurboModuleMethodValueKind valueKind,