2002/07/16 00:39:23
[org.ibex.core.git] / src / org / xwt / Static.java
index 59450a7..cb7a510 100644 (file)
@@ -8,10 +8,14 @@ import org.mozilla.javascript.*;
 public class Static extends JSObject {
 
     public static Static getStatic(String resourcename) {
+        return (Static)cache.get(resourcename);
+    }
+
+    public static Static createStatic(String resourcename) {
         Static ret = (Static)cache.get(resourcename);
         if (ret == null) {
             Template t = Template.getTemplate(resourcename, null);
-            if (t == null) return null;
+            if (t == null) return new Static(resourcename, true);
             ret = new Static(resourcename, false);
             t.link();
             return ret;
@@ -36,9 +40,7 @@ public class Static extends JSObject {
     }
     
     /** creates a new static representing a package */
-    public Static(String resourcename) {
-        this(resourcename, true);
-    }
+    public Static(String resourcename) { this(resourcename, true); }
 
     public Object get(String name, Scriptable start) {
         if (name == null) return null;
@@ -49,9 +51,14 @@ public class Static extends JSObject {
         if (name.equals("Function")) return JSObject.defaultObjects.get("Function", null);
         if (name.equals("TypeError")) return JSObject.defaultObjects.get("TypeError", null);
 
-        if ("xwt".equals(name)) return XWT.singleton;
+        if ("xwt".equals(name))
+            for(Scriptable cur = Context.enter().currentFunction; cur != null; cur = cur.getParentScope())
+                if (cur == this) return XWT.singleton;
+
         if (!ispackage) return super.get(name, start);
         return getStatic(resourcename + (resourcename.length() == 0 ? "" : ".") + name);
     }
 
+    static { createStatic(""); }
+
 }