1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 /** A JavaScript Scope */
9 class ScopeImpl extends JS.Obj {
10 private JS.Scope parentScope;
11 private static Object NULL = new Object();
12 public ScopeImpl(JS.Scope parentScope) { this(parentScope, false); }
13 public ScopeImpl(JS.Scope parentScope, boolean sealed) {
15 if (parentScope == this) throw new Error("can't make a scope its own parent!");
16 this.parentScope = parentScope;
18 public JS.Scope getParentScope() { return parentScope; }
20 // transparent scopes are not returned by THIS
21 public boolean isTransparent() { return false; }
23 public boolean has(Object key) { return super.get(key) != null; }
24 public Object get(Object key) {
25 if (!has(key)) return parentScope == null ? null : getParentScope().get(key);
26 Object ret = super.get(key); return ret == NULL ? null : ret;
28 public void put(Object key, Object val) {
29 if (!has(key) && parentScope != null) getParentScope().put(key, val);
30 else super.put(key, val == null ? NULL : val);
32 public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); }
33 public void declare(String s) {
34 if (isTransparent()) getParentScope().declare(s);
35 else super.put(s, NULL);