package org.ibex.js;
// FIXME: should allow parentScope to be a JS, not a JSScope
+// FIXME: Index local vars by number and lookup in an array
/** Implementation of a JavaScript Scope */
-public class JSScope extends JS {
+// HACK: JSScope doesn't really need the BT, this is just for Box.java
+public class JSScope extends JS.BT {
private JSScope parentScope;
- private static final Object NULL_PLACEHOLDER = new Object();
+ private static final JS NULL_PLACEHOLDER = new JS() { };
public JSScope(JSScope parentScope) { this.parentScope = parentScope; }
- public void declare(String s) throws JSExn { super.put(s, NULL_PLACEHOLDER); }
+ public void declare(JS s) throws JSExn { super.put(s, NULL_PLACEHOLDER); }
public JSScope getParentScope() { return parentScope; }
- public Object get(Object key) throws JSExn {
- Object o = super.get(key);
+ public JS get(JS key) throws JSExn {
+ JS o = super.get(key);
if (o != null) return o == NULL_PLACEHOLDER ? null : o;
else return parentScope == null ? null : parentScope.get(key);
}
- public boolean has(Object key) throws JSExn { return super.get(key) != null; }
- public void put(Object key, Object val) throws JSExn {
+ public boolean has(JS key) throws JSExn { return super.get(key) != null; }
+ public void put(JS key, JS val) throws JSExn {
if (parentScope != null && !has(key)) parentScope.put(key, val);
else super.put(key, val == null ? NULL_PLACEHOLDER : val);
}
return s;
}
- public static class Global extends JSScope {
+ // FIXME: Update this for new API, it also has some other problems
+ /*public static class Global extends JSScope {
private final static Double NaN = new Double(Double.NaN);
private final static Double POSITIVE_INFINITY = new Double(Double.POSITIVE_INFINITY);
case "undefined": return null;
case "stringFromCharCode": return METHOD;
case "parseInt": return METHOD;
+ case "parseFloat": return METHOD;
case "isNaN": return METHOD;
case "isFinite": return METHOD;
case "decodeURI": return METHOD;
case "encodeURIComponent": return METHOD;
case "escape": return METHOD;
case "unescape": return METHOD;
- case "parseInt": return METHOD;
//#end
return super.get(key);
}
case 1: {
//#switch(method)
case "parseInt": return parseInt(a0, N(0));
+ case "parseFloat": return parseFloat(a0);
case "isNaN": { double d = toDouble(a0); return d == d ? F : T; }
case "isFinite": { double d = toDouble(a0); return (d == d && !Double.isInfinite(d)) ? T : F; }
case "decodeURI": throw new JSExn("unimplemented");
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
- private Object parseInt(Object arg, Object r) {
+ private Object parseInt(Object arg, Object r) throws JSExn {
int radix = JS.toInt(r);
- String s = (String)arg;
+ String s = JS.toString(arg);
int start = 0;
int length = s.length();
int sign = 1;
return JS.N((long)sign*n);
}
- private Object parseFloat(Object arg) {
- String s = (String)arg;
+ private Object parseFloat(Object arg) throws JSExn {
+ String s = JS.toString(arg);
int start = 0;
int length = s.length();
while(start < length && Character.isWhitespace(s.charAt(0))) start++;
}
return NaN;
}
- }
+ }*/
}