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:
parent
67209e6396
commit
5b6b5a64d1
|
@ -28,6 +28,7 @@ import com.facebook.react.bridge.Arguments;
|
||||||
import com.facebook.react.bridge.CatalystInstance;
|
import com.facebook.react.bridge.CatalystInstance;
|
||||||
import com.facebook.react.bridge.JSBundleLoader;
|
import com.facebook.react.bridge.JSBundleLoader;
|
||||||
import com.facebook.react.bridge.JSCJavaScriptExecutor;
|
import com.facebook.react.bridge.JSCJavaScriptExecutor;
|
||||||
|
import com.facebook.react.bridge.JavaJSExecutor;
|
||||||
import com.facebook.react.bridge.JavaScriptExecutor;
|
import com.facebook.react.bridge.JavaScriptExecutor;
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
import com.facebook.react.bridge.JavaScriptModulesConfig;
|
import com.facebook.react.bridge.JavaScriptModulesConfig;
|
||||||
|
@ -97,8 +98,8 @@ public class ReactInstanceManager {
|
||||||
new ReactInstanceDevCommandsHandler() {
|
new ReactInstanceDevCommandsHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReloadWithJSDebugger(ProxyJavaScriptExecutor proxyExecutor) {
|
public void onReloadWithJSDebugger(JavaJSExecutor jsExecutor) {
|
||||||
ReactInstanceManager.this.onReloadWithJSDebugger(proxyExecutor);
|
ReactInstanceManager.this.onReloadWithJSDebugger(jsExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -474,9 +475,9 @@ public class ReactInstanceManager {
|
||||||
return mCurrentReactContext;
|
return mCurrentReactContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReloadWithJSDebugger(ProxyJavaScriptExecutor proxyExecutor) {
|
private void onReloadWithJSDebugger(JavaJSExecutor jsExecutor) {
|
||||||
recreateReactContextInBackground(
|
recreateReactContextInBackground(
|
||||||
proxyExecutor,
|
new ProxyJavaScriptExecutor(jsExecutor),
|
||||||
JSBundleLoader.createRemoteDebuggerBundleLoader(
|
JSBundleLoader.createRemoteDebuggerBundleLoader(
|
||||||
mDevSupportManager.getJSBundleURLForRemoteDebugging()));
|
mDevSupportManager.getJSBundleURLForRemoteDebugging()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -29,48 +29,6 @@ public class ProxyJavaScriptExecutor extends JavaScriptExecutor {
|
||||||
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
|
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;
|
private @Nullable JavaJSExecutor mJavaJSExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
* 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 long CONNECT_TIMEOUT_MS = 5000;
|
||||||
private static final int CONNECT_RETRY_COUNT = 3;
|
private static final int CONNECT_RETRY_COUNT = 3;
|
||||||
|
@ -146,7 +146,7 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeApplicationScript(String script, String sourceURL)
|
public void executeApplicationScript(String script, String sourceURL)
|
||||||
throws ProxyJavaScriptExecutor.ProxyExecutorException {
|
throws ProxyExecutorException {
|
||||||
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
|
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
|
||||||
Assertions.assertNotNull(mWebSocketClient).executeApplicationScript(
|
Assertions.assertNotNull(mWebSocketClient).executeApplicationScript(
|
||||||
sourceURL,
|
sourceURL,
|
||||||
|
@ -155,13 +155,13 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
|
||||||
try {
|
try {
|
||||||
callback.get();
|
callback.get();
|
||||||
} catch (Throwable cause) {
|
} catch (Throwable cause) {
|
||||||
throw new ProxyJavaScriptExecutor.ProxyExecutorException(cause);
|
throw new ProxyExecutorException(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String executeJSCall(String moduleName, String methodName, String jsonArgsArray)
|
public @Nullable String executeJSCall(String moduleName, String methodName, String jsonArgsArray)
|
||||||
throws ProxyJavaScriptExecutor.ProxyExecutorException {
|
throws ProxyExecutorException {
|
||||||
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
|
JSExecutorCallbackFuture callback = new JSExecutorCallbackFuture();
|
||||||
Assertions.assertNotNull(mWebSocketClient).executeJSCall(
|
Assertions.assertNotNull(mWebSocketClient).executeJSCall(
|
||||||
moduleName,
|
moduleName,
|
||||||
|
@ -171,7 +171,7 @@ public class WebsocketJavaScriptExecutor implements ProxyJavaScriptExecutor.Java
|
||||||
try {
|
try {
|
||||||
return callback.get();
|
return callback.get();
|
||||||
} catch (Throwable cause) {
|
} catch (Throwable cause) {
|
||||||
throw new ProxyJavaScriptExecutor.ProxyExecutorException(cause);
|
throw new ProxyExecutorException(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -541,7 +541,7 @@ public class DevSupportManager implements NativeModuleCallExceptionHandler {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mReactInstanceCommandsHandler.onReloadWithJSDebugger(
|
mReactInstanceCommandsHandler.onReloadWithJSDebugger(
|
||||||
new ProxyJavaScriptExecutor(webSocketJSExecutor));
|
webSocketJSExecutor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
package com.facebook.react.devsupport;
|
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
|
* 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.
|
* 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.
|
* Notify react instance manager about new JS bundle version downloaded from the server.
|
||||||
|
|
|
@ -808,7 +808,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||||
|
|
||||||
registerNatives("com/facebook/react/bridge/ProxyJavaScriptExecutor", {
|
registerNatives("com/facebook/react/bridge/ProxyJavaScriptExecutor", {
|
||||||
makeNativeMethod(
|
makeNativeMethod(
|
||||||
"initialize", "(Lcom/facebook/react/bridge/ProxyJavaScriptExecutor$JavaJSExecutor;)V",
|
"initialize", "(Lcom/facebook/react/bridge/JavaJSExecutor;)V",
|
||||||
executors::createProxyExecutor),
|
executors::createProxyExecutor),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
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) {
|
std::unique_ptr<JSExecutor> ProxyExecutorOneTimeFactory::createJSExecutor(FlushImmediateCallback ignoredCallback) {
|
||||||
FBASSERTMSGF(
|
FBASSERTMSGF(
|
||||||
|
|
Loading…
Reference in New Issue