show script eval errors in redbox

Differential Revision: D2624801

fb-gh-sync-id: 48741a8caf029415753a4c616a07f18d3660e6fb
This commit is contained in:
Felix Oghină 2015-11-06 11:42:24 -08:00 committed by facebook-github-bot-4
parent e6372719ea
commit 9647c5a257
4 changed files with 42 additions and 1 deletions

View File

@ -134,7 +134,11 @@ public class CatalystInstance {
incrementPendingJSCalls();
mJSBundleLoader.loadScript(mBridge);
try {
mJSBundleLoader.loadScript(mBridge);
} catch (JSExecutionException e) {
mNativeModuleCallExceptionHandler.handleException(e);
}
initLatch.countDown();
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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"));
}