修复 停止脚本时导致ANR的问题

This commit is contained in:
hyb1996
2019-01-26 10:06:21 +08:00
parent 9fb84e7ea2
commit 924dfe1e21
2 changed files with 10 additions and 9 deletions

View File

@@ -137,8 +137,8 @@ object Scripts {
} }
@Nullable @Nullable
fun getRhinoException(e: Throwable?): RhinoException? { fun getRhinoException(throwable: Throwable?): RhinoException? {
var e = e var e = throwable
while (e != null) { while (e != null) {
if (e is RhinoException) { if (e is RhinoException) {
return e return e

View File

@@ -7,6 +7,7 @@ import com.stardust.autojs.script.ScriptSource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
@@ -68,14 +69,14 @@ public interface ScriptEngine<S extends ScriptSource> {
abstract class AbstractScriptEngine<S extends ScriptSource> implements ScriptEngine<S> { abstract class AbstractScriptEngine<S extends ScriptSource> implements ScriptEngine<S> {
private Map<String, Object> mTags = new HashMap<>(); private Map<String, Object> mTags = new ConcurrentHashMap<>();
private OnDestroyListener mOnDestroyListener; private OnDestroyListener mOnDestroyListener;
private boolean mDestroyed = false; private volatile boolean mDestroyed = false;
private Throwable mUncaughtException; private Throwable mUncaughtException;
private volatile AtomicInteger mId = new AtomicInteger(ScriptExecution.NO_ID); private volatile AtomicInteger mId = new AtomicInteger(ScriptExecution.NO_ID);
@Override @Override
public synchronized void setTag(String key, Object value) { public void setTag(String key, Object value) {
if (value == null) { if (value == null) {
mTags.remove(key); mTags.remove(key);
} else { } else {
@@ -84,22 +85,22 @@ public interface ScriptEngine<S extends ScriptSource> {
} }
@Override @Override
public synchronized Object getTag(String key) { public Object getTag(String key) {
return mTags.get(key); return mTags.get(key);
} }
@Override @Override
public synchronized boolean isDestroyed() { public boolean isDestroyed() {
return mDestroyed; return mDestroyed;
} }
@CallSuper @CallSuper
@Override @Override
public synchronized void destroy() { public void destroy() {
mDestroyed = true;
if (mOnDestroyListener != null) { if (mOnDestroyListener != null) {
mOnDestroyListener.onDestroy(this); mOnDestroyListener.onDestroy(this);
} }
mDestroyed = true;
} }
public String cwd() { public String cwd() {