source: webkit/trunk/JavaScriptCore/runtime/JSNumberCell.h@ 50709

Last change on this file since 50709 was 49649, checked in by [email protected], 16 years ago

Make typeinfo flags default to false
https://bugs.webkit.org/show_bug.cgi?id=30372

Reviewed by Darin Adler

Part 2 -- Reverse the TypeInfo HasDefaultMark flag to OverridesMarkChildren, etc

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
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_h
25
26#include "CallFrame.h"
27#include "JSCell.h"
28#include "JSImmediate.h"
29#include "Collector.h"
30#include "UString.h"
31#include <stddef.h> // for size_t
32
33namespace JSC {
34
35 extern const double NaN;
36 extern const double Inf;
37
38#if USE(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 inline JSValue::JSValue(ExecState* exec, double d)
113 {
114 JSValue v = JSImmediate::from(d);
115 *this = v ? v : jsNumberCell(exec, d);
116 }
117
118 inline JSValue::JSValue(ExecState* exec, int i)
119 {
120 JSValue v = JSImmediate::from(i);
121 *this = v ? v : jsNumberCell(exec, i);
122 }
123
124 inline JSValue::JSValue(ExecState* exec, unsigned i)
125 {
126 JSValue v = JSImmediate::from(i);
127 *this = v ? v : jsNumberCell(exec, i);
128 }
129
130 inline JSValue::JSValue(ExecState* exec, long i)
131 {
132 JSValue v = JSImmediate::from(i);
133 *this = v ? v : jsNumberCell(exec, i);
134 }
135
136 inline JSValue::JSValue(ExecState* exec, unsigned long i)
137 {
138 JSValue v = JSImmediate::from(i);
139 *this = v ? v : jsNumberCell(exec, i);
140 }
141
142 inline JSValue::JSValue(ExecState* exec, long long i)
143 {
144 JSValue v = JSImmediate::from(i);
145 *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
146 }
147
148 inline JSValue::JSValue(ExecState* exec, unsigned long long i)
149 {
150 JSValue v = JSImmediate::from(i);
151 *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
152 }
153
154 inline JSValue::JSValue(JSGlobalData* globalData, double d)
155 {
156 JSValue v = JSImmediate::from(d);
157 *this = v ? v : jsNumberCell(globalData, d);
158 }
159
160 inline JSValue::JSValue(JSGlobalData* globalData, int i)
161 {
162 JSValue v = JSImmediate::from(i);
163 *this = v ? v : jsNumberCell(globalData, i);
164 }
165
166 inline JSValue::JSValue(JSGlobalData* globalData, unsigned i)
167 {
168 JSValue v = JSImmediate::from(i);
169 *this = v ? v : jsNumberCell(globalData, i);
170 }
171
172 inline bool JSValue::isDouble() const
173 {
174 return isNumberCell(asValue());
175 }
176
177 inline double JSValue::asDouble() const
178 {
179 return asNumberCell(asValue())->value();
180 }
181
182 inline bool JSValue::isNumber() const
183 {
184 return JSImmediate::isNumber(asValue()) || isDouble();
185 }
186
187 inline double JSValue::uncheckedGetNumber() const
188 {
189 ASSERT(isNumber());
190 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asDouble();
191 }
192
193#endif // USE(JSVALUE32)
194
195#if USE(JSVALUE64)
196 inline JSValue::JSValue(ExecState*, double d)
197 {
198 JSValue v = JSImmediate::from(d);
199 ASSERT(v);
200 *this = v;
201 }
202
203 inline JSValue::JSValue(ExecState*, int i)
204 {
205 JSValue v = JSImmediate::from(i);
206 ASSERT(v);
207 *this = v;
208 }
209
210 inline JSValue::JSValue(ExecState*, unsigned i)
211 {
212 JSValue v = JSImmediate::from(i);
213 ASSERT(v);
214 *this = v;
215 }
216
217 inline JSValue::JSValue(ExecState*, long i)
218 {
219 JSValue v = JSImmediate::from(i);
220 ASSERT(v);
221 *this = v;
222 }
223
224 inline JSValue::JSValue(ExecState*, unsigned long i)
225 {
226 JSValue v = JSImmediate::from(i);
227 ASSERT(v);
228 *this = v;
229 }
230
231 inline JSValue::JSValue(ExecState*, long long i)
232 {
233 JSValue v = JSImmediate::from(static_cast<double>(i));
234 ASSERT(v);
235 *this = v;
236 }
237
238 inline JSValue::JSValue(ExecState*, unsigned long long i)
239 {
240 JSValue v = JSImmediate::from(static_cast<double>(i));
241 ASSERT(v);
242 *this = v;
243 }
244
245 inline JSValue::JSValue(JSGlobalData*, double d)
246 {
247 JSValue v = JSImmediate::from(d);
248 ASSERT(v);
249 *this = v;
250 }
251
252 inline JSValue::JSValue(JSGlobalData*, int i)
253 {
254 JSValue v = JSImmediate::from(i);
255 ASSERT(v);
256 *this = v;
257 }
258
259 inline JSValue::JSValue(JSGlobalData*, unsigned i)
260 {
261 JSValue v = JSImmediate::from(i);
262 ASSERT(v);
263 *this = v;
264 }
265
266 inline bool JSValue::isDouble() const
267 {
268 return JSImmediate::isDouble(asValue());
269 }
270
271 inline double JSValue::asDouble() const
272 {
273 return JSImmediate::doubleValue(asValue());
274 }
275
276 inline bool JSValue::isNumber() const
277 {
278 return JSImmediate::isNumber(asValue());
279 }
280
281 inline double JSValue::uncheckedGetNumber() const
282 {
283 ASSERT(isNumber());
284 return JSImmediate::toDouble(asValue());
285 }
286
287#endif // USE(JSVALUE64)
288
289#if USE(JSVALUE32) || USE(JSVALUE64)
290
291 inline JSValue::JSValue(ExecState*, char i)
292 {
293 ASSERT(JSImmediate::from(i));
294 *this = JSImmediate::from(i);
295 }
296
297 inline JSValue::JSValue(ExecState*, unsigned char i)
298 {
299 ASSERT(JSImmediate::from(i));
300 *this = JSImmediate::from(i);
301 }
302
303 inline JSValue::JSValue(ExecState*, short i)
304 {
305 ASSERT(JSImmediate::from(i));
306 *this = JSImmediate::from(i);
307 }
308
309 inline JSValue::JSValue(ExecState*, unsigned short i)
310 {
311 ASSERT(JSImmediate::from(i));
312 *this = JSImmediate::from(i);
313 }
314
315 inline JSValue jsNaN(ExecState* exec)
316 {
317 return jsNumber(exec, NaN);
318 }
319
320 inline JSValue jsNaN(JSGlobalData* globalData)
321 {
322 return jsNumber(globalData, NaN);
323 }
324
325 // --- JSValue inlines ----------------------------
326
327 ALWAYS_INLINE JSValue JSValue::toJSNumber(ExecState* exec) const
328 {
329 return isNumber() ? asValue() : jsNumber(exec, this->toNumber(exec));
330 }
331
332 inline bool JSValue::getNumber(double &result) const
333 {
334 if (isInt32())
335 result = asInt32();
336 else if (LIKELY(isDouble()))
337 result = asDouble();
338 else {
339 ASSERT(!isNumber());
340 return false;
341 }
342 return true;
343 }
344
345#endif // USE(JSVALUE32) || USE(JSVALUE64)
346
347} // namespace JSC
348
349#endif // JSNumberCell_h
Note: See TracBrowser for help on using the repository browser.