]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | // -*- c-basic-offset: 2 -*- |
2 | /* | |
3 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
4 | * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
5 | * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) | |
6 | * Copyright (C) 2007 Maks Orlovich | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Library General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2 of the License, or (at your option) any later version. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Library General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Library General Public License | |
19 | * along with this library; see the file COPYING.LIB. If not, write to | |
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
21 | * Boston, MA 02110-1301, USA. | |
22 | * | |
23 | */ | |
24 | ||
25 | #ifndef KJS_FUNCTION_H | |
26 | #define KJS_FUNCTION_H | |
27 | ||
28 | #include "JSVariableObject.h" | |
29 | #include "LocalStorage.h" | |
30 | #include "SymbolTable.h" | |
31 | #include "nodes.h" | |
32 | #include "object.h" | |
33 | ||
34 | namespace KJS { | |
35 | ||
36 | class ActivationImp; | |
37 | class FunctionBodyNode; | |
38 | class FunctionPrototype; | |
39 | class JSGlobalObject; | |
40 | ||
41 | class InternalFunctionImp : public JSObject { | |
42 | public: | |
43 | InternalFunctionImp(); | |
44 | InternalFunctionImp(FunctionPrototype*, const Identifier&); | |
45 | ||
46 | virtual bool implementsCall() const; | |
47 | virtual JSValue* callAsFunction(ExecState*, JSObject* thisObjec, const List& args) = 0; | |
48 | virtual bool implementsHasInstance() const; | |
49 | ||
50 | virtual const ClassInfo* classInfo() const { return &info; } | |
51 | static const ClassInfo info; | |
52 | const Identifier& functionName() const { return m_name; } | |
53 | ||
54 | private: | |
55 | Identifier m_name; | |
56 | }; | |
57 | ||
58 | class FunctionImp : public InternalFunctionImp { | |
59 | friend class ActivationImp; | |
60 | public: | |
61 | FunctionImp(ExecState*, const Identifier& name, FunctionBodyNode*, const ScopeChain&); | |
62 | ||
63 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); | |
64 | virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None); | |
65 | virtual bool deleteProperty(ExecState*, const Identifier& propertyName); | |
66 | ||
67 | virtual bool implementsConstruct() const { return true; } | |
68 | virtual JSObject* construct(ExecState*, const List& args); | |
69 | ||
70 | virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args); | |
71 | ||
72 | // Note: unlike body->paramName, this returns Identifier::null for parameters | |
73 | // that will never get set, due to later param having the same name | |
74 | Identifier getParameterName(int index); | |
75 | ||
76 | virtual const ClassInfo* classInfo() const { return &info; } | |
77 | static const ClassInfo info; | |
78 | ||
79 | RefPtr<FunctionBodyNode> body; | |
80 | ||
81 | void setScope(const ScopeChain& s) { _scope = s; } | |
82 | const ScopeChain& scope() const { return _scope; } | |
83 | ||
84 | virtual void mark(); | |
85 | ||
86 | private: | |
87 | ScopeChain _scope; | |
88 | ||
89 | static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); | |
90 | static JSValue* callerGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); | |
91 | static JSValue* lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); | |
92 | }; | |
93 | ||
94 | class IndexToNameMap { | |
95 | public: | |
96 | IndexToNameMap(FunctionImp*, const List& args); | |
97 | ~IndexToNameMap(); | |
98 | ||
99 | Identifier& operator[](const Identifier& index); | |
100 | bool isMapped(const Identifier& index) const; | |
101 | void unMap(const Identifier& index); | |
102 | ||
103 | private: | |
104 | unsigned size; | |
105 | Identifier* _map; | |
106 | }; | |
107 | ||
108 | class Arguments : public JSObject { | |
109 | public: | |
110 | Arguments(ExecState*, FunctionImp* func, const List& args, ActivationImp* act); | |
111 | virtual void mark(); | |
112 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); | |
113 | virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None); | |
114 | virtual bool deleteProperty(ExecState*, const Identifier& propertyName); | |
115 | virtual const ClassInfo* classInfo() const { return &info; } | |
116 | static const ClassInfo info; | |
117 | private: | |
118 | static JSValue* mappedIndexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot); | |
119 | ||
120 | ActivationImp* _activationObject; | |
121 | mutable IndexToNameMap indexToNameMap; | |
122 | }; | |
123 | ||
124 | class PrototypeFunction : public InternalFunctionImp { | |
125 | public: | |
126 | typedef KJS::JSValue* (*JSMemberFunction)(ExecState*, JSObject*, const List&); | |
127 | ||
128 | PrototypeFunction(ExecState*, int len, const Identifier&, JSMemberFunction); | |
129 | PrototypeFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction); | |
130 | ||
131 | virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const List&); | |
132 | ||
133 | private: | |
134 | const JSMemberFunction m_function; | |
135 | }; | |
136 | ||
137 | ||
138 | // Global Functions | |
139 | JSValue* globalFuncEval(ExecState*, JSObject*, const List&); | |
140 | JSValue* globalFuncParseInt(ExecState*, JSObject*, const List&); | |
141 | JSValue* globalFuncParseFloat(ExecState*, JSObject*, const List&); | |
142 | JSValue* globalFuncIsNaN(ExecState*, JSObject*, const List&); | |
143 | JSValue* globalFuncIsFinite(ExecState*, JSObject*, const List&); | |
144 | JSValue* globalFuncDecodeURI(ExecState*, JSObject*, const List&); | |
145 | JSValue* globalFuncDecodeURIComponent(ExecState*, JSObject*, const List&); | |
146 | JSValue* globalFuncEncodeURI(ExecState*, JSObject*, const List&); | |
147 | JSValue* globalFuncEncodeURIComponent(ExecState*, JSObject*, const List&); | |
148 | JSValue* globalFuncEscape(ExecState*, JSObject*, const List&); | |
149 | JSValue* globalFuncUnescape(ExecState*, JSObject*, const List&); | |
150 | #ifndef NDEBUG | |
151 | JSValue* globalFuncKJSPrint(ExecState*, JSObject*, const List&); | |
152 | #endif | |
153 | ||
154 | static const double mantissaOverflowLowerBound = 9007199254740992.0; | |
155 | double parseIntOverflow(const char*, int length, int radix); | |
156 | ||
157 | } // namespace | |
158 | ||
159 | #endif |