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 activation object.
\r
43 * @see org.mozilla.javascript.Arguments
\r
44 * @author Norris Boyd
\r
46 public final class NativeCall extends IdScriptable {
\r
48 static void init(Context cx, Scriptable scope, boolean sealed) {
\r
49 NativeCall obj = new NativeCall();
\r
50 obj.prototypeFlag = true;
\r
51 obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
\r
54 NativeCall(Context cx, Scriptable scope, NativeFunction funObj,
\r
55 Scriptable thisObj, Object[] args)
\r
57 this.funObj = funObj;
\r
58 this.thisObj = thisObj;
\r
60 setParentScope(scope);
\r
61 // leave prototype null
\r
63 // save current activation
\r
64 this.caller = cx.currentActivation;
\r
65 cx.currentActivation = this;
\r
67 this.originalArgs = (args == null) ? ScriptRuntime.emptyArgs : args;
\r
69 // initialize values of arguments
\r
70 String[] argNames = funObj.argNames;
\r
71 if (argNames != null) {
\r
72 for (int i=0; i < funObj.argCount; i++) {
\r
73 Object val = i < args.length ? args[i]
\r
74 : Undefined.instance;
\r
75 super.put(argNames[i], this, val);
\r
79 // initialize "arguments" property
\r
80 super.put("arguments", this, new Arguments(this));
\r
83 private NativeCall() {
\r
86 public String getClassName() {
\r
90 private static Object jsConstructor(Context cx, Object[] args,
\r
91 Function ctorObj, boolean inNewExpr)
\r
94 throw Context.reportRuntimeError1("msg.only.from.new", "Call");
\r
96 ScriptRuntime.checkDeprecated(cx, "Call");
\r
97 NativeCall result = new NativeCall();
\r
98 result.setPrototype(getObjectPrototype(ctorObj));
\r
102 NativeCall getActivation(Function f) {
\r
103 NativeCall x = this;
\r
108 } while (x != null);
\r
112 public Function getFunctionObject() {
\r
116 public Object[] getOriginalArguments() {
\r
117 return originalArgs;
\r
120 public NativeCall getCaller() {
\r
124 public Scriptable getThisObj() {
\r
128 public int methodArity(int methodId) {
\r
129 if (prototypeFlag) {
\r
130 if (methodId == Id_constructor) return 1;
\r
132 return super.methodArity(methodId);
\r
135 public Object execMethod
\r
136 (int methodId, IdFunction f,
\r
137 Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
\r
138 throws JavaScriptException
\r
140 if (prototypeFlag) {
\r
141 if (methodId == Id_constructor) {
\r
142 return jsConstructor(cx, args, f, thisObj == null);
\r
145 return super.execMethod(methodId, f, cx, scope, thisObj, args);
\r
148 protected String getIdName(int id) {
\r
149 if (prototypeFlag) {
\r
150 if (id == Id_constructor) return "constructor";
\r
155 protected int mapNameToId(String s) {
\r
156 if (!prototypeFlag) { return 0; }
\r
157 return s.equals("constructor") ? Id_constructor : 0;
\r
160 private static final int
\r
161 Id_constructor = 1,
\r
162 MAX_PROTOTYPE_ID = 1;
\r
165 NativeFunction funObj;
\r
166 Scriptable thisObj;
\r
167 Object[] originalArgs;
\r
168 public int debugPC;
\r
170 private boolean prototypeFlag;
\r