Pass jsc config to JSC

Reviewed By: astreet

Differential Revision: D2965497

fb-gh-sync-id: 1aef5a1f2d7ccb8de8ca403e51ebcf247bd6b034
shipit-source-id: 1aef5a1f2d7ccb8de8ca403e51ebcf247bd6b034
This commit is contained in:
Andrei Coman
2016-02-26 03:23:19 -08:00
committed by Facebook Github Bot 6
parent 542432fc3e
commit d032cc967d
10 changed files with 71 additions and 26 deletions

View File

@@ -0,0 +1,12 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react;
import com.facebook.react.bridge.WritableNativeMap;
/**
* Interface for the configuration object that is passed to JSC.
*/
public interface JSCConfig {
public WritableNativeMap getConfigMap();
}

View File

@@ -181,6 +181,7 @@ public abstract class ReactInstanceManager {
protected @Nullable LifecycleState mInitialLifecycleState;
protected @Nullable UIImplementationProvider mUIImplementationProvider;
protected @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
protected @Nullable JSCConfig mJSCConfig;
protected Builder() {
}
@@ -274,6 +275,11 @@ public abstract class ReactInstanceManager {
return this;
}
public Builder setJSCConfig(JSCConfig jscConfig) {
mJSCConfig = jscConfig;
return this;
}
/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
@@ -307,7 +313,8 @@ public abstract class ReactInstanceManager {
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler);
mNativeModuleCallExceptionHandler,
mJSCConfig);
}
}
}

View File

@@ -127,6 +127,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.RUN_JS_BUNDLE_START
private final UIImplementationProvider mUIImplementationProvider;
private final MemoryPressureRouter mMemoryPressureRouter;
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final @Nullable JSCConfig mJSCConfig;
private final ReactInstanceDevCommandsHandler mDevInterface =
new ReactInstanceDevCommandsHandler() {
@@ -193,7 +194,9 @@ import static com.facebook.react.bridge.ReactMarkerConstants.RUN_JS_BUNDLE_START
protected Result<ReactApplicationContext> doInBackground(ReactContextInitParams... params) {
Assertions.assertCondition(params != null && params.length > 0 && params[0] != null);
try {
JavaScriptExecutor jsExecutor = params[0].getJsExecutorFactory().create();
JavaScriptExecutor jsExecutor =
params[0].getJsExecutorFactory().create(
mJSCConfig == null ? new WritableNativeMap() : mJSCConfig.getConfigMap());
return Result.of(createReactContext(jsExecutor, params[0].getJsBundleLoader()));
} catch (Exception e) {
// Pass exception to onPostExecute() so it can be handled on the main thread
@@ -274,7 +277,8 @@ import static com.facebook.react.bridge.ReactMarkerConstants.RUN_JS_BUNDLE_START
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
LifecycleState initialLifecycleState,
UIImplementationProvider uiImplementationProvider,
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler) {
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
@Nullable JSCConfig jscConfig) {
initializeSoLoaderIfNecessary(applicationContext);
// TODO(9577825): remove this
@@ -296,6 +300,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.RUN_JS_BUNDLE_START
mUIImplementationProvider = uiImplementationProvider;
mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mJSCConfig = jscConfig;
}
@Override

View File

@@ -16,8 +16,8 @@ import com.facebook.soloader.SoLoader;
public class JSCJavaScriptExecutor extends JavaScriptExecutor {
public static class Factory implements JavaScriptExecutor.Factory {
@Override
public JavaScriptExecutor create() throws Exception {
return new JSCJavaScriptExecutor();
public JavaScriptExecutor create(WritableNativeMap jscConfig) throws Exception {
return new JSCJavaScriptExecutor(jscConfig);
}
}
@@ -25,10 +25,10 @@ public class JSCJavaScriptExecutor extends JavaScriptExecutor {
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
}
public JSCJavaScriptExecutor() {
initialize();
public JSCJavaScriptExecutor(WritableNativeMap jscConfig) {
initialize(jscConfig);
}
private native void initialize();
private native void initialize(WritableNativeMap jscConfig);
}

View File

@@ -15,7 +15,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public abstract class JavaScriptExecutor extends Countable {
public interface Factory {
JavaScriptExecutor create() throws Exception;
JavaScriptExecutor create(WritableNativeMap jscConfig) throws Exception;
}
/**

View File

@@ -32,7 +32,7 @@ public class ProxyJavaScriptExecutor extends JavaScriptExecutor {
}
@Override
public JavaScriptExecutor create() throws Exception {
public JavaScriptExecutor create(WritableNativeMap jscConfig) throws Exception {
return new ProxyJavaScriptExecutor(mJavaJSExecutorFactory.create());
}
}