1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 /** Implementation of a JavaScript Scope */
9 class ScopeImpl extends JS.Obj {
10 private JS.Scope parentScope;
11 private static Object NULL_PLACEHOLDER = new Object();
12 public ScopeImpl(JS.Scope parentScope, boolean sealed) {
14 if (parentScope == this) throw new Error("can't make a scope its own parent!");
15 this.parentScope = parentScope;
17 public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); }
18 public boolean has(Object key) { return super.get(key) != null; }
19 // we use _get instead of get solely to work around a GCJ bug
20 public Object _get(Object key) {
21 if (!has(key)) return parentScope == null ? null : parentScope.get(key);
22 Object ret = super.get(key); return ret == NULL_PLACEHOLDER ? null : ret;
24 // we use _put instead of put solely to work around a GCJ bug
25 public void _put(Object key, Object val) {
26 if (!has(key) && parentScope != null) parentScope.put(key, val);
27 else super.put(key, val == null ? NULL_PLACEHOLDER : val);
29 public boolean isTransparent() { return false; }
30 public void declare(String s) {
31 if (isTransparent()) parentScope.declare(s);
32 else super.put(s, NULL_PLACEHOLDER);
34 public Scope getParentScope() { return parentScope; }