1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003, 2006 Apple Computer, Inc.
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.
24 #ifndef KJS_SCRIPTFUNCTION_H
25 #define KJS_SCRIPTFUNCTION_H
33 class FunctionBodyNode
;
36 * @short Implementation class for internal Functions.
38 class KJS_EXPORT FunctionImp
: public InternalFunctionImp
{
39 friend class ActivationImp
;
41 FunctionImp(ExecState
* exec
, const Identifier
& n
, FunctionBodyNode
* b
, const ScopeChain
&sc
);
42 virtual ~FunctionImp();
44 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
45 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
= None
);
46 virtual bool deleteProperty(ExecState
*exec
, const Identifier
&propertyName
);
48 virtual JSValue
*callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
);
50 bool implementsConstruct() const;
51 JSObject
*construct(ExecState
*exec
, const List
&args
);
53 // Note: implemented in nodes2string.cpp
54 UString
toSource() const;
56 // Note: unlike body->paramName, this returns Identifier::null for parameters
57 // that will never get set, due to later param having the same name
58 Identifier
getParameterName(int index
);
60 virtual const ClassInfo
*classInfo() const { return &info
; }
61 static const ClassInfo info
;
63 RefPtr
<FunctionBodyNode
> body
;
66 * Returns the scope of this object. This is used when execution declared
67 * functions - the execution context for the function is initialized with
68 * extra object in it's scope. An example of this is functions declared
69 * inside other functions:
81 * f.prototype = new String();
84 * When the function f.b is executed, its scope will include properties of
85 * f. So in the example above the return value of f.b() would be the new
86 * String object that was assigned to f.prototype.
88 * @param exec The current execution state
89 * @return The function's scope
91 const ScopeChain
&scope() const { return _scope
; }
92 void setScope(const ScopeChain
&s
) { _scope
= s
; }
96 void initialCompile(ExecState
* newExec
);
100 static JSValue
*argumentsGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
101 static JSValue
*callerGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
102 static JSValue
*lengthGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
103 static JSValue
*nameGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
105 void passInParameters(ExecState
*exec
, const List
&);
108 // For compatibility...
109 typedef FunctionImp DeclaredFunctionImp
;