1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo)
2 
3 #include "ExpoModulesHostObject.h"
4 
5 #include <folly/dynamic.h>
6 #include <jsi/JSIDynamic.h>
7 
8 namespace jsi = facebook::jsi;
9 
10 namespace expo {
11 
12 ExpoModulesHostObject::ExpoModulesHostObject(JSIInteropModuleRegistry *installer)
13   : installer(installer) {}
14 
15 jsi::Value ExpoModulesHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &name) {
16   auto cName = name.utf8(runtime);
17   auto module = installer->getModule(cName);
18   if (module == nullptr) {
19     return jsi::Value::undefined();
20   }
21 
22   module->cthis()->jsiInteropModuleRegistry = installer;
23   auto jsiObject = module->cthis()->getJSIObject(runtime);
24   return jsi::Value(runtime, *jsiObject);
25 }
26 
27 void ExpoModulesHostObject::set(jsi::Runtime &runtime, const jsi::PropNameID &name,
28                                 const jsi::Value &value) {
29   throw jsi::JSError(
30     runtime,
31     "RuntimeError: Cannot override the host object for expo module '" + name.utf8(runtime) + "'"
32   );
33 }
34 
35 std::vector<jsi::PropNameID> ExpoModulesHostObject::getPropertyNames(jsi::Runtime &rt) {
36   return {}; // TODO(@lukmccall): get list of all modules
37 }
38 } // namespace expo
39