X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2Fjs%2FScopeImpl.java;h=f64c952b70f3b9e5d4fa1d8ee1ded04c6581441d;hb=839318a1d25ee541869fdcfd67a94f3ab994b455;hp=10788fdcc188c3976778c34439e84aa4adb964ce;hpb=2fa20bbe798c44d0443d7b80d8dbcf7eb13fff4a;p=org.ibex.core.git diff --git a/src/org/xwt/js/ScopeImpl.java b/src/org/xwt/js/ScopeImpl.java index 10788fd..f64c952 100644 --- a/src/org/xwt/js/ScopeImpl.java +++ b/src/org/xwt/js/ScopeImpl.java @@ -5,33 +5,32 @@ import org.xwt.util.*; import java.io.*; import java.util.*; -/** A JavaScript Scope */ +/** Implementation of a JavaScript Scope */ class ScopeImpl extends JS.Obj { private JS.Scope parentScope; - private static Object NULL = new Object(); - public ScopeImpl(JS.Scope parentScope) { this(parentScope, false); } + private static final Object NULL_PLACEHOLDER = new Object(); public ScopeImpl(JS.Scope parentScope, boolean sealed) { - super(sealed); - if (parentScope == this) throw new Error("can't make a scope its own parent!"); - this.parentScope = parentScope; + super(sealed); + if (parentScope == this) throw new Error("can't make a scope its own parent!"); + this.parentScope = parentScope; } - public JS.Scope getParentScope() { return parentScope; } - - // transparent scopes are not returned by THIS - public boolean isTransparent() { return false; } - + public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); } public boolean has(Object key) { return super.get(key) != null; } - public Object get(Object key) { - if (!has(key)) return parentScope == null ? null : getParentScope().get(key); - Object ret = super.get(key); return ret == NULL ? null : ret; + // we use _get instead of get solely to work around a GCJ bug + public Object _get(Object key) { + Object o = super.get(key); + if (o != null) return o == NULL_PLACEHOLDER ? null : o; + else return parentScope == null ? null : parentScope.get(key); } - public void put(Object key, Object val) { - if (!has(key) && parentScope != null) getParentScope().put(key, val); - else super.put(key, val == null ? NULL : val); + // we use _put instead of put solely to work around a GCJ bug + public void _put(Object key, Object val) { + if (parentScope != null && !has(key)) parentScope.put(key, val); + else super.put(key, val == null ? NULL_PLACEHOLDER : val); } - public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); } + public boolean isTransparent() { return false; } public void declare(String s) { - if (isTransparent()) getParentScope().declare(s); - else super.put(s, NULL); + if (isTransparent()) parentScope.declare(s); + else super.put(s, NULL_PLACEHOLDER); } + public Scope getParentScope() { return parentScope; } }