Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,6 @@ T RCTConvertTo(SEL selector, id json)
TurboModuleMethodValueKind returnType,
id result)
{
std::string methodJsSignature = name_ + "." + methodNameCStr + "()";
std::string errorPrefix =
methodJsSignature + ": Error while converting return Objective C value to JavaScript type. ";

if (returnType == VoidKind) {
return jsi::Value::undefined();
}
Expand All @@ -617,6 +613,7 @@ T RCTConvertTo(SEL selector, id json)
return returnValue;
}

std::string methodJsSignature = name_ + "." + methodNameCStr + "()";
throw jsi::JSError(runtime, methodJsSignature + "Objective C type was unsupported.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ id convertJSIValueToObjCObject(
return convertJSIObjectToNSDictionary(runtime, o, jsInvoker, useNSNull);
}

throw std::runtime_error("Unsupported jsi::Value kind");
throw jsi::JSError(runtime, "Unsupported jsi::Value kind");
}

static jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string &message)
Expand Down Expand Up @@ -268,14 +268,12 @@ id convertJSIValueToObjCObject(
jsi::PropNameID::forAscii(runtime, "fn"),
2,
[invokeCopy, jsInvoker = jsInvoker_, moduleName = name_, methodName](
jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) {
// FIXME: do not allocate this upfront
std::string moduleMethod = moduleName + "." + methodName + "()";

jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) mutable {
if (count != 2) {
throw std::invalid_argument(
moduleMethod + ": Promise must pass constructor function two args. Passed " + std::to_string(count) +
" args.");
throw jsi::JSError(
rt,
moduleName + "." + methodName + "(): Promise must pass constructor function two args. Passed " +
std::to_string(count) + " args.");
}
if (!invokeCopy) {
return jsi::Value::undefined();
Expand Down Expand Up @@ -306,12 +304,16 @@ id convertJSIValueToObjCObject(
}

if (alreadyResolved) {
RCTLogError(@"%s: Tried to resolve a promise more than once.", moduleMethod.c_str());
RCTLogError(
@"%s.%s(): Tried to resolve a promise more than once.", moduleName.c_str(), methodName.c_str());
return;
}

if (alreadyRejected) {
RCTLogError(@"%s: Tried to resolve a promise after it's already been rejected.", moduleMethod.c_str());
RCTLogError(
@"%s.%s(): Tried to resolve a promise after it's already been rejected.",
moduleName.c_str(),
methodName.c_str());
return;
}

Expand Down Expand Up @@ -339,16 +341,18 @@ id convertJSIValueToObjCObject(

if (alreadyResolved) {
RCTLogError(
@"%s: Tried to reject a promise after it's already been resolved. Message: %s",
moduleMethod.c_str(),
@"%s.%s() Tried to reject a promise after it's already been resolved. Message: %s",
moduleName.c_str(),
methodName.c_str(),
message.UTF8String);
return;
}

if (alreadyRejected) {
RCTLogError(
@"%s: Tried to reject a promise more than once. Message: %s",
moduleMethod.c_str(),
@"%s.%s() Tried to reject a promise more than once. Message: %s",
moduleName.c_str(),
methodName.c_str(),
message.UTF8String);
return;
}
Expand Down Expand Up @@ -527,9 +531,9 @@ TraceSection s(
break;
}
case FunctionKind:
throw std::runtime_error("convertReturnIdToJSIValue: FunctionKind is not supported yet.");
throw jsi::JSError(runtime, "convertReturnIdToJSIValue: FunctionKind is not supported yet.");
case PromiseKind:
throw std::runtime_error("convertReturnIdToJSIValue: PromiseKind wasn't handled properly.");
throw jsi::JSError(runtime, "convertReturnIdToJSIValue: PromiseKind wasn't handled properly.");
}

return returnValue;
Expand Down Expand Up @@ -711,14 +715,13 @@ TraceSection s(
NSMutableArray *retainedObjectsForInvocation)
{
const char *moduleName = name_.c_str();
const NSObject<RCTBridgeModule> *module = instance_;

if (isSync) {
TurboModulePerfLogger::syncMethodCallArgConversionStart(moduleName, methodName);
} else {
TurboModulePerfLogger::asyncMethodCallArgConversionStart(moduleName, methodName);
}

const NSObject<RCTBridgeModule> *module = instance_;
NSMethodSignature *methodSignature = [module methodSignatureForSelector:selector];
if (count > methodSignature.numberOfArguments - 2) {
throw jsi::JSError(
Expand Down Expand Up @@ -751,7 +754,7 @@ TraceSection s(
return true;
}

return !(returnType == VoidKind || returnType == PromiseKind);
return returnType != VoidKind && returnType != PromiseKind;
}

ObjCTurboModule::ObjCTurboModule(const InitParams &params)
Expand Down