Skip to content

Commit 924dfe1

Browse files
author
hyb1996
committed
修复 停止脚本时导致ANR的问题
1 parent 9fb84e7 commit 924dfe1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

app/src/main/java/org/autojs/autojs/model/script/Scripts.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ object Scripts {
137137
}
138138

139139
@Nullable
140-
fun getRhinoException(e: Throwable?): RhinoException? {
141-
var e = e
140+
fun getRhinoException(throwable: Throwable?): RhinoException? {
141+
var e = throwable
142142
while (e != null) {
143143
if (e is RhinoException) {
144144
return e

autojs/src/main/java/com/stardust/autojs/engine/ScriptEngine.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.HashMap;
99
import java.util.Map;
10+
import java.util.concurrent.ConcurrentHashMap;
1011
import java.util.concurrent.atomic.AtomicInteger;
1112

1213
/**
@@ -68,14 +69,14 @@ interface OnDestroyListener {
6869
abstract class AbstractScriptEngine<S extends ScriptSource> implements ScriptEngine<S> {
6970

7071

71-
private Map<String, Object> mTags = new HashMap<>();
72+
private Map<String, Object> mTags = new ConcurrentHashMap<>();
7273
private OnDestroyListener mOnDestroyListener;
73-
private boolean mDestroyed = false;
74+
private volatile boolean mDestroyed = false;
7475
private Throwable mUncaughtException;
7576
private volatile AtomicInteger mId = new AtomicInteger(ScriptExecution.NO_ID);
7677

7778
@Override
78-
public synchronized void setTag(String key, Object value) {
79+
public void setTag(String key, Object value) {
7980
if (value == null) {
8081
mTags.remove(key);
8182
} else {
@@ -84,22 +85,22 @@ public synchronized void setTag(String key, Object value) {
8485
}
8586

8687
@Override
87-
public synchronized Object getTag(String key) {
88+
public Object getTag(String key) {
8889
return mTags.get(key);
8990
}
9091

9192
@Override
92-
public synchronized boolean isDestroyed() {
93+
public boolean isDestroyed() {
9394
return mDestroyed;
9495
}
9596

9697
@CallSuper
9798
@Override
98-
public synchronized void destroy() {
99-
mDestroyed = true;
99+
public void destroy() {
100100
if (mOnDestroyListener != null) {
101101
mOnDestroyListener.onDestroy(this);
102102
}
103+
mDestroyed = true;
103104
}
104105

105106
public String cwd() {

0 commit comments

Comments
 (0)