source: webkit/trunk/JavaScriptCore/runtime/JSFunction.h@ 47582

Last change on this file since 47582 was 47582, checked in by [email protected], 16 years ago

Roll out r47571 and related build fixes as it caused us to leak the world without warning.

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003, 2006, 2007, 2008, 2009 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 "Executable.h"
28#include "InternalFunction.h"
29
30namespace JSC {
31
32 class FunctionPrototype;
33 class JSActivation;
34 class JSGlobalObject;
35
36 class JSFunction : public InternalFunction {
37 friend class JIT;
38 friend struct VPtrSet;
39
40 typedef InternalFunction Base;
41
42 public:
43 JSFunction(ExecState*, PassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
44 JSFunction(ExecState*, PassRefPtr<FunctionExecutable>, ScopeChainNode*);
45 virtual ~JSFunction();
46
47 JSObject* construct(ExecState*, const ArgList&);
48 JSValue call(ExecState*, JSValue thisValue, const ArgList&);
49
50 void setScope(const ScopeChain& scopeChain) { setScopeChain(scopeChain); }
51 ScopeChain& scope() { return scopeChain(); }
52
53 FunctionExecutable* executable() const { return m_executable.get(); }
54
55 static JS_EXPORTDATA const ClassInfo info;
56
57 static PassRefPtr<Structure> createStructure(JSValue prototype)
58 {
59 return Structure::create(prototype, TypeInfo(ObjectType, ImplementsHasInstance));
60 }
61
62 NativeFunction nativeFunction()
63 {
64 return *reinterpret_cast<NativeFunction*>(m_data);
65 }
66
67 virtual ConstructType getConstructData(ConstructData&);
68 virtual CallType getCallData(CallData&);
69
70 private:
71 JSFunction(PassRefPtr<Structure>);
72
73 bool isHostFunction() const;
74 bool isHostFunctionNonInline() const;
75
76 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
77 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
78 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
79
80 virtual void markChildren(MarkStack&);
81
82 virtual const ClassInfo* classInfo() const { return &info; }
83
84 static JSValue argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
85 static JSValue callerGetter(ExecState*, const Identifier&, const PropertySlot&);
86 static JSValue lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
87
88 RefPtr<FunctionExecutable> m_executable;
89 ScopeChain& scopeChain()
90 {
91 ASSERT(!isHostFunctionNonInline());
92 return *reinterpret_cast<ScopeChain*>(m_data);
93 }
94 void clearScopeChain()
95 {
96 ASSERT(!isHostFunctionNonInline());
97 new (m_data) ScopeChain(NoScopeChain());
98 }
99 void setScopeChain(ScopeChainNode* sc)
100 {
101 ASSERT(!isHostFunctionNonInline());
102 new (m_data) ScopeChain(sc);
103 }
104 void setScopeChain(const ScopeChain& sc)
105 {
106 ASSERT(!isHostFunctionNonInline());
107 *reinterpret_cast<ScopeChain*>(m_data) = sc;
108 }
109 void setNativeFunction(NativeFunction func)
110 {
111 *reinterpret_cast<NativeFunction*>(m_data) = func;
112 }
113 unsigned char m_data[sizeof(void*)];
114 };
115
116 JSFunction* asFunction(JSValue);
117
118 inline JSFunction* asFunction(JSValue value)
119 {
120 ASSERT(asObject(value)->inherits(&JSFunction::info));
121 return static_cast<JSFunction*>(asObject(value));
122 }
123
124 inline JSFunction* FunctionExecutable::make(ExecState* exec, ScopeChainNode* scopeChain)
125 {
126 return new (exec) JSFunction(exec, this, scopeChain);
127 }
128
129} // namespace JSC
130
131#endif // JSFunction_h
Note: See TracBrowser for help on using the repository browser.