TM: removed unused virtual invokeMethod() and invalidate()

Summary:
* invokeMethod() ends up not useful because each platform has its own way of invoking the platform methods
* invalidate() is not necessary because there's already the destructor of each C++ class

Reviewed By: mdvacca

Differential Revision: D15187833

fbshipit-source-id: 9478ed1e6288da30c67179e03a7bc7da6043280b
This commit is contained in:
Kevin Gozali
2019-05-02 14:07:13 -07:00
committed by Facebook Github Bot
parent 4900077e83
commit 0708e28caf
5 changed files with 16 additions and 109 deletions

View File

@@ -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<facebook::xplat::module::CxxModule::Method> cxxMethods_;

View File

@@ -16,11 +16,7 @@ TurboModule::TurboModule(const std::string &name, std::shared_ptr<JSCallInvoker>
: 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

View File

@@ -40,24 +40,8 @@ public:
TurboModule(const std::string &name, std::shared_ptr<JSCallInvoker> 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<JSCallInvoker> jsInvoker_;

View File

@@ -33,13 +33,6 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
public:
ObjCTurboModule(const std::string &name, id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> 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,

View File

@@ -278,53 +278,6 @@ namespace react {
namespace {
SEL resolveMethodSelector(
TurboModuleMethodValueKind valueKind,
id<RCTTurboModule> 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,