-
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- //#switch(method)
- case "pop": {
- int oldSize = size();
- if(oldSize == 0) return null;
- return removeElementAt(oldSize-1);
- }
- case "reverse": return reverse();
+ public void put(JS key, JS val) throws JSExn {
+ if (JSU.str(key).equals("length")) { setSize(JSU.toInt(val)); }
+
+ if (key == null || !(key instanceof JSNumber.I)) throw new JSExn(
+ "arrays only support positive integer keys, can not use: "+JSU.str(key));
+ int i = ((JSNumber.I)key).toInt();
+ if (i < 0) throw new JSExn("arrays can not use negative integer keys "+i);
+ size(i + 1); while (size() < i) add(null);
+ set(i, val);
+ }
+ public InputStream getInputStream() { return null; }
+
+ public String[] getFormalArgs() { return empty; }
+ public String coerceToString() { return "array"; } // FIXME
+
+ public boolean hasKey(JS key) {
+ if (key == null || !(key instanceof JSNumber.I)) return false;
+ int i = ((JSNumber.I)key).toInt();
+ return 0 <= i && i < size();
+ }
+
+ public Object run(Object o) throws JSExn { return call(null); }
+ public void pause() throws NotPausableException { throw new NotPausableException(); }
+ public JS call(JS[] args) throws JSExn { throw new JSExn("can not call an array as a function"); }
+ public JS call(JS method, JS[] args) throws JSExn {
+ //#switch(JSU.str(method))
+ case "pop": return size() == 0 ? null : (JS)remove(size() - 1);
+ case "push": addAll(args); return JSU.N(size());
+ case "reverse": reverse(); return this;