]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSFunction.h
42fd62a4d16c4b673a7fff64416f6539f2d08b4a
[apple/javascriptcore.git] / runtime / JSFunction.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
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 "JSObjectWithGlobalObject.h"
28
29 namespace JSC {
30
31 class ExecutableBase;
32 class FunctionExecutable;
33 class FunctionPrototype;
34 class JSActivation;
35 class JSGlobalObject;
36 class NativeExecutable;
37 class VPtrHackExecutable;
38
39 EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
40
41 class JSFunction : public JSObjectWithGlobalObject {
42 friend class JIT;
43 friend class JSGlobalData;
44
45 typedef JSObjectWithGlobalObject Base;
46
47 public:
48 JSFunction(ExecState*, JSGlobalObject*, Structure*, int length, const Identifier&, NativeFunction);
49 JSFunction(ExecState*, JSGlobalObject*, Structure*, int length, const Identifier&, NativeExecutable*);
50 JSFunction(ExecState*, FunctionExecutable*, ScopeChainNode*);
51 virtual ~JSFunction();
52
53 const UString& name(ExecState*);
54 const UString displayName(ExecState*);
55 const UString calculatedDisplayName(ExecState*);
56
57 ScopeChainNode* scope()
58 {
59 ASSERT(!isHostFunctionNonInline());
60 return m_scopeChain.get();
61 }
62 void setScope(JSGlobalData& globalData, ScopeChainNode* scopeChain)
63 {
64 ASSERT(!isHostFunctionNonInline());
65 m_scopeChain.set(globalData, this, scopeChain);
66 }
67
68 ExecutableBase* executable() const { return m_executable.get(); }
69
70 // To call either of these methods include Executable.h
71 inline bool isHostFunction() const;
72 FunctionExecutable* jsExecutable() const;
73
74 static JS_EXPORTDATA const ClassInfo s_info;
75
76 static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
77 {
78 return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
79 }
80
81 NativeFunction nativeFunction();
82
83 virtual ConstructType getConstructData(ConstructData&);
84 virtual CallType getCallData(CallData&);
85
86 protected:
87 const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
88
89 private:
90 explicit JSFunction(VPtrStealingHackType);
91
92 bool isHostFunctionNonInline() const;
93
94 virtual void preventExtensions(JSGlobalData&);
95 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
96 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
97 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
98 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
99 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
100
101 virtual void visitChildren(SlotVisitor&);
102
103 static JSValue argumentsGetter(ExecState*, JSValue, const Identifier&);
104 static JSValue callerGetter(ExecState*, JSValue, const Identifier&);
105 static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
106
107 WriteBarrier<ExecutableBase> m_executable;
108 WriteBarrier<ScopeChainNode> m_scopeChain;
109 };
110
111 JSFunction* asFunction(JSValue);
112
113 inline JSFunction* asFunction(JSValue value)
114 {
115 ASSERT(asObject(value)->inherits(&JSFunction::s_info));
116 return static_cast<JSFunction*>(asObject(value));
117 }
118
119 } // namespace JSC
120
121 #endif // JSFunction_h