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;
38 EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*);
40 class JSFunction : public JSObjectWithGlobalObject {
42 friend class JSGlobalData;
44 typedef JSObjectWithGlobalObject Base;
47 JSFunction(ExecState*, JSGlobalObject*, NonNullPassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
49 JSFunction(ExecState*, JSGlobalObject*, NonNullPassRefPtr<Structure>, int length, const Identifier&, PassRefPtr<NativeExecutable>);
51 JSFunction(ExecState*, NonNullPassRefPtr<FunctionExecutable>, ScopeChainNode*);
52 virtual ~JSFunction();
54 const UString& name(ExecState*);
55 const UString displayName(ExecState*);
56 const UString calculatedDisplayName(ExecState*);
60 ASSERT(!isHostFunctionNonInline());
63 void setScope(const ScopeChain& scopeChain)
65 ASSERT(!isHostFunctionNonInline());
66 m_scopeChain = scopeChain;
69 ExecutableBase* executable() const { return m_executable.get(); }
71 // To call either of these methods include Executable.h
72 inline bool isHostFunction() const;
73 FunctionExecutable* jsExecutable() const;
75 static JS_EXPORTDATA const ClassInfo info;
77 static PassRefPtr<Structure> createStructure(JSValue prototype)
79 return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
82 NativeFunction nativeFunction();
84 virtual ConstructType getConstructData(ConstructData&);
85 virtual CallType getCallData(CallData&);
88 const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesMarkChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
91 JSFunction(NonNullPassRefPtr<Structure>);
93 bool isHostFunctionNonInline() const;
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 markChildren(MarkStack&);
103 virtual const ClassInfo* classInfo() const { return &info; }
105 static JSValue argumentsGetter(ExecState*, JSValue, const Identifier&);
106 static JSValue callerGetter(ExecState*, JSValue, const Identifier&);
107 static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
109 RefPtr<ExecutableBase> m_executable;
110 ScopeChain m_scopeChain;
113 JSFunction* asFunction(JSValue);
115 inline JSFunction* asFunction(JSValue value)
117 ASSERT(asObject(value)->inherits(&JSFunction::info));
118 return static_cast<JSFunction*>(asObject(value));
123 #endif // JSFunction_h