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)
.setRegistry(new NativeModuleRegistry(
mModuleSpecList,
Collections.<Class, ReactModuleInfo>emptyMap()))
Collections.<Class, ReactModuleInfo>emptyMap(),
false))
.setJSModuleRegistry(mJSModuleRegistryBuilder.build())
.setJSBundleLoader(JSBundleLoader.createAssetLoader(
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");
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);

View File

@ -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 :