Changeset 798 in webkit for trunk/JavaScriptCore/kjs/function.h
- Timestamp:
- Mar 21, 2002, 4:31:57 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.h
r6 r798 1 // -*- c-basic-offset: 2 -*- 1 2 /* 2 3 * This file is part of the KDE libraries … … 17 18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 19 * Boston, MA 02111-1307, USA. 20 * 21 * $Id$ 19 22 */ 20 23 … … 22 25 #define _KJS_FUNCTION_H_ 23 26 24 #include <assert.h> 25 26 #include "object.h" 27 #include "types.h" 27 #include "internal.h" 28 28 29 29 namespace KJS { 30 30 31 enum CodeType { GlobalCode,32 EvalCode,33 FunctionCode,34 AnonymousCode,35 HostCode };36 37 enum FunctionAttribute { ImplicitNone, ImplicitThis, ImplicitParents };38 39 class Function;40 31 class Parameter; 41 32 42 33 /** 43 * @short Implementation class for Functions.34 * @short Implementation class for internal Functions. 44 35 */ 45 class FunctionImp : public ObjectImp {36 class FunctionImp : public InternalFunctionImp { 46 37 friend class Function; 38 friend class ActivationImp; 47 39 public: 48 FunctionImp(); 49 FunctionImp(const UString &n); 40 FunctionImp(ExecState *exec, const UString &n = UString::null); 50 41 virtual ~FunctionImp(); 51 virtual const TypeInfo* typeInfo() const { return &info; } 52 static const TypeInfo info; 53 virtual Completion execute(const List &) = 0; 54 bool hasAttribute(FunctionAttribute a) const { return (attr & a) != 0; } 42 43 virtual void mark(); 44 45 virtual bool implementsCall() const; 46 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 47 48 void addParameter(const UString &n); 55 49 virtual CodeType codeType() const = 0; 56 KJSO thisValue() const; 57 v oid addParameter(const UString &n);58 void setLength(int l);59 KJSO executeCall(Imp *thisV, const List *args); 60 KJSO executeCall(Imp *thisV, const List *args, const List *extraScope);61 UString name() const;50 51 virtual Completion execute(ExecState *exec) = 0; 52 UString name() const { return ident; } 53 54 virtual const ClassInfo *classInfo() const { return &info; } 55 static const ClassInfo info; 62 56 protected: 57 Parameter *param; 63 58 UString ident; 64 FunctionAttribute attr; 65 Parameter *param; 59 66 60 private: 67 void processParameters(const List *); 61 void processParameters(ExecState *exec, const List &); 62 virtual void processVarDecls(ExecState *exec); 63 64 void pushArgs(ExecState *exec, const Object &args); 65 void popArgs(ExecState *exec); 66 ListImp *argStack; 68 67 }; 69 68 70 /** 71 * @short Abstract base class for internal functions. 72 */ 73 class InternalFunctionImp : public FunctionImp { 69 class DeclaredFunctionImp : public FunctionImp { 74 70 public: 75 InternalFunctionImp(); 76 InternalFunctionImp(int l); 77 InternalFunctionImp(const UString &n); 78 virtual ~InternalFunctionImp() { } 79 virtual String toString() const; 80 virtual KJSO toPrimitive(Type) const { return toString(); } 81 virtual const TypeInfo* typeInfo() const { return &info; } 82 static const TypeInfo info; 83 virtual Completion execute(const List &); 84 virtual CodeType codeType() const { return HostCode; } 71 DeclaredFunctionImp(ExecState *exec, const UString &n, 72 FunctionBodyNode *b, const List &sc); 73 ~DeclaredFunctionImp(); 74 75 bool implementsConstruct() const; 76 Object construct(ExecState *exec, const List &args); 77 78 virtual Completion execute(ExecState *exec); 79 CodeType codeType() const { return FunctionCode; } 80 FunctionBodyNode *body; 81 82 virtual const ClassInfo *classInfo() const { return &info; } 83 static const ClassInfo info; 84 private: 85 virtual void processVarDecls(ExecState *exec); 85 86 }; 86 87 87 /** 88 * @short Base class for Function objects. 89 */ 90 class Function : public KJSO{88 89 90 91 class ArgumentsImp : public ObjectImp { 91 92 public: 92 Function(Imp *); 93 virtual ~Function() { } 94 Completion execute(const List &); 95 bool hasAttribute(FunctionAttribute a) const; 96 CodeType codeType() const { return HostCode; } 97 KJSO thisValue() const; 98 }; 99 100 /** 101 * @short Implementation class for Constructors. 102 */ 103 class ConstructorImp : public InternalFunctionImp { 104 public: 105 ConstructorImp(); 106 ConstructorImp(const UString &n); /* TODO: add length */ 107 ConstructorImp(const KJSO &, int); 108 ConstructorImp(const UString &n, const KJSO &p, int len); 109 virtual ~ConstructorImp(); 110 virtual const TypeInfo* typeInfo() const { return &info; } 111 static const TypeInfo info; 112 virtual Completion execute(const List &); 113 virtual Object construct(const List &) = 0; 93 ArgumentsImp(ExecState *exec, FunctionImp *func, const List &args); 94 95 virtual const ClassInfo *classInfo() const { return &info; } 96 static const ClassInfo info; 114 97 }; 115 98 116 /** 117 * @short Constructor object for use with the 'new' operator 118 */ 119 class Constructor : public Function { 99 class ActivationImp : public ObjectImp { 120 100 public: 121 Constructor(Imp *);122 virtual ~Constructor();123 // Constructor(const Object& proto, int len); 124 /**125 * @return @ref ConstructorType 126 */127 Completion execute(const List &);128 Object construct(const List &args);129 static Constructor dynamicCast(const KJSO &obj);101 ActivationImp(ExecState *exec, FunctionImp *f, const List &args); 102 ~ActivationImp(); 103 104 Object argumentsObject() { return Object(arguments); } 105 106 virtual const ClassInfo *classInfo() const { return &info; } 107 static const ClassInfo info; 108 private: 109 ObjectImp* arguments; 130 110 }; 111 112 class GlobalFuncImp : public InternalFunctionImp { 113 public: 114 GlobalFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len); 115 virtual bool implementsCall() const; 116 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 117 virtual CodeType codeType() const; 118 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape }; 119 private: 120 int id; 121 }; 122 123 131 124 132 125 }; // namespace
Note:
See TracChangeset
for help on using the changeset viewer.