5162c0e8e2aa61a7bd6c52f527b6d0871062df80
[org.ibex.core.git] / src / org / xwt / js / ScopeImpl.java
1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] 
2
3 package org.xwt.js; 
4 import org.xwt.util.*; 
5 import java.io.*;
6 import java.util.*;
7
8 /** Implementation of 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, 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     public Object get(Object key) {
20         if (!has(key)) return parentScope == null ? null : parentScope.get(key);
21         Object ret = super.get(key); return ret == NULL ? null : ret;
22     }
23     public void put(Object key, Object val) {
24         if (!has(key) && parentScope != null) parentScope.put(key, val);
25         else super.put(key, val == null ? NULL : val);
26     }
27     public boolean isTransparent() { return false; }
28     public void declare(String s) {
29         if (isTransparent()) parentScope.declare(s);
30         else super.put(s, NULL);
31     }
32