X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FArrayImpl.java;h=84b33d1a2c406d1cb8da5a5079b54374d7d3fc9a;hb=8235361e8601ae7b36ab707058de3b52225d15a2;hp=40bc873c94aed04cea0e5b47470b3f96b10c7fbc;hpb=32473bd956f9bca69cfa7f860d65e4e2b439046f;p=org.ibex.core.git diff --git a/src/org/xwt/js/ArrayImpl.java b/src/org/xwt/js/ArrayImpl.java index 40bc873..84b33d1 100644 --- a/src/org/xwt/js/ArrayImpl.java +++ b/src/org/xwt/js/ArrayImpl.java @@ -5,8 +5,6 @@ import org.xwt.util.*; import java.io.*; import java.util.*; -// FIXME: could use some cleaning up... - /** A JavaScript Array */ class ArrayImpl extends JS.Obj { private Vec vec = new Vec(); @@ -23,12 +21,49 @@ class ArrayImpl extends JS.Obj { for(int i=0; i '9') return Integer.MIN_VALUE; return Integer.parseInt(s); } + + public Object callMethod(Object method, JS.Array args,boolean justChecking) { + if(method.equals("push")) { + if(justChecking) return Boolean.TRUE; + for(int i=0;i 0) { + Object o = vec.elementAt(0); + vec.removeElementAt(0); + return o; + } else { + return null; + } + } + if(method.equals("unshift")) { + if(justChecking) return Boolean.TRUE; + // FEATURE: could be optimized a bit with some help from Vec + for(int i=0;i=0;i--) + vec.addElement(oldVec.elementAt(i)); + return this; + } + + private Object slice(JS.Array args) { + int length = length(); + int start = JS.toInt(args.length() < 1 ? null : args.elementAt(0)); + int end = args.length() < 2 ? length : JS.toInt(args.elementAt(1)); + if(start < 0) start = length+start; + if(end < 0) end = length+end; + if(start < 0) start = 0; + if(end < 0) end = 0; + if(start > length) start = length; + if(end > length) end = length; + JS.Array a = new JS.Array(end-start); + for(int i=0;i oldLength) start = oldLength; + if(deleteCount < 0) deleteCount = 0; + if(deleteCount > oldLength-start) deleteCount = oldLength-start; + int newLength = oldLength - deleteCount + newCount; + int lengthChange = newLength - oldLength; + JS.Array ret = new JS.Array(deleteCount); + for(int i=0;i 0) { + setSize(newLength); + for(int i=newLength-1;i>=start+newCount;i--) + setElementAt(elementAt(i-lengthChange),i); + } else if(lengthChange < 0) { + for(int i=start+newCount;i