Refactor: Pass jsi::Runtime to getArgumentTypeName

Summary:
ObjCTurboModule::getArgumentTypeName:
1. Only called from JavaScript.
2. Can raise exceptions.

Thread the jsi::Runtime through this method:
1. So that it can throw jsi::JSErrors.
2. To enfore that it be called from JavaScript.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D44887177

fbshipit-source-id: 170399c2919f56d4c15593adf76ec50c061cce69
This commit is contained in:
Ramanpreet Nara
2023-04-30 03:28:33 -07:00
committed by Facebook GitHub Bot
parent d487fdf81b
commit 34caa8d552
2 changed files with 3 additions and 3 deletions
@@ -81,7 +81,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
bool isMethodSync(TurboModuleMethodValueKind returnType);
BOOL hasMethodArgConversionSelector(NSString *methodName, int argIndex);
SEL getMethodArgConversionSelector(NSString *methodName, int argIndex);
NSString *getArgumentTypeName(NSString *methodName, int argIndex);
NSString *getArgumentTypeName(jsi::Runtime &runtime, NSString *methodName, int argIndex);
NSInvocation *createMethodInvocation(
jsi::Runtime &runtime,
bool isSync,
@@ -494,7 +494,7 @@ jsi::Value ObjCTurboModule::convertReturnIdToJSIValue(
* Note: This is only being introduced for backward compatibility. It will be removed
* in the future.
*/
NSString *ObjCTurboModule::getArgumentTypeName(NSString *methodName, int argIndex)
NSString *ObjCTurboModule::getArgumentTypeName(jsi::Runtime &runtime, NSString *methodName, int argIndex)
{
if (!methodArgumentTypeNames_) {
NSMutableDictionary<NSString *, NSArray<NSString *> *> *methodArgumentTypeNames = [NSMutableDictionary new];
@@ -595,7 +595,7 @@ void ObjCTurboModule::setInvocationArg(
* Convert objects using RCTConvert.
*/
if (objCArgType == @encode(id)) {
NSString *argumentType = getArgumentTypeName(methodNameNSString, i);
NSString *argumentType = getArgumentTypeName(runtime, methodNameNSString, i);
if (argumentType != nil) {
NSString *rctConvertMethodName = [NSString stringWithFormat:@"%@:", argumentType];
SEL rctConvertSelector = NSSelectorFromString(rctConvertMethodName);