KJS

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

KDE's Doxygen guidelines are available online.