Split JavaSJExecutor and ProxyExecutorException into their own file

Summary: This makes the exception a nested class of the interface,
which eliminates the dependency of DevSupportManager on
ProxyJavaScriptExecutor.
public

Reviewed By: astreet

Differential Revision: D2651252

fb-gh-sync-id: 99de1c308b9bce717ab749c4e239d2773a920e1f
This commit is contained in:
Marc Horowitz 2015-11-20 12:16:19 -08:00 committed by facebook-github-bot-6
parent 67209e6396
commit 5b6b5a64d1
8 changed files with 69 additions and 56 deletions

View File

@ -28,6 +28,7 @@ import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutor;
import com.facebook.react.bridge.JavaJSExecutor;
import com.facebook.react.bridge.JavaScriptExecutor;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.JavaScriptModulesConfig;
@ -97,8 +98,8 @@ public class ReactInstanceManager {
new ReactInstanceDevCommandsHandler() {
@Override
public void onReloadWithJSDebugger(ProxyJavaScriptExecutor proxyExecutor) {
ReactInstanceManager.this.onReloadWithJSDebugger(proxyExecutor);
public void onReloadWithJSDebugger(JavaJSExecutor jsExecutor) {
ReactInstanceManager.this.onReloadWithJSDebugger(jsExecutor);
}
@Override
@ -474,9 +475,9 @@ public class ReactInstanceManager {
return mCurrentReactContext;
}
private void onReloadWithJSDebugger(ProxyJavaScriptExecutor proxyExecutor) {
private void onReloadWithJSDebugger(JavaJSExecutor jsExecutor) {
recreateReactContextInBackground(
proxyExecutor,
new ProxyJavaScriptExecutor(jsExecutor),
JSBundleLoader.createRemoteDebuggerBundleLoader(
mDevSupportManager.getJSBundleURLForRemoteDebugging()));
}

View File

@ -0,0 +1,54 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.bridge;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* This is class represents java version of native js executor interface. When set through
* {@link ProxyJavaScriptExecutor} as a {@link CatalystInstance} executor, native code will
* delegate js calls to the given implementation of this interface.
*/
@DoNotStrip
public interface JavaJSExecutor {
public static class ProxyExecutorException extends Exception {
public ProxyExecutorException(Throwable cause) {
super(cause);
}
}
/**
* Close this executor and cleanup any resources that it was using. No further calls are
* expected after this.
*/
void close();
/**
* Load javascript into the js context
* @param script script contet to be executed
* @param sourceURL url or file location from which script content was loaded
*/
@DoNotStrip
void executeApplicationScript(String script, String sourceURL) throws ProxyExecutorException;
/**
* Execute javascript method within js context
* @param modulename name of the common-js like module to execute the method from
* @param methodName name of the method to be executed
* @param jsonArgsArray json encoded array of arguments provided for the method call
* @return json encoded value returned from the method call
*/
@DoNotStrip
String executeJSCall(String modulename, String methodName, String jsonArgsArray)
throws ProxyExecutorException;
@DoNotStrip
void setGlobalVariable(String propertyName, String jsonEncodedValue);
}

View File

@ -29,48 +29,6 @@ public class ProxyJavaScriptExecutor extends JavaScriptExecutor {
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
}
public static class ProxyExecutorException extends Exception {
public ProxyExecutorException(Throwable cause) {
super(cause);
}
}
/**
* This is class represents java version of native js executor interface. When set through
* {@link ProxyJavaScriptExecutor} as a {@link CatalystInstance} executor, native code will
* delegate js calls to the given implementation of this interface.
*/
@DoNotStrip
public interface JavaJSExecutor {
/**
* Close this executor and cleanup any resources that it was using. No further calls are
* expected after this.
*/
void close();
/**
* Load javascript into the js context
* @param script script contet to be executed
* @param sourceURL url or file location from which script content was loaded
*/
@DoNotStrip
void executeApplicationScript(String script, String sourceURL) throws ProxyExecutorException;
/**
* Execute javascript method within js context
* @param modulename name of the common-js like module to execute the method from
* @param methodName name of the method to be executed
* @param jsonArgsArray json encoded array of arguments provided for the method call
* @return json encoded value returned from the method call
*/
@DoNotStrip
String executeJSCall(String modulename, String methodName, String jsonArgsArray)
throws ProxyExecutorException;
@DoNotStrip
void setGlobalVariable(String propertyName, String jsonEncodedValue);
}
private @Nullable JavaJSExecutor mJavaJSExecutor;
/**

View File

@ -23,7 +23,7 @@ import com.facebook.infer.annotation.Assertions;
/**
* Executes JS remotely via the react nodejs server as a proxy to a browser on the host machine.
*/
public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.JavaJSExecutor {
public class WebsocketJavaScriptExecutor implements JavaJSExecutor {
private static final long CONNECT_TIMEOUT_MS = 5000;
private static final int CONNECT_RETRY_COUNT = 3;
@ -146,7 +146,7 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
@Override
public void executeApplicationScript(String script, String sourceURL)
throws ProxyJavaScriptExecutor.ProxyExecutorException {
throws ProxyExecutorException {
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
Assertions.assertNotNull(mWebSocketClient).executeApplicationScript(
sourceURL,
@ -155,13 +155,13 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
try {
callback.get();
} catch (Throwable cause) {
throw new ProxyJavaScriptExecutor.ProxyExecutorException(cause);
throw new ProxyExecutorException(cause);
}
}
@Override
public @Nullable String executeJSCall(String moduleName, String methodName, String jsonArgsArray)
throws ProxyJavaScriptExecutor.ProxyExecutorException {
throws ProxyExecutorException {
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
Assertions.assertNotNull(mWebSocketClient).executeJSCall(
moduleName,
@ -171,7 +171,7 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
try {
return callback.get();
} catch (Throwable cause) {
throw new ProxyJavaScriptExecutor.ProxyExecutorException(cause);
throw new ProxyExecutorException(cause);
}
}

View File

@ -541,7 +541,7 @@ public class DevSupportManager implements NativeModuleCallExceptionHandler {
@Override
public void run() {
mReactInstanceCommandsHandler.onReloadWithJSDebugger(
new ProxyJavaScriptExecutor(webSocketJSExecutor));
webSocketJSExecutor);
}
});
}

View File

@ -9,7 +9,7 @@
package com.facebook.react.devsupport;
import com.facebook.react.bridge.ProxyJavaScriptExecutor;
import com.facebook.react.bridge.JavaJSExecutor;
/**
* Interface used by {@link DevSupportManager} for requesting React instance recreation
@ -20,7 +20,7 @@ public interface ReactInstanceDevCommandsHandler {
/**
* Request react instance recreation with JS debugging enabled.
*/
void onReloadWithJSDebugger(ProxyJavaScriptExecutor proxyExecutor);
void onReloadWithJSDebugger(JavaJSExecutor proxyExecutor);
/**
* Notify react instance manager about new JS bundle version downloaded from the server.

View File

@ -808,7 +808,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
registerNatives("com/facebook/react/bridge/ProxyJavaScriptExecutor", {
makeNativeMethod(
"initialize", "(Lcom/facebook/react/bridge/ProxyJavaScriptExecutor$JavaJSExecutor;)V",
"initialize", "(Lcom/facebook/react/bridge/JavaJSExecutor;)V",
executors::createProxyExecutor),
});

View File

@ -10,7 +10,7 @@
namespace facebook {
namespace react {
const auto EXECUTOR_BASECLASS = "com/facebook/react/bridge/ProxyJavaScriptExecutor$JavaJSExecutor";
const auto EXECUTOR_BASECLASS = "com/facebook/react/bridge/JavaJSExecutor";
std::unique_ptr<JSExecutor> ProxyExecutorOneTimeFactory::createJSExecutor(FlushImmediateCallback ignoredCallback) {
FBASSERTMSGF(