2003/06/18 07:38:54
[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     // 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 ? null : ret;
23     }
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 : val);
28     }
29     public boolean isTransparent() { return false; }
30     public void declare(String s) {
31         if (isTransparent()) parentScope.declare(s);
32         else super.put(s, NULL);
33     }
34