File indexing completed on 2024-05-12 15:43:17

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
0004  *
0005  *  This library is free software; you can redistribute it and/or
0006  *  modify it under the terms of the GNU Lesser General Public
0007  *  License as published by the Free Software Foundation; either
0008  *  version 2 of the License, or (at your option) any later version.
0009  *
0010  *  This library is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  *  Lesser General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU Lesser General Public
0016  *  License along with this library; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  *
0019  */
0020 
0021 #ifndef DATE_OBJECT_H
0022 #define DATE_OBJECT_H
0023 
0024 #include "function.h"
0025 #include "JSWrapperObject.h"
0026 
0027 struct tm;
0028 
0029 namespace KJS
0030 {
0031 
0032 class FunctionPrototype;
0033 class ObjectPrototype;
0034 
0035 class DateInstance : public JSWrapperObject
0036 {
0037 public:
0038     DateInstance(JSObject *proto);
0039 
0040     bool getTime(tm &t, int &gmtoffset) const;
0041     bool getUTCTime(tm &t) const;
0042     bool getTime(double &ms, int &gmtoffset) const;
0043     bool getUTCTime(double &ms) const;
0044 
0045     const ClassInfo *classInfo() const override
0046     {
0047         return &info;
0048     }
0049     static const ClassInfo info;
0050 
0051     JSObject *valueClone(Interpreter *targetCtx) const override;
0052 };
0053 
0054 /**
0055  * @internal
0056  *
0057  * The initial value of Date.prototype (and thus all objects created
0058  * with the Date constructor
0059  */
0060 class DatePrototype : public DateInstance
0061 {
0062 public:
0063     DatePrototype(ExecState *, ObjectPrototype *);
0064     using KJS::JSObject::getOwnPropertySlot;
0065     bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override;
0066     const ClassInfo *classInfo() const override
0067     {
0068         return &info;
0069     }
0070     static const ClassInfo info;
0071 };
0072 
0073 /**
0074     * @internal
0075  *
0076  * Class to implement all methods that are properties of the
0077  * Date.prototype object
0078  */
0079 class DateProtoFunc : public InternalFunctionImp
0080 {
0081 public:
0082     DateProtoFunc(ExecState *, int i, int len, const Identifier &date);
0083 
0084     JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args) override;
0085 
0086     enum { ToString, ToDateString, ToTimeString, ToLocaleString,
0087            ToLocaleDateString, ToLocaleTimeString, ValueOf, GetTime,
0088            GetFullYear, GetMonth, GetDate, GetDay, GetHours, GetMinutes,
0089            GetSeconds, GetMilliSeconds, GetTimezoneOffset, SetTime,
0090            SetMilliSeconds, SetSeconds, SetMinutes, SetHours, SetDate,
0091            SetMonth, SetFullYear, ToUTCString, ToISOString, ToJSON,
0092            // non-normative properties (Appendix B)
0093            GetYear, SetYear, ToGMTString
0094          };
0095 private:
0096     short id;
0097     bool utc;
0098 };
0099 
0100 /**
0101  * @internal
0102  *
0103  * The initial value of the global variable's "Date" property
0104  */
0105 class DateObjectImp : public InternalFunctionImp
0106 {
0107     using InternalFunctionImp::construct;
0108 public:
0109     DateObjectImp(ExecState *, FunctionPrototype *, DatePrototype *);
0110 
0111     bool implementsConstruct() const override;
0112     JSObject *construct(ExecState *, const List &args) override;
0113     JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args) override;
0114 
0115     Completion execute(const List &);
0116     JSObject *construct(const List &);
0117 };
0118 
0119 } // namespace
0120 
0121 #endif