mNameMap = new HashMap<>();
@Override
public String handleNode(Node node, StringBuilder layoutXml) {
@@ -75,7 +74,7 @@ public interface NodeHandler {
class VerticalHandler extends Adapter {
- private String mLinearLayoutClassName;
+ private final String mLinearLayoutClassName;
public VerticalHandler(String linearLayoutClassName) {
mLinearLayoutClassName = linearLayoutClassName;
diff --git a/autojs/src/main/java/com/stardust/autojs/core/ui/xml/XmlConverter.java b/autojs/src/main/java/com/stardust/autojs/core/ui/xml/XmlConverter.java
index 439dd8c6..ceb39553 100644
--- a/autojs/src/main/java/com/stardust/autojs/core/ui/xml/XmlConverter.java
+++ b/autojs/src/main/java/com/stardust/autojs/core/ui/xml/XmlConverter.java
@@ -49,7 +49,6 @@ import javax.xml.parsers.ParserConfigurationException;
/**
* Created by Stardust on 2017/5/14.
*/
-
public class XmlConverter {
private static final NodeHandler NODE_HANDLER = new NodeHandler.NameRouter()
@@ -60,9 +59,11 @@ public class XmlConverter {
.map("horizontal", JsLinearLayout.class.getName())
.map("relative", JsRelativeLayout.class.getName())
.map("button", JsButton.class.getName())
- .map("text", Build.VERSION.SDK_INT < Build.VERSION_CODES.O
- ? JsTextViewLegacy.class.getName()
- : JsTextView.class.getName())
+ .map("text",
+ // @Reference to TonyJiangWJ/Auto.js on Mar 20, 2022
+ Build.VERSION.SDK_INT < Build.VERSION_CODES.O
+ ? JsTextViewLegacy.class.getName()
+ : JsTextView.class.getName())
.map("input", JsEditText.class.getName())
.map("img", JsImageView.class.getName())
.map("datepicker", DatePicker.class.getName())
diff --git a/autojs/src/main/java/com/stardust/autojs/core/util/ProcessShell.java b/autojs/src/main/java/com/stardust/autojs/core/util/ProcessShell.java
index 26755b48..4fe4af42 100644
--- a/autojs/src/main/java/com/stardust/autojs/core/util/ProcessShell.java
+++ b/autojs/src/main/java/com/stardust/autojs/core/util/ProcessShell.java
@@ -1,10 +1,8 @@
package com.stardust.autojs.core.util;
-
import android.util.Log;
import com.stardust.autojs.runtime.api.AbstractShell;
-import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
import com.stardust.autojs.util.ProcessUtils;
import com.stardust.pio.UncheckedIOException;
@@ -19,7 +17,6 @@ import java.io.InputStreamReader;
*
* 来自网络~~
*/
-
public class ProcessShell extends AbstractShell {
private static final String TAG = "ProcessShell";
@@ -29,8 +26,8 @@ public class ProcessShell extends AbstractShell {
private BufferedReader mSucceedReader;
private BufferedReader mErrorReader;
- private StringBuilder mSucceedOutput = new StringBuilder();
- private StringBuilder mErrorOutput = new StringBuilder();
+ private final StringBuilder mSucceedOutput = new StringBuilder();
+ private final StringBuilder mErrorOutput = new StringBuilder();
public ProcessShell() {
@@ -202,7 +199,20 @@ public class ProcessShell extends AbstractShell {
commandResult.error = readAll(process.getErrorStream());
Log.d(TAG, commandResult.toString());
} catch (Exception e) {
- throw new ScriptInterruptedException(e);
+ // @Overwrite by SuperMonster003 on Apr 26, 2022.
+ // ! Try write exception into commandResult and make it visible to AutoJs6 console.
+ // ! Example (for non-root devices): log(shell('date', true));
+
+ // throw new ScriptInterruptedException(e);
+
+ String message = e.getMessage();
+ String aimErrStr = "error=";
+
+ int index = message != null ? message.indexOf(aimErrStr) : -1;
+
+ commandResult.code = index < 0 ? 1 : Integer.parseInt(message.substring(index + aimErrStr.length()).replaceAll("^(\\d+).+", "$1"));
+ commandResult.result = "";
+ commandResult.error = message != null ? message : "";
} finally {
try {
if (os != null) os.close();
@@ -235,5 +245,4 @@ public class ProcessShell extends AbstractShell {
return execCommand(commands, isRoot);
}
-
}
\ No newline at end of file
diff --git a/autojs/src/main/java/com/stardust/autojs/core/util/ScriptPromiseAdapter.kt b/autojs/src/main/java/com/stardust/autojs/core/util/ScriptPromiseAdapter.kt
index 3e116da5..ef25a97f 100644
--- a/autojs/src/main/java/com/stardust/autojs/core/util/ScriptPromiseAdapter.kt
+++ b/autojs/src/main/java/com/stardust/autojs/core/util/ScriptPromiseAdapter.kt
@@ -1,7 +1,5 @@
package com.stardust.autojs.core.util
-import com.stardust.autojs.core.internal.Functions
-
class ScriptPromiseAdapter {
interface Callback {
diff --git a/autojs/src/main/java/com/stardust/autojs/core/util/Shell.java b/autojs/src/main/java/com/stardust/autojs/core/util/Shell.java
index 993721f7..7bd7f878 100644
--- a/autojs/src/main/java/com/stardust/autojs/core/util/Shell.java
+++ b/autojs/src/main/java/com/stardust/autojs/core/util/Shell.java
@@ -20,7 +20,6 @@ import jackpal.androidterm.util.TermSettings;
/**
* Created by Stardust on 2017/4/24.
*/
-
public class Shell extends AbstractShell {
public interface Callback {
@@ -213,8 +212,8 @@ public class Shell extends AbstractShell {
private class MyShellTermSession extends ShellTermSession {
- private StringBuilder mStringBuffer = new StringBuilder();
- private ArrayList mCommandOutputs = new ArrayList<>();
+ private final StringBuilder mStringBuffer = new StringBuilder();
+ private final ArrayList mCommandOutputs = new ArrayList<>();
public MyShellTermSession(TermSettings settings, String initialCommand) throws IOException {
super(settings, initialCommand);
diff --git a/autojs/src/main/java/com/stardust/autojs/core/web/InjectableWebClient.java b/autojs/src/main/java/com/stardust/autojs/core/web/InjectableWebClient.java
index 95eee69c..6505358c 100644
--- a/autojs/src/main/java/com/stardust/autojs/core/web/InjectableWebClient.java
+++ b/autojs/src/main/java/com/stardust/autojs/core/web/InjectableWebClient.java
@@ -21,22 +21,16 @@ import java.util.Queue;
/**
* Created by Stardust on 2017/4/1.
*/
-
public class InjectableWebClient extends WebViewClient {
private static final String TAG = "InjectableWebClient";
- private Queue>> mToInjectJavaScripts = new LinkedList<>();
- private final ValueCallback defaultCallback = new ValueCallback() {
- @Override
- public void onReceiveValue(String value) {
- Log.i(TAG, "onReceiveValue: " + value);
- }
- };
+ private final Queue>> mToInjectJavaScripts = new LinkedList<>();
+ private final ValueCallback defaultCallback = value -> Log.i(TAG, "onReceiveValue: " + value);
private WebView mWebView;
- private Context mContext;
- private Scriptable mScriptable;
- private ScriptBridge mScriptBridge = new ScriptBridge();
+ private final Context mContext;
+ private final Scriptable mScriptable;
+ private final ScriptBridge mScriptBridge = new ScriptBridge();
public InjectableWebClient(Context context, Scriptable scriptable) {
mContext = context;
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/JavaScriptEngine.java b/autojs/src/main/java/com/stardust/autojs/engine/JavaScriptEngine.java
index 586ade0d..fe23e9bc 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/JavaScriptEngine.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/JavaScriptEngine.java
@@ -1,5 +1,7 @@
package com.stardust.autojs.engine;
+import androidx.annotation.NonNull;
+
import com.stardust.autojs.runtime.ScriptRuntime;
import com.stardust.autojs.script.JavaScriptSource;
import com.stardust.autojs.script.ScriptSource;
@@ -7,7 +9,6 @@ import com.stardust.autojs.script.ScriptSource;
/**
* Created by Stardust on 2017/8/3.
*/
-
public abstract class JavaScriptEngine extends ScriptEngine.AbstractScriptEngine {
private ScriptRuntime mRuntime;
private Object mExecArgv;
@@ -60,6 +61,7 @@ public abstract class JavaScriptEngine extends ScriptEngine.AbstractScriptEngine
super.destroy();
}
+ @NonNull
@Override
public String toString() {
return "ScriptEngine@" + Integer.toHexString(hashCode()) + "{" +
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/LoopBasedJavaScriptEngine.java b/autojs/src/main/java/com/stardust/autojs/engine/LoopBasedJavaScriptEngine.java
index 9c118f70..c0cff2ba 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/LoopBasedJavaScriptEngine.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/LoopBasedJavaScriptEngine.java
@@ -4,20 +4,16 @@ import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
-import android.os.MessageQueue;
-import android.util.Log;
import com.stardust.autojs.core.looper.LooperHelper;
import com.stardust.autojs.script.JavaScriptSource;
import com.stardust.autojs.script.ScriptSource;
-import com.stardust.util.Callback;
import org.mozilla.javascript.ContinuationPending;
/**
* Created by Stardust on 2017/7/28.
*/
-
public class LoopBasedJavaScriptEngine extends RhinoJavaScriptEngine {
public interface ExecuteCallback {
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/RhinoJavaScriptEngine.kt b/autojs/src/main/java/com/stardust/autojs/engine/RhinoJavaScriptEngine.kt
index 0fd0bbc1..79c5d15a 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/RhinoJavaScriptEngine.kt
+++ b/autojs/src/main/java/com/stardust/autojs/engine/RhinoJavaScriptEngine.kt
@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap
/**
* Created by Stardust on 2017/4/2.
*/
-
open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Context) : JavaScriptEngine() {
val context: Context
@@ -36,16 +35,14 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
private val initScript: Script
get() {
- return sInitScript ?: {
- try {
- val reader = InputStreamReader(mAndroidContext.assets.open("init.js"))
- val script = context.compileReader(reader, SOURCE_NAME_INIT, 1, null)
- sInitScript = script
- script
- } catch (e: IOException) {
- throw UncheckedIOException(e)
- }
- }()
+ return sInitScript ?: try {
+ val reader = InputStreamReader(mAndroidContext.assets.open("init.js"))
+ val script = context.compileReader(reader, SOURCE_NAME_INIT, 1, null)
+ sInitScript = script
+ script
+ } catch (e: IOException) {
+ throw UncheckedIOException(e)
+ }
}
val scriptable: Scriptable
@@ -96,7 +93,6 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
thread.interrupt()
}
-
@Synchronized
override fun destroy() {
super.destroy()
@@ -120,14 +116,16 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
}
}
- internal fun initRequireBuilder(context: Context, scope: Scriptable) {
- val provider = AssetAndUrlModuleSourceProvider(mAndroidContext, MODULES_PATH,
- listOf(File("/").toURI()))
+ private fun initRequireBuilder(context: Context, scope: Scriptable) {
+ val provider = AssetAndUrlModuleSourceProvider(
+ mAndroidContext, MODULES_PATH,
+ listOf(File("/").toURI())
+ )
RequireBuilder()
- .setModuleScriptProvider(SoftCachingModuleScriptProvider(provider))
- .setSandboxed(true)
- .createRequire(context, scope)
- .install(scope)
+ .setModuleScriptProvider(SoftCachingModuleScriptProvider(provider))
+ .setSandboxed(true)
+ .createRequire(context, scope)
+ .install(scope)
}
@@ -174,11 +172,11 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
companion object {
- val SOURCE_NAME_INIT = ""
+ const val SOURCE_NAME_INIT = ""
- private val LOG_TAG = "RhinoJavaScriptEngine"
+ private const val LOG_TAG = "RhinoJavaScriptEngine"
- private val MODULES_PATH = "modules"
+ private const val MODULES_PATH = "modules"
private var sInitScript: Script? = null
private val sContextEngineMap = ConcurrentHashMap()
@@ -188,5 +186,4 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
}
}
-
}
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/RootAutomatorEngine.java b/autojs/src/main/java/com/stardust/autojs/engine/RootAutomatorEngine.java
index 71832dbc..fcef44bc 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/RootAutomatorEngine.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/RootAutomatorEngine.java
@@ -22,7 +22,6 @@ import java.util.regex.Pattern;
/**
* Created by Stardust on 2017/8/1.
*/
-
public class RootAutomatorEngine extends ScriptEngine.AbstractScriptEngine {
public static final int VERSION = 1;
@@ -34,7 +33,7 @@ public class RootAutomatorEngine extends ScriptEngine.AbstractScriptEngine
*/
-
public interface ScriptEngine {
String TAG_ENV_PATH = "env_path";
@@ -68,11 +66,11 @@ public interface ScriptEngine {
abstract class AbstractScriptEngine implements ScriptEngine {
- private Map mTags = new ConcurrentHashMap<>();
+ private final Map mTags = new ConcurrentHashMap<>();
private OnDestroyListener mOnDestroyListener;
private volatile boolean mDestroyed = false;
private Throwable mUncaughtException;
- private volatile AtomicInteger mId = new AtomicInteger(ScriptExecution.NO_ID);
+ private final AtomicInteger mId = new AtomicInteger(ScriptExecution.NO_ID);
@Override
public void setTag(String key, Object value) {
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineFactory.java b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineFactory.java
index f374f5de..eb0e6ac7 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineFactory.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineFactory.java
@@ -12,7 +12,6 @@ import java.util.Map;
/**
* Created by Stardust on 2017/8/2.
*/
-
public class ScriptEngineFactory {
public static class EngineNotFoundException extends RuntimeException {
@@ -22,9 +21,9 @@ public class ScriptEngineFactory {
}
}
- private static ScriptEngineFactory sInstance = new ScriptEngineFactory();
- private Map> mEngines = new HashMap<>();
- private Map mGlobalVariableMap = new HashMap<>();
+ private static final ScriptEngineFactory sInstance = new ScriptEngineFactory();
+ private final Map> mEngines = new HashMap<>();
+ private final Map mGlobalVariableMap = new HashMap<>();
ScriptEngineFactory() {
@@ -74,7 +73,7 @@ public class ScriptEngineFactory {
public ScriptEngine createEngineOfSourceOrThrow(ScriptSource source) {
ScriptEngine engine = createEngineOfSource(source);
if (engine == null)
- throw new EngineNotFoundException("source: " + source.toString());
+ throw new EngineNotFoundException("source: " + source);
return engine;
}
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineManager.java b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineManager.java
index 6b89fc9f..ec304da9 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineManager.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineManager.java
@@ -16,7 +16,6 @@ import java.util.Set;
/**
* Created by Stardust on 2017/1/27.
*/
-
public class ScriptEngineManager {
public interface EngineLifecycleCallback {
@@ -30,15 +29,10 @@ public class ScriptEngineManager {
private final Set mEngines = new HashSet<>();
private EngineLifecycleCallback mEngineLifecycleCallback;
- private Map> mEngineSuppliers = new HashMap<>();
- private Map mGlobalVariableMap = new HashMap<>();
- private android.content.Context mAndroidContext;
- private ScriptEngine.OnDestroyListener mOnEngineDestroyListener = new ScriptEngine.OnDestroyListener() {
- @Override
- public void onDestroy(ScriptEngine engine) {
- removeEngine(engine);
- }
- };
+ private final Map> mEngineSuppliers = new HashMap<>();
+ private final Map mGlobalVariableMap = new HashMap<>();
+ private final android.content.Context mAndroidContext;
+ private final ScriptEngine.OnDestroyListener mOnEngineDestroyListener = engine -> removeEngine(engine);
public ScriptEngineManager(Context androidContext) {
mAndroidContext = androidContext;
@@ -118,7 +112,7 @@ public class ScriptEngineManager {
public ScriptEngine createEngineOfSourceOrThrow(ScriptSource source, int id) {
ScriptEngine engine = createEngineOfSource(source, id);
if (engine == null)
- throw new ScriptEngineFactory.EngineNotFoundException("source: " + source.toString());
+ throw new ScriptEngineFactory.EngineNotFoundException("source: " + source);
return engine;
}
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineProxy.java b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineProxy.java
index 889774d3..0a718586 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineProxy.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/ScriptEngineProxy.java
@@ -5,7 +5,6 @@ import com.stardust.autojs.script.ScriptSource;
/**
* Created by Stardust on 2018/3/17.
*/
-
public class ScriptEngineProxy implements ScriptEngine {
private final ScriptEngine mScriptEngine;
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/module/AssetAndUrlModuleSourceProvider.java b/autojs/src/main/java/com/stardust/autojs/engine/module/AssetAndUrlModuleSourceProvider.java
index cc981d8b..03edf132 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/module/AssetAndUrlModuleSourceProvider.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/module/AssetAndUrlModuleSourceProvider.java
@@ -21,10 +21,9 @@ import java.util.List;
/**
* Created by Stardust on 2017/5/9.
*/
-
public class AssetAndUrlModuleSourceProvider extends UrlModuleSourceProvider {
- private android.content.Context mContext;
+ private final android.content.Context mContext;
private final URI mBaseURI;
private final String mAssetDirPath;
private final AssetManager mAssetManager;
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/module/UrlModuleSourceProvider.java b/autojs/src/main/java/com/stardust/autojs/engine/module/UrlModuleSourceProvider.java
index c3e668df..c70da784 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/module/UrlModuleSourceProvider.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/module/UrlModuleSourceProvider.java
@@ -136,8 +136,7 @@ public class UrlModuleSourceProvider extends ModuleSourceProviderBase {
final long request_time = System.currentTimeMillis();
final URLConnection urlConnection = openUrlConnection(url);
final URLValidator applicableValidator;
- if (validator instanceof URLValidator) {
- final URLValidator uriValidator = ((URLValidator) validator);
+ if (validator instanceof final URLValidator uriValidator) {
applicableValidator = uriValidator.appliesTo(uri) ? uriValidator :
null;
} else {
@@ -161,10 +160,7 @@ public class UrlModuleSourceProvider extends ModuleSourceProviderBase {
urlConnectionExpiryCalculator));
} catch (FileNotFoundException e) {
return null;
- } catch (RuntimeException e) {
- close(urlConnection);
- throw e;
- } catch (IOException e) {
+ } catch (RuntimeException | IOException e) {
close(urlConnection);
throw e;
}
@@ -280,7 +276,7 @@ public class UrlModuleSourceProvider extends ModuleSourceProviderBase {
final String cacheControl = urlConnection.getHeaderField(
"Cache-Control");
if (cacheControl != null) {
- if (cacheControl.indexOf("no-cache") != -1) {
+ if (cacheControl.contains("no-cache")) {
return 0L;
}
final int max_age = getMaxAge(cacheControl);
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/AbstractProcessor.java b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/AbstractProcessor.java
index 44ab0378..d6367c34 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/AbstractProcessor.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/AbstractProcessor.java
@@ -7,7 +7,6 @@ import java.io.Reader;
/**
* Created by Stardust on 2017/5/15.
*/
-
public abstract class AbstractProcessor implements Preprocessor {
@Override
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/MultiLinePreprocessor.java b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/MultiLinePreprocessor.java
index 94d18b67..eb0caaf4 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/MultiLinePreprocessor.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/MultiLinePreprocessor.java
@@ -1,14 +1,11 @@
package com.stardust.autojs.engine.preprocess;
-import androidx.annotation.VisibleForTesting;
-
import java.io.Reader;
import java.io.StringReader;
/**
* Created by Stardust on 2017/5/15.
*/
-
public class MultiLinePreprocessor extends AbstractProcessor {
private static final int STATE_SINGLE_QUOTE_LITERAL = 0x00000001;
diff --git a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/Preprocessor.java b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/Preprocessor.java
index d702634b..a6398e64 100644
--- a/autojs/src/main/java/com/stardust/autojs/engine/preprocess/Preprocessor.java
+++ b/autojs/src/main/java/com/stardust/autojs/engine/preprocess/Preprocessor.java
@@ -6,7 +6,6 @@ import java.io.Reader;
/**
* Created by Stardust on 2017/5/15.
*/
-
public interface Preprocessor {
Reader preprocess(Reader reader) throws IOException;
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/LoopedBasedJavaScriptExecution.java b/autojs/src/main/java/com/stardust/autojs/execution/LoopedBasedJavaScriptExecution.java
index db829a74..d998d84c 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/LoopedBasedJavaScriptExecution.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/LoopedBasedJavaScriptExecution.java
@@ -9,7 +9,6 @@ import com.stardust.autojs.script.JavaScriptSource;
/**
* Created by Stardust on 2017/10/27.
*/
-
public class LoopedBasedJavaScriptExecution extends RunnableScriptExecution {
public LoopedBasedJavaScriptExecution(ScriptEngineManager manager, ScriptExecutionTask task) {
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/RunnableScriptExecution.java b/autojs/src/main/java/com/stardust/autojs/execution/RunnableScriptExecution.java
index 6e35444e..665b4bc4 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/RunnableScriptExecution.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/RunnableScriptExecution.java
@@ -8,17 +8,14 @@ import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
import com.stardust.autojs.script.ScriptSource;
import com.stardust.lang.ThreadCompat;
-import org.mozilla.javascript.ContinuationPending;
-
/**
* Created by Stardust on 2017/5/1.
*/
-
public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecution implements Runnable {
private static final String TAG = "RunnableJSExecution";
private ScriptEngine mScriptEngine;
- private ScriptEngineManager mScriptEngineManager;
+ private final ScriptEngineManager mScriptEngineManager;
public RunnableScriptExecution(ScriptEngineManager manager, ScriptExecutionTask task) {
super(task);
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecuteActivity.java b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecuteActivity.java
index b671b9ee..6246368c 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecuteActivity.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecuteActivity.java
@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
@@ -28,7 +29,6 @@ import org.mozilla.javascript.ContinuationPending;
/**
* Created by Stardust on 2017/2/5.
*/
-
public class ScriptExecuteActivity extends AppCompatActivity {
@@ -64,7 +64,7 @@ public class ScriptExecuteActivity extends AppCompatActivity {
return;
}
ScriptExecution execution = ScriptEngineService.getInstance().getScriptExecution(executionId);
- if (execution == null || !(execution instanceof ActivityScriptExecution)) {
+ if (!(execution instanceof ActivityScriptExecution)) {
super.finish();
return;
}
@@ -151,7 +151,7 @@ public class ScriptExecuteActivity extends AppCompatActivity {
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (mScriptExecution != null)
outState.putInt(EXTRA_EXECUTION_ID, mScriptExecution.getId());
@@ -226,7 +226,7 @@ public class ScriptExecuteActivity extends AppCompatActivity {
public void emit(String event, Object... args) {
try {
- mEventEmitter.emit(event, (Object[]) args);
+ mEventEmitter.emit(event, args);
} catch (Exception e) {
mRuntime.exit(e);
}
@@ -235,7 +235,7 @@ public class ScriptExecuteActivity extends AppCompatActivity {
private static class ActivityScriptExecution extends ScriptExecution.AbstractScriptExecution {
private ScriptEngine mScriptEngine;
- private ScriptEngineManager mScriptEngineManager;
+ private final ScriptEngineManager mScriptEngineManager;
ActivityScriptExecution(ScriptEngineManager manager, ScriptExecutionTask task) {
super(task);
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecution.java b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecution.java
index ca131499..90dce0d8 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecution.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecution.java
@@ -1,16 +1,13 @@
package com.stardust.autojs.execution;
import com.stardust.autojs.engine.ScriptEngine;
-import com.stardust.autojs.runtime.ScriptRuntime;
import com.stardust.autojs.script.ScriptSource;
-import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by Stardust on 2017/4/3.
*/
-
public interface ScriptExecution {
int NO_ID = -1;
@@ -27,7 +24,7 @@ public interface ScriptExecution {
abstract class AbstractScriptExecution implements ScriptExecution {
- private static AtomicInteger sMaxId = new AtomicInteger(0);
+ private static final AtomicInteger sMaxId = new AtomicInteger(0);
protected ScriptExecutionTask mScriptExecutionTask;
protected int mId;
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionListener.java b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionListener.java
index 9d76cef3..08fe28a9 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionListener.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionListener.java
@@ -5,7 +5,6 @@ import java.io.Serializable;
/**
* Created by Stardust on 2017/4/2.
*/
-
public interface ScriptExecutionListener extends Serializable {
void onStart(ScriptExecution execution);
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionObserver.java b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionObserver.java
index 117bc848..cb9dff24 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionObserver.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionObserver.java
@@ -5,9 +5,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
/**
* Created by Stardust on 2017/5/3.
*/
-
public class ScriptExecutionObserver implements ScriptExecutionListener {
- private CopyOnWriteArraySet mScriptExecutionListeners = new CopyOnWriteArraySet<>();
+ private final CopyOnWriteArraySet mScriptExecutionListeners = new CopyOnWriteArraySet<>();
@Override
public void onStart(ScriptExecution execution) {
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionTask.java b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionTask.java
index c900c8df..67ca2fb4 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionTask.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/ScriptExecutionTask.java
@@ -7,12 +7,11 @@ import java.io.Serializable;
/**
* Created by Stardust on 2017/4/2.
*/
-
public class ScriptExecutionTask implements Serializable {
- private ScriptSource mScriptSource;
+ private final ScriptSource mScriptSource;
private ScriptExecutionListener mExecutionListener;
- private ExecutionConfig mExecutionConfig;
+ private final ExecutionConfig mExecutionConfig;
public ScriptExecutionTask(ScriptSource source, ScriptExecutionListener listener, ExecutionConfig config) {
mScriptSource = source;
diff --git a/autojs/src/main/java/com/stardust/autojs/execution/SimpleScriptExecutionListener.java b/autojs/src/main/java/com/stardust/autojs/execution/SimpleScriptExecutionListener.java
index d6fe1398..b8dfd1df 100644
--- a/autojs/src/main/java/com/stardust/autojs/execution/SimpleScriptExecutionListener.java
+++ b/autojs/src/main/java/com/stardust/autojs/execution/SimpleScriptExecutionListener.java
@@ -3,7 +3,6 @@ package com.stardust.autojs.execution;
/**
* Created by Stardust on 2017/4/2.
*/
-
public class SimpleScriptExecutionListener implements ScriptExecutionListener {
@Override
diff --git a/autojs/src/main/java/com/stardust/autojs/project/LaunchConfig.java b/autojs/src/main/java/com/stardust/autojs/project/LaunchConfig.java
index a10d38e8..66757f1e 100644
--- a/autojs/src/main/java/com/stardust/autojs/project/LaunchConfig.java
+++ b/autojs/src/main/java/com/stardust/autojs/project/LaunchConfig.java
@@ -5,7 +5,6 @@ import com.google.gson.annotations.SerializedName;
/**
* Created by Stardust on 2018/1/25.
*/
-
public class LaunchConfig {
@SerializedName("hideLogs")
diff --git a/autojs/src/main/java/com/stardust/autojs/project/ProjectConfig.java b/autojs/src/main/java/com/stardust/autojs/project/ProjectConfig.java
index 0f61c122..f7c9c25b 100644
--- a/autojs/src/main/java/com/stardust/autojs/project/ProjectConfig.java
+++ b/autojs/src/main/java/com/stardust/autojs/project/ProjectConfig.java
@@ -18,7 +18,6 @@ import java.util.Map;
/**
* Created by Stardust on 2018/1/24.
*/
-
public class ProjectConfig {
public static final String CONFIG_FILE_NAME = "project.json";
@@ -53,7 +52,7 @@ public class ProjectConfig {
private String mIcon;
@SerializedName("scripts")
- private Map mScriptConfigs = new HashMap<>();
+ private final Map mScriptConfigs = new HashMap<>();
@SerializedName("useFeatures")
private List mFeatures = new ArrayList<>();
@@ -83,10 +82,7 @@ public class ProjectConfig {
if (TextUtils.isEmpty(config.getMainScriptFile())) {
return false;
}
- if (config.getVersionCode() == -1) {
- return false;
- }
- return true;
+ return config.getVersionCode() != -1;
}
diff --git a/autojs/src/main/java/com/stardust/autojs/project/ProjectLauncher.java b/autojs/src/main/java/com/stardust/autojs/project/ProjectLauncher.java
index c8e85349..c0102c93 100644
--- a/autojs/src/main/java/com/stardust/autojs/project/ProjectLauncher.java
+++ b/autojs/src/main/java/com/stardust/autojs/project/ProjectLauncher.java
@@ -8,9 +8,9 @@ import java.io.File;
public class ProjectLauncher {
- private String mProjectDir;
- private File mMainScriptFile;
- private ProjectConfig mProjectConfig;
+ private final String mProjectDir;
+ private final File mMainScriptFile;
+ private final ProjectConfig mProjectConfig;
public ProjectLauncher(String projectDir) {
mProjectDir = projectDir;
diff --git a/autojs/src/main/java/com/stardust/autojs/project/ScriptConfig.kt b/autojs/src/main/java/com/stardust/autojs/project/ScriptConfig.kt
index 5737a34b..1162fa7c 100644
--- a/autojs/src/main/java/com/stardust/autojs/project/ScriptConfig.kt
+++ b/autojs/src/main/java/com/stardust/autojs/project/ScriptConfig.kt
@@ -13,6 +13,6 @@ data class ScriptConfig(
}
companion object {
- val FEATURE_CONTINUATION = "continuation"
+ const val FEATURE_CONTINUATION = "continuation"
}
}
\ No newline at end of file
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/AndroidClassLoader.java b/autojs/src/main/java/com/stardust/autojs/rhino/AndroidClassLoader.java
index e189f645..05e4de75 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/AndroidClassLoader.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/AndroidClassLoader.java
@@ -25,7 +25,6 @@ import dalvik.system.DexClassLoader;
/**
* Created by Stardust on 2017/4/5.
*/
-
public class AndroidClassLoader extends ClassLoader implements GeneratedClassLoader {
private static final String LOG_TAG = "AndroidClassLoader";
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/AndroidContextFactory.java b/autojs/src/main/java/com/stardust/autojs/rhino/AndroidContextFactory.java
index 25252b27..a0b66501 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/AndroidContextFactory.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/AndroidContextFactory.java
@@ -11,7 +11,6 @@ import java.io.File;
/**
* Created by Stardust on 2017/4/5.
*/
-
public class AndroidContextFactory extends ShellContextFactory {
private final File cacheDirectory;
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/InterruptibleAndroidContextFactory.java b/autojs/src/main/java/com/stardust/autojs/rhino/InterruptibleAndroidContextFactory.java
index 07fcc61b..8b473448 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/InterruptibleAndroidContextFactory.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/InterruptibleAndroidContextFactory.java
@@ -12,7 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class InterruptibleAndroidContextFactory extends AndroidContextFactory {
- private AtomicInteger mContextCount = new AtomicInteger();
+ private final AtomicInteger mContextCount = new AtomicInteger();
private static final String LOG_TAG = "ContextFactory";
/**
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaClassWithPrototype.java b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaClassWithPrototype.java
index e8c15cb9..3c843466 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaClassWithPrototype.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaClassWithPrototype.java
@@ -2,7 +2,6 @@ package com.stardust.autojs.rhino;
import org.mozilla.javascript.EvaluatorException;
import org.mozilla.javascript.NativeJavaClass;
-import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.Scriptable;
import java.util.concurrent.ConcurrentHashMap;
@@ -10,11 +9,10 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Stardust on 2018/4/4.
*/
-
public class NativeJavaClassWithPrototype extends NativeJavaClass {
private static final Object NULL = new Object();
- private ConcurrentHashMap mProperties = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap mProperties = new ConcurrentHashMap<>();
public NativeJavaClassWithPrototype(Scriptable scope, Class> javaClass) {
super(scope, javaClass);
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java
index 3de1ffc3..0b4d11a7 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/NativeJavaObjectWithPrototype.java
@@ -6,7 +6,6 @@ import org.mozilla.javascript.Scriptable;
/**
* Created by Stardust on 2018/4/4.
*/
-
public class NativeJavaObjectWithPrototype extends NativeJavaObject {
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/NoSecurityController.java b/autojs/src/main/java/com/stardust/autojs/rhino/NoSecurityController.java
index bca52b71..e34c9955 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/NoSecurityController.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/NoSecurityController.java
@@ -9,7 +9,6 @@ import java.io.Serializable;
/**
* Created by Stardust on 2017/4/5.
*/
-
public class NoSecurityController extends SecurityController implements Serializable {
@Override
public GeneratedClassLoader createClassLoader(ClassLoader classLoader, Object o) {
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/ProxyJavaObject.java b/autojs/src/main/java/com/stardust/autojs/rhino/ProxyJavaObject.java
index cb9bf9e3..4ea43132 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/ProxyJavaObject.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/ProxyJavaObject.java
@@ -10,7 +10,6 @@ import org.mozilla.javascript.UniqueTag;
/**
* Created by Stardust on 2017/12/6.
*/
-
public class ProxyJavaObject extends NativeJavaObject {
private NativeFunction mGetter;
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/ProxyObject.java b/autojs/src/main/java/com/stardust/autojs/rhino/ProxyObject.java
index 8fd84f56..c60fef85 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/ProxyObject.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/ProxyObject.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.UniqueTag;
/**
* Created by Stardust on 2017/5/17.
*/
-
public class ProxyObject extends NativeObject {
private NativeFunction mGetter;
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/RhinoAndroidHelper.java b/autojs/src/main/java/com/stardust/autojs/rhino/RhinoAndroidHelper.java
index b3ec0809..e485ccda 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/RhinoAndroidHelper.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/RhinoAndroidHelper.java
@@ -13,7 +13,6 @@ import java.io.IOException;
/**
* Created by Stardust on 2017/4/5.
*/
-
public class RhinoAndroidHelper {
private final File cacheDirectory;
diff --git a/autojs/src/main/java/com/stardust/autojs/rhino/TokenStream.java b/autojs/src/main/java/com/stardust/autojs/rhino/TokenStream.java
index 66b2619e..9e9b3e69 100644
--- a/autojs/src/main/java/com/stardust/autojs/rhino/TokenStream.java
+++ b/autojs/src/main/java/com/stardust/autojs/rhino/TokenStream.java
@@ -14,2306 +14,2297 @@ import java.io.IOException;
import java.io.Reader;
-public class TokenStream {
- public static final double NaN = Double
- .longBitsToDouble(0x7ff8000000000000L);
-
- static double stringToNumber(String s, int start, int radix) {
- char digitMax = '9';
- char lowerCaseBound = 'a';
- char upperCaseBound = 'A';
- int len = s.length();
- if (radix < 10) {
- digitMax = (char) ('0' + radix - 1);
- }
- if (radix > 10) {
- lowerCaseBound = (char) ('a' + radix - 10);
- upperCaseBound = (char) ('A' + radix - 10);
- }
- int end;
- double sum = 0.0;
- for (end = start; end < len; end++) {
- char c = s.charAt(end);
- int newDigit;
- if ('0' <= c && c <= digitMax)
- newDigit = c - '0';
- else if ('a' <= c && c < lowerCaseBound)
- newDigit = c - 'a' + 10;
- else if ('A' <= c && c < upperCaseBound)
- newDigit = c - 'A' + 10;
- else
- break;
- sum = sum * radix + newDigit;
- }
- if (start == end) {
- return NaN;
- }
- if (sum >= 9007199254740992.0) {
- if (radix == 10) {
- /*
- * If we're accumulating a decimal number and the number is >=
- * 2^53, then the result from the repeated multiply-add above
- * may be inaccurate. Call Java to get the correct answer.
- */
- try {
- return Double.parseDouble(s.substring(start, end));
- } catch (NumberFormatException nfe) {
- return NaN;
- }
- } else if (radix == 2 || radix == 4 || radix == 8 || radix == 16
- || radix == 32) {
- /*
- * The number may also be inaccurate for one of these bases.
- * This happens if the addition in value*radix + digit causes a
- * round-down to an even least significant mantissa bit when the
- * first dropped bit is a one. If any of the following digits in
- * the number (which haven't been added in yet) are nonzero then
- * the correct action would have been to round up instead of
- * down. An example of this occurs when reading the number
- * 0x1000000000000081, which rounds to 0x1000000000000000
- * instead of 0x1000000000000100.
- */
- int bitShiftInChar = 1;
- int digit = 0;
-
- final int SKIP_LEADING_ZEROS = 0;
- final int FIRST_EXACT_53_BITS = 1;
- final int AFTER_BIT_53 = 2;
- final int ZEROS_AFTER_54 = 3;
- final int MIXED_AFTER_54 = 4;
-
- int state = SKIP_LEADING_ZEROS;
- int exactBitsLimit = 53;
- double factor = 0.0;
- boolean bit53 = false;
- // bit54 is the 54th bit (the first dropped from the mantissa)
- boolean bit54 = false;
-
- for (;;) {
- if (bitShiftInChar == 1) {
- if (start == end)
- break;
- digit = s.charAt(start++);
- if ('0' <= digit && digit <= '9')
- digit -= '0';
- else if ('a' <= digit && digit <= 'z')
- digit -= 'a' - 10;
- else
- digit -= 'A' - 10;
- bitShiftInChar = radix;
- }
- bitShiftInChar >>= 1;
- boolean bit = (digit & bitShiftInChar) != 0;
-
- switch (state) {
- case SKIP_LEADING_ZEROS:
- if (bit) {
- --exactBitsLimit;
- sum = 1.0;
- state = FIRST_EXACT_53_BITS;
- }
- break;
- case FIRST_EXACT_53_BITS:
- sum *= 2.0;
- if (bit)
- sum += 1.0;
- --exactBitsLimit;
- if (exactBitsLimit == 0) {
- bit53 = bit;
- state = AFTER_BIT_53;
- }
- break;
- case AFTER_BIT_53:
- bit54 = bit;
- factor = 2.0;
- state = ZEROS_AFTER_54;
- break;
- case ZEROS_AFTER_54:
- if (bit) {
- state = MIXED_AFTER_54;
- }
- // fallthrough
- case MIXED_AFTER_54:
- factor *= 2;
- break;
- }
- }
- switch (state) {
- case SKIP_LEADING_ZEROS:
- sum = 0.0;
- break;
- case FIRST_EXACT_53_BITS:
- case AFTER_BIT_53:
- // do nothing
- break;
- case ZEROS_AFTER_54:
- // x1.1 -> x1 + 1 (round up)
- // x0.1 -> x0 (round down)
- if (bit54 & bit53)
- sum += 1.0;
- sum *= factor;
- break;
- case MIXED_AFTER_54:
- // x.100...1.. -> x + 1 (round up)
- // x.0anything -> x (round down)
- if (bit54)
- sum += 1.0;
- sum *= factor;
- break;
- }
- }
- /* We don't worry about inaccurate numbers for any other base. */
- }
- return sum;
- }
-
- /*
- * For chars - because we need something out-of-range to check. (And
- * checking EOF by exception is annoying.) Note distinction from EOF token
- * type!
- */
- private final static int EOF_CHAR = -1;
-
- private final static char BYTE_ORDER_MARK = '\uFEFF';
-
- public TokenStream(Reader sourceReader, String sourceString, int lineno) {
- this.lineno = lineno;
- if (sourceReader != null) {
- if (sourceString != null)
- org.mozilla.javascript.Kit.codeBug();
- this.sourceReader = sourceReader;
- this.sourceBuffer = new char[512];
- this.sourceEnd = 0;
- } else {
- if (sourceString == null)
- org.mozilla.javascript.Kit.codeBug();
- this.sourceString = sourceString;
- this.sourceEnd = sourceString.length();
- }
- this.sourceCursor = this.cursor = 0;
- }
-
- /*
- * This function uses the cached op, string and number fields in
- * TokenStream; if getToken has been called since the passed token was
- * scanned, the op or string printed may be incorrect.
- */
- String tokenToString(int token) {
- if (Token.printTrees) {
- String name = Token.name(token);
-
- switch (token) {
- case Token.STRING:
- case Token.REGEXP:
- case Token.NAME:
- return name + " `" + this.string + "'";
-
- case Token.NUMBER:
- return "NUMBER " + this.number;
- }
-
- return name;
- }
- return "";
- }
-
- static boolean isKeyword(String s) {
- return Token.EOF != stringToKeyword(s);
- }
-
- private static int stringToKeyword(String name) {
- return stringToKeywordForJS(name);
- }
-
- /**
- * JavaScript 1.8 and earlier
- */
- private static int stringToKeywordForJS(String name) {
- // #string_id_map#
- // The following assumes that Token.EOF == 0
- final int Id_break = Token.BREAK, Id_case = Token.CASE, Id_continue = Token.CONTINUE, Id_default = Token.DEFAULT, Id_delete = Token.DELPROP, Id_do = Token.DO, Id_else = Token.ELSE, Id_export = Token.RESERVED, Id_false = Token.FALSE, Id_for = Token.FOR, Id_function = Token.FUNCTION, Id_if = Token.IF, Id_in = Token.IN, Id_let = Token.LET, // reserved
- // ES5
- // strict
- Id_new = Token.NEW, Id_null = Token.NULL, Id_return = Token.RETURN, Id_switch = Token.SWITCH, Id_this = Token.THIS, Id_true = Token.TRUE, Id_typeof = Token.TYPEOF, Id_var = Token.VAR, Id_void = Token.VOID, Id_while = Token.WHILE, Id_with = Token.WITH, Id_yield = Token.YIELD, // reserved
- // ES5
- // strict
-
- // the following are #ifdef RESERVE_JAVA_KEYWORDS in jsscan.c
- Id_abstract = Token.RESERVED, // ES3 only
- Id_boolean = Token.RESERVED, // ES3 only
- Id_byte = Token.RESERVED, // ES3 only
- Id_catch = Token.CATCH, Id_char = Token.RESERVED, // ES3 only
- Id_class = Token.RESERVED, Id_const = Token.CONST, // reserved
- Id_debugger = Token.DEBUGGER, Id_double = Token.RESERVED, // ES3 only
- Id_enum = Token.RESERVED, Id_extends = Token.RESERVED, Id_final = Token.RESERVED, // ES3
- // only
- Id_finally = Token.FINALLY, Id_float = Token.RESERVED, // ES3 only
- Id_goto = Token.RESERVED, // ES3 only
- Id_implements = Token.RESERVED, // ES3, ES5 strict
- Id_import = Token.RESERVED, Id_instanceof = Token.INSTANCEOF, Id_int = Token.RESERVED, // ES3
- Id_interface = Token.RESERVED, // ES3, ES5 strict
- Id_long = Token.RESERVED, // ES3 only
- Id_native = Token.RESERVED, // ES3 only
- Id_package = Token.RESERVED, // ES3, ES5 strict
- Id_private = Token.RESERVED, // ES3, ES5 strict
- Id_protected = Token.RESERVED, // ES3, ES5 strict
- Id_public = Token.RESERVED, // ES3, ES5 strict
- Id_short = Token.RESERVED, // ES3 only
- Id_static = Token.RESERVED, // ES3, ES5 strict
- Id_super = Token.RESERVED, Id_synchronized = Token.RESERVED, // ES3 only
- Id_throw = Token.THROW, Id_throws = Token.RESERVED, // ES3 only
- Id_transient = Token.RESERVED, // ES3 only
- Id_try = Token.TRY, Id_volatile = Token.RESERVED; // ES3 only
-
- int id;
- String s = name;
- // #generated# Last update: 2007-04-18 13:53:30 PDT
- L0: {
- id = 0;
- String X = null;
- int c;
- L: switch (s.length()) {
- case 2:
- c = s.charAt(1);
- if (c == 'f') {
- if (s.charAt(0) == 'i') {
- id = Id_if;
- break L0;
- }
- } else if (c == 'n') {
- if (s.charAt(0) == 'i') {
- id = Id_in;
- break L0;
- }
- } else if (c == 'o') {
- if (s.charAt(0) == 'd') {
- id = Id_do;
- break L0;
- }
- }
- break L;
- case 3:
- switch (s.charAt(0)) {
- case 'f':
- if (s.charAt(2) == 'r' && s.charAt(1) == 'o') {
- id = Id_for;
- break L0;
- }
- break L;
- case 'i':
- if (s.charAt(2) == 't' && s.charAt(1) == 'n') {
- id = Id_int;
- break L0;
- }
- break L;
- case 'l':
- if (s.charAt(2) == 't' && s.charAt(1) == 'e') {
- id = Id_let;
- break L0;
- }
- break L;
- case 'n':
- if (s.charAt(2) == 'w' && s.charAt(1) == 'e') {
- id = Id_new;
- break L0;
- }
- break L;
- case 't':
- if (s.charAt(2) == 'y' && s.charAt(1) == 'r') {
- id = Id_try;
- break L0;
- }
- break L;
- case 'v':
- if (s.charAt(2) == 'r' && s.charAt(1) == 'a') {
- id = Id_var;
- break L0;
- }
- break L;
- }
- break L;
- case 4:
- switch (s.charAt(0)) {
- case 'b':
- X = "byte";
- id = Id_byte;
- break L;
- case 'c':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 's' && s.charAt(1) == 'a') {
- id = Id_case;
- break L0;
- }
- } else if (c == 'r') {
- if (s.charAt(2) == 'a' && s.charAt(1) == 'h') {
- id = Id_char;
- break L0;
- }
- }
- break L;
- case 'e':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 's' && s.charAt(1) == 'l') {
- id = Id_else;
- break L0;
- }
- } else if (c == 'm') {
- if (s.charAt(2) == 'u' && s.charAt(1) == 'n') {
- id = Id_enum;
- break L0;
- }
- }
- break L;
- case 'g':
- X = "goto";
- id = Id_goto;
- break L;
- case 'l':
- X = "long";
- id = Id_long;
- break L;
- case 'n':
- X = "null";
- id = Id_null;
- break L;
- case 't':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 'u' && s.charAt(1) == 'r') {
- id = Id_true;
- break L0;
- }
- } else if (c == 's') {
- if (s.charAt(2) == 'i' && s.charAt(1) == 'h') {
- id = Id_this;
- break L0;
- }
- }
- break L;
- case 'v':
- X = "void";
- id = Id_void;
- break L;
- case 'w':
- X = "with";
- id = Id_with;
- break L;
- }
- break L;
- case 5:
- switch (s.charAt(2)) {
- case 'a':
- X = "class";
- id = Id_class;
- break L;
- case 'e':
- c = s.charAt(0);
- if (c == 'b') {
- X = "break";
- id = Id_break;
- } else if (c == 'y') {
- X = "yield";
- id = Id_yield;
- }
- break L;
- case 'i':
- X = "while";
- id = Id_while;
- break L;
- case 'l':
- X = "false";
- id = Id_false;
- break L;
- case 'n':
- c = s.charAt(0);
- if (c == 'c') {
- X = "const";
- id = Id_const;
- } else if (c == 'f') {
- X = "final";
- id = Id_final;
- }
- break L;
- case 'o':
- c = s.charAt(0);
- if (c == 'f') {
- X = "float";
- id = Id_float;
- } else if (c == 's') {
- X = "short";
- id = Id_short;
- }
- break L;
- case 'p':
- X = "super";
- id = Id_super;
- break L;
- case 'r':
- X = "throw";
- id = Id_throw;
- break L;
- case 't':
- X = "catch";
- id = Id_catch;
- break L;
- }
- break L;
- case 6:
- switch (s.charAt(1)) {
- case 'a':
- X = "native";
- id = Id_native;
- break L;
- case 'e':
- c = s.charAt(0);
- if (c == 'd') {
- X = "delete";
- id = Id_delete;
- } else if (c == 'r') {
- X = "return";
- id = Id_return;
- }
- break L;
- case 'h':
- X = "throws";
- id = Id_throws;
- break L;
- case 'm':
- X = "import";
- id = Id_import;
- break L;
- case 'o':
- X = "double";
- id = Id_double;
- break L;
- case 't':
- X = "static";
- id = Id_static;
- break L;
- case 'u':
- X = "public";
- id = Id_public;
- break L;
- case 'w':
- X = "switch";
- id = Id_switch;
- break L;
- case 'x':
- X = "export";
- id = Id_export;
- break L;
- case 'y':
- X = "typeof";
- id = Id_typeof;
- break L;
- }
- break L;
- case 7:
- switch (s.charAt(1)) {
- case 'a':
- X = "package";
- id = Id_package;
- break L;
- case 'e':
- X = "default";
- id = Id_default;
- break L;
- case 'i':
- X = "finally";
- id = Id_finally;
- break L;
- case 'o':
- X = "boolean";
- id = Id_boolean;
- break L;
- case 'r':
- X = "private";
- id = Id_private;
- break L;
- case 'x':
- X = "extends";
- id = Id_extends;
- break L;
- }
- break L;
- case 8:
- switch (s.charAt(0)) {
- case 'a':
- X = "abstract";
- id = Id_abstract;
- break L;
- case 'c':
- X = "continue";
- id = Id_continue;
- break L;
- case 'd':
- X = "debugger";
- id = Id_debugger;
- break L;
- case 'f':
- X = "function";
- id = Id_function;
- break L;
- case 'v':
- X = "volatile";
- id = Id_volatile;
- break L;
- }
- break L;
- case 9:
- c = s.charAt(0);
- if (c == 'i') {
- X = "interface";
- id = Id_interface;
- } else if (c == 'p') {
- X = "protected";
- id = Id_protected;
- } else if (c == 't') {
- X = "transient";
- id = Id_transient;
- }
- break L;
- case 10:
- c = s.charAt(1);
- if (c == 'm') {
- X = "implements";
- id = Id_implements;
- } else if (c == 'n') {
- X = "instanceof";
- id = Id_instanceof;
- }
- break L;
- case 12:
- X = "synchronized";
- id = Id_synchronized;
- break L;
- }
- if (X != null && X != s && !X.equals(s))
- id = 0;
- }
- // #/generated#
- // #/string_id_map#
- if (id == 0) {
- return Token.EOF;
- }
- return id & 0xff;
- }
-
- /**
- * ECMAScript 6.
- */
- private static int stringToKeywordForES(String name, boolean isStrict) {
- // #string_id_map#
- // The following assumes that Token.EOF == 0
- final int
- // 11.6.2.1 Keywords (ECMAScript2015)
- Id_break = Token.BREAK, Id_case = Token.CASE, Id_catch = Token.CATCH, Id_class = Token.RESERVED, Id_const = Token.CONST, Id_continue = Token.CONTINUE, Id_debugger = Token.DEBUGGER, Id_default = Token.DEFAULT, Id_delete = Token.DELPROP, Id_do = Token.DO, Id_else = Token.ELSE, Id_export = Token.RESERVED, Id_extends = Token.RESERVED, Id_finally = Token.FINALLY, Id_for = Token.FOR, Id_function = Token.FUNCTION, Id_if = Token.IF, Id_import = Token.RESERVED, Id_in = Token.IN, Id_instanceof = Token.INSTANCEOF, Id_new = Token.NEW, Id_return = Token.RETURN, Id_super = Token.RESERVED, Id_switch = Token.SWITCH, Id_this = Token.THIS, Id_throw = Token.THROW, Id_try = Token.TRY, Id_typeof = Token.TYPEOF, Id_var = Token.VAR, Id_void = Token.VOID, Id_while = Token.WHILE, Id_with = Token.WITH, Id_yield = Token.YIELD,
-
- // 11.6.2.2 Future Reserved Words
- Id_await = Token.RESERVED, Id_enum = Token.RESERVED,
-
- // 11.6.2.2 NOTE Strict Future Reserved Words
- Id_implements = Token.RESERVED, Id_interface = Token.RESERVED, Id_package = Token.RESERVED, Id_private = Token.RESERVED, Id_protected = Token.RESERVED, Id_public = Token.RESERVED,
-
- // 11.8 Literals
- Id_false = Token.FALSE, Id_null = Token.NULL, Id_true = Token.TRUE,
-
- // Non ReservedWord, but Non IdentifierName in strict mode code.
- // 12.1.1 Static Semantics: Early Errors
- Id_let = Token.LET, // TODO : Valid IdentifierName in non-strict mode.
- Id_static = Token.RESERVED;
-
- int id;
- String s = name;
- // #generated# Last update: 2007-04-18 13:53:30 PDT
- L0: {
- id = 0;
- String X = null;
- int c;
- L: switch (s.length()) {
- case 2:
- c = s.charAt(1);
- if (c == 'f') {
- if (s.charAt(0) == 'i') {
- id = Id_if;
- break L0;
- }
- } else if (c == 'n') {
- if (s.charAt(0) == 'i') {
- id = Id_in;
- break L0;
- }
- } else if (c == 'o') {
- if (s.charAt(0) == 'd') {
- id = Id_do;
- break L0;
- }
- }
- break L;
- case 3:
- switch (s.charAt(0)) {
- case 'f':
- if (s.charAt(2) == 'r' && s.charAt(1) == 'o') {
- id = Id_for;
- break L0;
- }
- break L;
- case 'l':
- if (s.charAt(2) == 't' && s.charAt(1) == 'e') {
- id = Id_let;
- break L0;
- }
- break L;
- case 'n':
- if (s.charAt(2) == 'w' && s.charAt(1) == 'e') {
- id = Id_new;
- break L0;
- }
- break L;
- case 't':
- if (s.charAt(2) == 'y' && s.charAt(1) == 'r') {
- id = Id_try;
- break L0;
- }
- break L;
- case 'v':
- if (s.charAt(2) == 'r' && s.charAt(1) == 'a') {
- id = Id_var;
- break L0;
- }
- break L;
- }
- break L;
- case 4:
- switch (s.charAt(0)) {
- case 'c':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 's' && s.charAt(1) == 'a') {
- id = Id_case;
- break L0;
- }
- }
- break L;
- case 'e':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 's' && s.charAt(1) == 'l') {
- id = Id_else;
- break L0;
- }
- } else if (c == 'm') {
- if (s.charAt(2) == 'u' && s.charAt(1) == 'n') {
- id = Id_enum;
- break L0;
- }
- }
- break L;
- case 'n':
- X = "null";
- id = Id_null;
- break L;
- case 't':
- c = s.charAt(3);
- if (c == 'e') {
- if (s.charAt(2) == 'u' && s.charAt(1) == 'r') {
- id = Id_true;
- break L0;
- }
- } else if (c == 's') {
- if (s.charAt(2) == 'i' && s.charAt(1) == 'h') {
- id = Id_this;
- break L0;
- }
- }
- break L;
- case 'v':
- X = "void";
- id = Id_void;
- break L;
- case 'w':
- X = "with";
- id = Id_with;
- break L;
- }
- break L;
- case 5:
- switch (s.charAt(2)) {
- case 'a':
- c = s.charAt(0);
- if (c == 'c') {
- X = "class";
- id = Id_class;
- } else if (c == 'a') {
- X = "await";
- id = Id_await;
- }
- break L;
- case 'e':
- c = s.charAt(0);
- if (c == 'b') {
- X = "break";
- id = Id_break;
- } else if (c == 'y') {
- X = "yield";
- id = Id_yield;
- }
- break L;
- case 'i':
- X = "while";
- id = Id_while;
- break L;
- case 'l':
- X = "false";
- id = Id_false;
- break L;
- case 'n':
- X = "const";
- id = Id_const;
- break L;
- case 'p':
- X = "super";
- id = Id_super;
- break L;
- case 'r':
- X = "throw";
- id = Id_throw;
- break L;
- case 't':
- X = "catch";
- id = Id_catch;
- break L;
- }
- break L;
- case 6:
- switch (s.charAt(1)) {
- case 'e':
- c = s.charAt(0);
- if (c == 'd') {
- X = "delete";
- id = Id_delete;
- } else if (c == 'r') {
- X = "return";
- id = Id_return;
- }
- break L;
- case 'm':
- X = "import";
- id = Id_import;
- break L;
- case 't':
- if (isStrict) {
- X = "static";
- id = Id_static;
- break L;
- }
- // fallthru
- case 'u':
- if (isStrict) {
- X = "public";
- id = Id_public;
- break L;
- }
- // fallthru
- case 'w':
- X = "switch";
- id = Id_switch;
- break L;
- case 'x':
- X = "export";
- id = Id_export;
- break L;
- case 'y':
- X = "typeof";
- id = Id_typeof;
- break L;
- }
- break L;
- case 7:
- switch (s.charAt(1)) {
- case 'a':
- if (isStrict) {
- X = "package";
- id = Id_package;
- break L;
- }
- // fallthru
- case 'e':
- X = "default";
- id = Id_default;
- break L;
- case 'i':
- X = "finally";
- id = Id_finally;
- break L;
- case 'r':
- if (isStrict) {
- X = "private";
- id = Id_private;
- break L;
- }
- // fallthru
- case 'x':
- X = "extends";
- id = Id_extends;
- break L;
- }
- break L;
- case 8:
- switch (s.charAt(0)) {
- case 'c':
- X = "continue";
- id = Id_continue;
- break L;
- case 'd':
- X = "debugger";
- id = Id_debugger;
- break L;
- case 'f':
- X = "function";
- id = Id_function;
- break L;
- }
- break L;
- case 9:
- c = s.charAt(0);
- if (c == 'i' && isStrict) {
- X = "interface";
- id = Id_interface;
- } else if (c == 'p' && isStrict) {
- X = "protected";
- id = Id_protected;
- }
- break L;
- case 10:
- c = s.charAt(1);
- if (c == 'm' && isStrict) {
- X = "implements";
- id = Id_implements;
- } else if (c == 'n') {
- X = "instanceof";
- id = Id_instanceof;
- }
- break L;
- }
- if (X != null && X != s && !X.equals(s))
- id = 0;
- }
- // #/generated#
- // #/string_id_map#
- if (id == 0) {
- return Token.EOF;
- }
- return id & 0xff;
- }
-
- final String getSourceString() {
- return sourceString;
- }
-
- final int getLineno() {
- return lineno;
- }
-
- final String getString() {
- return string;
- }
-
- final char getQuoteChar() {
- return (char) quoteChar;
- }
-
- final double getNumber() {
- return number;
- }
-
- final boolean isNumberBinary() {
- return isBinary;
- }
-
- final boolean isNumberOldOctal() {
- return isOldOctal;
- }
-
- final boolean isNumberOctal() {
- return isOctal;
- }
-
- final boolean isNumberHex() {
- return isHex;
- }
-
- final boolean eof() {
- return hitEOF;
- }
-
- public final int getToken() throws IOException {
- int c;
-
- retry: for (;;) {
- // Eat whitespace, possibly sensitive to newlines.
- for (;;) {
- c = getChar();
- if (c == EOF_CHAR) {
- tokenBeg = cursor - 1;
- tokenEnd = cursor;
- return Token.EOF;
- } else if (c == '\n') {
- dirtyLine = false;
- tokenBeg = cursor - 1;
- tokenEnd = cursor;
- return Token.EOL;
- } else if (!isJSSpace(c)) {
- if (c != '-') {
- dirtyLine = true;
- }
- break;
- }
- }
-
- // Assume the token will be 1 char - fixed up below.
- tokenBeg = cursor - 1;
- tokenEnd = cursor;
-
- if (c == '@')
- return Token.XMLATTR;
-
- // identifier/keyword/instanceof?
- // watch out for starting with a
- boolean identifierStart;
- boolean isUnicodeEscapeStart = false;
- if (c == '\\') {
- c = getChar();
- if (c == 'u') {
- identifierStart = true;
- isUnicodeEscapeStart = true;
- stringBufferTop = 0;
- } else {
- identifierStart = false;
- ungetChar(c);
- c = '\\';
- }
- } else {
- identifierStart = Character.isJavaIdentifierStart((char) c);
- if (identifierStart) {
- stringBufferTop = 0;
- addToString(c);
- }
- }
-
- if (identifierStart) {
- boolean containsEscape = isUnicodeEscapeStart;
- for (;;) {
- if (isUnicodeEscapeStart) {
- // strictly speaking we should probably push-back
- // all the bad characters if the uXXXX
- // sequence is malformed. But since there isn't a
- // correct context(is there?) for a bad Unicode
- // escape sequence in an identifier, we can report
- // an error here.
- int escapeVal = 0;
- for (int i = 0; i != 4; ++i) {
- c = getChar();
- escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
- // Next check takes care about c < 0 and bad escape
- if (escapeVal < 0) {
- break;
- }
- }
- if (escapeVal < 0) {
- return Token.ERROR;
- }
- addToString(escapeVal);
- isUnicodeEscapeStart = false;
- } else {
- c = getChar();
- if (c == '\\') {
- c = getChar();
- if (c == 'u') {
- isUnicodeEscapeStart = true;
- containsEscape = true;
- } else {
- return Token.ERROR;
- }
- } else {
- if (c == EOF_CHAR
- || c == BYTE_ORDER_MARK
- || !Character
- .isJavaIdentifierPart((char) c)) {
- break;
- }
- addToString(c);
- }
- }
- }
- ungetChar(c);
-
- String str = getStringFromBuffer();
- int result = stringToKeyword(str);
- if (result != Token.EOF) {
- return result;
- }
- this.string = (String) allStrings.intern(str);
- return Token.NAME;
- }
-
- // is it a number?
- if (isDigit(c) || (c == '.' && isDigit(peekChar()))) {
- stringBufferTop = 0;
- int base = 10;
- isHex = isOldOctal = isOctal = isBinary = false;
- boolean es6 = false;
-
- if (c == '0') {
- c = getChar();
- if (c == 'x' || c == 'X') {
- base = 16;
- isHex = true;
- c = getChar();
- } else if (es6 && (c == 'o' || c == 'O')) {
- base = 8;
- isOctal = true;
- c = getChar();
- } else if (es6 && (c == 'b' || c == 'B')) {
- base = 2;
- isBinary = true;
- c = getChar();
- } else if (isDigit(c)) {
- base = 8;
- isOldOctal = true;
- } else {
- addToString('0');
- }
- }
-
- boolean isEmpty = true;
- if (base == 16) {
- while (0 <= org.mozilla.javascript.Kit.xDigitToInt(c, 0)) {
- addToString(c);
- c = getChar();
- isEmpty = false;
- }
- } else {
- while ('0' <= c && c <= '9') {
- if (base == 8 && c >= '8') {
- if (isOldOctal) {
- base = 10;
- } else {
- return Token.ERROR;
- }
- } else if (base == 2 && c >= '2') {
- return Token.ERROR;
- }
- addToString(c);
- c = getChar();
- isEmpty = false;
- }
- }
- if (isEmpty && (isBinary || isOctal || isHex)) {
- return Token.ERROR;
- }
-
- boolean isInteger = true;
-
- if (base == 10 && (c == '.' || c == 'e' || c == 'E')) {
- isInteger = false;
- if (c == '.') {
- do {
- addToString(c);
- c = getChar();
- } while (isDigit(c));
- }
- if (c == 'e' || c == 'E') {
- addToString(c);
- c = getChar();
- if (c == '+' || c == '-') {
- addToString(c);
- c = getChar();
- }
- if (!isDigit(c)) {
- return Token.ERROR;
- }
- do {
- addToString(c);
- c = getChar();
- } while (isDigit(c));
- }
- }
- ungetChar(c);
- String numString = getStringFromBuffer();
- this.string = numString;
-
- double dval;
- if (base == 10 && !isInteger) {
- try {
- // Use Java conversion to number from string...
- dval = Double.parseDouble(numString);
- } catch (NumberFormatException ex) {
- return Token.ERROR;
- }
- } else {
- dval = stringToNumber(numString, 0, base);
- }
-
- this.number = dval;
- return Token.NUMBER;
- }
-
- // is it a string?
- if (c == '"' || c == '\'') {
- // We attempt to accumulate a string the fast way, by
- // building it directly out of the reader. But if there
- // are any escaped characters in the string, we revert to
- // building it out of a StringBuffer.
-
- quoteChar = c;
- stringBufferTop = 0;
-
- c = getChar(false);
- strLoop: while (c != quoteChar) {
- if (c == '\n' || c == EOF_CHAR) {
- ungetChar(c);
- tokenEnd = cursor;
- return Token.ERROR;
- }
-
- if (c == '\\') {
- // We've hit an escaped character
- int escapeVal;
-
- c = getChar();
- switch (c) {
- case 'b':
- c = '\b';
- break;
- case 'f':
- c = '\f';
- break;
- case 'n':
- c = '\n';
- break;
- case 'r':
- c = '\r';
- break;
- case 't':
- c = '\t';
- break;
-
- // \v a late addition to the ECMA spec,
- // it is not in Java, so use 0xb
- case 'v':
- c = 0xb;
- break;
-
- case 'u':
- // Get 4 hex digits; if the u escape is not
- // followed by 4 hex digits, use 'u' + the
- // literal character sequence that follows.
- int escapeStart = stringBufferTop;
- addToString('u');
- escapeVal = 0;
- for (int i = 0; i != 4; ++i) {
- c = getChar();
- escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
- if (escapeVal < 0) {
- continue strLoop;
- }
- addToString(c);
- }
- // prepare for replace of stored 'u' sequence
- // by escape value
- stringBufferTop = escapeStart;
- c = escapeVal;
- break;
- case 'x':
- // Get 2 hex digits, defaulting to 'x'+literal
- // sequence, as above.
- c = getChar();
- escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, 0);
- if (escapeVal < 0) {
- addToString('x');
- continue strLoop;
- } else {
- int c1 = c;
- c = getChar();
- escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
- if (escapeVal < 0) {
- addToString('x');
- addToString(c1);
- continue strLoop;
- } else {
- // got 2 hex digits
- c = escapeVal;
- }
- }
- break;
-
- case '\n':
- // Remove line terminator after escape to follow
- // SpiderMonkey and C/C++
- c = getChar();
- continue strLoop;
-
- default:
- if ('0' <= c && c < '8') {
- int val = c - '0';
- c = getChar();
- if ('0' <= c && c < '8') {
- val = 8 * val + c - '0';
- c = getChar();
- if ('0' <= c && c < '8' && val <= 037) {
- // c is 3rd char of octal sequence only
- // if the resulting val <= 0377
- val = 8 * val + c - '0';
- c = getChar();
- }
- }
- ungetChar(c);
- c = val;
- }
- }
- }
- addToString(c);
- c = getChar(false);
- }
-
- String str = getStringFromBuffer();
- this.string = (String) allStrings.intern(str);
- return Token.STRING;
- }
-
- switch (c) {
- case ';':
- return Token.SEMI;
- case '[':
- return Token.LB;
- case ']':
- return Token.RB;
- case '{':
- return Token.LC;
- case '}':
- return Token.RC;
- case '(':
- return Token.LP;
- case ')':
- return Token.RP;
- case ',':
- return Token.COMMA;
- case '?':
- return Token.HOOK;
- case ':':
- if (matchChar(':')) {
- return Token.COLONCOLON;
- } else {
- return Token.COLON;
- }
- case '.':
- if (matchChar('.')) {
- return Token.DOTDOT;
- } else if (matchChar('(')) {
- return Token.DOTQUERY;
- } else {
- return Token.DOT;
- }
-
- case '|':
- if (matchChar('|')) {
- return Token.OR;
- } else if (matchChar('=')) {
- return Token.ASSIGN_BITOR;
- } else {
- return Token.BITOR;
- }
-
- case '^':
- if (matchChar('=')) {
- return Token.ASSIGN_BITXOR;
- } else {
- return Token.BITXOR;
- }
-
- case '&':
- if (matchChar('&')) {
- return Token.AND;
- } else if (matchChar('=')) {
- return Token.ASSIGN_BITAND;
- } else {
- return Token.BITAND;
- }
-
- case '=':
- if (matchChar('=')) {
- if (matchChar('=')) {
- return Token.SHEQ;
- } else {
- return Token.EQ;
- }
- } else if (matchChar('>')) {
- return Token.ARROW;
- } else {
- return Token.ASSIGN;
- }
-
- case '!':
- if (matchChar('=')) {
- if (matchChar('=')) {
- return Token.SHNE;
- } else {
- return Token.NE;
- }
- } else {
- return Token.NOT;
- }
-
- case '<':
- /* NB:treat HTML begin-comment as comment-till-eol */
- if (matchChar('!')) {
- if (matchChar('-')) {
- if (matchChar('-')) {
- tokenBeg = cursor - 4;
- skipLine();
- commentType = Token.CommentType.HTML;
- return Token.COMMENT;
- }
- ungetCharIgnoreLineEnd('-');
- }
- ungetCharIgnoreLineEnd('!');
- }
- if (matchChar('<')) {
- if (matchChar('=')) {
- return Token.ASSIGN_LSH;
- } else {
- return Token.LSH;
- }
- } else {
- if (matchChar('=')) {
- return Token.LE;
- } else {
- return Token.LT;
- }
- }
-
- case '>':
- if (matchChar('>')) {
- if (matchChar('>')) {
- if (matchChar('=')) {
- return Token.ASSIGN_URSH;
- } else {
- return Token.URSH;
- }
- } else {
- if (matchChar('=')) {
- return Token.ASSIGN_RSH;
- } else {
- return Token.RSH;
- }
- }
- } else {
- if (matchChar('=')) {
- return Token.GE;
- } else {
- return Token.GT;
- }
- }
-
- case '*':
- if (matchChar('=')) {
- return Token.ASSIGN_MUL;
- } else {
- return Token.MUL;
- }
-
- case '/':
- // is it a // comment?
- if (matchChar('/')) {
- tokenBeg = cursor - 2;
- skipLine();
- commentType = Token.CommentType.LINE;
- return Token.COMMENT;
- }
- // is it a /* or /** comment?
- if (matchChar('*')) {
- boolean lookForSlash = false;
- tokenBeg = cursor - 2;
- if (matchChar('*')) {
- lookForSlash = true;
- commentType = Token.CommentType.JSDOC;
- } else {
- commentType = Token.CommentType.BLOCK_COMMENT;
- }
- for (;;) {
- c = getChar();
- if (c == EOF_CHAR) {
- tokenEnd = cursor - 1;
- return Token.COMMENT;
- } else if (c == '*') {
- lookForSlash = true;
- } else if (c == '/') {
- if (lookForSlash) {
- tokenEnd = cursor;
- return Token.COMMENT;
- }
- } else {
- lookForSlash = false;
- tokenEnd = cursor;
- }
- }
- }
-
- if (matchChar('=')) {
- return Token.ASSIGN_DIV;
- } else {
- return Token.DIV;
- }
-
- case '%':
- if (matchChar('=')) {
- return Token.ASSIGN_MOD;
- } else {
- return Token.MOD;
- }
-
- case '~':
- return Token.BITNOT;
-
- case '+':
- if (matchChar('=')) {
- return Token.ASSIGN_ADD;
- } else if (matchChar('+')) {
- return Token.INC;
- } else {
- return Token.ADD;
- }
-
- case '-':
- if (matchChar('=')) {
- c = Token.ASSIGN_SUB;
- } else if (matchChar('-')) {
- if (!dirtyLine) {
- // treat HTML end-comment after possible whitespace
- // after line start as comment-until-eol
- if (matchChar('>')) {
- skipLine();
- commentType = Token.CommentType.HTML;
- return Token.COMMENT;
- }
- }
- c = Token.DEC;
- } else {
- c = Token.SUB;
- }
- dirtyLine = true;
- return c;
-
- default:
- return Token.ERROR;
- }
- }
- }
-
- private static boolean isAlpha(int c) {
- // Use 'Z' < 'a'
- if (c <= 'Z') {
- return 'A' <= c;
- } else {
- return 'a' <= c && c <= 'z';
- }
- }
-
- static boolean isDigit(int c) {
- return '0' <= c && c <= '9';
- }
-
- /*
- * As defined in ECMA. jsscan.c uses C isspace() (which allows \v, I think.)
- * note that code in getChar() implicitly accepts '\r' == as well.
- */
- static boolean isJSSpace(int c) {
- if (c <= 127) {
- return c == 0x20 || c == 0x9 || c == 0xC || c == 0xB;
- } else {
- return c == 0xA0 || c == BYTE_ORDER_MARK
- || Character.getType((char) c) == Character.SPACE_SEPARATOR;
- }
- }
-
- private static boolean isJSFormatChar(int c) {
- return c > 127 && Character.getType((char) c) == Character.FORMAT;
- }
-
- /**
- * Parser calls the method when it gets / or /= in literal context.
- */
- void readRegExp(int startToken) throws IOException {
- int start = tokenBeg;
- stringBufferTop = 0;
- if (startToken == Token.ASSIGN_DIV) {
- // Miss-scanned /=
- addToString('=');
- } else {
- if (startToken != Token.DIV)
- org.mozilla.javascript.Kit.codeBug();
- }
-
- boolean inCharSet = false; // true if inside a '['..']' pair
- int c;
- while ((c = getChar()) != '/' || inCharSet) {
- if (c == '\n' || c == EOF_CHAR) {
- ungetChar(c);
- tokenEnd = cursor - 1;
- this.string = new String(stringBuffer, 0, stringBufferTop);
- return;
- }
- if (c == '\\') {
- addToString(c);
- c = getChar();
- } else if (c == '[') {
- inCharSet = true;
- } else if (c == ']') {
- inCharSet = false;
- }
- addToString(c);
- }
- int reEnd = stringBufferTop;
-
- while (true) {
- if (matchChar('g'))
- addToString('g');
- else if (matchChar('i'))
- addToString('i');
- else if (matchChar('m'))
- addToString('m');
- else if (matchChar('y')) // FireFox 3
- addToString('y');
- else
- break;
- }
- tokenEnd = start + stringBufferTop + 2; // include slashes
-
- if (isAlpha(peekChar())) {
- }
-
- this.string = new String(stringBuffer, 0, reEnd);
- this.regExpFlags = new String(stringBuffer, reEnd, stringBufferTop
- - reEnd);
- }
-
- String readAndClearRegExpFlags() {
- String flags = this.regExpFlags;
- this.regExpFlags = null;
- return flags;
- }
-
- boolean isXMLAttribute() {
- return xmlIsAttribute;
- }
-
- int getFirstXMLToken() throws IOException {
- xmlOpenTagsCount = 0;
- xmlIsAttribute = false;
- xmlIsTagContent = false;
- if (!canUngetChar())
- return Token.ERROR;
- ungetChar('<');
- return getNextXMLToken();
- }
-
- int getNextXMLToken() throws IOException {
- tokenBeg = cursor;
- stringBufferTop = 0; // remember the XML
-
- for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
- if (xmlIsTagContent) {
- switch (c) {
- case '>':
- addToString(c);
- xmlIsTagContent = false;
- xmlIsAttribute = false;
- break;
- case '/':
- addToString(c);
- if (peekChar() == '>') {
- c = getChar();
- addToString(c);
- xmlIsTagContent = false;
- xmlOpenTagsCount--;
- }
- break;
- case '{':
- ungetChar(c);
- this.string = getStringFromBuffer();
- return Token.XML;
- case '\'':
- case '"':
- addToString(c);
- if (!readQuotedString(c))
- return Token.ERROR;
- break;
- case '=':
- addToString(c);
- xmlIsAttribute = true;
- break;
- case ' ':
- case '\t':
- case '\r':
- case '\n':
- addToString(c);
- break;
- default:
- addToString(c);
- xmlIsAttribute = false;
- break;
- }
-
- if (!xmlIsTagContent && xmlOpenTagsCount == 0) {
- this.string = getStringFromBuffer();
- return Token.XMLEND;
- }
- } else {
- switch (c) {
- case '<':
- addToString(c);
- c = peekChar();
- switch (c) {
- case '!':
- c = getChar(); // Skip !
- addToString(c);
- c = peekChar();
- switch (c) {
- case '-':
- c = getChar(); // Skip -
- addToString(c);
- c = getChar();
- if (c == '-') {
- addToString(c);
- if (!readXmlComment())
- return Token.ERROR;
- } else {
- // throw away the string in progress
- stringBufferTop = 0;
- this.string = null;
- return Token.ERROR;
- }
- break;
- case '[':
- c = getChar(); // Skip [
- addToString(c);
- if (getChar() == 'C' && getChar() == 'D'
- && getChar() == 'A' && getChar() == 'T'
- && getChar() == 'A' && getChar() == '[') {
- addToString('C');
- addToString('D');
- addToString('A');
- addToString('T');
- addToString('A');
- addToString('[');
- if (!readCDATA())
- return Token.ERROR;
-
- } else {
- // throw away the string in progress
- stringBufferTop = 0;
- this.string = null;
- return Token.ERROR;
- }
- break;
- default:
- if (!readEntity())
- return Token.ERROR;
- break;
- }
- break;
- case '?':
- c = getChar(); // Skip ?
- addToString(c);
- if (!readPI())
- return Token.ERROR;
- break;
- case '/':
- // End tag
- c = getChar(); // Skip /
- addToString(c);
- if (xmlOpenTagsCount == 0) {
- // throw away the string in progress
- stringBufferTop = 0;
- this.string = null;
- return Token.ERROR;
- }
- xmlIsTagContent = true;
- xmlOpenTagsCount--;
- break;
- default:
- // Start tag
- xmlIsTagContent = true;
- xmlOpenTagsCount++;
- break;
- }
- break;
- case '{':
- ungetChar(c);
- this.string = getStringFromBuffer();
- return Token.XML;
- default:
- addToString(c);
- break;
- }
- }
- }
-
- tokenEnd = cursor;
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return Token.ERROR;
- }
-
- /**
+public class TokenStream {
+ public static final double NaN = Double
+ .longBitsToDouble(0x7ff8000000000000L);
+
+ static double stringToNumber(String s, int start, int radix) {
+ char digitMax = '9';
+ char lowerCaseBound = 'a';
+ char upperCaseBound = 'A';
+ int len = s.length();
+ if (radix < 10) {
+ digitMax = (char) ('0' + radix - 1);
+ }
+ if (radix > 10) {
+ lowerCaseBound = (char) ('a' + radix - 10);
+ upperCaseBound = (char) ('A' + radix - 10);
+ }
+ int end;
+ double sum = 0.0;
+ for (end = start; end < len; end++) {
+ char c = s.charAt(end);
+ int newDigit;
+ if ('0' <= c && c <= digitMax)
+ newDigit = c - '0';
+ else if ('a' <= c && c < lowerCaseBound)
+ newDigit = c - 'a' + 10;
+ else if ('A' <= c && c < upperCaseBound)
+ newDigit = c - 'A' + 10;
+ else
+ break;
+ sum = sum * radix + newDigit;
+ }
+ if (start == end) {
+ return NaN;
+ }
+ if (sum >= 9007199254740992.0) {
+ if (radix == 10) {
+ /*
+ * If we're accumulating a decimal number and the number is >=
+ * 2^53, then the result from the repeated multiply-add above
+ * may be inaccurate. Call Java to get the correct answer.
+ */
+ try {
+ return Double.parseDouble(s.substring(start, end));
+ } catch (NumberFormatException nfe) {
+ return NaN;
+ }
+ } else if (radix == 2 || radix == 4 || radix == 8 || radix == 16
+ || radix == 32) {
+ /*
+ * The number may also be inaccurate for one of these bases.
+ * This happens if the addition in value*radix + digit causes a
+ * round-down to an even least significant mantissa bit when the
+ * first dropped bit is a one. If any of the following digits in
+ * the number (which haven't been added in yet) are nonzero then
+ * the correct action would have been to round up instead of
+ * down. An example of this occurs when reading the number
+ * 0x1000000000000081, which rounds to 0x1000000000000000
+ * instead of 0x1000000000000100.
+ */
+ int bitShiftInChar = 1;
+ int digit = 0;
+
+ final int SKIP_LEADING_ZEROS = 0;
+ final int FIRST_EXACT_53_BITS = 1;
+ final int AFTER_BIT_53 = 2;
+ final int ZEROS_AFTER_54 = 3;
+ final int MIXED_AFTER_54 = 4;
+
+ int state = SKIP_LEADING_ZEROS;
+ int exactBitsLimit = 53;
+ double factor = 0.0;
+ boolean bit53 = false;
+ // bit54 is the 54th bit (the first dropped from the mantissa)
+ boolean bit54 = false;
+
+ for (; ; ) {
+ if (bitShiftInChar == 1) {
+ if (start == end)
+ break;
+ digit = s.charAt(start++);
+ if ('0' <= digit && digit <= '9')
+ digit -= '0';
+ else if ('a' <= digit && digit <= 'z')
+ digit -= 'a' - 10;
+ else
+ digit -= 'A' - 10;
+ bitShiftInChar = radix;
+ }
+ bitShiftInChar >>= 1;
+ boolean bit = (digit & bitShiftInChar) != 0;
+
+ switch (state) {
+ case SKIP_LEADING_ZEROS:
+ if (bit) {
+ --exactBitsLimit;
+ sum = 1.0;
+ state = FIRST_EXACT_53_BITS;
+ }
+ break;
+ case FIRST_EXACT_53_BITS:
+ sum *= 2.0;
+ if (bit)
+ sum += 1.0;
+ --exactBitsLimit;
+ if (exactBitsLimit == 0) {
+ bit53 = bit;
+ state = AFTER_BIT_53;
+ }
+ break;
+ case AFTER_BIT_53:
+ bit54 = bit;
+ factor = 2.0;
+ state = ZEROS_AFTER_54;
+ break;
+ case ZEROS_AFTER_54:
+ if (bit) {
+ state = MIXED_AFTER_54;
+ }
+ // fallthrough
+ case MIXED_AFTER_54:
+ factor *= 2;
+ break;
+ }
+ }
+ switch (state) {
+ case SKIP_LEADING_ZEROS:
+ sum = 0.0;
+ break;
+ case FIRST_EXACT_53_BITS:
+ case AFTER_BIT_53:
+ // do nothing
+ break;
+ case ZEROS_AFTER_54:
+ // x1.1 -> x1 + 1 (round up)
+ // x0.1 -> x0 (round down)
+ if (bit54 & bit53)
+ sum += 1.0;
+ sum *= factor;
+ break;
+ case MIXED_AFTER_54:
+ // x.100...1.. -> x + 1 (round up)
+ // x.0anything -> x (round down)
+ if (bit54)
+ sum += 1.0;
+ sum *= factor;
+ break;
+ }
+ }
+ /* We don't worry about inaccurate numbers for any other base. */
+ }
+ return sum;
+ }
+
+ /*
+ * For chars - because we need something out-of-range to check. (And
+ * checking EOF by exception is annoying.) Note distinction from EOF token
+ * type!
+ */
+ private final static int EOF_CHAR = -1;
+
+ private final static char BYTE_ORDER_MARK = '\uFEFF';
+
+ public TokenStream(Reader sourceReader, String sourceString, int lineno) {
+ this.lineno = lineno;
+ if (sourceReader != null) {
+ if (sourceString != null)
+ org.mozilla.javascript.Kit.codeBug();
+ this.sourceReader = sourceReader;
+ this.sourceBuffer = new char[512];
+ this.sourceEnd = 0;
+ } else {
+ if (sourceString == null)
+ org.mozilla.javascript.Kit.codeBug();
+ this.sourceString = sourceString;
+ this.sourceEnd = sourceString.length();
+ }
+ this.sourceCursor = this.cursor = 0;
+ }
+
+ /*
+ * This function uses the cached op, string and number fields in
+ * TokenStream; if getToken has been called since the passed token was
+ * scanned, the op or string printed may be incorrect.
+ */
+ String tokenToString(int token) {
+ if (Token.printTrees) {
+ String name = Token.name(token);
+
+ return switch (token) {
+ case Token.STRING, Token.REGEXP, Token.NAME -> name + " `" + this.string + "'";
+ case Token.NUMBER -> "NUMBER " + this.number;
+ default -> name;
+ };
+ }
+ return "";
+ }
+
+ static boolean isKeyword(String s) {
+ return Token.EOF != stringToKeyword(s);
+ }
+
+ private static int stringToKeyword(String name) {
+ return stringToKeywordForJS(name);
+ }
+
+ /**
+ * JavaScript 1.8 and earlier
+ */
+ private static int stringToKeywordForJS(String name) {
+ // #string_id_map#
+ // The following assumes that Token.EOF == 0
+ final int Id_break = Token.BREAK, Id_case = Token.CASE, Id_continue = Token.CONTINUE, Id_default = Token.DEFAULT, Id_delete = Token.DELPROP, Id_do = Token.DO, Id_else = Token.ELSE, Id_export = Token.RESERVED, Id_false = Token.FALSE, Id_for = Token.FOR, Id_function = Token.FUNCTION, Id_if = Token.IF, Id_in = Token.IN, Id_let = Token.LET, // reserved
+ // ES5
+ // strict
+ Id_new = Token.NEW, Id_null = Token.NULL, Id_return = Token.RETURN, Id_switch = Token.SWITCH, Id_this = Token.THIS, Id_true = Token.TRUE, Id_typeof = Token.TYPEOF, Id_var = Token.VAR, Id_void = Token.VOID, Id_while = Token.WHILE, Id_with = Token.WITH, Id_yield = Token.YIELD, // reserved
+ // ES5
+ // strict
+
+ // the following are #ifdef RESERVE_JAVA_KEYWORDS in jsscan.c
+ Id_abstract = Token.RESERVED, // ES3 only
+ Id_boolean = Token.RESERVED, // ES3 only
+ Id_byte = Token.RESERVED, // ES3 only
+ Id_catch = Token.CATCH, Id_char = Token.RESERVED, // ES3 only
+ Id_class = Token.RESERVED, Id_const = Token.CONST, // reserved
+ Id_debugger = Token.DEBUGGER, Id_double = Token.RESERVED, // ES3 only
+ Id_enum = Token.RESERVED, Id_extends = Token.RESERVED, Id_final = Token.RESERVED, // ES3
+ // only
+ Id_finally = Token.FINALLY, Id_float = Token.RESERVED, // ES3 only
+ Id_goto = Token.RESERVED, // ES3 only
+ Id_implements = Token.RESERVED, // ES3, ES5 strict
+ Id_import = Token.RESERVED, Id_instanceof = Token.INSTANCEOF, Id_int = Token.RESERVED, // ES3
+ Id_interface = Token.RESERVED, // ES3, ES5 strict
+ Id_long = Token.RESERVED, // ES3 only
+ Id_native = Token.RESERVED, // ES3 only
+ Id_package = Token.RESERVED, // ES3, ES5 strict
+ Id_private = Token.RESERVED, // ES3, ES5 strict
+ Id_protected = Token.RESERVED, // ES3, ES5 strict
+ Id_public = Token.RESERVED, // ES3, ES5 strict
+ Id_short = Token.RESERVED, // ES3 only
+ Id_static = Token.RESERVED, // ES3, ES5 strict
+ Id_super = Token.RESERVED, Id_synchronized = Token.RESERVED, // ES3 only
+ Id_throw = Token.THROW, Id_throws = Token.RESERVED, // ES3 only
+ Id_transient = Token.RESERVED, // ES3 only
+ Id_try = Token.TRY, Id_volatile = Token.RESERVED; // ES3 only
+
+ int id;
+ String s = name;
+ // #generated# Last update: 2007-04-18 13:53:30 PDT
+ L0:
+ {
+ id = 0;
+ String X = null;
+ int c;
+ L:
+ switch (s.length()) {
+ case 2:
+ c = s.charAt(1);
+ if (c == 'f') {
+ if (s.charAt(0) == 'i') {
+ id = Id_if;
+ break L0;
+ }
+ } else if (c == 'n') {
+ if (s.charAt(0) == 'i') {
+ id = Id_in;
+ break L0;
+ }
+ } else if (c == 'o') {
+ if (s.charAt(0) == 'd') {
+ id = Id_do;
+ break L0;
+ }
+ }
+ break;
+ case 3:
+ switch (s.charAt(0)) {
+ case 'f':
+ if (s.charAt(2) == 'r' && s.charAt(1) == 'o') {
+ id = Id_for;
+ break L0;
+ }
+ break L;
+ case 'i':
+ if (s.charAt(2) == 't' && s.charAt(1) == 'n') {
+ id = Id_int;
+ break L0;
+ }
+ break L;
+ case 'l':
+ if (s.charAt(2) == 't' && s.charAt(1) == 'e') {
+ id = Id_let;
+ break L0;
+ }
+ break L;
+ case 'n':
+ if (s.charAt(2) == 'w' && s.charAt(1) == 'e') {
+ id = Id_new;
+ break L0;
+ }
+ break L;
+ case 't':
+ if (s.charAt(2) == 'y' && s.charAt(1) == 'r') {
+ id = Id_try;
+ break L0;
+ }
+ break L;
+ case 'v':
+ if (s.charAt(2) == 'r' && s.charAt(1) == 'a') {
+ id = Id_var;
+ break L0;
+ }
+ break L;
+ }
+ break;
+ case 4:
+ switch (s.charAt(0)) {
+ case 'b' -> {
+ X = "byte";
+ id = Id_byte;
+ }
+ case 'c' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 's' && s.charAt(1) == 'a') {
+ id = Id_case;
+ break L0;
+ }
+ } else if (c == 'r') {
+ if (s.charAt(2) == 'a' && s.charAt(1) == 'h') {
+ id = Id_char;
+ break L0;
+ }
+ }
+ }
+ case 'e' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 's' && s.charAt(1) == 'l') {
+ id = Id_else;
+ break L0;
+ }
+ } else if (c == 'm') {
+ if (s.charAt(2) == 'u' && s.charAt(1) == 'n') {
+ id = Id_enum;
+ break L0;
+ }
+ }
+ }
+ case 'g' -> {
+ X = "goto";
+ id = Id_goto;
+ }
+ case 'l' -> {
+ X = "long";
+ id = Id_long;
+ }
+ case 'n' -> {
+ X = "null";
+ id = Id_null;
+ }
+ case 't' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 'u' && s.charAt(1) == 'r') {
+ id = Id_true;
+ break L0;
+ }
+ } else if (c == 's') {
+ if (s.charAt(2) == 'i' && s.charAt(1) == 'h') {
+ id = Id_this;
+ break L0;
+ }
+ }
+ }
+ case 'v' -> {
+ X = "void";
+ id = Id_void;
+ }
+ case 'w' -> {
+ X = "with";
+ id = Id_with;
+ }
+ }
+ break;
+ case 5:
+ switch (s.charAt(2)) {
+ case 'a' -> {
+ X = "class";
+ id = Id_class;
+ }
+ case 'e' -> {
+ c = s.charAt(0);
+ if (c == 'b') {
+ X = "break";
+ id = Id_break;
+ } else if (c == 'y') {
+ X = "yield";
+ id = Id_yield;
+ }
+ }
+ case 'i' -> {
+ X = "while";
+ id = Id_while;
+ }
+ case 'l' -> {
+ X = "false";
+ id = Id_false;
+ }
+ case 'n' -> {
+ c = s.charAt(0);
+ if (c == 'c') {
+ X = "const";
+ id = Id_const;
+ } else if (c == 'f') {
+ X = "final";
+ id = Id_final;
+ }
+ }
+ case 'o' -> {
+ c = s.charAt(0);
+ if (c == 'f') {
+ X = "float";
+ id = Id_float;
+ } else if (c == 's') {
+ X = "short";
+ id = Id_short;
+ }
+ }
+ case 'p' -> {
+ X = "super";
+ id = Id_super;
+ }
+ case 'r' -> {
+ X = "throw";
+ id = Id_throw;
+ }
+ case 't' -> {
+ X = "catch";
+ id = Id_catch;
+ }
+ }
+ break;
+ case 6:
+ switch (s.charAt(1)) {
+ case 'a' -> {
+ X = "native";
+ id = Id_native;
+ }
+ case 'e' -> {
+ c = s.charAt(0);
+ if (c == 'd') {
+ X = "delete";
+ id = Id_delete;
+ } else if (c == 'r') {
+ X = "return";
+ id = Id_return;
+ }
+ }
+ case 'h' -> {
+ X = "throws";
+ id = Id_throws;
+ }
+ case 'm' -> {
+ X = "import";
+ id = Id_import;
+ }
+ case 'o' -> {
+ X = "double";
+ id = Id_double;
+ }
+ case 't' -> {
+ X = "static";
+ id = Id_static;
+ }
+ case 'u' -> {
+ X = "public";
+ id = Id_public;
+ }
+ case 'w' -> {
+ X = "switch";
+ id = Id_switch;
+ }
+ case 'x' -> {
+ X = "export";
+ id = Id_export;
+ }
+ case 'y' -> {
+ X = "typeof";
+ id = Id_typeof;
+ }
+ }
+ break;
+ case 7:
+ switch (s.charAt(1)) {
+ case 'a' -> {
+ X = "package";
+ id = Id_package;
+ }
+ case 'e' -> {
+ X = "default";
+ id = Id_default;
+ }
+ case 'i' -> {
+ X = "finally";
+ id = Id_finally;
+ }
+ case 'o' -> {
+ X = "boolean";
+ id = Id_boolean;
+ }
+ case 'r' -> {
+ X = "private";
+ id = Id_private;
+ }
+ case 'x' -> {
+ X = "extends";
+ id = Id_extends;
+ }
+ }
+ break;
+ case 8:
+ switch (s.charAt(0)) {
+ case 'a' -> {
+ X = "abstract";
+ id = Id_abstract;
+ }
+ case 'c' -> {
+ X = "continue";
+ id = Id_continue;
+ }
+ case 'd' -> {
+ X = "debugger";
+ id = Id_debugger;
+ }
+ case 'f' -> {
+ X = "function";
+ id = Id_function;
+ }
+ case 'v' -> {
+ X = "volatile";
+ id = Id_volatile;
+ }
+ }
+ break;
+ case 9:
+ c = s.charAt(0);
+ if (c == 'i') {
+ X = "interface";
+ id = Id_interface;
+ } else if (c == 'p') {
+ X = "protected";
+ id = Id_protected;
+ } else if (c == 't') {
+ X = "transient";
+ id = Id_transient;
+ }
+ break;
+ case 10:
+ c = s.charAt(1);
+ if (c == 'm') {
+ X = "implements";
+ id = Id_implements;
+ } else if (c == 'n') {
+ X = "instanceof";
+ id = Id_instanceof;
+ }
+ break;
+ case 12:
+ X = "synchronized";
+ id = Id_synchronized;
+ break;
+ }
+ if (X != null && X != s && !X.equals(s))
+ id = 0;
+ }
+ // #/generated#
+ // #/string_id_map#
+ if (id == 0) {
+ return Token.EOF;
+ }
+ return id & 0xff;
+ }
+
+ /**
+ * ECMAScript 6.
+ */
+ private static int stringToKeywordForES(String name, boolean isStrict) {
+ // #string_id_map#
+ // The following assumes that Token.EOF == 0
+ final int
+ // 11.6.2.1 Keywords (ECMAScript2015)
+ Id_break = Token.BREAK, Id_case = Token.CASE, Id_catch = Token.CATCH, Id_class = Token.RESERVED, Id_const = Token.CONST, Id_continue = Token.CONTINUE, Id_debugger = Token.DEBUGGER, Id_default = Token.DEFAULT, Id_delete = Token.DELPROP, Id_do = Token.DO, Id_else = Token.ELSE, Id_export = Token.RESERVED, Id_extends = Token.RESERVED, Id_finally = Token.FINALLY, Id_for = Token.FOR, Id_function = Token.FUNCTION, Id_if = Token.IF, Id_import = Token.RESERVED, Id_in = Token.IN, Id_instanceof = Token.INSTANCEOF, Id_new = Token.NEW, Id_return = Token.RETURN, Id_super = Token.RESERVED, Id_switch = Token.SWITCH, Id_this = Token.THIS, Id_throw = Token.THROW, Id_try = Token.TRY, Id_typeof = Token.TYPEOF, Id_var = Token.VAR, Id_void = Token.VOID, Id_while = Token.WHILE, Id_with = Token.WITH, Id_yield = Token.YIELD,
+
+ // 11.6.2.2 Future Reserved Words
+ Id_await = Token.RESERVED, Id_enum = Token.RESERVED,
+
+ // 11.6.2.2 NOTE Strict Future Reserved Words
+ Id_implements = Token.RESERVED, Id_interface = Token.RESERVED, Id_package = Token.RESERVED, Id_private = Token.RESERVED, Id_protected = Token.RESERVED, Id_public = Token.RESERVED,
+
+ // 11.8 Literals
+ Id_false = Token.FALSE, Id_null = Token.NULL, Id_true = Token.TRUE,
+
+ // Non ReservedWord, but Non IdentifierName in strict mode code.
+ // 12.1.1 Static Semantics: Early Errors
+ Id_let = Token.LET, // TODO : Valid IdentifierName in non-strict mode.
+ Id_static = Token.RESERVED;
+
+ int id;
+ String s = name;
+ // #generated# Last update: 2007-04-18 13:53:30 PDT
+ L0:
+ {
+ id = 0;
+ String X = null;
+ int c;
+ L:
+ switch (s.length()) {
+ case 2:
+ c = s.charAt(1);
+ if (c == 'f') {
+ if (s.charAt(0) == 'i') {
+ id = Id_if;
+ break L0;
+ }
+ } else if (c == 'n') {
+ if (s.charAt(0) == 'i') {
+ id = Id_in;
+ break L0;
+ }
+ } else if (c == 'o') {
+ if (s.charAt(0) == 'd') {
+ id = Id_do;
+ break L0;
+ }
+ }
+ break;
+ case 3:
+ switch (s.charAt(0)) {
+ case 'f':
+ if (s.charAt(2) == 'r' && s.charAt(1) == 'o') {
+ id = Id_for;
+ break L0;
+ }
+ break L;
+ case 'l':
+ if (s.charAt(2) == 't' && s.charAt(1) == 'e') {
+ id = Id_let;
+ break L0;
+ }
+ break L;
+ case 'n':
+ if (s.charAt(2) == 'w' && s.charAt(1) == 'e') {
+ id = Id_new;
+ break L0;
+ }
+ break L;
+ case 't':
+ if (s.charAt(2) == 'y' && s.charAt(1) == 'r') {
+ id = Id_try;
+ break L0;
+ }
+ break L;
+ case 'v':
+ if (s.charAt(2) == 'r' && s.charAt(1) == 'a') {
+ id = Id_var;
+ break L0;
+ }
+ break L;
+ }
+ break;
+ case 4:
+ switch (s.charAt(0)) {
+ case 'c' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 's' && s.charAt(1) == 'a') {
+ id = Id_case;
+ break L0;
+ }
+ }
+ }
+ case 'e' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 's' && s.charAt(1) == 'l') {
+ id = Id_else;
+ break L0;
+ }
+ } else if (c == 'm') {
+ if (s.charAt(2) == 'u' && s.charAt(1) == 'n') {
+ id = Id_enum;
+ break L0;
+ }
+ }
+ }
+ case 'n' -> {
+ X = "null";
+ id = Id_null;
+ }
+ case 't' -> {
+ c = s.charAt(3);
+ if (c == 'e') {
+ if (s.charAt(2) == 'u' && s.charAt(1) == 'r') {
+ id = Id_true;
+ break L0;
+ }
+ } else if (c == 's') {
+ if (s.charAt(2) == 'i' && s.charAt(1) == 'h') {
+ id = Id_this;
+ break L0;
+ }
+ }
+ }
+ case 'v' -> {
+ X = "void";
+ id = Id_void;
+ }
+ case 'w' -> {
+ X = "with";
+ id = Id_with;
+ }
+ }
+ break;
+ case 5:
+ switch (s.charAt(2)) {
+ case 'a' -> {
+ c = s.charAt(0);
+ if (c == 'c') {
+ X = "class";
+ id = Id_class;
+ } else if (c == 'a') {
+ X = "await";
+ id = Id_await;
+ }
+ }
+ case 'e' -> {
+ c = s.charAt(0);
+ if (c == 'b') {
+ X = "break";
+ id = Id_break;
+ } else if (c == 'y') {
+ X = "yield";
+ id = Id_yield;
+ }
+ }
+ case 'i' -> {
+ X = "while";
+ id = Id_while;
+ }
+ case 'l' -> {
+ X = "false";
+ id = Id_false;
+ }
+ case 'n' -> {
+ X = "const";
+ id = Id_const;
+ }
+ case 'p' -> {
+ X = "super";
+ id = Id_super;
+ }
+ case 'r' -> {
+ X = "throw";
+ id = Id_throw;
+ }
+ case 't' -> {
+ X = "catch";
+ id = Id_catch;
+ }
+ }
+ break;
+ case 6:
+ switch (s.charAt(1)) {
+ case 'e':
+ c = s.charAt(0);
+ if (c == 'd') {
+ X = "delete";
+ id = Id_delete;
+ } else if (c == 'r') {
+ X = "return";
+ id = Id_return;
+ }
+ break L;
+ case 'm':
+ X = "import";
+ id = Id_import;
+ break L;
+ case 't':
+ if (isStrict) {
+ X = "static";
+ id = Id_static;
+ break L;
+ }
+ // fallthru
+ case 'u':
+ if (isStrict) {
+ X = "public";
+ id = Id_public;
+ break L;
+ }
+ // fallthru
+ case 'w':
+ X = "switch";
+ id = Id_switch;
+ break L;
+ case 'x':
+ X = "export";
+ id = Id_export;
+ break L;
+ case 'y':
+ X = "typeof";
+ id = Id_typeof;
+ break L;
+ }
+ break;
+ case 7:
+ switch (s.charAt(1)) {
+ case 'a':
+ if (isStrict) {
+ X = "package";
+ id = Id_package;
+ break L;
+ }
+ // fallthru
+ case 'e':
+ X = "default";
+ id = Id_default;
+ break L;
+ case 'i':
+ X = "finally";
+ id = Id_finally;
+ break L;
+ case 'r':
+ if (isStrict) {
+ X = "private";
+ id = Id_private;
+ break L;
+ }
+ // fallthru
+ case 'x':
+ X = "extends";
+ id = Id_extends;
+ break L;
+ }
+ break;
+ case 8:
+ switch (s.charAt(0)) {
+ case 'c' -> {
+ X = "continue";
+ id = Id_continue;
+ }
+ case 'd' -> {
+ X = "debugger";
+ id = Id_debugger;
+ }
+ case 'f' -> {
+ X = "function";
+ id = Id_function;
+ }
+ }
+ break;
+ case 9:
+ c = s.charAt(0);
+ if (c == 'i' && isStrict) {
+ X = "interface";
+ id = Id_interface;
+ } else if (c == 'p' && isStrict) {
+ X = "protected";
+ id = Id_protected;
+ }
+ break;
+ case 10:
+ c = s.charAt(1);
+ if (c == 'm' && isStrict) {
+ X = "implements";
+ id = Id_implements;
+ } else if (c == 'n') {
+ X = "instanceof";
+ id = Id_instanceof;
+ }
+ break;
+ }
+ if (X != null && X != s && !X.equals(s))
+ id = 0;
+ }
+ // #/generated#
+ // #/string_id_map#
+ if (id == 0) {
+ return Token.EOF;
+ }
+ return id & 0xff;
+ }
+
+ final String getSourceString() {
+ return sourceString;
+ }
+
+ final int getLineno() {
+ return lineno;
+ }
+
+ final String getString() {
+ return string;
+ }
+
+ final char getQuoteChar() {
+ return (char) quoteChar;
+ }
+
+ final double getNumber() {
+ return number;
+ }
+
+ final boolean isNumberBinary() {
+ return isBinary;
+ }
+
+ final boolean isNumberOldOctal() {
+ return isOldOctal;
+ }
+
+ final boolean isNumberOctal() {
+ return isOctal;
+ }
+
+ final boolean isNumberHex() {
+ return isHex;
+ }
+
+ final boolean eof() {
+ return hitEOF;
+ }
+
+ public final int getToken() throws IOException {
+ int c;
+
+ retry:
+ for (; ; ) {
+ // Eat whitespace, possibly sensitive to newlines.
+ for (; ; ) {
+ c = getChar();
+ if (c == EOF_CHAR) {
+ tokenBeg = cursor - 1;
+ tokenEnd = cursor;
+ return Token.EOF;
+ } else if (c == '\n') {
+ dirtyLine = false;
+ tokenBeg = cursor - 1;
+ tokenEnd = cursor;
+ return Token.EOL;
+ } else if (!isJSSpace(c)) {
+ if (c != '-') {
+ dirtyLine = true;
+ }
+ break;
+ }
+ }
+
+ // Assume the token will be 1 char - fixed up below.
+ tokenBeg = cursor - 1;
+ tokenEnd = cursor;
+
+ if (c == '@')
+ return Token.XMLATTR;
+
+ // identifier/keyword/instanceof?
+ // watch out for starting with a
+ boolean identifierStart;
+ boolean isUnicodeEscapeStart = false;
+ if (c == '\\') {
+ c = getChar();
+ if (c == 'u') {
+ identifierStart = true;
+ isUnicodeEscapeStart = true;
+ stringBufferTop = 0;
+ } else {
+ identifierStart = false;
+ ungetChar(c);
+ c = '\\';
+ }
+ } else {
+ identifierStart = Character.isJavaIdentifierStart((char) c);
+ if (identifierStart) {
+ stringBufferTop = 0;
+ addToString(c);
+ }
+ }
+
+ if (identifierStart) {
+ boolean containsEscape = isUnicodeEscapeStart;
+ for (; ; ) {
+ if (isUnicodeEscapeStart) {
+ // strictly speaking we should probably push-back
+ // all the bad characters if the uXXXX
+ // sequence is malformed. But since there isn't a
+ // correct context(is there?) for a bad Unicode
+ // escape sequence in an identifier, we can report
+ // an error here.
+ int escapeVal = 0;
+ for (int i = 0; i != 4; ++i) {
+ c = getChar();
+ escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
+ // Next check takes care about c < 0 and bad escape
+ if (escapeVal < 0) {
+ break;
+ }
+ }
+ if (escapeVal < 0) {
+ return Token.ERROR;
+ }
+ addToString(escapeVal);
+ isUnicodeEscapeStart = false;
+ } else {
+ c = getChar();
+ if (c == '\\') {
+ c = getChar();
+ if (c == 'u') {
+ isUnicodeEscapeStart = true;
+ containsEscape = true;
+ } else {
+ return Token.ERROR;
+ }
+ } else {
+ if (c == EOF_CHAR
+ || c == BYTE_ORDER_MARK
+ || !Character
+ .isJavaIdentifierPart((char) c)) {
+ break;
+ }
+ addToString(c);
+ }
+ }
+ }
+ ungetChar(c);
+
+ String str = getStringFromBuffer();
+ int result = stringToKeyword(str);
+ if (result != Token.EOF) {
+ return result;
+ }
+ this.string = (String) allStrings.intern(str);
+ return Token.NAME;
+ }
+
+ // is it a number?
+ if (isDigit(c) || (c == '.' && isDigit(peekChar()))) {
+ stringBufferTop = 0;
+ int base = 10;
+ isHex = isOldOctal = isOctal = isBinary = false;
+ boolean es6 = false;
+
+ if (c == '0') {
+ c = getChar();
+ if (c == 'x' || c == 'X') {
+ base = 16;
+ isHex = true;
+ c = getChar();
+ } else if (es6 && (c == 'o' || c == 'O')) {
+ base = 8;
+ isOctal = true;
+ c = getChar();
+ } else if (es6 && (c == 'b' || c == 'B')) {
+ base = 2;
+ isBinary = true;
+ c = getChar();
+ } else if (isDigit(c)) {
+ base = 8;
+ isOldOctal = true;
+ } else {
+ addToString('0');
+ }
+ }
+
+ boolean isEmpty = true;
+ if (base == 16) {
+ while (0 <= org.mozilla.javascript.Kit.xDigitToInt(c, 0)) {
+ addToString(c);
+ c = getChar();
+ isEmpty = false;
+ }
+ } else {
+ while ('0' <= c && c <= '9') {
+ if (base == 8 && c >= '8') {
+ if (isOldOctal) {
+ base = 10;
+ } else {
+ return Token.ERROR;
+ }
+ } else if (base == 2 && c >= '2') {
+ return Token.ERROR;
+ }
+ addToString(c);
+ c = getChar();
+ isEmpty = false;
+ }
+ }
+ if (isEmpty && (isBinary || isOctal || isHex)) {
+ return Token.ERROR;
+ }
+
+ boolean isInteger = true;
+
+ if (base == 10 && (c == '.' || c == 'e' || c == 'E')) {
+ isInteger = false;
+ if (c == '.') {
+ do {
+ addToString(c);
+ c = getChar();
+ } while (isDigit(c));
+ }
+ if (c == 'e' || c == 'E') {
+ addToString(c);
+ c = getChar();
+ if (c == '+' || c == '-') {
+ addToString(c);
+ c = getChar();
+ }
+ if (!isDigit(c)) {
+ return Token.ERROR;
+ }
+ do {
+ addToString(c);
+ c = getChar();
+ } while (isDigit(c));
+ }
+ }
+ ungetChar(c);
+ String numString = getStringFromBuffer();
+ this.string = numString;
+
+ double dval;
+ if (base == 10 && !isInteger) {
+ try {
+ // Use Java conversion to number from string...
+ dval = Double.parseDouble(numString);
+ } catch (NumberFormatException ex) {
+ return Token.ERROR;
+ }
+ } else {
+ dval = stringToNumber(numString, 0, base);
+ }
+
+ this.number = dval;
+ return Token.NUMBER;
+ }
+
+ // is it a string?
+ if (c == '"' || c == '\'') {
+ // We attempt to accumulate a string the fast way, by
+ // building it directly out of the reader. But if there
+ // are any escaped characters in the string, we revert to
+ // building it out of a StringBuffer.
+
+ quoteChar = c;
+ stringBufferTop = 0;
+
+ c = getChar(false);
+ strLoop:
+ while (c != quoteChar) {
+ if (c == '\n' || c == EOF_CHAR) {
+ ungetChar(c);
+ tokenEnd = cursor;
+ return Token.ERROR;
+ }
+
+ if (c == '\\') {
+ // We've hit an escaped character
+ int escapeVal;
+
+ c = getChar();
+ switch (c) {
+ case 'b':
+ c = '\b';
+ break;
+ case 'f':
+ c = '\f';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+
+ // \v a late addition to the ECMA spec,
+ // it is not in Java, so use 0xb
+ case 'v':
+ c = 0xb;
+ break;
+
+ case 'u':
+ // Get 4 hex digits; if the u escape is not
+ // followed by 4 hex digits, use 'u' + the
+ // literal character sequence that follows.
+ int escapeStart = stringBufferTop;
+ addToString('u');
+ escapeVal = 0;
+ for (int i = 0; i != 4; ++i) {
+ c = getChar();
+ escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
+ if (escapeVal < 0) {
+ continue strLoop;
+ }
+ addToString(c);
+ }
+ // prepare for replace of stored 'u' sequence
+ // by escape value
+ stringBufferTop = escapeStart;
+ c = escapeVal;
+ break;
+ case 'x':
+ // Get 2 hex digits, defaulting to 'x'+literal
+ // sequence, as above.
+ c = getChar();
+ escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, 0);
+ if (escapeVal < 0) {
+ addToString('x');
+ continue strLoop;
+ } else {
+ int c1 = c;
+ c = getChar();
+ escapeVal = org.mozilla.javascript.Kit.xDigitToInt(c, escapeVal);
+ if (escapeVal < 0) {
+ addToString('x');
+ addToString(c1);
+ continue strLoop;
+ } else {
+ // got 2 hex digits
+ c = escapeVal;
+ }
+ }
+ break;
+
+ case '\n':
+ // Remove line terminator after escape to follow
+ // SpiderMonkey and C/C++
+ c = getChar();
+ continue strLoop;
+
+ default:
+ if ('0' <= c && c < '8') {
+ int val = c - '0';
+ c = getChar();
+ if ('0' <= c && c < '8') {
+ val = 8 * val + c - '0';
+ c = getChar();
+ if ('0' <= c && c < '8' && val <= 037) {
+ // c is 3rd char of octal sequence only
+ // if the resulting val <= 0377
+ val = 8 * val + c - '0';
+ c = getChar();
+ }
+ }
+ ungetChar(c);
+ c = val;
+ }
+ }
+ }
+ addToString(c);
+ c = getChar(false);
+ }
+
+ String str = getStringFromBuffer();
+ this.string = (String) allStrings.intern(str);
+ return Token.STRING;
+ }
+
+ switch (c) {
+ case ';':
+ return Token.SEMI;
+ case '[':
+ return Token.LB;
+ case ']':
+ return Token.RB;
+ case '{':
+ return Token.LC;
+ case '}':
+ return Token.RC;
+ case '(':
+ return Token.LP;
+ case ')':
+ return Token.RP;
+ case ',':
+ return Token.COMMA;
+ case '?':
+ return Token.HOOK;
+ case ':':
+ if (matchChar(':')) {
+ return Token.COLONCOLON;
+ } else {
+ return Token.COLON;
+ }
+ case '.':
+ if (matchChar('.')) {
+ return Token.DOTDOT;
+ } else if (matchChar('(')) {
+ return Token.DOTQUERY;
+ } else {
+ return Token.DOT;
+ }
+
+ case '|':
+ if (matchChar('|')) {
+ return Token.OR;
+ } else if (matchChar('=')) {
+ return Token.ASSIGN_BITOR;
+ } else {
+ return Token.BITOR;
+ }
+
+ case '^':
+ if (matchChar('=')) {
+ return Token.ASSIGN_BITXOR;
+ } else {
+ return Token.BITXOR;
+ }
+
+ case '&':
+ if (matchChar('&')) {
+ return Token.AND;
+ } else if (matchChar('=')) {
+ return Token.ASSIGN_BITAND;
+ } else {
+ return Token.BITAND;
+ }
+
+ case '=':
+ if (matchChar('=')) {
+ if (matchChar('=')) {
+ return Token.SHEQ;
+ } else {
+ return Token.EQ;
+ }
+ } else if (matchChar('>')) {
+ return Token.ARROW;
+ } else {
+ return Token.ASSIGN;
+ }
+
+ case '!':
+ if (matchChar('=')) {
+ if (matchChar('=')) {
+ return Token.SHNE;
+ } else {
+ return Token.NE;
+ }
+ } else {
+ return Token.NOT;
+ }
+
+ case '<':
+ /* NB:treat HTML begin-comment as comment-till-eol */
+ if (matchChar('!')) {
+ if (matchChar('-')) {
+ if (matchChar('-')) {
+ tokenBeg = cursor - 4;
+ skipLine();
+ commentType = Token.CommentType.HTML;
+ return Token.COMMENT;
+ }
+ ungetCharIgnoreLineEnd('-');
+ }
+ ungetCharIgnoreLineEnd('!');
+ }
+ if (matchChar('<')) {
+ if (matchChar('=')) {
+ return Token.ASSIGN_LSH;
+ } else {
+ return Token.LSH;
+ }
+ } else {
+ if (matchChar('=')) {
+ return Token.LE;
+ } else {
+ return Token.LT;
+ }
+ }
+
+ case '>':
+ if (matchChar('>')) {
+ if (matchChar('>')) {
+ if (matchChar('=')) {
+ return Token.ASSIGN_URSH;
+ } else {
+ return Token.URSH;
+ }
+ } else {
+ if (matchChar('=')) {
+ return Token.ASSIGN_RSH;
+ } else {
+ return Token.RSH;
+ }
+ }
+ } else {
+ if (matchChar('=')) {
+ return Token.GE;
+ } else {
+ return Token.GT;
+ }
+ }
+
+ case '*':
+ if (matchChar('=')) {
+ return Token.ASSIGN_MUL;
+ } else {
+ return Token.MUL;
+ }
+
+ case '/':
+ // is it a // comment?
+ if (matchChar('/')) {
+ tokenBeg = cursor - 2;
+ skipLine();
+ commentType = Token.CommentType.LINE;
+ return Token.COMMENT;
+ }
+ // is it a /* or /** comment?
+ if (matchChar('*')) {
+ boolean lookForSlash = false;
+ tokenBeg = cursor - 2;
+ if (matchChar('*')) {
+ lookForSlash = true;
+ commentType = Token.CommentType.JSDOC;
+ } else {
+ commentType = Token.CommentType.BLOCK_COMMENT;
+ }
+ for (; ; ) {
+ c = getChar();
+ if (c == EOF_CHAR) {
+ tokenEnd = cursor - 1;
+ return Token.COMMENT;
+ } else if (c == '*') {
+ lookForSlash = true;
+ } else if (c == '/') {
+ if (lookForSlash) {
+ tokenEnd = cursor;
+ return Token.COMMENT;
+ }
+ } else {
+ lookForSlash = false;
+ tokenEnd = cursor;
+ }
+ }
+ }
+
+ if (matchChar('=')) {
+ return Token.ASSIGN_DIV;
+ } else {
+ return Token.DIV;
+ }
+
+ case '%':
+ if (matchChar('=')) {
+ return Token.ASSIGN_MOD;
+ } else {
+ return Token.MOD;
+ }
+
+ case '~':
+ return Token.BITNOT;
+
+ case '+':
+ if (matchChar('=')) {
+ return Token.ASSIGN_ADD;
+ } else if (matchChar('+')) {
+ return Token.INC;
+ } else {
+ return Token.ADD;
+ }
+
+ case '-':
+ if (matchChar('=')) {
+ c = Token.ASSIGN_SUB;
+ } else if (matchChar('-')) {
+ if (!dirtyLine) {
+ // treat HTML end-comment after possible whitespace
+ // after line start as comment-until-eol
+ if (matchChar('>')) {
+ skipLine();
+ commentType = Token.CommentType.HTML;
+ return Token.COMMENT;
+ }
+ }
+ c = Token.DEC;
+ } else {
+ c = Token.SUB;
+ }
+ dirtyLine = true;
+ return c;
+
+ default:
+ return Token.ERROR;
+ }
+ }
+ }
+
+ private static boolean isAlpha(int c) {
+ // Use 'Z' < 'a'
+ if (c <= 'Z') {
+ return 'A' <= c;
+ } else {
+ return 'a' <= c && c <= 'z';
+ }
+ }
+
+ static boolean isDigit(int c) {
+ return '0' <= c && c <= '9';
+ }
+
+ /*
+ * As defined in ECMA. jsscan.c uses C isspace() (which allows \v, I think.)
+ * note that code in getChar() implicitly accepts '\r' == as well.
+ */
+ static boolean isJSSpace(int c) {
+ if (c <= 127) {
+ return c == 0x20 || c == 0x9 || c == 0xC || c == 0xB;
+ } else {
+ return c == 0xA0 || c == BYTE_ORDER_MARK
+ || Character.getType((char) c) == Character.SPACE_SEPARATOR;
+ }
+ }
+
+ private static boolean isJSFormatChar(int c) {
+ return c > 127 && Character.getType((char) c) == Character.FORMAT;
+ }
+
+ /**
+ * Parser calls the method when it gets / or /= in literal context.
+ */
+ void readRegExp(int startToken) throws IOException {
+ int start = tokenBeg;
+ stringBufferTop = 0;
+ if (startToken == Token.ASSIGN_DIV) {
+ // Miss-scanned /=
+ addToString('=');
+ } else {
+ if (startToken != Token.DIV)
+ org.mozilla.javascript.Kit.codeBug();
+ }
+
+ boolean inCharSet = false; // true if inside a '['..']' pair
+ int c;
+ while ((c = getChar()) != '/' || inCharSet) {
+ if (c == '\n' || c == EOF_CHAR) {
+ ungetChar(c);
+ tokenEnd = cursor - 1;
+ this.string = new String(stringBuffer, 0, stringBufferTop);
+ return;
+ }
+ if (c == '\\') {
+ addToString(c);
+ c = getChar();
+ } else if (c == '[') {
+ inCharSet = true;
+ } else if (c == ']') {
+ inCharSet = false;
+ }
+ addToString(c);
+ }
+ int reEnd = stringBufferTop;
+
+ while (true) {
+ if (matchChar('g'))
+ addToString('g');
+ else if (matchChar('i'))
+ addToString('i');
+ else if (matchChar('m'))
+ addToString('m');
+ else if (matchChar('y')) // FireFox 3
+ addToString('y');
+ else
+ break;
+ }
+ tokenEnd = start + stringBufferTop + 2; // include slashes
+
+ if (isAlpha(peekChar())) {
+ }
+
+ this.string = new String(stringBuffer, 0, reEnd);
+ this.regExpFlags = new String(stringBuffer, reEnd, stringBufferTop
+ - reEnd);
+ }
+
+ String readAndClearRegExpFlags() {
+ String flags = this.regExpFlags;
+ this.regExpFlags = null;
+ return flags;
+ }
+
+ boolean isXMLAttribute() {
+ return xmlIsAttribute;
+ }
+
+ int getFirstXMLToken() throws IOException {
+ xmlOpenTagsCount = 0;
+ xmlIsAttribute = false;
+ xmlIsTagContent = false;
+ if (!canUngetChar())
+ return Token.ERROR;
+ ungetChar('<');
+ return getNextXMLToken();
+ }
+
+ int getNextXMLToken() throws IOException {
+ tokenBeg = cursor;
+ stringBufferTop = 0; // remember the XML
+
+ for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
+ if (xmlIsTagContent) {
+ switch (c) {
+ case '>' -> {
+ addToString(c);
+ xmlIsTagContent = false;
+ xmlIsAttribute = false;
+ }
+ case '/' -> {
+ addToString(c);
+ if (peekChar() == '>') {
+ c = getChar();
+ addToString(c);
+ xmlIsTagContent = false;
+ xmlOpenTagsCount--;
+ }
+ }
+ case '{' -> {
+ ungetChar(c);
+ this.string = getStringFromBuffer();
+ return Token.XML;
+ }
+ case '\'', '"' -> {
+ addToString(c);
+ if (!readQuotedString(c))
+ return Token.ERROR;
+ }
+ case '=' -> {
+ addToString(c);
+ xmlIsAttribute = true;
+ }
+ case ' ', '\t', '\r', '\n' -> addToString(c);
+ default -> {
+ addToString(c);
+ xmlIsAttribute = false;
+ }
+ }
+
+ if (!xmlIsTagContent && xmlOpenTagsCount == 0) {
+ this.string = getStringFromBuffer();
+ return Token.XMLEND;
+ }
+ } else {
+ switch (c) {
+ case '<' -> {
+ addToString(c);
+ c = peekChar();
+ switch (c) {
+ case '!' -> {
+ c = getChar(); // Skip !
+ addToString(c);
+ c = peekChar();
+ switch (c) {
+ case '-':
+ c = getChar(); // Skip -
+ addToString(c);
+ c = getChar();
+ if (c == '-') {
+ addToString(c);
+ if (!readXmlComment())
+ return Token.ERROR;
+ } else {
+ // throw away the string in progress
+ stringBufferTop = 0;
+ this.string = null;
+ return Token.ERROR;
+ }
+ break;
+ case '[':
+ c = getChar(); // Skip [
+ addToString(c);
+ if (getChar() == 'C' && getChar() == 'D'
+ && getChar() == 'A' && getChar() == 'T'
+ && getChar() == 'A' && getChar() == '[') {
+ addToString('C');
+ addToString('D');
+ addToString('A');
+ addToString('T');
+ addToString('A');
+ addToString('[');
+ if (!readCDATA())
+ return Token.ERROR;
+
+ } else {
+ // throw away the string in progress
+ stringBufferTop = 0;
+ this.string = null;
+ return Token.ERROR;
+ }
+ break;
+ default:
+ if (!readEntity())
+ return Token.ERROR;
+ break;
+ }
+ }
+ case '?' -> {
+ c = getChar(); // Skip ?
+ addToString(c);
+ if (!readPI())
+ return Token.ERROR;
+ }
+ case '/' -> {
+ // End tag
+ c = getChar(); // Skip /
+ addToString(c);
+ if (xmlOpenTagsCount == 0) {
+ // throw away the string in progress
+ stringBufferTop = 0;
+ this.string = null;
+ return Token.ERROR;
+ }
+ xmlIsTagContent = true;
+ xmlOpenTagsCount--;
+ }
+ default -> {
+ // Start tag
+ xmlIsTagContent = true;
+ xmlOpenTagsCount++;
+ }
+ }
+ }
+ case '{' -> {
+ ungetChar(c);
+ this.string = getStringFromBuffer();
+ return Token.XML;
+ }
+ default -> addToString(c);
+ }
+ }
+ }
+
+ tokenEnd = cursor;
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return Token.ERROR;
+ }
+
+ /**
*
*/
- private boolean readQuotedString(int quote) throws IOException {
- for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
- addToString(c);
- if (c == quote)
- return true;
- }
+ private boolean readQuotedString(int quote) throws IOException {
+ for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
+ addToString(c);
+ if (c == quote)
+ return true;
+ }
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return false;
- }
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return false;
+ }
- /**
+ /**
*
*/
- private boolean readXmlComment() throws IOException {
- for (int c = getChar(); c != EOF_CHAR;) {
- addToString(c);
- if (c == '-' && peekChar() == '-') {
- c = getChar();
- addToString(c);
- if (peekChar() == '>') {
- c = getChar(); // Skip >
- addToString(c);
- return true;
- } else {
- continue;
- }
- }
- c = getChar();
- }
+ private boolean readXmlComment() throws IOException {
+ for (int c = getChar(); c != EOF_CHAR; ) {
+ addToString(c);
+ if (c == '-' && peekChar() == '-') {
+ c = getChar();
+ addToString(c);
+ if (peekChar() == '>') {
+ c = getChar(); // Skip >
+ addToString(c);
+ return true;
+ } else {
+ continue;
+ }
+ }
+ c = getChar();
+ }
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return false;
- }
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return false;
+ }
- /**
+ /**
*
*/
- private boolean readCDATA() throws IOException {
- for (int c = getChar(); c != EOF_CHAR;) {
- addToString(c);
- if (c == ']' && peekChar() == ']') {
- c = getChar();
- addToString(c);
- if (peekChar() == '>') {
- c = getChar(); // Skip >
- addToString(c);
- return true;
- } else {
- continue;
- }
- }
- c = getChar();
- }
+ private boolean readCDATA() throws IOException {
+ for (int c = getChar(); c != EOF_CHAR; ) {
+ addToString(c);
+ if (c == ']' && peekChar() == ']') {
+ c = getChar();
+ addToString(c);
+ if (peekChar() == '>') {
+ c = getChar(); // Skip >
+ addToString(c);
+ return true;
+ } else {
+ continue;
+ }
+ }
+ c = getChar();
+ }
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return false;
- }
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return false;
+ }
- /**
+ /**
*
*/
- private boolean readEntity() throws IOException {
- int declTags = 1;
- for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
- addToString(c);
- switch (c) {
- case '<':
- declTags++;
- break;
- case '>':
- declTags--;
- if (declTags == 0)
- return true;
- break;
- }
- }
+ private boolean readEntity() throws IOException {
+ int declTags = 1;
+ for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
+ addToString(c);
+ switch (c) {
+ case '<' -> declTags++;
+ case '>' -> {
+ declTags--;
+ if (declTags == 0)
+ return true;
+ }
+ }
+ }
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return false;
- }
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return false;
+ }
- /**
+ /**
*
*/
- private boolean readPI() throws IOException {
- for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
- addToString(c);
- if (c == '?' && peekChar() == '>') {
- c = getChar(); // Skip >
- addToString(c);
- return true;
- }
- }
+ private boolean readPI() throws IOException {
+ for (int c = getChar(); c != EOF_CHAR; c = getChar()) {
+ addToString(c);
+ if (c == '?' && peekChar() == '>') {
+ c = getChar(); // Skip >
+ addToString(c);
+ return true;
+ }
+ }
- stringBufferTop = 0; // throw away the string in progress
- this.string = null;
- return false;
- }
+ stringBufferTop = 0; // throw away the string in progress
+ this.string = null;
+ return false;
+ }
- private String getStringFromBuffer() {
- tokenEnd = cursor;
- return new String(stringBuffer, 0, stringBufferTop);
- }
+ private String getStringFromBuffer() {
+ tokenEnd = cursor;
+ return new String(stringBuffer, 0, stringBufferTop);
+ }
- private void addToString(int c) {
- int N = stringBufferTop;
- if (N == stringBuffer.length) {
- char[] tmp = new char[stringBuffer.length * 2];
- System.arraycopy(stringBuffer, 0, tmp, 0, N);
- stringBuffer = tmp;
- }
- stringBuffer[N] = (char) c;
- stringBufferTop = N + 1;
- }
+ private void addToString(int c) {
+ int N = stringBufferTop;
+ if (N == stringBuffer.length) {
+ char[] tmp = new char[stringBuffer.length * 2];
+ System.arraycopy(stringBuffer, 0, tmp, 0, N);
+ stringBuffer = tmp;
+ }
+ stringBuffer[N] = (char) c;
+ stringBufferTop = N + 1;
+ }
- private boolean canUngetChar() {
- return ungetCursor == 0 || ungetBuffer[ungetCursor - 1] != '\n';
- }
+ private boolean canUngetChar() {
+ return ungetCursor == 0 || ungetBuffer[ungetCursor - 1] != '\n';
+ }
- private void ungetChar(int c) {
- // can not unread past across line boundary
- if (ungetCursor != 0 && ungetBuffer[ungetCursor - 1] == '\n')
- org.mozilla.javascript.Kit.codeBug();
- ungetBuffer[ungetCursor++] = c;
- cursor--;
- }
+ private void ungetChar(int c) {
+ // can not unread past across line boundary
+ if (ungetCursor != 0 && ungetBuffer[ungetCursor - 1] == '\n')
+ org.mozilla.javascript.Kit.codeBug();
+ ungetBuffer[ungetCursor++] = c;
+ cursor--;
+ }
- private boolean matchChar(int test) throws IOException {
- int c = getCharIgnoreLineEnd();
- if (c == test) {
- tokenEnd = cursor;
- return true;
- } else {
- ungetCharIgnoreLineEnd(c);
- return false;
- }
- }
+ private boolean matchChar(int test) throws IOException {
+ int c = getCharIgnoreLineEnd();
+ if (c == test) {
+ tokenEnd = cursor;
+ return true;
+ } else {
+ ungetCharIgnoreLineEnd(c);
+ return false;
+ }
+ }
- private int peekChar() throws IOException {
- int c = getChar();
- ungetChar(c);
- return c;
- }
+ private int peekChar() throws IOException {
+ int c = getChar();
+ ungetChar(c);
+ return c;
+ }
- private int getChar() throws IOException {
- return getChar(true);
- }
+ private int getChar() throws IOException {
+ return getChar(true);
+ }
- private int getChar(boolean skipFormattingChars) throws IOException {
- if (ungetCursor != 0) {
- cursor++;
- return ungetBuffer[--ungetCursor];
- }
+ private int getChar(boolean skipFormattingChars) throws IOException {
+ if (ungetCursor != 0) {
+ cursor++;
+ return ungetBuffer[--ungetCursor];
+ }
- for (;;) {
- int c;
- if (sourceString != null) {
- if (sourceCursor == sourceEnd) {
- hitEOF = true;
- return EOF_CHAR;
- }
- cursor++;
- c = sourceString.charAt(sourceCursor++);
- } else {
- if (sourceCursor == sourceEnd) {
- if (!fillSourceBuffer()) {
- hitEOF = true;
- return EOF_CHAR;
- }
- }
- cursor++;
- c = sourceBuffer[sourceCursor++];
- }
+ for (; ; ) {
+ int c;
+ if (sourceString != null) {
+ if (sourceCursor == sourceEnd) {
+ hitEOF = true;
+ return EOF_CHAR;
+ }
+ cursor++;
+ c = sourceString.charAt(sourceCursor++);
+ } else {
+ if (sourceCursor == sourceEnd) {
+ if (!fillSourceBuffer()) {
+ hitEOF = true;
+ return EOF_CHAR;
+ }
+ }
+ cursor++;
+ c = sourceBuffer[sourceCursor++];
+ }
- if (lineEndChar >= 0) {
- if (lineEndChar == '\r' && c == '\n') {
- lineEndChar = '\n';
- continue;
- }
- lineEndChar = -1;
- lineStart = sourceCursor - 1;
- lineno++;
- }
+ if (lineEndChar >= 0) {
+ if (lineEndChar == '\r' && c == '\n') {
+ lineEndChar = '\n';
+ continue;
+ }
+ lineEndChar = -1;
+ lineStart = sourceCursor - 1;
+ lineno++;
+ }
- if (c <= 127) {
- if (c == '\n' || c == '\r') {
- lineEndChar = c;
- c = '\n';
- }
- } else {
- if (c == BYTE_ORDER_MARK)
- return c; // BOM is considered whitespace
- if (skipFormattingChars && isJSFormatChar(c)) {
- continue;
- }
- if (isJSLineTerminator(c)) {
- lineEndChar = c;
- c = '\n';
- }
- }
- return c;
- }
- }
+ if (c <= 127) {
+ if (c == '\n' || c == '\r') {
+ lineEndChar = c;
+ c = '\n';
+ }
+ } else {
+ if (c == BYTE_ORDER_MARK)
+ return c; // BOM is considered whitespace
+ if (skipFormattingChars && isJSFormatChar(c)) {
+ continue;
+ }
+ if (isJSLineTerminator(c)) {
+ lineEndChar = c;
+ c = '\n';
+ }
+ }
+ return c;
+ }
+ }
- private int getCharIgnoreLineEnd() throws IOException {
- if (ungetCursor != 0) {
- cursor++;
- return ungetBuffer[--ungetCursor];
- }
+ private int getCharIgnoreLineEnd() throws IOException {
+ if (ungetCursor != 0) {
+ cursor++;
+ return ungetBuffer[--ungetCursor];
+ }
- for (;;) {
- int c;
- if (sourceString != null) {
- if (sourceCursor == sourceEnd) {
- hitEOF = true;
- return EOF_CHAR;
- }
- cursor++;
- c = sourceString.charAt(sourceCursor++);
- } else {
- if (sourceCursor == sourceEnd) {
- if (!fillSourceBuffer()) {
- hitEOF = true;
- return EOF_CHAR;
- }
- }
- cursor++;
- c = sourceBuffer[sourceCursor++];
- }
+ for (; ; ) {
+ int c;
+ if (sourceString != null) {
+ if (sourceCursor == sourceEnd) {
+ hitEOF = true;
+ return EOF_CHAR;
+ }
+ cursor++;
+ c = sourceString.charAt(sourceCursor++);
+ } else {
+ if (sourceCursor == sourceEnd) {
+ if (!fillSourceBuffer()) {
+ hitEOF = true;
+ return EOF_CHAR;
+ }
+ }
+ cursor++;
+ c = sourceBuffer[sourceCursor++];
+ }
- if (c <= 127) {
- if (c == '\n' || c == '\r') {
- lineEndChar = c;
- c = '\n';
- }
- } else {
- if (c == BYTE_ORDER_MARK)
- return c; // BOM is considered whitespace
- if (isJSFormatChar(c)) {
- continue;
- }
- if (isJSLineTerminator(c)) {
- lineEndChar = c;
- c = '\n';
- }
- }
- return c;
- }
- }
+ if (c <= 127) {
+ if (c == '\n' || c == '\r') {
+ lineEndChar = c;
+ c = '\n';
+ }
+ } else {
+ if (c == BYTE_ORDER_MARK)
+ return c; // BOM is considered whitespace
+ if (isJSFormatChar(c)) {
+ continue;
+ }
+ if (isJSLineTerminator(c)) {
+ lineEndChar = c;
+ c = '\n';
+ }
+ }
+ return c;
+ }
+ }
- private void ungetCharIgnoreLineEnd(int c) {
- ungetBuffer[ungetCursor++] = c;
- cursor--;
- }
+ private void ungetCharIgnoreLineEnd(int c) {
+ ungetBuffer[ungetCursor++] = c;
+ cursor--;
+ }
- private void skipLine() throws IOException {
- // skip to end of line
- int c;
- while ((c = getChar()) != EOF_CHAR && c != '\n') {
- }
- ungetChar(c);
- tokenEnd = cursor;
- }
+ private void skipLine() throws IOException {
+ // skip to end of line
+ int c;
+ while ((c = getChar()) != EOF_CHAR && c != '\n') {
+ }
+ ungetChar(c);
+ tokenEnd = cursor;
+ }
- /**
- * Returns the offset into the current line.
- */
- final int getOffset() {
- int n = sourceCursor - lineStart;
- if (lineEndChar >= 0) {
- --n;
- }
- return n;
- }
+ /**
+ * Returns the offset into the current line.
+ */
+ final int getOffset() {
+ int n = sourceCursor - lineStart;
+ if (lineEndChar >= 0) {
+ --n;
+ }
+ return n;
+ }
- private final int charAt(int index) {
- if (index < 0) {
- return EOF_CHAR;
- }
- if (sourceString != null) {
- if (index >= sourceEnd) {
- return EOF_CHAR;
- }
- return sourceString.charAt(index);
- } else {
- if (index >= sourceEnd) {
- int oldSourceCursor = sourceCursor;
- try {
- if (!fillSourceBuffer()) {
- return EOF_CHAR;
- }
- } catch (IOException ioe) {
- // ignore it, we're already displaying an error...
- return EOF_CHAR;
- }
- // index recalculuation as fillSourceBuffer can move saved
- // line buffer and change sourceCursor
- index -= (oldSourceCursor - sourceCursor);
- }
- return sourceBuffer[index];
- }
- }
+ private final int charAt(int index) {
+ if (index < 0) {
+ return EOF_CHAR;
+ }
+ if (sourceString != null) {
+ if (index >= sourceEnd) {
+ return EOF_CHAR;
+ }
+ return sourceString.charAt(index);
+ } else {
+ if (index >= sourceEnd) {
+ int oldSourceCursor = sourceCursor;
+ try {
+ if (!fillSourceBuffer()) {
+ return EOF_CHAR;
+ }
+ } catch (IOException ioe) {
+ // ignore it, we're already displaying an error...
+ return EOF_CHAR;
+ }
+ // index recalculuation as fillSourceBuffer can move saved
+ // line buffer and change sourceCursor
+ index -= (oldSourceCursor - sourceCursor);
+ }
+ return sourceBuffer[index];
+ }
+ }
- private final String substring(int beginIndex, int endIndex) {
- if (sourceString != null) {
- return sourceString.substring(beginIndex, endIndex);
- } else {
- int count = endIndex - beginIndex;
- return new String(sourceBuffer, beginIndex, count);
- }
- }
+ private final String substring(int beginIndex, int endIndex) {
+ if (sourceString != null) {
+ return sourceString.substring(beginIndex, endIndex);
+ } else {
+ int count = endIndex - beginIndex;
+ return new String(sourceBuffer, beginIndex, count);
+ }
+ }
- public static boolean isJSLineTerminator(int c) {
- // Optimization for faster check for eol character:
- // they do not have 0xDFD0 bits set
- if ((c & 0xDFD0) != 0) {
- return false;
- }
- return c == '\n' || c == '\r' || c == 0x2028 || c == 0x2029;
- }
+ public static boolean isJSLineTerminator(int c) {
+ // Optimization for faster check for eol character:
+ // they do not have 0xDFD0 bits set
+ if ((c & 0xDFD0) != 0) {
+ return false;
+ }
+ return c == '\n' || c == '\r' || c == 0x2028 || c == 0x2029;
+ }
- final String getLine() {
- int lineEnd = sourceCursor;
- if (lineEndChar >= 0) {
- // move cursor before newline sequence
- lineEnd -= 1;
- if (lineEndChar == '\n' && charAt(lineEnd - 1) == '\r') {
- lineEnd -= 1;
- }
- } else {
- // Read until the end of line
- int lineLength = lineEnd - lineStart;
- for (;; ++lineLength) {
- int c = charAt(lineStart + lineLength);
- if (c == EOF_CHAR || isJSLineTerminator(c)) {
- break;
- }
- }
- lineEnd = lineStart + lineLength;
- }
- return substring(lineStart, lineEnd);
- }
+ final String getLine() {
+ int lineEnd = sourceCursor;
+ if (lineEndChar >= 0) {
+ // move cursor before newline sequence
+ lineEnd -= 1;
+ if (lineEndChar == '\n' && charAt(lineEnd - 1) == '\r') {
+ lineEnd -= 1;
+ }
+ } else {
+ // Read until the end of line
+ int lineLength = lineEnd - lineStart;
+ for (; ; ++lineLength) {
+ int c = charAt(lineStart + lineLength);
+ if (c == EOF_CHAR || isJSLineTerminator(c)) {
+ break;
+ }
+ }
+ lineEnd = lineStart + lineLength;
+ }
+ return substring(lineStart, lineEnd);
+ }
- final String getLine(int position, int[] linep) {
- assert position >= 0 && position <= cursor;
- assert linep.length == 2;
- int delta = (cursor + ungetCursor) - position;
- int cur = sourceCursor;
- if (delta > cur) {
- // requested line outside of source buffer
- return null;
- }
- // read back until position
- int end = 0, lines = 0;
- for (; delta > 0; --delta, --cur) {
- assert cur > 0;
- int c = charAt(cur - 1);
- if (isJSLineTerminator(c)) {
- if (c == '\n' && charAt(cur - 2) == '\r') {
- // \r\n sequence
- delta -= 1;
- cur -= 1;
- }
- lines += 1;
- end = cur - 1;
- }
- }
- // read back until line start
- int start = 0, offset = 0;
- for (; cur > 0; --cur, ++offset) {
- int c = charAt(cur - 1);
- if (isJSLineTerminator(c)) {
- start = cur;
- break;
- }
- }
- linep[0] = lineno - lines + (lineEndChar >= 0 ? 1 : 0);
- linep[1] = offset;
- if (lines == 0) {
- return getLine();
- } else {
- return substring(start, end);
- }
- }
+ final String getLine(int position, int[] linep) {
+ assert position >= 0 && position <= cursor;
+ assert linep.length == 2;
+ int delta = (cursor + ungetCursor) - position;
+ int cur = sourceCursor;
+ if (delta > cur) {
+ // requested line outside of source buffer
+ return null;
+ }
+ // read back until position
+ int end = 0, lines = 0;
+ for (; delta > 0; --delta, --cur) {
+ assert cur > 0;
+ int c = charAt(cur - 1);
+ if (isJSLineTerminator(c)) {
+ if (c == '\n' && charAt(cur - 2) == '\r') {
+ // \r\n sequence
+ delta -= 1;
+ cur -= 1;
+ }
+ lines += 1;
+ end = cur - 1;
+ }
+ }
+ // read back until line start
+ int start = 0, offset = 0;
+ for (; cur > 0; --cur, ++offset) {
+ int c = charAt(cur - 1);
+ if (isJSLineTerminator(c)) {
+ start = cur;
+ break;
+ }
+ }
+ linep[0] = lineno - lines + (lineEndChar >= 0 ? 1 : 0);
+ linep[1] = offset;
+ if (lines == 0) {
+ return getLine();
+ } else {
+ return substring(start, end);
+ }
+ }
- private boolean fillSourceBuffer() throws IOException {
- if (sourceString != null)
- org.mozilla.javascript.Kit.codeBug();
- if (sourceEnd == sourceBuffer.length) {
- if (lineStart != 0 && !isMarkingComment()) {
- System.arraycopy(sourceBuffer, lineStart, sourceBuffer, 0,
- sourceEnd - lineStart);
- sourceEnd -= lineStart;
- sourceCursor -= lineStart;
- lineStart = 0;
- } else {
- char[] tmp = new char[sourceBuffer.length * 2];
- System.arraycopy(sourceBuffer, 0, tmp, 0, sourceEnd);
- sourceBuffer = tmp;
- }
- }
- int n = sourceReader.read(sourceBuffer, sourceEnd, sourceBuffer.length
- - sourceEnd);
- if (n < 0) {
- return false;
- }
- sourceEnd += n;
- return true;
- }
+ private boolean fillSourceBuffer() throws IOException {
+ if (sourceString != null)
+ org.mozilla.javascript.Kit.codeBug();
+ if (sourceEnd == sourceBuffer.length) {
+ if (lineStart != 0 && !isMarkingComment()) {
+ System.arraycopy(sourceBuffer, lineStart, sourceBuffer, 0,
+ sourceEnd - lineStart);
+ sourceEnd -= lineStart;
+ sourceCursor -= lineStart;
+ lineStart = 0;
+ } else {
+ char[] tmp = new char[sourceBuffer.length * 2];
+ System.arraycopy(sourceBuffer, 0, tmp, 0, sourceEnd);
+ sourceBuffer = tmp;
+ }
+ }
+ int n = sourceReader.read(sourceBuffer, sourceEnd, sourceBuffer.length
+ - sourceEnd);
+ if (n < 0) {
+ return false;
+ }
+ sourceEnd += n;
+ return true;
+ }
- /**
- * Return the current position of the scanner cursor.
- */
- public int getCursor() {
- return cursor;
- }
+ /**
+ * Return the current position of the scanner cursor.
+ */
+ public int getCursor() {
+ return cursor;
+ }
- /**
- * Return the absolute source offset of the last scanned token.
- */
- public int getTokenBeg() {
- return tokenBeg;
- }
+ /**
+ * Return the absolute source offset of the last scanned token.
+ */
+ public int getTokenBeg() {
+ return tokenBeg;
+ }
- /**
- * Return the absolute source end-offset of the last scanned token.
- */
- public int getTokenEnd() {
- return tokenEnd;
- }
+ /**
+ * Return the absolute source end-offset of the last scanned token.
+ */
+ public int getTokenEnd() {
+ return tokenEnd;
+ }
- /**
- * Return tokenEnd - tokenBeg
- */
- public int getTokenLength() {
- return tokenEnd - tokenBeg;
- }
+ /**
+ * Return tokenEnd - tokenBeg
+ */
+ public int getTokenLength() {
+ return tokenEnd - tokenBeg;
+ }
- /**
- * Return the type of the last scanned comment.
- *
- * @return type of last scanned comment, or 0 if none have been scanned.
- */
- public Token.CommentType getCommentType() {
- return commentType;
- }
+ /**
+ * Return the type of the last scanned comment.
+ *
+ * @return type of last scanned comment, or 0 if none have been scanned.
+ */
+ public Token.CommentType getCommentType() {
+ return commentType;
+ }
- private boolean isMarkingComment() {
- return commentCursor != -1;
- }
+ private boolean isMarkingComment() {
+ return commentCursor != -1;
+ }
- final String getAndResetCurrentComment() {
- if (sourceString != null) {
- if (isMarkingComment())
- org.mozilla.javascript.Kit.codeBug();
- return sourceString.substring(tokenBeg, tokenEnd);
- } else {
- if (!isMarkingComment())
- Kit.codeBug();
- StringBuilder comment = new StringBuilder(commentPrefix);
- comment.append(sourceBuffer, commentCursor, getTokenLength()
- - commentPrefix.length());
- commentCursor = -1;
- return comment.toString();
- }
- }
+ final String getAndResetCurrentComment() {
+ if (sourceString != null) {
+ if (isMarkingComment())
+ org.mozilla.javascript.Kit.codeBug();
+ return sourceString.substring(tokenBeg, tokenEnd);
+ } else {
+ if (!isMarkingComment())
+ Kit.codeBug();
+ commentCursor = -1;
+ String comment = commentPrefix + String.valueOf(sourceBuffer, commentCursor, getTokenLength()
+ - commentPrefix.length());
+ return comment;
+ }
+ }
- private String convertLastCharToHex(String str) {
- int lastIndex = str.length() - 1;
- StringBuilder buf = new StringBuilder(str.substring(0, lastIndex));
- buf.append("\\u");
- String hexCode = Integer.toHexString(str.charAt(lastIndex));
- for (int i = 0; i < 4 - hexCode.length(); ++i) {
- buf.append('0');
- }
- buf.append(hexCode);
- return buf.toString();
- }
+ private String convertLastCharToHex(String str) {
+ int lastIndex = str.length() - 1;
+ StringBuilder buf = new StringBuilder(str.substring(0, lastIndex));
+ buf.append("\\u");
+ String hexCode = Integer.toHexString(str.charAt(lastIndex));
+ for (int i = 0; i < 4 - hexCode.length(); ++i) {
+ buf.append('0');
+ }
+ buf.append(hexCode);
+ return buf.toString();
+ }
- // stuff other than whitespace since start of line
- private boolean dirtyLine;
+ // stuff other than whitespace since start of line
+ private boolean dirtyLine;
- String regExpFlags;
+ String regExpFlags;
- // Set this to an initial non-null value so that the Parser has
- // something to retrieve even if an error has occurred and no
- // string is found. Fosters one class of error, but saves lots of
- // code.
- private String string = "";
- private double number;
- private boolean isBinary;
- private boolean isOldOctal;
- private boolean isOctal;
- private boolean isHex;
+ // Set this to an initial non-null value so that the Parser has
+ // something to retrieve even if an error has occurred and no
+ // string is found. Fosters one class of error, but saves lots of
+ // code.
+ private String string = "";
+ private double number;
+ private boolean isBinary;
+ private boolean isOldOctal;
+ private boolean isOctal;
+ private boolean isHex;
- // delimiter for last string literal scanned
- private int quoteChar;
+ // delimiter for last string literal scanned
+ private int quoteChar;
- private char[] stringBuffer = new char[128];
- private int stringBufferTop;
- private ObjToIntMap allStrings = new ObjToIntMap(50);
+ private char[] stringBuffer = new char[128];
+ private int stringBufferTop;
+ private final ObjToIntMap allStrings = new ObjToIntMap(50);
- // Room to backtrace from to < on failed match of the last - in
-
-
-
+
+
+
+
-
+ android:name=".App"
+ android:allowBackup="false"
+ android:icon="@mipmap/ic_launcher"
+ android:label="inrt"
+ android:supportsRtl="true"
+ android:theme="@style/ScriptTheme"
+ android:usesCleartextTraffic="true"
+ tools:replace="android:label, android:allowBackup"
+ tools:targetApi="m"
+ tools:ignore="DataExtractionRules">
-
+
+ android:name=".SplashActivity"
+ android:theme="@style/AppTheme.Splash"
+ android:exported="true">
-
+
-
+
-
+
+ android:name="com.stardust.notification.NotificationListenerService"
+ android:label="inrt"
+ android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
+ android:exported="false">
-
+
+ android:name="androidx.core.content.FileProvider"
+ android:authorities="org.autojs.autojs6.inrt.fileprovider"
+ android:exported="false"
+ android:grantUriPermissions="true">
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/provider_paths" />
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/App.kt b/inrt/src/main/java/com/stardust/autojs/inrt/App.kt
similarity index 94%
rename from inrt/src/main/java/com/stardust/auojs/inrt/App.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/App.kt
index 806da5e7..6634dedd 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/App.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/App.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt
+package com.stardust.autojs.inrt
import android.app.Application
import android.graphics.Bitmap
@@ -11,15 +11,14 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.stardust.app.GlobalAppContext
-import com.stardust.auojs.inrt.autojs.AutoJs
-import com.stardust.auojs.inrt.autojs.GlobalKeyObserver
+import com.stardust.autojs.inrt.autojs.AutoJs
+import com.stardust.autojs.inrt.autojs.GlobalKeyObserver
import com.stardust.autojs.core.ui.inflater.ImageLoader
import com.stardust.autojs.core.ui.inflater.util.Drawables
/**
* Created by Stardust on 2017/7/1.
*/
-
class App : Application() {
override fun onCreate() {
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/LogActivity.kt b/inrt/src/main/java/com/stardust/autojs/inrt/LogActivity.kt
similarity index 87%
rename from inrt/src/main/java/com/stardust/auojs/inrt/LogActivity.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/LogActivity.kt
index 37378525..f7406145 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/LogActivity.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/LogActivity.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt
+package com.stardust.autojs.inrt
import android.content.Intent
import android.os.Bundle
@@ -8,8 +8,8 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
-import com.stardust.auojs.inrt.autojs.AutoJs
-import com.stardust.auojs.inrt.launch.GlobalProjectLauncher
+import com.stardust.autojs.inrt.autojs.AutoJs
+import com.stardust.autojs.inrt.launch.GlobalProjectLauncher
import com.stardust.autojs.core.console.ConsoleView
import com.stardust.autojs.core.console.ConsoleImpl
@@ -45,6 +45,6 @@ class LogActivity : AppCompatActivity() {
companion object {
- val EXTRA_LAUNCH_SCRIPT = "launch_script"
+ const val EXTRA_LAUNCH_SCRIPT = "launch_script"
}
}
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/Pref.kt b/inrt/src/main/java/com/stardust/autojs/inrt/Pref.kt
similarity index 97%
rename from inrt/src/main/java/com/stardust/auojs/inrt/Pref.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/Pref.kt
index 0b3af98b..97c75279 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/Pref.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/Pref.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt
+package com.stardust.autojs.inrt
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
@@ -8,7 +8,6 @@ import com.stardust.app.GlobalAppContext
/**
* Created by Stardust on 2017/12/8.
*/
-
object Pref {
private const val KEY_FIRST_USING = "key_first_using"
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/SettingsActivity.kt b/inrt/src/main/java/com/stardust/autojs/inrt/SettingsActivity.kt
similarity index 97%
rename from inrt/src/main/java/com/stardust/auojs/inrt/SettingsActivity.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/SettingsActivity.kt
index d525a877..4d1582f3 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/SettingsActivity.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/SettingsActivity.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt
+package com.stardust.autojs.inrt
import android.os.Bundle
import androidx.annotation.Nullable
@@ -8,7 +8,6 @@ import androidx.appcompat.widget.Toolbar
/**
* Created by Stardust on 2017/12/8.
*/
-
class SettingsActivity : AppCompatActivity() {
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/SplashActivity.kt b/inrt/src/main/java/com/stardust/autojs/inrt/SplashActivity.kt
similarity index 91%
rename from inrt/src/main/java/com/stardust/auojs/inrt/SplashActivity.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/SplashActivity.kt
index 43ded450..fabfa307 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/SplashActivity.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/SplashActivity.kt
@@ -1,10 +1,9 @@
-package com.stardust.auojs.inrt
+package com.stardust.autojs.inrt
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_DENIED
import android.graphics.Typeface
-import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
@@ -12,15 +11,13 @@ import android.widget.TextView
import android.widget.Toast
import androidx.annotation.NonNull
import androidx.annotation.Nullable
-import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
-import com.stardust.auojs.inrt.autojs.AutoJs
-import com.stardust.auojs.inrt.launch.GlobalProjectLauncher
+import com.stardust.autojs.inrt.autojs.AutoJs
+import com.stardust.autojs.inrt.launch.GlobalProjectLauncher
/**
* Created by Stardust on 2018/2/2.
*/
-
class SplashActivity : AppCompatActivity() {
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
@@ -71,7 +68,6 @@ class SplashActivity : AppCompatActivity() {
}
- @RequiresApi(api = Build.VERSION_CODES.M)
private fun getRequestPermissions(permissions: Array): Array {
val list = ArrayList()
for (permission in permissions) {
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/AutoJs.kt b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/AutoJs.kt
similarity index 92%
rename from inrt/src/main/java/com/stardust/auojs/inrt/autojs/AutoJs.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/autojs/AutoJs.kt
index 6104abc4..c77582f0 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/AutoJs.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/AutoJs.kt
@@ -1,12 +1,12 @@
-package com.stardust.auojs.inrt.autojs
+package com.stardust.autojs.inrt.autojs
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.stardust.app.GlobalAppContext
-import com.stardust.auojs.inrt.LogActivity
-import com.stardust.auojs.inrt.R
-import com.stardust.auojs.inrt.SettingsActivity
+import com.stardust.autojs.inrt.LogActivity
+import com.stardust.autojs.inrt.R
+import com.stardust.autojs.inrt.SettingsActivity
import com.stardust.autojs.core.accessibility.AccessibilityServiceTool
import com.stardust.autojs.runtime.ScriptRuntime
import com.stardust.autojs.runtime.api.AppUtils
@@ -19,7 +19,6 @@ import com.stardust.view.accessibility.AccessibilityService
/**
* Created by Stardust on 2017/4/2.
*/
-
class AutoJs private constructor(application: Application) : com.stardust.autojs.AutoJs(application) {
init {
@@ -46,7 +45,7 @@ class AutoJs private constructor(application: Application) : com.stardust.autojs
}
}
- override fun waitForAccessibilityServiceEnabled() {
+ override fun waitForAccessibilityServiceEnabled(timeout: Long) {
if (AccessibilityService.instance != null) {
return
}
@@ -58,7 +57,7 @@ class AutoJs private constructor(application: Application) : com.stardust.autojs
}
if (errorMessage != null) {
getAccessibilityServiceTool().goToAccessibilitySetting()
- if (!AccessibilityService.waitForEnabled(-1)) {
+ if (!AccessibilityService.waitForEnabled(timeout)) {
throw ScriptInterruptedException()
}
}
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/GlobalKeyObserver.kt b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/GlobalKeyObserver.kt
similarity index 97%
rename from inrt/src/main/java/com/stardust/auojs/inrt/autojs/GlobalKeyObserver.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/autojs/GlobalKeyObserver.kt
index 2666bbe0..98279a74 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/GlobalKeyObserver.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/GlobalKeyObserver.kt
@@ -1,10 +1,10 @@
-package com.stardust.auojs.inrt.autojs
+package com.stardust.autojs.inrt.autojs
import android.util.Log
import android.view.KeyEvent
import com.stardust.app.GlobalAppContext
-import com.stardust.auojs.inrt.Pref
+import com.stardust.autojs.inrt.Pref
import com.stardust.autojs.core.inputevent.InputEventObserver
import com.stardust.autojs.core.inputevent.ShellKeyObserver
import com.stardust.view.accessibility.AccessibilityService
@@ -13,7 +13,6 @@ import com.stardust.view.accessibility.OnKeyListener
/**
* Created by Stardust on 2017/8/14.
*/
-
class GlobalKeyObserver internal constructor() : OnKeyListener, ShellKeyObserver.KeyListener {
private var mVolumeDownFromShell: Boolean = false
private var mVolumeDownFromAccessibility: Boolean = false
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/ScriptExecutionGlobalListener.kt b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/ScriptExecutionGlobalListener.kt
similarity index 93%
rename from inrt/src/main/java/com/stardust/auojs/inrt/autojs/ScriptExecutionGlobalListener.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/autojs/ScriptExecutionGlobalListener.kt
index 753fd97e..94b01e10 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/ScriptExecutionGlobalListener.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/ScriptExecutionGlobalListener.kt
@@ -1,14 +1,13 @@
-package com.stardust.auojs.inrt.autojs
+package com.stardust.autojs.inrt.autojs
import com.stardust.app.GlobalAppContext
-import com.stardust.auojs.inrt.R
+import com.stardust.autojs.inrt.R
import com.stardust.autojs.execution.ScriptExecution
import com.stardust.autojs.execution.ScriptExecutionListener
/**
* Created by Stardust on 2017/5/3.
*/
-
class ScriptExecutionGlobalListener : ScriptExecutionListener {
override fun onStart(execution: ScriptExecution) {
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/XJavaScriptEngine.kt b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/XJavaScriptEngine.kt
similarity index 97%
rename from inrt/src/main/java/com/stardust/auojs/inrt/autojs/XJavaScriptEngine.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/autojs/XJavaScriptEngine.kt
index 75e95481..cbd970ed 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/autojs/XJavaScriptEngine.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/autojs/XJavaScriptEngine.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt.autojs
+package com.stardust.autojs.inrt.autojs
import android.content.Context
import com.stardust.autojs.engine.LoopBasedJavaScriptEngine
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/launch/AssetsProjectLauncher.kt b/inrt/src/main/java/com/stardust/autojs/inrt/launch/AssetsProjectLauncher.kt
similarity index 93%
rename from inrt/src/main/java/com/stardust/auojs/inrt/launch/AssetsProjectLauncher.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/launch/AssetsProjectLauncher.kt
index 5adbbe31..4c8d4721 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/launch/AssetsProjectLauncher.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/launch/AssetsProjectLauncher.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt.launch
+package com.stardust.autojs.inrt.launch
import android.app.Activity
import android.content.Context
@@ -6,30 +6,25 @@ import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
-
-import com.stardust.auojs.inrt.BuildConfig
-import com.stardust.auojs.inrt.LogActivity
-import com.stardust.auojs.inrt.Pref
-import com.stardust.auojs.inrt.autojs.AutoJs
import com.stardust.autojs.engine.encryption.ScriptEncryption
import com.stardust.autojs.execution.ExecutionConfig
import com.stardust.autojs.execution.ScriptExecution
+import com.stardust.autojs.inrt.BuildConfig
+import com.stardust.autojs.inrt.LogActivity
+import com.stardust.autojs.inrt.Pref
+import com.stardust.autojs.inrt.autojs.AutoJs
import com.stardust.autojs.project.ProjectConfig
import com.stardust.autojs.script.JavaScriptFileSource
import com.stardust.autojs.script.JavaScriptSource
-import com.stardust.autojs.script.ScriptSource
import com.stardust.pio.PFiles
import com.stardust.pio.UncheckedIOException
import com.stardust.util.MD5
-
import java.io.File
import java.io.IOException
-import java.lang.reflect.Field
/**
* Created by Stardust on 2018/1/24.
*/
-
open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private val mActivity: Context) {
private val mProjectDir: String = File(mActivity.filesDir, "project/").path
private val mProjectConfig: ProjectConfig = ProjectConfig.fromAssets(mActivity, ProjectConfig.configFileOfDir(mAssetsProjectDir))
diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/launch/GlobalProjectLauncher.kt b/inrt/src/main/java/com/stardust/autojs/inrt/launch/GlobalProjectLauncher.kt
similarity index 86%
rename from inrt/src/main/java/com/stardust/auojs/inrt/launch/GlobalProjectLauncher.kt
rename to inrt/src/main/java/com/stardust/autojs/inrt/launch/GlobalProjectLauncher.kt
index 20742c8c..98a6d59e 100644
--- a/inrt/src/main/java/com/stardust/auojs/inrt/launch/GlobalProjectLauncher.kt
+++ b/inrt/src/main/java/com/stardust/autojs/inrt/launch/GlobalProjectLauncher.kt
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt.launch
+package com.stardust.autojs.inrt.launch
import android.annotation.SuppressLint
import com.stardust.app.GlobalAppContext
@@ -6,6 +6,5 @@ import com.stardust.app.GlobalAppContext
/**
* Created by Stardust on 2018/3/21.
*/
-
@SuppressLint("StaticFieldLeak")
object GlobalProjectLauncher: AssetsProjectLauncher("project", GlobalAppContext.get())
diff --git a/inrt/src/test/java/com/stardust/auojs/inrt/ExampleUnitTest.java b/inrt/src/test/java/com/stardust/autojs/inrt/ExampleUnitTest.java
similarity index 92%
rename from inrt/src/test/java/com/stardust/auojs/inrt/ExampleUnitTest.java
rename to inrt/src/test/java/com/stardust/autojs/inrt/ExampleUnitTest.java
index 4defcd24..c0522461 100644
--- a/inrt/src/test/java/com/stardust/auojs/inrt/ExampleUnitTest.java
+++ b/inrt/src/test/java/com/stardust/autojs/inrt/ExampleUnitTest.java
@@ -1,4 +1,4 @@
-package com.stardust.auojs.inrt;
+package com.stardust.autojs.inrt;
import com.stardust.util.AdvancedEncryptionStandard;
@@ -6,8 +6,6 @@ import org.junit.Test;
import java.util.Arrays;
-import static org.junit.Assert.*;
-
/**
* Example local unit test, which will execute on the development machine (host).
*
diff --git a/libs/com.tencent.bugly.crashreport-2.6.6/build.gradle b/libs/com.tencent.bugly.crashreport-2.6.6/build.gradle
deleted file mode 100644
index 5d7b73f7..00000000
--- a/libs/com.tencent.bugly.crashreport-2.6.6/build.gradle
+++ /dev/null
@@ -1,2 +0,0 @@
-configurations.maybeCreate('default')
-artifacts.add('default', file('crashreport-2.6.6.aar'))
\ No newline at end of file
diff --git a/libs/com.tencent.bugly.crashreport-2.6.6/crashreport-2.6.6.aar b/libs/com.tencent.bugly.crashreport-2.6.6/crashreport-2.6.6.aar
deleted file mode 100644
index 82a86732..00000000
Binary files a/libs/com.tencent.bugly.crashreport-2.6.6/crashreport-2.6.6.aar and /dev/null differ
diff --git a/libs/com.tencent.bugly.crashreport-4.0.4/build.gradle b/libs/com.tencent.bugly.crashreport-4.0.4/build.gradle
new file mode 100644
index 00000000..d4eeee95
--- /dev/null
+++ b/libs/com.tencent.bugly.crashreport-4.0.4/build.gradle
@@ -0,0 +1,2 @@
+configurations.maybeCreate('default')
+artifacts.add('default', file('crashreport-4.0.4.aar'))
\ No newline at end of file
diff --git a/libs/com.tencent.bugly.crashreport-4.0.4/crashreport-4.0.4.aar b/libs/com.tencent.bugly.crashreport-4.0.4/crashreport-4.0.4.aar
new file mode 100644
index 00000000..4fe38d96
Binary files /dev/null and b/libs/com.tencent.bugly.crashreport-4.0.4/crashreport-4.0.4.aar differ
diff --git a/libs/org.mozilla.rhino-1.7.14/build.gradle b/libs/org.mozilla.rhino-1.7.14/build.gradle
deleted file mode 100644
index 1386eba5..00000000
--- a/libs/org.mozilla.rhino-1.7.14/build.gradle
+++ /dev/null
@@ -1,8 +0,0 @@
-tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
- kotlinOptions {
- jvmTarget = JavaVersion.VERSION_16
- }
-}
-
-configurations.maybeCreate('default')
-artifacts.add('default', file('rhino-1.7.14.jar'))
\ No newline at end of file
diff --git a/libs/org.mozilla.rhino-1.7.14/rhino-1.7.14.jar b/libs/org.mozilla.rhino-1.7.14/rhino-1.7.14.jar
deleted file mode 100644
index 63532d7d..00000000
Binary files a/libs/org.mozilla.rhino-1.7.14/rhino-1.7.14.jar and /dev/null differ
diff --git a/libs/org.mozilla.rhino-1.7.15-snapshot/build.gradle b/libs/org.mozilla.rhino-1.7.15-snapshot/build.gradle
new file mode 100644
index 00000000..a31341f9
--- /dev/null
+++ b/libs/org.mozilla.rhino-1.7.15-snapshot/build.gradle
@@ -0,0 +1,2 @@
+configurations.maybeCreate('default')
+artifacts.add('default', file('rhino-1.7.15-SNAPSHOT.jar'))
\ No newline at end of file
diff --git a/libs/org.mozilla.rhino-1.7.15-snapshot/rhino-1.7.15-SNAPSHOT.jar b/libs/org.mozilla.rhino-1.7.15-snapshot/rhino-1.7.15-SNAPSHOT.jar
new file mode 100644
index 00000000..2017eaf3
Binary files /dev/null and b/libs/org.mozilla.rhino-1.7.15-snapshot/rhino-1.7.15-SNAPSHOT.jar differ
diff --git a/libs/org.opencv-4.5.5/build.gradle b/libs/org.opencv-4.5.5/build.gradle
index a85fe299..19a50a38 100644
--- a/libs/org.opencv-4.5.5/build.gradle
+++ b/libs/org.opencv-4.5.5/build.gradle
@@ -1,2 +1,5 @@
configurations.maybeCreate('default')
-artifacts.add('default', file('opencv-4.5.5.aar'))
\ No newline at end of file
+artifacts.add('default',
+ // @Reference to TonyJiangWJ/Auto.js on Mar 18, 2022.
+ file('opencv-4.5.5.aar')
+)
\ No newline at end of file
diff --git a/project-versions.json b/project-versions.json
deleted file mode 100644
index 6d4c0dc3..00000000
--- a/project-versions.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "appVersionCode": 751,
- "appVersionName": "6.0.3",
- "appSinceDate": "Mar 31, 2022",
- "target": 28,
- "mini": 24,
- "compile": 32
-}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 6c0840d6..637fbcf1 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,11 +1,11 @@
include ':app', ':automator', ':common', ':autojs', ':inrt'
include ':libs:com.android.dx-1.7.0'
-include ':libs:com.tencent.bugly.crashreport-2.6.6'
+include ':libs:com.tencent.bugly.crashreport-4.0.4'
include ':libs:com.zeugmasolutions.localehelper-1.5.1'
include ':libs:jackpal.androidterm.emulatorview-1.0.42'
include ':libs:jackpal.androidterm.libtermexec-1.0'
include ':libs:jackpal.androidterm-1.0.70'
-include ':libs:org.mozilla.rhino-1.7.14'
+include ':libs:org.mozilla.rhino-1.7.15-snapshot'
include ':libs:org.opencv-4.5.5'
include ':libs:androidx.appcompat-1.0.2'
\ No newline at end of file
diff --git a/version.properties b/version.properties
new file mode 100644
index 00000000..963457bf
--- /dev/null
+++ b/version.properties
@@ -0,0 +1,8 @@
+#Thu May 26 18:59:04 CST 2022
+BUILD_TIME=1653562744879
+COMPILE_SDK_VERSION=32
+JAVA_VERSION=17
+MIN_SDK_VERSION=24
+TARGET_SDK_VERSION=32
+VERSION_BUILD=886
+VERSION_NAME=6.1.0