Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSNumberCell.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library 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 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef JSNumberCell_h
24 #define JSNumberCell_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSNumberCell.h:24:9`!
25
26 #include "CallFrame.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/CallFrame.h`/
27 #include "JSCell.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSCell.h`/
28 #include "JSImmediate.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSImmediate.h`/
29 #include "Collector.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.h`/
30 #include "UString.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/UString.h`/
31 #include <stddef.h> // for size_t
32
33 namespace JSCcxx . . $ QTJSC/ {
34
35 extern const double NaNcxx . . $ QTJSC/NaN.;
36 extern const double Infcxx . . $ QTJSC/Inf.;
37
38 #if USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSVALUE32)
39 JSValue jsNumberCell(ExecState*, double);
40
41 class Identifier;
42 class JSCell;
43 class JSObject;
44 class JSString;
45 class PropertySlot;
46
47 struct ClassInfo;
48 struct Instruction;
49
50 class JSNumberCell : public JSCell {
51 friend class JIT;
52 friend JSValue jsNumberCell(JSGlobalData*, double);
53 friend JSValue jsNumberCell(ExecState*, double);
54
55 public:
56 double value() const { return m_value; }
57
58 virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
59 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
60 virtual bool toBoolean(ExecState*) const;
61 virtual double toNumber(ExecState*) const;
62 virtual UString toString(ExecState*) const;
63 virtual JSObject* toObject(ExecState*) const;
64
65 virtual UString toThisString(ExecState*) const;
66 virtual JSObject* toThisObject(ExecState*) const;
67 virtual JSValue getJSNumber();
68
69 void* operator new(size_t size, ExecState* exec)
70 {
71 return exec->heap()->allocateNumber(size);
72 }
73
74 void* operator new(size_t size, JSGlobalData* globalData)
75 {
76 return globalData->heap.allocateNumber(size);
77 }
78
79 static PassRefPtr<Structure> createStructure(JSValue proto) { return Structure::create(proto, TypeInfo(NumberType, OverridesGetOwnPropertySlot | NeedsThisConversion)); }
80
81 private:
82 JSNumberCell(JSGlobalData* globalData, double value)
83 : JSCell(globalData->numberStructure.get())
84 , m_value(value)
85 {
86 }
87
88 JSNumberCell(ExecState* exec, double value)
89 : JSCell(exec->globalData().numberStructure.get())
90 , m_value(value)
91 {
92 }
93
94 virtual bool getUInt32(uint32_t&) const;
95
96 double m_value;
97 };
98
99 JSValue jsNumberCell(JSGlobalData*, double);
100
101 inline bool isNumberCell(JSValue v)
102 {
103 return v.isCell() && v.asCell()->isNumber();
104 }
105
106 inline JSNumberCell* asNumberCell(JSValue v)
107 {
108 ASSERT(isNumberCell(v));
109 return static_cast<JSNumberCell*>(v.asCell());
110 }
111
112 ALWAYS_INLINE JSValue::JSValue(EncodeAsDoubleTag, ExecState* exec, double d)
113 {
114 *this = jsNumberCell(exec, d);
115 }
116
117 inline JSValue::JSValue(ExecState* exec, double d)
118 {
119 JSValue v = JSImmediate::from(d);
120 *this = v ? v : jsNumberCell(exec, d);
121 }
122
123 inline JSValue::JSValue(ExecState* exec, int i)
124 {
125 JSValue v = JSImmediate::from(i);
126 *this = v ? v : jsNumberCell(exec, i);
127 }
128
129 inline JSValue::JSValue(ExecState* exec, unsigned i)
130 {
131 JSValue v = JSImmediate::from(i);
132 *this = v ? v : jsNumberCell(exec, i);
133 }
134
135 inline JSValue::JSValue(ExecState* exec, long i)
136 {
137 JSValue v = JSImmediate::from(i);
138 *this = v ? v : jsNumberCell(exec, i);
139 }
140
141 inline JSValue::JSValue(ExecState* exec, unsigned long i)
142 {
143 JSValue v = JSImmediate::from(i);
144 *this = v ? v : jsNumberCell(exec, i);
145 }
146
147 inline JSValue::JSValue(ExecState* exec, long long i)
148 {
149 JSValue v = JSImmediate::from(i);
150 *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
151 }
152
153 inline JSValue::JSValue(ExecState* exec, unsigned long long i)
154 {
155 JSValue v = JSImmediate::from(i);
156 *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
157 }
158
159 inline JSValue::JSValue(JSGlobalData* globalData, double d)
160 {
161 JSValue v = JSImmediate::from(d);
162 *this = v ? v : jsNumberCell(globalData, d);
163 }
164
165 inline JSValue::JSValue(JSGlobalData* globalData, int i)
166 {
167 JSValue v = JSImmediate::from(i);
168 *this = v ? v : jsNumberCell(globalData, i);
169 }
170
171 inline JSValue::JSValue(JSGlobalData* globalData, unsigned i)
172 {
173 JSValue v = JSImmediate::from(i);
174 *this = v ? v : jsNumberCell(globalData, i);
175 }
176
177 inline bool JSValue::isDouble() const
178 {
179 return isNumberCell(asValue());
180 }
181
182 inline double JSValue::asDouble() const
183 {
184 return asNumberCell(asValue())->value();
185 }
186
187 inline bool JSValue::isNumber() const
188 {
189 return JSImmediate::isNumber(asValue()) || isDouble();
190 }
191
192 inline double JSValue::uncheckedGetNumber() const
193 {
194 ASSERT(isNumber());
195 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asDouble();
196 }
197
198 #endif // USE(JSVALUE32)
199
200 #if USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSVALUE64)
201 ALWAYS_INLINEcxx . . $ `../3rdparty/javascriptcore/JavaScriptCore/wtf/AlwaysInline.h:25:9`! JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(5fe54dd8cb234ce6).(EncodeAsDoubleTagcxx . . $ QTJSC/JSValue#EncodeAsDoubleTag#, ExecStatecxx . . $ QTJSC/ExecState#*, double d)
202 {
203 *this =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). JSImmediatecxx . . $ QTJSC/JSImmediate#::fromNumberOutsideIntegerRangecxx . . $ QTJSC/JSImmediate#fromNumberOutsideIntegerRange(c1bdc4891e834261).(d);
204 }
205
206 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(33eae00a62075347).(ExecStatecxx . . $ QTJSC/ExecState#*, double d)
207 {
208 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(2518cc0365fa71e2).(d);
209 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
210 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
211 }
212
213 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(4670b007b83e7883).(ExecStatecxx . . $ QTJSC/ExecState#*, int i)
214 {
215 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(62cd4205711aa0e8).(i);
216 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
217 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
218 }
219
220 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(7dbbf77d47108298).(ExecStatecxx . . $ QTJSC/ExecState#*, unsigned i)
221 {
222 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(65de979777e37a3b).(i);
223 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
224 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
225 }
226
227 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(47ec9b1e7154582e).(ExecStatecxx . . $ QTJSC/ExecState#*, long i)
228 {
229 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(48382e65e89b9a3).(i);
230 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
231 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
232 }
233
234 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(5296ab2051074c5a).(ExecStatecxx . . $ QTJSC/ExecState#*, unsigned long i)
235 {
236 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(ec27527144380d24).(i);
237 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
238 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
239 }
240
241 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(81444fa371ee5a97).(ExecStatecxx . . $ QTJSC/ExecState#*, long long i)
242 {
243 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(2518cc0365fa71e2).(static_cast<double>(i));
244 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
245 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
246 }
247
248 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(1c6990820eb95d48).(ExecStatecxx . . $ QTJSC/ExecState#*, unsigned long long i)
249 {
250 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(2518cc0365fa71e2).(static_cast<double>(i));
251 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
252 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
253 }
254
255 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(61f1d91c89410fd3).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#*, double d)
256 {
257 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(2518cc0365fa71e2).(d);
258 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
259 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
260 }
261
262 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(22b54ecaa1089487).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#*, int i)
263 {
264 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(62cd4205711aa0e8).(i);
265 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
266 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
267 }
268
269 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(59a652c37c73989d).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#*, unsigned i)
270 {
271 JSValuecxx . . $ QTJSC/JSValue# v = JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(65de979777e37a3b).(i);
272 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(v);
273 *this =cxx . . $ QTJSC/JSValue#`operator=`(af0e8a528f82a1b5). v;
274 }
275
276 inline bool JSValuecxx . . $ QTJSC/JSValue#::isDoublecxx . . $ QTJSC/JSValue#isDouble(50ce9a9e25b4a850).() const
277 {
278 return JSImmediatecxx . . $ QTJSC/JSImmediate#::isDoublecxx . . $ QTJSC/JSImmediate#isDouble(a6f765323ba532ee).(asValuecxx . . $ QTJSC/JSValue#asValue(2b3a0f51c71d9b1b).());
279 }
280
281 inline double JSValuecxx . . $ QTJSC/JSValue#::asDoublecxx . . $ QTJSC/JSValue#asDouble(21b6c25e127938e2).() const
282 {
283 return JSImmediatecxx . . $ QTJSC/JSImmediate#::doubleValuecxx . . $ QTJSC/JSImmediate#doubleValue(4dcc3f5c9d69f4c5).(asValuecxx . . $ QTJSC/JSValue#asValue(2b3a0f51c71d9b1b).());
284 }
285
286 inline bool JSValuecxx . . $ QTJSC/JSValue#::isNumbercxx . . $ QTJSC/JSValue#isNumber(50ce9a9e25b4a850).() const
287 {
288 return JSImmediatecxx . . $ QTJSC/JSImmediate#::isNumbercxx . . $ QTJSC/JSImmediate#isNumber(a6f765323ba532ee).(asValuecxx . . $ QTJSC/JSValue#asValue(2b3a0f51c71d9b1b).());
289 }
290
291 inline double JSValuecxx . . $ QTJSC/JSValue#::uncheckedGetNumbercxx . . $ QTJSC/JSValue#uncheckedGetNumber(21b6c25e127938e2).() const
292 {
293 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(isNumber());
294 return JSImmediatecxx . . $ QTJSC/JSImmediate#::toDoublecxx . . $ QTJSC/JSImmediate#toDouble(4dcc3f5c9d69f4c5).(asValuecxx . . $ QTJSC/JSValue#asValue(2b3a0f51c71d9b1b).());
295 }
296
297 #endif // USE(JSVALUE64)
298
299 #if USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSVALUE32) || USEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:55:9`!(JSVALUE64)
300
301 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(6a1e3ba498d3f383).(ExecStatecxx . . $ QTJSC/ExecState#*, char i)
302 {
303 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(JSImmediate::from(i));
304 *this =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(e0395d9cc24f05a8).(i);
305 }
306
307 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(431e2dbec511728e).(ExecStatecxx . . $ QTJSC/ExecState#*, unsigned char i)
308 {
309 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(JSImmediate::from(i));
310 *this =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(40f1e8f801f1768b).(i);
311 }
312
313 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(85b9461a0539e308).(ExecStatecxx . . $ QTJSC/ExecState#*, short i)
314 {
315 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(JSImmediate::from(i));
316 *this =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(1b80fab67474f4a4).(i);
317 }
318
319 inline JSValuecxx . . $ QTJSC/JSValue#::JSValuecxx . . $ QTJSC/JSValue#JSValue(fae765621880a10f).(ExecStatecxx . . $ QTJSC/ExecState#*, unsigned short i)
320 {
321 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(JSImmediate::from(i));
322 *this =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). JSImmediatecxx . . $ QTJSC/JSImmediate#::fromcxx . . $ QTJSC/JSImmediate#from(3e49540df8297168).(i);
323 }
324
325 inline JSValuecxx . . $ QTJSC/JSValue# jsNaNcxx . . $ QTJSC/jsNaN(3fbe51058e39576a).(ExecStatecxx . . $ QTJSC/ExecState#* exec)
326 {
327 return jsNumbercxx . . $ QTJSC/jsNumber(88e66938454912cb).(exec, NaNcxx . . $ QTJSC/NaN.);
328 }
329
330 inline JSValuecxx . . $ QTJSC/JSValue# jsNaNcxx . . $ QTJSC/jsNaN(5f262fe1c647dd02).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#* globalData)
331 {
332 return jsNumbercxx . . $ QTJSC/jsNumber(cd43e1c860546154).(globalData, NaNcxx . . $ QTJSC/NaN.);
333 }
334
335 // --- JSValue inlines ----------------------------
336
337 ALWAYS_INLINEcxx . . $ `../3rdparty/javascriptcore/JavaScriptCore/wtf/AlwaysInline.h:25:9`! JSValuecxx . . $ QTJSC/JSValue# JSValuecxx . . $ QTJSC/JSValue#::toJSNumbercxx . . $ QTJSC/JSValue#toJSNumber(3edd4bd77d4e7240).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
338 {
339 return isNumbercxx . . $ QTJSC/JSValue#isNumber(50ce9a9e25b4a850).() ? asValuecxx . . $ QTJSC/JSValue#asValue(2b3a0f51c71d9b1b).() : jsNumbercxx . . $ QTJSC/jsNumber(88e66938454912cb).(exec, this->toNumbercxx . . $ QTJSC/JSValue#toNumber(1fd034e372fd1279).(exec));
340 }
341
342 inline bool JSValuecxx . . $ QTJSC/JSValue#::getNumbercxx . . $ QTJSC/JSValue#getNumber(c49d02341edf1b7e).(double &result) const
343 {
344 if (isInt32cxx . . $ QTJSC/JSValue#isInt32(50ce9a9e25b4a850).())
345 result = asInt32cxx . . $ QTJSC/JSValue#asInt32(455f465bc33b4cdf).();
346 else if (LIKELYcxx . . $ `../3rdparty/javascriptcore/JavaScriptCore/wtf/AlwaysInline.h:53:9`!(isDouble()))
347 result = asDoublecxx . . $ QTJSC/JSValue#asDouble(21b6c25e127938e2).();
348 else {
349 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!isNumber());
350 return false;
351 }
352 return true;
353 }
354
355 #endif // USE(JSVALUE32) || USE(JSVALUE64)
356
357 } // namespace JSC
358
359 #endif // JSNumberCell_h