From: megacz Date: Fri, 30 Jan 2004 07:41:36 +0000 (+0000) Subject: 2003/11/17 01:53:25 X-Git-Tag: RC3~342 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=8c1756ef3fd42cc2f324baf47e13a83f51045efe 2003/11/17 01:53:25 darcs-hash:20040130074136-2ba56-23f7e0eb79a2ee30722d69fc7140bdf5d031cd45.gz --- diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index e9a9465..0652e09 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -185,10 +185,8 @@ public abstract class Res extends JS { int ret = super.read(b, off, len); if (ret != 1) bytesDownloaded += ret; Scheduler.add(new Scheduler.Task() { public void perform() { - JSArray args = new JSArray(); - args.addElement(new Integer(bytesDownloaded)); - args.addElement(new Integer(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0)); - callback.call(args); + callback.call(N(bytesDownloaded), + N(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0), null, null, 2); } }); return ret; } diff --git a/src/org/xwt/SOAP.java b/src/org/xwt/SOAP.java index 4ffb8a0..113e01b 100644 --- a/src/org/xwt/SOAP.java +++ b/src/org/xwt/SOAP.java @@ -43,7 +43,7 @@ class SOAP extends XMLRPC { if (name.equals("SOAP-ENV:Fault")) fault = true; // add a generic struct; we'll change this if our type is different - objects.addElement(new JSObj()); + objects.addElement(new JS()); for(int i=0; i 0) { - Object o = vec.elementAt(0); - vec.removeElementAt(0); - return o; - } else { - return null; - } - } - if(method.equals("unshift")) { - // FEATURE: could be optimized a bit with some help from Vec - for(int i=0;i=0;i--) - vec.addElement(oldVec.elementAt(i)); + for(int i=size-1;i>=0;i--) vec.addElement(oldVec.elementAt(i)); return this; } - private Object slice(JSArray args) { + private Object slice(int start, int end) { 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; @@ -145,8 +151,7 @@ public class JSArray extends JSCallable { return JS.toString(a).compareTo(JS.toString(b)); } }; - private Object sort(JSArray args) { - Object tmp = args.length() < 1 ? null : args.elementAt(0); + private Object sort(Object tmp) { if(tmp instanceof JSCallable) { final JSArray funcArgs = new JSArray(2); final JSCallable jsFunc = (JSCallable) tmp; @@ -154,7 +159,7 @@ public class JSArray extends JSCallable { public int compare(Object a, Object b) { funcArgs.setElementAt(a,0); funcArgs.setElementAt(b,1); - return JS.toInt(jsFunc.call(null, funcArgs)); + return JS.toInt(jsFunc.call(a, b, null, null, 2)); } }); } else { diff --git a/src/org/xwt/js/JSCallable.java b/src/org/xwt/js/JSCallable.java index 8865f3b..c9c09d0 100644 --- a/src/org/xwt/js/JSCallable.java +++ b/src/org/xwt/js/JSCallable.java @@ -1,35 +1,18 @@ package org.xwt.js; /** anything that is callable with the () operator and wasn't compiled from JS code */ -public abstract class JSCallable extends JSObj { - public Object call0(Object method) throws JS.Exn { - JSArray args = new JSArray(); - return call(method, args); - } - public Object call1(Object method, Object arg1) throws JS.Exn { - JSArray args = new JSArray(); - args.addElement(arg1); - return call(method, args); - } - public Object call2(Object method, Object arg1, Object arg2) throws JS.Exn { - JSArray args = new JSArray(); - args.addElement(arg1); - args.addElement(arg2); - return call(method, args); +public abstract class JSCallable extends JS { + + // return this from get() if the key was actually a method. + public static final Object METHOD = new Object(); + + public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) { + throw new JS.Exn("attempted to call an undefined method"); } - public Object call(Object method, JSArray args) throws JS.Exn { - if (method != null) { - Object meth = get(method); - if (meth == null) throw new JS.Exn("attempt to invoke the null method"); - if (!(meth instanceof JSCallable)) throw new JS.Exn("cannot call a " + meth.getClass().getName()); - switch (args.size()) { - case 0: return ((JSCallable)meth).call0(null); - case 1: return ((JSCallable)meth).call1(null, args.elementAt(0)); - case 2: return ((JSCallable)meth).call2(null, args.elementAt(0), args.elementAt(1)); - default: return ((JSCallable)meth).call(null, args); - } - } - throw new JS.Exn("cannot invoke method " + method + " on object " + this.getClass().getName() + " with " + args.size() + " arguments"); + + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + throw new JS.Exn("you cannot call this object"); } + } diff --git a/src/org/xwt/js/JSDate.java b/src/org/xwt/js/JSDate.java index 37624b4..901ee9d 100644 --- a/src/org/xwt/js/JSDate.java +++ b/src/org/xwt/js/JSDate.java @@ -46,6 +46,7 @@ import java.text.SimpleDateFormat; * This class implements the Date native object. * See ECMA 15.9. * @author Mike McCabe + * @author Adam Megacz (many modifications */ public class JSDate extends JSCallable { @@ -60,207 +61,118 @@ public class JSDate extends JSCallable { public String coerceToString() { return date_format(date, FORMATSPEC_FULL); } - public Object call(Object name, JSArray args_) { - Object[] args = new Object[args_.length()]; - for(int i=0; iunpauseable context. */ - public Object call(JSArray args) { + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { JSContext cx = new JSContext(this, false); + JSArray args = new JSArray(); + if (nargs > 0) args.addElement(a0); + if (nargs > 1) args.addElement(a1); + if (nargs > 2) args.addElement(a2); + for(int i=3; i= s.length()) { @@ -117,11 +118,11 @@ public class JSRegexp extends JSCallable { public String toString() { StringBuffer sb = new StringBuffer(); sb.append('/'); - sb.append(_get("source")); + sb.append(get("source")); sb.append('/'); if(global) sb.append('g'); - if(Boolean.TRUE.equals(_get("ignoreCase"))) sb.append('i'); - if(Boolean.TRUE.equals(_get("multiline"))) sb.append('m'); + if(Boolean.TRUE.equals(get("ignoreCase"))) sb.append('i'); + if(Boolean.TRUE.equals(get("multiline"))) sb.append('m'); return sb.toString(); } diff --git a/src/org/xwt/js/JSScope.java b/src/org/xwt/js/JSScope.java index 54dc446..44bfec1 100644 --- a/src/org/xwt/js/JSScope.java +++ b/src/org/xwt/js/JSScope.java @@ -34,39 +34,61 @@ public class JSScope extends JSCallable { private final static Double NaN = new Double(Double.NaN); private final static Double POSITIVE_INFINITY = new Double(Double.POSITIVE_INFINITY); - public Global(JSScope parent) { - super(parent); - } - public Object get(Object key) { - if(key.equals("NaN")) return NaN; - if(key.equals("Infinity")) return POSITIVE_INFINITY; - if(key.equals("undefined")) return null; - return super.get(key); - } - - public Object call(Object method, JSArray args) { - if (method.equals("stringFromCharCode")) return stringFromCharCode(args); - return super.call(method, args); - } + public Global(JSScope parent) { super(parent); } - public Object call1(Object method, Object arg0) { - //#switch(method) - case "parseInt": return parseInt(arg0, N(0)); - case "isNaN": { double d = toDouble(arg0); return d == d ? F : T; } - case "isFinite": { double d = toDouble(arg0); return (d == d && !Double.isInfinite(d)) ? T : F; } - case "decodeURI": throw new JS.Exn("unimplemented"); - case "decodeURIComponent": throw new JS.Exn("unimplemented"); - case "encodeURI": throw new JS.Exn("unimplemented"); - case "encodeURIComponent": throw new JS.Exn("unimplemented"); - case "escape": throw new JS.Exn("unimplemented"); - case "unescape": throw new JS.Exn("unimplemented"); + public Object get(Object key) { + //#switch(key) + case "NaN": return NaN; + case "Infinity": return POSITIVE_INFINITY; + case "undefined": return null; + case "stringFromCharCode": return METHOD; + case "parseInt": return METHOD; + case "isNaN": return METHOD; + case "isFinite": return METHOD; + case "decodeURI": return METHOD; + case "decodeURIComponent": return METHOD; + case "encodeURI": return METHOD; + case "encodeURIComponent": return METHOD; + case "escape": return METHOD; + case "unescape": return METHOD; + case "parseInt": return METHOD; //#end - return super.call1(method, arg0); + return super.get(key); } - public Object call2(Object method, Object arg1, Object arg2) { - if (method.equals("parseInt")) return parseInt(arg1, arg2); - return super.call2(method, arg1, arg2); + public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) { + switch(nargs) { + case 0: { + //#switch(method) + case "stringFromCharCode": + JSArray args = new JSArray(); + for(int i=0; i