X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2Fjs%2FCompiledFunctionImpl.java;h=366ff8c61c92bc68e4dcf8f08602928af6f1432d;hb=52ffc2a48fc74d013ae7fa401d9d0d405543c38e;hp=09374a396fe0e95fe4b2de0f1c1bbaa6e374fdc6;hpb=bbb487fd11dbe2f295f4b729ca55b6cdc22cea16;p=org.ibex.core.git diff --git a/src/org/xwt/js/CompiledFunctionImpl.java b/src/org/xwt/js/CompiledFunctionImpl.java index 09374a3..366ff8c 100644 --- a/src/org/xwt/js/CompiledFunctionImpl.java +++ b/src/org/xwt/js/CompiledFunctionImpl.java @@ -223,7 +223,7 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { } Object ret = null; if (o == null) throw je("tried to get property \"" + v + "\" from the null value"); - if (v == null) throw je("tried to get the null key from " + v); + if (v == null) throw je("tried to get the null key from " + o); if (o instanceof String) { ret = getFromString((String)o, v); } else if (o instanceof Boolean) { @@ -331,6 +331,7 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { boolean ret; if (l == null) { Object tmp = r; r = l; l = tmp; } if (l == null && r == null) ret = true; + else if (r == null) ret = false; // l != null, so its false else if (l instanceof Boolean) ret = new Boolean(JS.toBoolean(r)).equals(l); else if (l instanceof Number) ret = JS.toNumber(r).doubleValue() == JS.toNumber(l).doubleValue(); else if (l instanceof String) ret = r != null && l.equals(r.toString()); @@ -379,6 +380,38 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { if (args.length() != 1) return null; return new Integer(((String)o).indexOf(args.elementAt(0).toString())); } }; + // This is just a quick and dirty split implementation. its could be optimized a lot and it doesn't + // do regexps yet. this will need to be rewritten when we get regexp support anyway + else if (v.equals("split")) return new JS.Callable() { + public Object call(JS.Array args) { + String sep; + int limit, s,p,matches=0; + int seplen; + JS.Array ret; + + if(args.length() > 1) limit = JS.toNumber(args.elementAt(1)).intValue(); + else limit = 0; + if(args.length() > 0) sep = args.elementAt(0).toString(); + else sep = null; + + seplen = sep!=null ? sep.length() : 0; + + // special case sep == null, split up chars + if(seplen == 0) { + ret = new JS.Array(o.length()); + for(int i=0;i