1 28 29 package com.caucho.es; 30 31 import com.caucho.util.IntMap; 32 33 import java.util.HashMap ; 34 35 class ESArguments extends ESObject { 36 static ESId CALLEE = ESId.intern("callee"); 37 static ESId ARGUMENTS = ESId.intern("arguments"); 38 static ESId LENGTH = ESId.intern("length"); 39 40 HashMap aliases = new HashMap (); 41 42 private ESArguments(ESId []formals, Call eval, int length) 43 throws ESException 44 { 45 super("Arguments", Global.getGlobalProto().arrayProto); 46 47 for (int i = 0; i < length; i++) 48 super.put(ESString.create(i), eval.getArg(i, length), DONT_ENUM); 49 50 for (int i = 0; i < formals.length; i++) { 51 super.put(formals[i], eval.getArg(i, length), DONT_ENUM|DONT_DELETE); 52 aliases.put(formals[i], ESString.create(i)); 53 aliases.put(ESString.create(i), formals[i]); 54 } 55 56 super.put(LENGTH, ESNumber.create(length), DONT_ENUM); 57 super.put(CALLEE, eval.callee, DONT_ENUM); 58 } 59 60 static ESObject create(ESId []formals, Call eval, int length) 61 throws ESException 62 { 63 ESArguments args = new ESArguments(formals, eval, length); 64 65 args.put(ARGUMENTS, args, DONT_ENUM|DONT_DELETE); 66 67 return args; 68 } 69 70 public ESString toSource(IntMap map, boolean isLoopPass) throws Throwable 71 { 72 return ESArray.arrayToSource(this, map, isLoopPass); 73 } 74 75 public void setProperty(ESString key, ESBase value) throws Throwable 76 { 77 ESId alias = (ESId) aliases.get(key); 78 79 super.setProperty(key, value); 80 81 if (alias != null) 82 super.setProperty(alias, value); 83 } 84 85 public void put(ESString key, ESBase value, int flags) 86 { 87 ESId alias = (ESId) aliases.get(key); 88 89 super.put(key, value, flags); 90 91 if (alias != null) 92 super.put(alias, value, flags); 93 } 94 95 public ESBase delete(ESString key) throws Throwable 96 { 97 ESId alias = (ESId) aliases.get(key); 98 99 if (alias == null) 100 return super.delete(key); 101 else { 102 return ESBoolean.FALSE; 103 } 105 } 106 107 protected ESArguments() {} 108 protected ESObject dup() { return new ESArguments(); } 109 110 protected void copy(HashMap refs, Object newObj) 111 { 112 ESArguments newArgs = (ESArguments) newObj; 113 114 newArgs.aliases = aliases; 115 116 super.copy(refs, newObj); 117 } 118 } 119 | Popular Tags |