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
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.
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.
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.
27 #include "JSObjectWithGlobalObject.h"
32 class FunctionExecutable
;
33 class FunctionPrototype
;
36 class NativeExecutable
;
37 class VPtrHackExecutable
;
39 EncodedJSValue JSC_HOST_CALL
callHostFunctionAsConstructor(ExecState
*);
41 class JSFunction
: public JSObjectWithGlobalObject
{
43 friend class JSGlobalData
;
45 typedef JSObjectWithGlobalObject Base
;
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();
53 const UString
& name(ExecState
*);
54 const UString
displayName(ExecState
*);
55 const UString
calculatedDisplayName(ExecState
*);
57 ScopeChainNode
* scope()
59 ASSERT(!isHostFunctionNonInline());
60 return m_scopeChain
.get();
62 void setScope(JSGlobalData
& globalData
, ScopeChainNode
* scopeChain
)
64 ASSERT(!isHostFunctionNonInline());
65 m_scopeChain
.set(globalData
, this, scopeChain
);
68 ExecutableBase
* executable() const { return m_executable
.get(); }
70 // To call either of these methods include Executable.h
71 inline bool isHostFunction() const;
72 FunctionExecutable
* jsExecutable() const;
74 static JS_EXPORTDATA
const ClassInfo s_info
;
76 static Structure
* createStructure(JSGlobalData
& globalData
, JSValue prototype
)
78 return Structure::create(globalData
, prototype
, TypeInfo(ObjectType
, StructureFlags
), AnonymousSlotCount
, &s_info
);
81 NativeFunction
nativeFunction();
83 virtual ConstructType
getConstructData(ConstructData
&);
84 virtual CallType
getCallData(CallData
&);
87 const static unsigned StructureFlags
= OverridesGetOwnPropertySlot
| ImplementsHasInstance
| OverridesVisitChildren
| OverridesGetPropertyNames
| JSObject::StructureFlags
;
90 explicit JSFunction(VPtrStealingHackType
);
92 bool isHostFunctionNonInline() const;
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
);
101 virtual void visitChildren(SlotVisitor
&);
103 static JSValue
argumentsGetter(ExecState
*, JSValue
, const Identifier
&);
104 static JSValue
callerGetter(ExecState
*, JSValue
, const Identifier
&);
105 static JSValue
lengthGetter(ExecState
*, JSValue
, const Identifier
&);
107 WriteBarrier
<ExecutableBase
> m_executable
;
108 WriteBarrier
<ScopeChainNode
> m_scopeChain
;
111 JSFunction
* asFunction(JSValue
);
113 inline JSFunction
* asFunction(JSValue value
)
115 ASSERT(asObject(value
)->inherits(&JSFunction::s_info
));
116 return static_cast<JSFunction
*>(asObject(value
));
121 #endif // JSFunction_h