-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt.js;
import org.xwt.util.*;
import java.io.*;
import java.util.*;
+// FIXME: should allow parentScope to be a JS, not a JSScope
/** Implementation of a JavaScript Scope */
public class JSScope extends JS {
private static final Object NULL_PLACEHOLDER = new Object();
public JSScope(JSScope parentScope) { this.parentScope = parentScope; }
- public void declare(String s) { super.put(s, NULL_PLACEHOLDER); }
+ public void declare(String s) throws JSExn { super.put(s, NULL_PLACEHOLDER); }
public JSScope getParentScope() { return parentScope; }
- public Object get(Object key) {
+ public Object get(Object key) throws JSExn {
Object 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) { return super.get(key) != null; }
- public void put(Object key, Object val) {
+ public boolean has(Object key) throws JSExn { return super.get(key) != null; }
+ public void put(Object key, Object val) throws JSExn {
if (parentScope != null && !has(key)) parentScope.put(key, val);
else super.put(key, val == null ? NULL_PLACEHOLDER : val);
}
+
+ public JSScope top() {
+ JSScope s = this;
+ while(s.parentScope != null) s = s.parentScope;
+ return s;
+ }
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);
public Global() { super(null); }
- public Object get(Object key) {
+ public Object get(Object key) throws JSExn {
//#switch(key)
case "NaN": return NaN;
case "Infinity": return POSITIVE_INFINITY;
return super.get(key);
}
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+ public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
switch(nargs) {
case 0: {
//#switch(method)