From 5b6b5a64d195d03bf407f5e460915d50268370ce Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Fri, 20 Nov 2015 12:16:19 -0800 Subject: [PATCH] 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 --- .../facebook/react/ReactInstanceManager.java | 9 ++-- .../facebook/react/bridge/JavaJSExecutor.java | 54 +++++++++++++++++++ .../react/bridge/ProxyJavaScriptExecutor.java | 42 --------------- .../bridge/WebsocketJavaScriptExecutor.java | 10 ++-- .../react/devsupport/DevSupportManager.java | 2 +- .../ReactInstanceDevCommandsHandler.java | 4 +- .../src/main/jni/react/jni/OnLoad.cpp | 2 +- .../src/main/jni/react/jni/ProxyExecutor.cpp | 2 +- 8 files changed, 69 insertions(+), 56 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/bridge/JavaJSExecutor.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index b8cf21b234..ba4cd8d12a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -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())); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaJSExecutor.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaJSExecutor.java new file mode 100644 index 0000000000..76b8a1cb52 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaJSExecutor.java @@ -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); +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ProxyJavaScriptExecutor.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ProxyJavaScriptExecutor.java index 08447802bf..f9e58869b3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ProxyJavaScriptExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ProxyJavaScriptExecutor.java @@ -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; /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/WebsocketJavaScriptExecutor.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/WebsocketJavaScriptExecutor.java index 4557d9fe67..e044ca8cd6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/WebsocketJavaScriptExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/WebsocketJavaScriptExecutor.java @@ -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); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java index 69ef7fa962..bd8add591b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java @@ -541,7 +541,7 @@ public class DevSupportManager implements NativeModuleCallExceptionHandler { @Override public void run() { mReactInstanceCommandsHandler.onReloadWithJSDebugger( - new ProxyJavaScriptExecutor(webSocketJSExecutor)); + webSocketJSExecutor); } }); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReactInstanceDevCommandsHandler.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReactInstanceDevCommandsHandler.java index 5489853b08..e97b16f7d7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReactInstanceDevCommandsHandler.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReactInstanceDevCommandsHandler.java @@ -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. diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index bc35feeb2b..6d3a1c2d8b 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -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), }); diff --git a/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp b/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp index 129d737fc5..ab86a66985 100644 --- a/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp +++ b/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp @@ -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 ProxyExecutorOneTimeFactory::createJSExecutor(FlushImmediateCallback ignoredCallback) { FBASSERTMSGF(