001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es;
030:
031: import com.caucho.util.IntMap;
032:
033: import java.util.HashMap;
034:
035: class ESArguments extends ESObject {
036: static ESId CALLEE = ESId.intern("callee");
037: static ESId ARGUMENTS = ESId.intern("arguments");
038: static ESId LENGTH = ESId.intern("length");
039:
040: HashMap aliases = new HashMap();
041:
042: private ESArguments(ESId[] formals, Call eval, int length)
043: throws ESException {
044: super ("Arguments", Global.getGlobalProto().arrayProto);
045:
046: for (int i = 0; i < length; i++)
047: super .put(ESString.create(i), eval.getArg(i, length),
048: DONT_ENUM);
049:
050: for (int i = 0; i < formals.length; i++) {
051: super .put(formals[i], eval.getArg(i, length), DONT_ENUM
052: | DONT_DELETE);
053: aliases.put(formals[i], ESString.create(i));
054: aliases.put(ESString.create(i), formals[i]);
055: }
056:
057: super .put(LENGTH, ESNumber.create(length), DONT_ENUM);
058: super .put(CALLEE, eval.callee, DONT_ENUM);
059: }
060:
061: static ESObject create(ESId[] formals, Call eval, int length)
062: throws ESException {
063: ESArguments args = new ESArguments(formals, eval, length);
064:
065: args.put(ARGUMENTS, args, DONT_ENUM | DONT_DELETE);
066:
067: return args;
068: }
069:
070: public ESString toSource(IntMap map, boolean isLoopPass)
071: throws Throwable {
072: return ESArray.arrayToSource(this , map, isLoopPass);
073: }
074:
075: public void setProperty(ESString key, ESBase value)
076: throws Throwable {
077: ESId alias = (ESId) aliases.get(key);
078:
079: super .setProperty(key, value);
080:
081: if (alias != null)
082: super .setProperty(alias, value);
083: }
084:
085: public void put(ESString key, ESBase value, int flags) {
086: ESId alias = (ESId) aliases.get(key);
087:
088: super .put(key, value, flags);
089:
090: if (alias != null)
091: super .put(alias, value, flags);
092: }
093:
094: public ESBase delete(ESString key) throws Throwable {
095: ESId alias = (ESId) aliases.get(key);
096:
097: if (alias == null)
098: return super .delete(key);
099: else {
100: return ESBoolean.FALSE;
101: // aliases.remove(key); // XXX: is this right? 10.1.8
102: }
103: }
104:
105: protected ESArguments() {
106: }
107:
108: protected ESObject dup() {
109: return new ESArguments();
110: }
111:
112: protected void copy(HashMap refs, Object newObj) {
113: ESArguments newArgs = (ESArguments) newObj;
114:
115: newArgs.aliases = aliases;
116:
117: super.copy(refs, newObj);
118: }
119: }
|