feat(ui): fix debug mode exception on orientation change
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user