1
2
3 package org.xwt.js;
4 import org.xwt.util.*;
5 import java.io.*;
6 import java.util.*;
7
8
9 class ScopeImpl extends JS.Obj {
10 private JS.Scope parentScope;
11 private static final Object NULL_PLACEHOLDER = new Object();
12 public ScopeImpl(JS.Scope parentScope, boolean sealed) {
13 super(sealed);
14 if (parentScope == this) throw new Error("can't make a scope its own parent!");
15 this.parentScope = parentScope;
16 }
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
20 public Object _get(Object key) {
21 Object o = super.get(key);
22 if (o != null) return o == NULL_PLACEHOLDER ? null : o;
23 else return parentScope == null ? null : parentScope.get(key);
24 }
25
26 public void _put(Object key, Object val) {
27 if (parentScope != null && !has(key)) parentScope.put(key, val);
28 else super.put(key, val == null ? NULL_PLACEHOLDER : val);
29 }
30 public boolean isTransparent() { return false; }
31 public void declare(String s) { super.put(s, NULL_PLACEHOLDER); }
32 public Scope getParentScope() { return parentScope; }
33 }
34
35