@@ -16,21 +16,30 @@ std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::singleBundleRegistry(std::
16
16
return std::unique_ptr<RAMBundleRegistry>(registry);
17
17
}
18
18
19
- std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry (std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t )> factory) {
19
+ std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry (std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(std::string )> factory) {
20
20
RAMBundleRegistry *registry = new RAMBundleRegistry (std::move (mainBundle), std::move (factory));
21
21
return std::unique_ptr<RAMBundleRegistry>(registry);
22
22
}
23
23
24
- RAMBundleRegistry::RAMBundleRegistry (std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t )> factory): m_factory(factory) {
24
+ RAMBundleRegistry::RAMBundleRegistry (std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(std::string )> factory): m_factory(factory) {
25
25
m_bundles.emplace (MAIN_BUNDLE_ID, std::move (mainBundle));
26
26
}
27
27
28
+ void RAMBundleRegistry::registerBundle (uint32_t bundleId, std::string bundlePath) {
29
+ m_bundlePaths.emplace (bundleId, bundlePath);
30
+ }
31
+
28
32
JSModulesUnbundle::Module RAMBundleRegistry::getModule (uint32_t bundleId, uint32_t moduleId) {
29
33
if (m_bundles.find (bundleId) == m_bundles.end ()) {
30
34
if (!m_factory) {
31
35
throw std::runtime_error (" You need to register factory function in order to support multiple RAM bundles." );
32
36
}
33
- m_bundles.emplace (bundleId, m_factory (bundleId));
37
+
38
+ auto bundlePath = m_bundlePaths.find (bundleId);
39
+ if (bundlePath == m_bundlePaths.end ()) {
40
+ throw std::runtime_error (" In order to fetch RAM bundle from the registry, its file path needs to be registered first." );
41
+ }
42
+ m_bundles.emplace (bundleId, m_factory (bundlePath->second ));
34
43
}
35
44
36
45
return getBundle (bundleId)->getModule (moduleId);
0 commit comments