Skip to content

Commit

Permalink
fix: Throw JS errors if JSI <-> JNI conversion failed (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 5, 2021
1 parent 25ab538 commit 1c32726
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions android/src/main/cpp/JSIJNIConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,30 @@ jobject JSIJNIConversion::convertJSIValueToJNIObject(jsi::Runtime &runtime, cons
return hostObject->frame.get();
} else {
// it's different kind of HostObject. We don't support it.
return nullptr;
throw std::runtime_error("Received an unknown HostObject! Cannot convert to a JNI value.");
}

} else if (object.isFunction(runtime)) {
// jsi::Function

// TODO: Convert Function to Callback
return nullptr;
throw std::runtime_error("Cannot convert a JS Function to a JNI value (yet)!");

} else {
// jsi::Object

auto dynamic = jsi::dynamicFromValue(runtime, value);
auto map = react::ReadableNativeMap::createWithContents(std::move(dynamic));
return map.release();

}
} else {
// unknown jsi type!

auto stringRepresentation = value.toString(runtime).utf8(runtime);
auto message = "Received unknown JSI value! (" + stringRepresentation + ") Cannot convert to JNI Object.";
__android_log_write(ANDROID_LOG_ERROR, "VisionCamera", message.c_str());
return nullptr;
auto message = "Received unknown JSI value! (" + stringRepresentation + ") Cannot convert to a JNI value.";
throw std::runtime_error(message);

}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guides/FRAME_PROCESSORS_CREATE_OVERVIEW.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Similar to a TurboModule, the Frame Processor Plugin Registry API automatically
| `number` | `NSNumber*` (double) | `Double` |
| `boolean` | `NSNumber*` (boolean) | `Boolean` |
| `string` | `NSString*` | `String` |
| `[]` | `NSArray*` | `ArrayList<E>` |
| `{}` | `NSDictionary*` | `HashMap<K, V>` |
| `[]` | `NSArray*` | `ReadableNativeArray` |
| `{}` | `NSDictionary*` | `ReadableNativeMap` |
| `undefined` / `null` | `nil` | `null` |
| `(any, any) => void` | [`RCTResponseSenderBlock`][4] | `(Object, Object) -> void` |
| [`Frame`][1] | [`Frame*`][2] | [`ImageProxy`][3] |
Expand Down

0 comments on commit 1c32726

Please sign in to comment.