-public class JSArray extends JS.O {
- private static final Object NULL = new Object();
- private final BalancedTree bt = new BalancedTree();
-
- public JSArray() { }
- public JSArray(int size) { setSize(size); }
-
- /*private static int intVal(Object o) {
- if (o instanceof Number) {
- int intVal = ((Number)o).intValue();
- if (intVal == ((Number)o).doubleValue()) return intVal;
- return Integer.MIN_VALUE;
- }
- if (!(o instanceof String)) return Integer.MIN_VALUE;
- String s = (String)o;
- for(int i=0; i<s.length(); i++) if (s.charAt(i) < '0' || s.charAt(i) > '9') return Integer.MIN_VALUE;
- return Integer.parseInt(s);
- }*/
-
- public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
- //#switch(JS.toString(method))
- case "pop": {
- int oldSize = size();
- if(oldSize == 0) return null;
- return removeElementAt(oldSize-1);
+class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
+ private static final JS.Method METHOD = new JS.Method();
+ private static final String[] empty = new String[0];
+
+ JSArray() { }
+ JSArray(int size) { super(size); }
+ JSArray(JS[] args) { super(args.length); addAll(args); }
+ JSArray(JS arg) { super(1); add(arg); }
+
+ public JS unclone() { return this; }
+ public JS.Enumeration keys() throws JSExn {
+ return new Enumeration(null) {
+ private int n = 0;
+ public boolean _hasNext() { return n < size(); }
+ public JS _next() { return JSU.N(n++); }
+ };
+ }
+ public JS get(JS key) throws JSExn {
+ if (key == null || !(key instanceof JSNumber.I)) {
+ //#switch(JSU.str(key))
+ case "pop": return METHOD;
+ case "reverse": return METHOD;
+ case "toString": return METHOD;
+ case "shift": return METHOD;
+ case "join": return METHOD;
+ case "sort": return METHOD;
+ case "slice": return METHOD;
+ case "push": return METHOD;
+ case "unshift": return METHOD;
+ case "splice": return METHOD;
+ case "length": return JSU.N(size());
+ //#end
+ throw new JSExn("arrays only support positive integer keys, can not use: "+JSU.str(key));