remove dead code from JSScope
[org.ibex.js.git] / src / org / ibex / js / JSScope.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.js; 
6
7 /** Implementation of a JavaScript Scope */
8 class JSScope {
9
10     private final int base;
11     private final JS[] vars;
12     final JSScope parent;
13
14     public static class Top extends JSScope {
15         private final JS global;
16         public Top(JS global) { super(null,0,0); this.global = global; }
17         JS get(int i) throws JSExn { throw new JSExn("scope index out of range"); }
18         void put(int i, JS o) throws JSExn { throw new JSExn("scope index out of range"); }
19         JS getGlobal() { return global; }
20     };
21         
22     // NOTE: We can't just set base to parent.base + parent.vars.length
23     // sometimes we only access part of a parent's scope
24     public JSScope(JSScope parent, int base, int size) {
25         this.parent = parent;
26         this.base = base;
27         this.vars = new JS[size];
28     }
29     
30     final JS get(JS i) throws JSExn {
31         if(i==null) throw new NullPointerException();
32         try {
33             return get(Script.toInt(i));
34         } catch(ArrayIndexOutOfBoundsException e) { 
35             throw new JSExn("scope index out of range");
36         }
37     }
38     final void put(JS i, JS o) throws JSExn {
39         if(i==null) throw new NullPointerException();
40         try {
41             put(Script.toInt(i), o);
42         } catch(ArrayIndexOutOfBoundsException e) { 
43             throw new JSExn("scope index out of range");
44         }
45     }
46     JS get(int i) throws JSExn { return i < base ? parent.get(i) : vars[i-base]; }
47     void put(int i, JS o) throws JSExn { if(i < base) parent.put(i,o); else vars[i-base] = o; }
48     
49     JS getGlobal() { return parent.getGlobal(); }
50 }