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

Last change on this file since 13153 was 13153, checked in by darin, 19 years ago

Reviewed by Maciej.

  • kjs/Parser.cpp: Added.
  • kjs/Parser.h: Added.
  • kjs/internal.cpp: Removed the Parser class.
  • kjs/internal.h: Ditto. Also removed unnecessary declarations of classes not used in this header.
  • kjs/nodes.h: Added an include of "Parser.h".
  • kjs/function.h: Added a declaration of FunctionBodyNode.
  • Property svn:eol-style set to native
File size: 5.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 <kxmlcore/OwnPtr.h>
29
30namespace KJS {
31
32 class ActivationImp;
33 class FunctionBodyNode;
34 class Parameter;
35
36 /**
37 * @short Implementation class for internal Functions.
38 */
39 class FunctionImp : public InternalFunctionImp {
40 friend class ActivationImp;
41 public:
42 FunctionImp(ExecState *exec, const Identifier &n = Identifier::null());
43 virtual ~FunctionImp();
44
45 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&);
46 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
47 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
48
49 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
50
51 void addParameter(const Identifier &n);
52 Identifier getParameterName(int index);
53 // parameters in string representation, e.g. (a, b, c)
54 UString parameterString() const;
55 virtual CodeType codeType() const = 0;
56
57 virtual Completion execute(ExecState *exec) = 0;
58
59 virtual const ClassInfo *classInfo() const { return &info; }
60 static const ClassInfo info;
61 protected:
62 OwnPtr<Parameter> param;
63
64 private:
65 static JSValue *argumentsGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot&);
66 static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot&);
67
68 void processParameters(ExecState *exec, const List &);
69 virtual void processVarDecls(ExecState *exec);
70 };
71
72 class DeclaredFunctionImp : public FunctionImp {
73 public:
74 DeclaredFunctionImp(ExecState *exec, const Identifier &n,
75 FunctionBodyNode *b, const ScopeChain &sc);
76
77 bool implementsConstruct() const;
78 JSObject *construct(ExecState *exec, const List &args);
79
80 virtual Completion execute(ExecState *exec);
81 CodeType codeType() const { return FunctionCode; }
82 RefPtr<FunctionBodyNode> body;
83
84 virtual const ClassInfo *classInfo() const { return &info; }
85 static const ClassInfo info;
86 private:
87 virtual void processVarDecls(ExecState *exec);
88 };
89
90 class IndexToNameMap {
91 public:
92 IndexToNameMap(FunctionImp *func, const List &args);
93 ~IndexToNameMap();
94
95 Identifier& operator[](int index);
96 Identifier& operator[](const Identifier &indexIdentifier);
97 bool isMapped(const Identifier &index) const;
98 void unMap(const Identifier &index);
99
100 private:
101 IndexToNameMap(); // prevent construction w/o parameters
102 int size;
103 Identifier * _map;
104 };
105
106 class Arguments : public JSObject {
107 public:
108 Arguments(ExecState *exec, FunctionImp *func, const List &args, ActivationImp *act);
109 virtual void mark();
110 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&);
111 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
112 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
113 virtual const ClassInfo *classInfo() const { return &info; }
114 static const ClassInfo info;
115 private:
116 static JSValue *mappedIndexGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot& slot);
117
118 ActivationImp *_activationObject;
119 mutable IndexToNameMap indexToNameMap;
120 };
121
122 class ActivationImp : public JSObject {
123 public:
124 ActivationImp(FunctionImp *function, const List &arguments);
125
126 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier &, PropertySlot&);
127 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
128 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
129
130 virtual const ClassInfo *classInfo() const { return &info; }
131 static const ClassInfo info;
132
133 virtual void mark();
134
135 bool isActivation() { return true; }
136 private:
137 static PropertySlot::GetValueFunc getArgumentsGetter();
138 static JSValue *argumentsGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot& slot);
139 void createArgumentsObject(ExecState *exec) const;
140
141 FunctionImp *_function;
142 List _arguments;
143 mutable Arguments *_argumentsObject;
144 };
145
146 class GlobalFuncImp : public InternalFunctionImp {
147 public:
148 GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
149 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
150 virtual CodeType codeType() const;
151 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape,
152 DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent
153#ifndef NDEBUG
154 , KJSPrint
155#endif
156};
157 private:
158 int id;
159 };
160
161
162
163} // namespace
164
165#endif
Note: See TracBrowser for help on using the repository browser.