source: webkit/trunk/JavaScriptCore/kjs/function.h@ 18517

Last change on this file since 18517 was 17483, checked in by ap, 19 years ago

2006-10-31 Vladimir Olexa <[email protected]>

Reviewed by Geoff.

http://bugs.webkit.org/show_bug.cgi?id=4166
Function object does not support caller property

Test: fast/js/caller-property.html

  • kjs/function.cpp: (KJS::FunctionImp::callerGetter): added (KJS::FunctionImp::getOwnPropertySlot): added if statement to handle callerGetter()
  • kjs/function.h: added callerGetter() declaration
  • kjs/identifier.h: added caller property macro
  • tests/mozilla/expected.html:
  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
5 * Copyright (C) 2003, 2006 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef KJS_FUNCTION_H
25#define KJS_FUNCTION_H
26
27#include "internal.h"
28#include <wtf/OwnPtr.h>
29#include <wtf/Vector.h>
30
31namespace KJS {
32
33 class ActivationImp;
34 class FunctionBodyNode;
35 class Parameter;
36
37 /**
38 * @short Implementation class for internal Functions.
39 */
40 class FunctionImp : public InternalFunctionImp {
41 friend class ActivationImp;
42 public:
43 FunctionImp(ExecState*, const Identifier& n, FunctionBodyNode* b);
44 virtual ~FunctionImp();
45
46 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
47 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
48 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
49
50 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
51
52 void addParameter(const Identifier& n);
53 Identifier getParameterName(int index);
54 // parameters in string representation, e.g. (a, b, c)
55 UString parameterString() const;
56 virtual CodeType codeType() const = 0;
57
58 virtual Completion execute(ExecState*) = 0;
59
60 virtual const ClassInfo* classInfo() const { return &info; }
61 static const ClassInfo info;
62
63 RefPtr<FunctionBodyNode> body;
64
65 /**
66 * Returns the scope of this object. This is used when execution declared
67 * functions - the execution context for the function is initialized with
68 * extra object in it's scope. An example of this is functions declared
69 * inside other functions:
70 *
71 * \code
72 * function f() {
73 *
74 * function b() {
75 * return prototype;
76 * }
77 *
78 * var x = 4;
79 * // do some stuff
80 * }
81 * f.prototype = new String();
82 * \endcode
83 *
84 * When the function f.b is executed, its scope will include properties of
85 * f. So in the example above the return value of f.b() would be the new
86 * String object that was assigned to f.prototype.
87 *
88 * @param exec The current execution state
89 * @return The function's scope
90 */
91 const ScopeChain& scope() const { return _scope; }
92 void setScope(const ScopeChain& s) { _scope = s; }
93
94 virtual void mark();
95 protected:
96 OwnPtr<Vector<Parameter> > parameters;
97
98 private:
99 ScopeChain _scope;
100
101 static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
102 static JSValue* callerGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
103 static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
104
105 void processParameters(ExecState*, const List&);
106 virtual void processVarDecls(ExecState*);
107 };
108
109 class DeclaredFunctionImp : public FunctionImp {
110 public:
111 DeclaredFunctionImp(ExecState*, const Identifier& n,
112 FunctionBodyNode* b, const ScopeChain& sc);
113
114 bool implementsConstruct() const;
115 JSObject* construct(ExecState*, const List& args);
116
117 virtual Completion execute(ExecState*);
118 CodeType codeType() const { return FunctionCode; }
119
120 virtual const ClassInfo* classInfo() const { return &info; }
121 static const ClassInfo info;
122
123 private:
124 virtual void processVarDecls(ExecState*);
125 };
126
127 class IndexToNameMap {
128 public:
129 IndexToNameMap(FunctionImp* func, const List& args);
130 ~IndexToNameMap();
131
132 Identifier& operator[](int index);
133 Identifier& operator[](const Identifier &indexIdentifier);
134 bool isMapped(const Identifier& index) const;
135 void unMap(const Identifier& index);
136
137 private:
138 IndexToNameMap(); // prevent construction w/o parameters
139 int size;
140 Identifier* _map;
141 };
142
143 class Arguments : public JSObject {
144 public:
145 Arguments(ExecState*, FunctionImp* func, const List& args, ActivationImp* act);
146 virtual void mark();
147 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
148 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
149 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
150 virtual const ClassInfo* classInfo() const { return &info; }
151 static const ClassInfo info;
152 private:
153 static JSValue* mappedIndexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
154
155 ActivationImp* _activationObject;
156 mutable IndexToNameMap indexToNameMap;
157 };
158
159 class ActivationImp : public JSObject {
160 public:
161 ActivationImp(FunctionImp* function, const List& arguments);
162
163 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
164 virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
165 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
166
167 virtual const ClassInfo* classInfo() const { return &info; }
168 static const ClassInfo info;
169
170 virtual void mark();
171
172 bool isActivation() { return true; }
173 private:
174 static PropertySlot::GetValueFunc getArgumentsGetter();
175 static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
176 void createArgumentsObject(ExecState*) const;
177
178 FunctionImp* _function;
179 List _arguments;
180 mutable Arguments* _argumentsObject;
181 };
182
183 class GlobalFuncImp : public InternalFunctionImp {
184 public:
185 GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
186 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
187 virtual CodeType codeType() const;
188 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape,
189 DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent
190#ifndef NDEBUG
191 , KJSPrint
192#endif
193};
194 private:
195 int id;
196 };
197
198UString escapeStringForPrettyPrinting(const UString& s);
199
200} // namespace
201
202#endif
Note: See TracBrowser for help on using the repository browser.