1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifndef NUMBER_OBJECT_H_
23#define NUMBER_OBJECT_H_
24
25#include "function_object.h"
26#include "JSWrapperObject.h"
27
28namespace KJS {
29
30 class NumberInstance : public JSWrapperObject {
31 public:
32 NumberInstance(JSObject *proto);
33
34 virtual const ClassInfo *classInfo() const { return &info; }
35 static const ClassInfo info;
36
37 virtual JSObject* valueClone(Interpreter* targetCtx) const;
38 };
39
40 /**
41 * @internal
42 *
43 * The initial value of Number.prototype (and thus all objects created
44 * with the Number constructor
45 */
46 class NumberPrototype : public NumberInstance {
47 public:
48 NumberPrototype(ExecState *exec,
49 ObjectPrototype *objProto,
50 FunctionPrototype *funcProto);
51 };
52
53 /**
54 * @internal
55 *
56 * Class to implement all methods that are properties of the
57 * Number.prototype object
58 */
59 class NumberProtoFunc : public InternalFunctionImp {
60 public:
61 NumberProtoFunc(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
62
63 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
64
65 enum { ToString, ToLocaleString, ValueOf, ToFixed, ToExponential, ToPrecision };
66 private:
67 int id;
68 };
69
70 /**
71 * @internal
72 *
73 * The initial value of the global variable's "Number" property
74 */
75 class NumberObjectImp : public InternalFunctionImp {
76 using InternalFunctionImp::construct;
77 public:
78 NumberObjectImp(ExecState *exec,
79 FunctionPrototype *funcProto,
80 NumberPrototype *numberProto);
81
82 virtual bool implementsConstruct() const;
83 virtual JSObject *construct(ExecState *exec, const List &args);
84
85 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
86
87 using KJS::JSObject::getOwnPropertySlot;
88 bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
89 JSValue *getValueProperty(ExecState *exec, int token) const;
90
91 virtual const ClassInfo *classInfo() const { return &info; }
92 static const ClassInfo info;
93 enum { NaNValue, NegInfinity, PosInfinity, MaxValue, MinValue,
94 //ES6 (Draft 08.11.2013)
95 MaxSafeInteger, MinSafeInteger,
96 IsFinite, IsInteger, IsNaN, IsSafeInteger, ParseInt, ParseFloat
97 };
98
99 Completion execute(const List &);
100 JSObject *construct(const List &);
101 };
102
103 class NumberFuncImp : public InternalFunctionImp {
104 public:
105 NumberFuncImp(ExecState *exec, int i, int l, const Identifier&);
106 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
107 private:
108 int id;
109 };
110
111} // namespace
112
113#endif
114