force crash if a Java Module isn't lazifi-able in a Lazified app

Reviewed By: achen1

Differential Revision: D4317878

fbshipit-source-id: 61ee4b24f0de206f53d6f4b3801d81aa6f3ab36c
This commit is contained in:
Aaron Chiu 2016-12-13 03:51:53 -08:00 committed by Facebook Github Bot
parent 8c7f36021a
commit a76547f7ac
3 changed files with 16 additions and 7 deletions

View File

@ -80,7 +80,8 @@ public class ReactTestHelper {
.setJSExecutor(executor) .setJSExecutor(executor)
.setRegistry(new NativeModuleRegistry( .setRegistry(new NativeModuleRegistry(
mModuleSpecList, mModuleSpecList,
Collections.<Class, ReactModuleInfo>emptyMap())) Collections.<Class, ReactModuleInfo>emptyMap(),
false))
.setJSModuleRegistry(mJSModuleRegistryBuilder.build()) .setJSModuleRegistry(mJSModuleRegistryBuilder.build())
.setJSBundleLoader(JSBundleLoader.createAssetLoader( .setJSBundleLoader(JSBundleLoader.createAssetLoader(
mContext, mContext,

View File

@ -892,7 +892,10 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry"); Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
NativeModuleRegistry nativeModuleRegistry; NativeModuleRegistry nativeModuleRegistry;
try { try {
nativeModuleRegistry = new NativeModuleRegistry(moduleSpecs, reactModuleInfoMap); nativeModuleRegistry = new NativeModuleRegistry(
moduleSpecs,
reactModuleInfoMap,
mLazyNativeModulesEnabled);
} finally { } finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END); ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END);

View File

@ -36,14 +36,19 @@ public class NativeModuleRegistry {
public NativeModuleRegistry( public NativeModuleRegistry(
List<ModuleSpec> moduleSpecList, List<ModuleSpec> moduleSpecList,
Map<Class, ReactModuleInfo> reactModuleInfoMap) { Map<Class, ReactModuleInfo> reactModuleInfoMap,
boolean isLazyNativeModulesEnabled) {
Map<String, Pair<Class<? extends NativeModule>, ModuleHolder>> namesToSpecs = new HashMap<>(); Map<String, Pair<Class<? extends NativeModule>, ModuleHolder>> namesToSpecs = new HashMap<>();
for (ModuleSpec module : moduleSpecList) { for (ModuleSpec module : moduleSpecList) {
Class<? extends NativeModule> type = module.getType(); Class<? extends NativeModule> type = module.getType();
ModuleHolder holder = new ModuleHolder( ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type);
type, if (isLazyNativeModulesEnabled &&
reactModuleInfoMap.get(type), reactModuleInfo == null &&
module.getProvider()); 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(); String name = holder.getInfo().name();
Class<? extends NativeModule> existing = namesToSpecs.containsKey(name) ? Class<? extends NativeModule> existing = namesToSpecs.containsKey(name) ?
namesToSpecs.get(name).first : namesToSpecs.get(name).first :