1 | /*
|
---|
2 | * Copyright (C) 1999-2000 Harri Porten ([email protected])
|
---|
3 | * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
|
---|
4 | * Copyright (C) 2007 Cameron Zwarich ([email protected])
|
---|
5 | * Copyright (C) 2007 Maks Orlovich
|
---|
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 JSFunction_h
|
---|
25 | #define JSFunction_h
|
---|
26 |
|
---|
27 | #include "InternalFunction.h"
|
---|
28 | #include "JSVariableObject.h"
|
---|
29 | #include "SymbolTable.h"
|
---|
30 | #include "nodes.h"
|
---|
31 | #include "JSObject.h"
|
---|
32 |
|
---|
33 | namespace JSC {
|
---|
34 |
|
---|
35 | class FunctionBodyNode;
|
---|
36 | class FunctionPrototype;
|
---|
37 | class JSActivation;
|
---|
38 | class JSGlobalObject;
|
---|
39 |
|
---|
40 | class JSFunction : public InternalFunction {
|
---|
41 | friend class CTI;
|
---|
42 | friend class Machine;
|
---|
43 |
|
---|
44 | typedef InternalFunction Base;
|
---|
45 | JSFunction(PassRefPtr<JSC::StructureID> st) : InternalFunction(st), m_scopeChain(NoScopeChain()) {}
|
---|
46 | public:
|
---|
47 | JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
|
---|
48 | ~JSFunction();
|
---|
49 |
|
---|
50 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
|
---|
51 | virtual void put(ExecState*, const Identifier& propertyName, JSValue*, PutPropertySlot&);
|
---|
52 | virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
|
---|
53 |
|
---|
54 | JSObject* construct(ExecState*, const ArgList&);
|
---|
55 | JSValue* call(ExecState*, JSValue* thisValue, const ArgList&);
|
---|
56 |
|
---|
57 | // Note: Returns a null identifier for any parameters that will never get set
|
---|
58 | // due to a later parameter with the same name.
|
---|
59 | const Identifier& getParameterName(int index);
|
---|
60 |
|
---|
61 | void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
|
---|
62 | ScopeChain& scope() { return m_scopeChain; }
|
---|
63 |
|
---|
64 | virtual void mark();
|
---|
65 |
|
---|
66 | static const ClassInfo info;
|
---|
67 |
|
---|
68 | // FIXME: This should be private
|
---|
69 | RefPtr<FunctionBodyNode> m_body;
|
---|
70 |
|
---|
71 | static PassRefPtr<StructureID> createStructureID(JSValue* prototype)
|
---|
72 | {
|
---|
73 | return StructureID::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance));
|
---|
74 | }
|
---|
75 |
|
---|
76 | private:
|
---|
77 | virtual const ClassInfo* classInfo() const { return &info; }
|
---|
78 |
|
---|
79 | virtual ConstructType getConstructData(ConstructData&);
|
---|
80 | virtual CallType getCallData(CallData&);
|
---|
81 |
|
---|
82 | static JSValue* argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
|
---|
83 | static JSValue* callerGetter(ExecState*, const Identifier&, const PropertySlot&);
|
---|
84 | static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
|
---|
85 |
|
---|
86 | ScopeChain m_scopeChain;
|
---|
87 | };
|
---|
88 |
|
---|
89 | JSFunction* asFunction(JSValue*);
|
---|
90 |
|
---|
91 | inline JSFunction* asFunction(JSValue* value)
|
---|
92 | {
|
---|
93 | ASSERT(asObject(value)->inherits(&JSFunction::info));
|
---|
94 | return static_cast<JSFunction*>(asObject(value));
|
---|
95 | }
|
---|
96 |
|
---|
97 | } // namespace kJS
|
---|
98 |
|
---|
99 | #endif // JSFunction_h
|
---|