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

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

structure typeinfo flags should be inherited.
https://bugs.webkit.org/show_bug.cgi?id=30468

Reviewed by Gavin Barraclough.

Add StructureFlag constant to the various JSC classes and use
it for the TypeInfo construction. This allows us to simply
accumulate flags by basing each classes StructureInfo on its parents.

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