Debian Codegraph @

rhino/src/org/mozilla/javascript/NativeCall.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript;
8
9 /**
10 * This class implements the activation object.
11 *
12 * See ECMA 10.1.6
13 *
14 * @see org.mozilla.javascript.Arguments
15 * @author Norris Boyd
16 */
17 public final class NativeCall extends IdScriptableObject
18 {
19 static final long serialVersionUID = -7471457301304454454L;
20
21 private static final Object CALL_TAG = "Call";
22
23 static void init(Scriptable scope, boolean sealed)
24 {
25 NativeCall obj = new NativeCall();
26 obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
27 }
28
29 NativeCall() { }
30
31 NativeCall(NativeFunction function, Scriptable scope, Object[] args, boolean isArrow, boolean isStrict)
32 {
33 this.function = function;
34
35 setParentScope(scope);
36 // leave prototype null
37
38 this.originalArgs = (args == null) ? ScriptRuntime.emptyArgs : args;
39 this.isStrict = isStrict;
40
41 // initialize values of arguments
42 int paramAndVarCount = function.getParamAndVarCount();
43 int paramCount = function.getParamCount();
44 if (paramAndVarCount != 0) {
45 for (int i = 0; i < paramCount; ++i) {
46 String name = function.getParamOrVarName(i);
47 Object val = i < args.length ? args[i]
48 : Undefined.instance;
49 defineProperty(name, val, PERMANENT);
50 }
51 }
52
53 // initialize "arguments" property but only if it was not overridden by
54 // the parameter with the same name
55 if (!super.has("arguments", this) && !isArrow) {
56 arguments = new Arguments(this);
57 defineProperty("arguments", arguments, PERMANENT);
58 }
59
60 if (paramAndVarCount != 0) {
61 for (int i = paramCount; i < paramAndVarCount; ++i) {
62 String name = function.getParamOrVarName(i);
63 if (!super.has(name, this)) {
64 if (function.getParamOrVarConst(i))
65 defineProperty(name, Undefined.instance, CONST);
66 else
67 defineProperty(name, Undefined.instance, PERMANENT);
68 }
69 }
70 }
71 }
72
73 @Override
74 public String getClassName()
75 {
76 return "Call";
77 }
78
79 @Override
80 protected int findPrototypeId(String s)
81 {
82 return s.equals("constructor") ? Id_constructor : 0;
83 }
84
85 @Override
86 protected void initPrototypeId(int id)
87 {
88 String s;
89 int arity;
90 if (id == Id_constructor) {
91 arity=1; s="constructor";
92 } else {
93 throw new IllegalArgumentException(String.valueOf(id));
94 }
95 initPrototypeMethod(CALL_TAG, id, s, arity);
96 }
97
98 @Override
99 public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
100 Scriptable thisObj, Object[] args)
101 {
102 if (!f.hasTag(CALL_TAG)) {
103 return super.execIdCall(f, cx, scope, thisObj, args);
104 }
105 int id = f.methodId();
106 if (id == Id_constructor) {
107 if (thisObj != null) {
108 throw Context.reportRuntimeError1("msg.only.from.new", "Call");
109 }
110 ScriptRuntime.checkDeprecated(cx, "Call");
111 NativeCall result = new NativeCall();
112 result.setPrototype(getObjectPrototype(scope));
113 return result;
114 }
115 throw new IllegalArgumentException(String.valueOf(id));
116 }
117
118 public void defineAttributesForArguments() {
119 if (arguments != null) {
120 arguments.defineAttributesForStrictMode();
121 }
122 }
123
124 private static final int
125 Id_constructor = 1,
126 MAX_PROTOTYPE_ID = 1;
127
128 NativeFunction function;
129 Object[] originalArgs;
130 boolean isStrict;
131 private Arguments arguments;
132
133 transient NativeCall parentActivationCall;
134 }
135