1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
\r
3 * The contents of this file are subject to the Netscape Public
\r
4 * License Version 1.1 (the "License"); you may not use this file
\r
5 * except in compliance with the License. You may obtain a copy of
\r
6 * the License at http://www.mozilla.org/NPL/
\r
8 * Software distributed under the License is distributed on an "AS
\r
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
\r
10 * implied. See the License for the specific language governing
\r
11 * rights and limitations under the License.
\r
13 * The Original Code is Rhino code, released
\r
16 * The Initial Developer of the Original Code is Netscape
\r
17 * Communications Corporation. Portions created by Netscape are
\r
18 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
\r
24 * Alternatively, the contents of this file may be used under the
\r
25 * terms of the GNU Public License (the "GPL"), in which case the
\r
26 * provisions of the GPL are applicable instead of those above.
\r
27 * If you wish to allow use of your version of this file only
\r
28 * under the terms of the GPL and not to allow others to use your
\r
29 * version of this file under the NPL, indicate your decision by
\r
30 * deleting the provisions above and replace them with the notice
\r
31 * and other provisions required by the GPL. If you do not delete
\r
32 * the provisions above, a recipient may use your version of this
\r
33 * file under either the NPL or the GPL.
\r
36 package org.mozilla.javascript;
\r
39 * This class implements the "arguments" object.
\r
43 * @see org.mozilla.javascript.NativeCall
\r
44 * @author Norris Boyd
\r
46 class Arguments extends ScriptableObject {
\r
48 public Arguments(NativeCall activation) {
\r
49 this.activation = activation;
\r
51 Scriptable parent = activation.getParentScope();
\r
52 setParentScope(parent);
\r
53 setPrototype(ScriptableObject.getObjectPrototype(parent));
\r
55 args = activation.getOriginalArguments();
\r
56 int length = args.length;
\r
57 Object callee = activation.funObj;
\r
59 defineProperty("length", new Integer(length),
\r
60 ScriptableObject.DONTENUM);
\r
61 defineProperty("callee", callee, ScriptableObject.DONTENUM);
\r
63 hasCaller = (activation.funObj.version <= Context.VERSION_1_3 &&
\r
64 activation.funObj.version != Context.VERSION_DEFAULT);
\r
67 public String getClassName() {
\r
71 public boolean has(String name, Scriptable start) {
\r
72 return (hasCaller && name.equals("caller")) || super.has(name, start);
\r
75 public boolean has(int index, Scriptable start) {
\r
76 Object[] args = activation.getOriginalArguments();
\r
77 return (0 <= index && index < args.length) || super.has(index, start);
\r
80 public Object get(String name, Scriptable start) {
\r
81 if (hasCaller && name.equals("caller")) {
\r
82 NativeCall caller = activation.caller;
\r
83 if (caller == null || caller.originalArgs == null) return null;
\r
84 return caller.get("arguments", caller);
\r
86 } else if (name.equals("cascade")) {
\r
87 return org.xwt.Trap.cascadeFunction;
\r
89 } else if (name.equals("trapee")) {
\r
90 return org.xwt.Trap.currentTrapee();
\r
93 return super.get(name, start);
\r
96 public Object get(int index, Scriptable start) {
\r
97 if (0 <= index && index < args.length) {
\r
98 NativeFunction f = activation.funObj;
\r
99 if (index < f.argCount)
\r
100 return activation.get(f.argNames[index], activation);
\r
101 return args[index];
\r
103 return super.get(index, start);
\r
106 public void put(String name, Scriptable start, Object value) {
\r
107 if (name.equals("caller")) {
\r
108 // Set "hasCaller" to false so that we won't look up a
\r
112 super.put(name, start, value);
\r
115 public void put(int index, Scriptable start, Object value) {
\r
116 if (0 <= index && index < args.length) {
\r
117 NativeFunction f = activation.funObj;
\r
118 if (index < f.argCount)
\r
119 activation.put(f.argNames[index], activation, value);
\r
121 args[index] = value;
\r
124 super.put(index, start, value);
\r
127 public void delete(String name) {
\r
128 if (name.equals("caller"))
\r
130 super.delete(name);
\r
133 public void delete(int index) {
\r
134 if (0 <= index && index < args.length) {
\r
135 NativeFunction f = activation.funObj;
\r
136 if (index < f.argCount)
\r
137 activation.delete(f.argNames[index]);
\r
139 args[index] = Undefined.instance;
\r
143 private NativeCall activation;
\r
144 private Object[] args;
\r
145 private boolean hasCaller;
\r