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

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 NUMBER_OBJECT_H_
0022 #define NUMBER_OBJECT_H_
0023 
0024 #include "function_object.h"
0025 #include "JSWrapperObject.h"
0026 
0027 namespace KJS
0028 {
0029 
0030 class NumberInstance : public JSWrapperObject
0031 {
0032 public:
0033     NumberInstance(JSObject *proto);
0034 
0035     const ClassInfo *classInfo() const override
0036     {
0037         return &info;
0038     }
0039     static const ClassInfo info;
0040 
0041     JSObject *valueClone(Interpreter *targetCtx) const override;
0042 };
0043 
0044 /**
0045  * @internal
0046  *
0047  * The initial value of Number.prototype (and thus all objects created
0048  * with the Number constructor
0049  */
0050 class NumberPrototype : public NumberInstance
0051 {
0052 public:
0053     NumberPrototype(ExecState *exec,
0054                     ObjectPrototype *objProto,
0055                     FunctionPrototype *funcProto);
0056 };
0057 
0058 /**
0059  * @internal
0060  *
0061  * Class to implement all methods that are properties of the
0062  * Number.prototype object
0063  */
0064 class NumberProtoFunc : public InternalFunctionImp
0065 {
0066 public:
0067     NumberProtoFunc(ExecState *, FunctionPrototype *, int i, int len, const Identifier &);
0068 
0069     JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
0070 
0071     enum { ToString, ToLocaleString, ValueOf, ToFixed, ToExponential, ToPrecision };
0072 private:
0073     int id;
0074 };
0075 
0076 /**
0077  * @internal
0078  *
0079  * The initial value of the global variable's "Number" property
0080  */
0081 class NumberObjectImp : public InternalFunctionImp
0082 {
0083     using InternalFunctionImp::construct;
0084 public:
0085     NumberObjectImp(ExecState *exec,
0086                     FunctionPrototype *funcProto,
0087                     NumberPrototype *numberProto);
0088 
0089     bool implementsConstruct() const override;
0090     JSObject *construct(ExecState *exec, const List &args) override;
0091 
0092     JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
0093 
0094     using KJS::JSObject::getOwnPropertySlot;
0095     bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override;
0096     JSValue *getValueProperty(ExecState *exec, int token) const;
0097 
0098     const ClassInfo *classInfo() const override
0099     {
0100         return &info;
0101     }
0102     static const ClassInfo info;
0103     enum { NaNValue, NegInfinity, PosInfinity, MaxValue, MinValue,
0104         //ES6 (Draft 08.11.2013)
0105         MaxSafeInteger, MinSafeInteger,
0106         IsFinite, IsInteger, IsNaN, IsSafeInteger, ParseInt, ParseFloat
0107     };
0108 
0109     Completion execute(const List &);
0110     JSObject *construct(const List &);
0111 };
0112 
0113 class NumberFuncImp : public InternalFunctionImp {
0114 public:
0115     NumberFuncImp(ExecState *exec, int i, int l, const Identifier&);
0116     JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
0117 private:
0118     int id;
0119 };
0120 
0121 } // namespace
0122 
0123 #endif