X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJSScope.java;fp=src%2Forg%2Fxwt%2Fjs%2FJSScope.java;h=971d550c10a6eb0cf1b5f277383fed23f69c3333;hb=c2a138c3882a4bd8dce0212ac59765af5cb126c6;hp=44bfec1462a54341da05dad53cf3cd613c4b0de6;hpb=add9c1c1765814ff41c3ae54ec0e5496aa747c6e;p=org.ibex.core.git diff --git a/src/org/xwt/js/JSScope.java b/src/org/xwt/js/JSScope.java index 44bfec1..971d550 100644 --- a/src/org/xwt/js/JSScope.java +++ b/src/org/xwt/js/JSScope.java @@ -5,37 +5,34 @@ import org.xwt.util.*; import java.io.*; import java.util.*; -/** Implementation of a JavaScript JSScope */ -public class JSScope extends JSCallable { - private JSScope parentJSScope; +/** Implementation of a JavaScript Scope */ +public class JSScope extends JS { + + private JSScope parentScope; + private static final Object NULL_PLACEHOLDER = new Object(); - public JSScope(JSScope parentJSScope) { - if (parentJSScope == this) throw new Error("can't make a scope its own parent!"); - this.parentJSScope = parentJSScope; - } - public boolean isTransparent() { return false; } + public JSScope(JSScope parentScope) { this.parentScope = parentScope; } public void declare(String s) { super.put(s, NULL_PLACEHOLDER); } - public JSScope getParentJSScope() { return parentJSScope; } - public boolean has(Object key) { return super.get(key) != null; } + public JSScope getParentScope() { return parentScope; } public Object get(Object key) { Object o = super.get(key); if (o != null) return o == NULL_PLACEHOLDER ? null : o; - else return parentJSScope == null ? null : parentJSScope.get(key); + else return parentScope == null ? null : parentScope.get(key); } + public boolean has(Object key) { return super.get(key) != null; } public void put(Object key, Object val) { - if (parentJSScope != null && !has(key)) parentJSScope.put(key, val); + if (parentScope != null && !has(key)) parentScope.put(key, val); else super.put(key, val == null ? NULL_PLACEHOLDER : val); } public static class Global extends JSScope { private final static Double NaN = new Double(Double.NaN); private final static Double POSITIVE_INFINITY = new Double(Double.POSITIVE_INFINITY); - - public Global(JSScope parent) { super(parent); } + public Global() { super(null); } public Object get(Object key) { //#switch(key) case "NaN": return NaN; @@ -61,42 +58,36 @@ public class JSScope extends JSCallable { case 0: { //#switch(method) case "stringFromCharCode": - JSArray args = new JSArray(); - for(int i=0; i