show script eval errors in redbox
Differential Revision: D2624801 fb-gh-sync-id: 48741a8caf029415753a4c616a07f18d3660e6fb
This commit is contained in:
parent
e6372719ea
commit
9647c5a257
|
@ -134,7 +134,11 @@ public class CatalystInstance {
|
|||
|
||||
incrementPendingJSCalls();
|
||||
|
||||
mJSBundleLoader.loadScript(mBridge);
|
||||
try {
|
||||
mJSBundleLoader.loadScript(mBridge);
|
||||
} catch (JSExecutionException e) {
|
||||
mNativeModuleCallExceptionHandler.handleException(e);
|
||||
}
|
||||
|
||||
initLatch.countDown();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
/**
|
||||
* Exception thrown when there is an error evaluating JS, e.g. a syntax error.
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class JSExecutionException extends RuntimeException {
|
||||
|
||||
@DoNotStrip
|
||||
public JSExecutionException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
#include <fb/log.h>
|
||||
#include <folly/json.h>
|
||||
#include <folly/String.h>
|
||||
#include <jni/fbjni/Exceptions.h>
|
||||
#include "Value.h"
|
||||
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
|
@ -24,6 +25,8 @@ using fbsystrace::FbSystraceSection;
|
|||
// Add native performance markers support
|
||||
#include <react/JSCPerfLogging.h>
|
||||
|
||||
using namespace facebook::jni;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -53,6 +56,17 @@ static JSValueRef evaluateScriptWithJSC(
|
|||
JSValueProtect(ctx, exn);
|
||||
std::string exceptionText = Value(ctx, exn).toString().str();
|
||||
FBLOGE("Got JS Exception: %s", exceptionText.c_str());
|
||||
auto line = Value(ctx, JSObjectGetProperty(ctx,
|
||||
JSValueToObject(ctx, exn, nullptr),
|
||||
JSStringCreateWithUTF8CString("line"), nullptr
|
||||
));
|
||||
std::ostringstream lineInfo;
|
||||
if (line != nullptr && line.isNumber()) {
|
||||
lineInfo << " (line " << line.asInteger() << " in the generated bundle)";
|
||||
} else {
|
||||
lineInfo << " (no line info)";
|
||||
}
|
||||
throwNewJavaException("com/facebook/react/bridge/JSExecutionException", (exceptionText + lineInfo.str()).c_str());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -648,6 +648,9 @@ static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager,
|
|||
|
||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromAssets_read"));
|
||||
executeApplicationScript(bridge, script, assetNameStr);
|
||||
if (env->ExceptionCheck()) {
|
||||
return;
|
||||
}
|
||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromAssets_done"));
|
||||
}
|
||||
|
||||
|
@ -666,6 +669,9 @@ static void loadScriptFromFile(JNIEnv* env, jobject obj, jstring fileName, jstri
|
|||
#endif
|
||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromFile_read"));
|
||||
executeApplicationScript(bridge, script, jni::fromJString(env, sourceURL));
|
||||
if (env->ExceptionCheck()) {
|
||||
return;
|
||||
}
|
||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromFile_exec"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue