Skip to content

Commit

Permalink
force crash if a Java Module isn't lazifi-able in a Lazified app
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D4317878

fbshipit-source-id: 61ee4b24f0de206f53d6f4b3801d81aa6f3ab36c
  • Loading branch information
aaronechiu authored and Facebook Github Bot committed Dec 13, 2016
1 parent 8c7f360 commit a76547f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public CatalystInstance build() {
.setJSExecutor(executor)
.setRegistry(new NativeModuleRegistry(
mModuleSpecList,
Collections.<Class, ReactModuleInfo>emptyMap()))
Collections.<Class, ReactModuleInfo>emptyMap(),
false))
.setJSModuleRegistry(mJSModuleRegistryBuilder.build())
.setJSBundleLoader(JSBundleLoader.createAssetLoader(
mContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,10 @@ private ReactApplicationContext createReactContext(
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
NativeModuleRegistry nativeModuleRegistry;
try {
nativeModuleRegistry = new NativeModuleRegistry(moduleSpecs, reactModuleInfoMap);
nativeModuleRegistry = new NativeModuleRegistry(
moduleSpecs,
reactModuleInfoMap,
mLazyNativeModulesEnabled);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ public class NativeModuleRegistry {

public NativeModuleRegistry(
List<ModuleSpec> moduleSpecList,
Map<Class, ReactModuleInfo> reactModuleInfoMap) {
Map<Class, ReactModuleInfo> reactModuleInfoMap,
boolean isLazyNativeModulesEnabled) {
Map<String, Pair<Class<? extends NativeModule>, ModuleHolder>> namesToSpecs = new HashMap<>();
for (ModuleSpec module : moduleSpecList) {
Class<? extends NativeModule> type = module.getType();
ModuleHolder holder = new ModuleHolder(
type,
reactModuleInfoMap.get(type),
module.getProvider());
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type);
if (isLazyNativeModulesEnabled &&
reactModuleInfo == null &&
BaseJavaModule.class.isAssignableFrom(type)) {
throw new IllegalStateException("Native Java module " + type.getSimpleName() +
" should be annotated with @ReactModule and added to a @ReactModuleList.");
}
ModuleHolder holder = new ModuleHolder(type, reactModuleInfo, module.getProvider());
String name = holder.getInfo().name();
Class<? extends NativeModule> existing = namesToSpecs.containsKey(name) ?
namesToSpecs.get(name).first :
Expand Down

0 comments on commit a76547f

Please sign in to comment.