1 28 29 package com.caucho.es; 30 31 import com.caucho.util.IntMap; 32 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 36 39 class ESThunk extends ESBase { 40 static final int OBJ_PROTO_THUNK = 0; 41 static final int OBJ_THUNK = OBJ_PROTO_THUNK + 1; 42 static final int FUN_PROTO_THUNK = OBJ_THUNK + 1; 43 static final int FUN_THUNK = FUN_PROTO_THUNK + 1; 44 static final int ARRAY_PROTO_THUNK = FUN_THUNK + 1; 45 static final int ARRAY_THUNK = ARRAY_PROTO_THUNK + 1; 46 static final int STRING_PROTO_THUNK = ARRAY_THUNK + 1; 47 static final int STRING_THUNK = STRING_PROTO_THUNK + 1; 48 static final int BOOL_PROTO_THUNK = STRING_THUNK + 1; 49 static final int BOOL_THUNK = BOOL_PROTO_THUNK + 1; 50 static final int NUM_PROTO_THUNK = BOOL_THUNK + 1; 51 static final int NUM_THUNK = NUM_PROTO_THUNK + 1; 52 static final int DATE_PROTO_THUNK = NUM_THUNK + 1; 53 static final int DATE_THUNK = DATE_PROTO_THUNK + 1; 54 static final int MATH_THUNK = DATE_THUNK + 1; 55 static final int REGEXP_PROTO_THUNK = MATH_THUNK + 1; 56 static final int REGEXP_THUNK = REGEXP_PROTO_THUNK + 1; 57 58 private int index; 59 60 63 ESThunk(int index) 64 { 65 this.index = index; 66 } 67 68 ESBase getObject() 69 { 70 return getThunk(index); 71 } 72 73 76 public ESBase getProperty(ESString name) throws Throwable 77 { 78 ESBase object = getThunk(index); 79 80 return object.getProperty(name); 81 } 82 85 public ESBase hasProperty(ESString name) throws Throwable 86 { 87 ESBase object = getThunk(index); 88 89 return object.hasProperty(name); 90 } 91 92 95 public void setProperty(ESString name, ESBase value) throws Throwable 96 { 97 ESBase object = getThunk(index); 98 99 object.setProperty(name, value); 100 } 101 102 105 public ESBase delete(ESString name) throws Throwable 106 { 107 ESBase object = getThunk(index); 108 109 return object.delete(name); 110 } 111 112 public Iterator keys() throws Throwable 113 { 114 ESBase object = getThunk(index); 115 116 return object.keys(); 117 } 118 119 public ESBase typeof() throws ESException 120 { 121 ESBase object = getThunk(index); 122 123 return object.typeof(); 124 } 125 126 129 public ESBase toPrimitive(int hint) throws Throwable 130 { 131 ESBase object = getThunk(index); 132 133 return object.toPrimitive(hint); 134 } 135 136 public ESObject toObject() throws ESException 137 { 138 ESBase object = getThunk(index); 139 140 return object.toObject(); 141 } 142 143 public Object toJavaObject() throws ESException 144 { 145 ESBase object = getThunk(index); 146 147 return object.toJavaObject(); 148 } 149 150 153 public double toNum() throws Throwable 154 { 155 ESBase object = getThunk(index); 156 157 return object.toNum(); 158 } 159 160 163 public ESString toStr() throws Throwable 164 { 165 ESBase object = getThunk(index); 166 167 return object.toStr(); 168 } 169 170 public ESString toSource(IntMap map, boolean isLoopPass) throws Throwable 171 { 172 ESBase object = getThunk(index); 173 174 return object.toSource(map, isLoopPass); 175 } 176 177 public boolean toBoolean() 178 { 179 ESBase object = getThunk(index); 180 181 return object.toBoolean(); 182 } 183 184 public Object copy(HashMap refs) 185 { 186 return this; 187 } 188 189 public boolean ecmaEquals(ESBase b) throws Throwable 190 { 191 ESBase object = getThunk(index); 192 193 if (this == b) 194 return true; 195 else 196 return object.ecmaEquals(b); 197 } 198 199 public ESBase call(Call call, int length) throws Throwable 200 { 201 ESBase object = getThunk(index); 202 203 return object.call(call, length); 204 } 205 206 public ESBase construct(Call call, int length) throws Throwable 207 { 208 ESBase object = getThunk(index); 209 210 return object.construct(call, length); 211 } 212 213 static ESBase getThunk(int index) 214 { 215 Global resin = Global.getGlobalProto(); 216 217 switch (index) { 218 case OBJ_PROTO_THUNK: 219 return resin.objProto; 220 221 case OBJ_THUNK: 222 return resin.object; 223 224 case FUN_PROTO_THUNK: 225 return resin.funProto; 226 227 case FUN_THUNK: 228 return resin.fun; 229 230 case ARRAY_PROTO_THUNK: 231 return resin.arrayProto; 232 233 case ARRAY_THUNK: 234 return resin.array; 235 236 case STRING_PROTO_THUNK: 237 return resin.stringProto; 238 239 case STRING_THUNK: 240 return resin.string; 241 242 case BOOL_PROTO_THUNK: 243 return resin.boolProto; 244 245 case BOOL_THUNK: 246 return resin.bool; 247 248 case NUM_PROTO_THUNK: 249 return resin.numProto; 250 251 case NUM_THUNK: 252 return resin.num; 253 254 case DATE_PROTO_THUNK: 255 return resin.dateProto; 256 257 case DATE_THUNK: 258 return resin.date; 259 260 case MATH_THUNK: 261 return resin.math; 262 263 case REGEXP_PROTO_THUNK: 264 return resin.getRegexpProto(); 265 266 case REGEXP_THUNK: 267 return resin.getRegexp(); 268 269 default: 270 throw new RuntimeException (); 271 } 272 } 273 } 274 | Popular Tags |