feat(ui): fix debug mode exception on orientation change

This commit is contained in:
hyb1996
2018-09-08 01:53:51 +08:00
parent 32805aad34
commit c56157d8da
13 changed files with 127 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
package com.stardust.autojs;
import android.content.Context;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import com.stardust.autojs.engine.JavaScriptEngine;
@@ -25,6 +26,9 @@ import com.stardust.util.UiHandler;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.ScriptStackElement;
import org.mozilla.javascript.WrappedException;
import java.io.BufferedReader;
import java.io.IOException;
@@ -209,7 +213,7 @@ public class ScriptEngineService {
@Nullable
public ScriptExecution getScriptExecution(int id) {
if(id == ScriptExecution.NO_ID){
if (id == ScriptExecution.NO_ID) {
return null;
}
return mScriptExecutions.get(id);
@@ -275,7 +279,17 @@ public class ScriptEngineService {
}
}
private static String getScriptTrace(Exception e) {
public static String getScriptTrace(Exception e) {
StringBuilder scriptTrace = new StringBuilder();
if (e instanceof RhinoException) {
RhinoException rhinoException = (RhinoException) e;
scriptTrace.append(rhinoException.details()).append("\n");
for (ScriptStackElement element : rhinoException.getScriptStack()) {
element.renderV8Style(scriptTrace);
scriptTrace.append("\n");
}
scriptTrace.append("- - - - - - - - - - -\n");
}
try {
PipedReader reader = new PipedReader(8192);
PrintWriter writer = new PrintWriter(new PipedWriter(reader));
@@ -283,10 +297,9 @@ public class ScriptEngineService {
writer.close();
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
StringBuilder scriptTrace = new StringBuilder(TextUtils.toEmptyIfNull(e.getMessage()));
//scriptTrace.append(TextUtils.toEmptyIfNull(e.getMessage()));
while ((line = bufferedReader.readLine()) != null) {
if (line.trim().startsWith("at script"))
scriptTrace.append("\n").append(line);
scriptTrace.append("\n").append(line);
}
return scriptTrace.toString();
} catch (IOException e1) {

View File

@@ -4,6 +4,7 @@ import android.os.Handler;
import android.os.Looper;
import android.support.annotation.CallSuper;
import com.stardust.autojs.ScriptEngineService;
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
import com.stardust.autojs.runtime.ScriptBridges;
import com.stardust.autojs.runtime.ScriptRuntime;
@@ -48,7 +49,7 @@ public class TimerThread extends ThreadCompat {
Looper.loop();
} catch (Exception e) {
if (!ScriptInterruptedException.causedByInterrupted(e)) {
mRuntime.console.error(Thread.currentThread().toString() + ": " + e);
mRuntime.console.error(Thread.currentThread().toString() + ": " + ScriptEngineService.getScriptTrace(e));
}
} finally {
onExit();

View File

@@ -32,6 +32,7 @@ public class Dim {
public static final int GO = 3;
public static final int BREAK = 4;
public static final int EXIT = 5;
public static final String TAG = Dim.class.getName();
// Constants for the DimIProxy interface implementation class.
private static final int IPROXY_DEBUG = 0;
@@ -1027,6 +1028,7 @@ public class Dim {
cx.setDebugger(debugger, contextData);
cx.setGeneratingDebug(true);
cx.setOptimizationLevel(-1);
engine.setTag(TAG, Dim.this);
}
@Override

View File

@@ -372,7 +372,7 @@ public class ScriptRuntime {
try {
events.emit("exit");
} catch (Exception ignored) {
console.error("exception on exit: " + ignored);
console.error("exception on exit: " + ScriptEngineService.getScriptTrace(ignored));
}
ignoresException(threads::shutDownAll);
ignoresException(events::recycle);