mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-12 10:26:49 +08:00
Bind methods instead of using eval
Reviewed By: astreet Differential Revision: D3417452 fbshipit-source-id: 437daa2dfcd01efb749465a94c1a72ce8a2cb315
This commit is contained in:
committed by
Facebook Github Bot 0
parent
cd542f0656
commit
d63d4f0e9c
@@ -914,8 +914,14 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
return null;
|
||||
}
|
||||
}).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof RuntimeException) {
|
||||
throw (RuntimeException) e.getCause();
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return reactContext;
|
||||
|
||||
@@ -27,7 +27,8 @@ android_library(
|
||||
react_native_dep('third-party/java/okhttp:okhttp3-ws'),
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/common:common'),
|
||||
],
|
||||
react_native_target('java/com/facebook/react/devsupport:devsupport'),
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
|
||||
@@ -11,6 +11,9 @@ package com.facebook.react.cxxbridge;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.facebook.react.devsupport.DebugServerException;
|
||||
import com.facebook.react.devsupport.DevServerHelper;
|
||||
|
||||
/**
|
||||
* A class that stores JS bundle information and allows {@link CatalystInstance} to load a correct
|
||||
* bundle through {@link ReactBridge}.
|
||||
@@ -55,7 +58,11 @@ public abstract class JSBundleLoader {
|
||||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public void loadScript(CatalystInstanceImpl instance) {
|
||||
instance.loadScriptFromFile(cachedFileLocation, sourceURL);
|
||||
try {
|
||||
instance.loadScriptFromFile(cachedFileLocation, sourceURL);
|
||||
} catch (Exception e) {
|
||||
throw DebugServerException.makeGeneric(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,22 @@ import org.json.JSONObject;
|
||||
* Tracks errors connecting to or received from the debug derver.
|
||||
* The debug server returns errors as json objects. This exception represents that error.
|
||||
*/
|
||||
public class DebugServerException extends IOException {
|
||||
public class DebugServerException extends RuntimeException {
|
||||
private static final String GENERIC_ERROR_MESSAGE =
|
||||
"\n\nTry the following to fix the issue:\n" +
|
||||
"\u2022 Ensure that the packager server is running\n" +
|
||||
"\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n" +
|
||||
"\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n" +
|
||||
"\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n";
|
||||
|
||||
public static DebugServerException makeGeneric(String reason, Throwable t) {
|
||||
return makeGeneric(reason, "", t);
|
||||
}
|
||||
|
||||
public static DebugServerException makeGeneric(String reason, String extra, Throwable t) {
|
||||
return new DebugServerException(reason + GENERIC_ERROR_MESSAGE + extra, t);
|
||||
}
|
||||
|
||||
private DebugServerException(String description, String fileName, int lineNumber, int column) {
|
||||
super(description + "\n at " + fileName + ":" + lineNumber + ":" + column);
|
||||
}
|
||||
@@ -34,6 +49,10 @@ public class DebugServerException extends IOException {
|
||||
super(description);
|
||||
}
|
||||
|
||||
public DebugServerException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a DebugServerException from the server json string.
|
||||
* @param str json string returned by the debug server
|
||||
|
||||
@@ -47,7 +47,6 @@ import okio.Sink;
|
||||
* - Genymotion emulator with default settings: 10.0.3.2
|
||||
*/
|
||||
public class DevServerHelper {
|
||||
|
||||
public static final String RELOAD_APP_EXTRA_JS_PROXY = "jsproxy";
|
||||
private static final String RELOAD_APP_ACTION_SUFFIX = ".RELOAD_APP_ACTION";
|
||||
|
||||
@@ -185,15 +184,10 @@ public class DevServerHelper {
|
||||
}
|
||||
mDownloadBundleFromURLCall = null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Could not connect to development server.\n\n")
|
||||
.append("Try the following to fix the issue:\n")
|
||||
.append("\u2022 Ensure that the packager server is running\n")
|
||||
.append("\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n")
|
||||
.append("\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n")
|
||||
.append("\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n")
|
||||
.append("URL: ").append(call.request().url().toString());
|
||||
callback.onFailure(new DebugServerException(sb.toString()));
|
||||
callback.onFailure(DebugServerException.makeGeneric(
|
||||
"Could not connect to development server.",
|
||||
"URL: " + call.request().url().toString(),
|
||||
e));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user