~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/JavaScriptCore/runtime/JSNumberCell.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
namespace JSC {
34
34
 
 
35
    extern const double NaN;
 
36
    extern const double Inf;
 
37
 
 
38
#if USE(JSVALUE32)
 
39
    JSValue jsNumberCell(ExecState*, double);
 
40
 
35
41
    class Identifier;
36
42
    class JSCell;
37
43
    class JSObject;
43
49
 
44
50
    class JSNumberCell : public JSCell {
45
51
        friend class JIT;
46
 
        friend JSValuePtr jsNumberCell(JSGlobalData*, double);
47
 
        friend JSValuePtr jsNaN(JSGlobalData*);
48
 
        friend JSValuePtr jsNumberCell(ExecState*, double);
49
 
        friend JSValuePtr jsNaN(ExecState*);
 
52
        friend JSValue jsNumberCell(JSGlobalData*, double);
 
53
        friend JSValue jsNumberCell(ExecState*, double);
 
54
 
50
55
    public:
51
56
        double value() const { return m_value; }
52
57
 
53
 
        virtual JSValuePtr toPrimitive(ExecState*, PreferredPrimitiveType) const;
54
 
        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValuePtr& value);
 
58
        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
 
59
        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
55
60
        virtual bool toBoolean(ExecState*) const;
56
61
        virtual double toNumber(ExecState*) const;
57
62
        virtual UString toString(ExecState*) const;
59
64
 
60
65
        virtual UString toThisString(ExecState*) const;
61
66
        virtual JSObject* toThisObject(ExecState*) const;
62
 
        virtual JSValuePtr getJSNumber();
63
 
 
64
 
        int32_t toInt32() const;
65
 
        uint32_t toUInt32() const;
 
67
        virtual JSValue getJSNumber();
66
68
 
67
69
        void* operator new(size_t size, ExecState* exec)
68
70
        {
82
84
    #endif
83
85
        }
84
86
 
85
 
        static PassRefPtr<Structure> createStructure(JSValuePtr proto) { return Structure::create(proto, TypeInfo(NumberType, NeedsThisConversion)); }
 
87
        static PassRefPtr<Structure> createStructure(JSValue proto) { return Structure::create(proto, TypeInfo(NumberType, NeedsThisConversion | HasDefaultMark)); }
86
88
 
87
89
    private:
88
90
        JSNumberCell(JSGlobalData* globalData, double value)
98
100
        }
99
101
 
100
102
        virtual bool getUInt32(uint32_t&) const;
101
 
        virtual bool getTruncatedInt32(int32_t&) const;
102
 
        virtual bool getTruncatedUInt32(uint32_t&) const;
103
103
 
104
104
        double m_value;
105
105
    };
106
106
 
107
 
    extern const double NaN;
108
 
    extern const double Inf;
109
 
 
110
 
    JSNumberCell* asNumberCell(JSValuePtr);
111
 
 
112
 
    JSValuePtr jsNumberCell(JSGlobalData*, double);
113
 
    JSValuePtr jsNaN(JSGlobalData*);
114
 
    JSValuePtr jsNumberCell(ExecState*, double);
115
 
    JSValuePtr jsNaN(ExecState*);
116
 
 
117
 
    inline JSNumberCell* asNumberCell(JSValuePtr value)
118
 
    {
119
 
        ASSERT(asCell(value)->isNumber());
120
 
        return static_cast<JSNumberCell*>(asCell(value));
121
 
    }
122
 
 
123
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, double d)
124
 
    {
125
 
        JSValuePtr v = JSImmediate::from(d);
126
 
        return v ? v : jsNumberCell(exec, d);
127
 
    }
128
 
 
129
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, short i)
130
 
    {
131
 
        JSValuePtr v = JSImmediate::from(i);
132
 
        return v ? v : jsNumberCell(exec, i);
133
 
    }
134
 
 
135
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned short i)
136
 
    {
137
 
        JSValuePtr v = JSImmediate::from(i);
138
 
        return v ? v : jsNumberCell(exec, i);
139
 
    }
140
 
 
141
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, int i)
142
 
    {
143
 
        JSValuePtr v = JSImmediate::from(i);
144
 
        return v ? v : jsNumberCell(exec, i);
145
 
    }
146
 
 
147
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned i)
148
 
    {
149
 
        JSValuePtr v = JSImmediate::from(i);
150
 
        return v ? v : jsNumberCell(exec, i);
151
 
    }
152
 
 
153
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, long i)
154
 
    {
155
 
        JSValuePtr v = JSImmediate::from(i);
156
 
        return v ? v : jsNumberCell(exec, i);
157
 
    }
158
 
 
159
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned long i)
160
 
    {
161
 
        JSValuePtr v = JSImmediate::from(i);
162
 
        return v ? v : jsNumberCell(exec, i);
163
 
    }
164
 
 
165
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, long long i)
166
 
    {
167
 
        JSValuePtr v = JSImmediate::from(i);
168
 
        return v ? v : jsNumberCell(exec, static_cast<double>(i));
169
 
    }
170
 
 
171
 
    ALWAYS_INLINE JSValuePtr jsNumber(ExecState* exec, unsigned long long i)
172
 
    {
173
 
        JSValuePtr v = JSImmediate::from(i);
174
 
        return v ? v : jsNumberCell(exec, static_cast<double>(i));
175
 
    }
176
 
 
177
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, double d)
178
 
    {
179
 
        JSValuePtr v = JSImmediate::from(d);
180
 
        return v ? v : jsNumberCell(globalData, d);
181
 
    }
182
 
 
183
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, short i)
184
 
    {
185
 
        JSValuePtr v = JSImmediate::from(i);
186
 
        return v ? v : jsNumberCell(globalData, i);
187
 
    }
188
 
 
189
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned short i)
190
 
    {
191
 
        JSValuePtr v = JSImmediate::from(i);
192
 
        return v ? v : jsNumberCell(globalData, i);
193
 
    }
194
 
 
195
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, int i)
196
 
    {
197
 
        JSValuePtr v = JSImmediate::from(i);
198
 
        return v ? v : jsNumberCell(globalData, i);
199
 
    }
200
 
 
201
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned i)
202
 
    {
203
 
        JSValuePtr v = JSImmediate::from(i);
204
 
        return v ? v : jsNumberCell(globalData, i);
205
 
    }
206
 
 
207
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, long i)
208
 
    {
209
 
        JSValuePtr v = JSImmediate::from(i);
210
 
        return v ? v : jsNumberCell(globalData, i);
211
 
    }
212
 
 
213
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long i)
214
 
    {
215
 
        JSValuePtr v = JSImmediate::from(i);
216
 
        return v ? v : jsNumberCell(globalData, i);
217
 
    }
218
 
 
219
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, long long i)
220
 
    {
221
 
        JSValuePtr v = JSImmediate::from(i);
222
 
        return v ? v : jsNumberCell(globalData, static_cast<double>(i));
223
 
    }
224
 
 
225
 
    ALWAYS_INLINE JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long long i)
226
 
    {
227
 
        JSValuePtr v = JSImmediate::from(i);
228
 
        return v ? v : jsNumberCell(globalData, static_cast<double>(i));
 
107
    JSValue jsNumberCell(JSGlobalData*, double);
 
108
 
 
109
    inline bool isNumberCell(JSValue v)
 
110
    {
 
111
        return v.isCell() && v.asCell()->isNumber();
 
112
    }
 
113
 
 
114
    inline JSNumberCell* asNumberCell(JSValue v)
 
115
    {
 
116
        ASSERT(isNumberCell(v));
 
117
        return static_cast<JSNumberCell*>(v.asCell());
 
118
    }
 
119
 
 
120
    inline JSValue::JSValue(ExecState* exec, double d)
 
121
    {
 
122
        JSValue v = JSImmediate::from(d);
 
123
        *this = v ? v : jsNumberCell(exec, d);
 
124
    }
 
125
 
 
126
    inline JSValue::JSValue(ExecState* exec, int i)
 
127
    {
 
128
        JSValue v = JSImmediate::from(i);
 
129
        *this = v ? v : jsNumberCell(exec, i);
 
130
    }
 
131
 
 
132
    inline JSValue::JSValue(ExecState* exec, unsigned i)
 
133
    {
 
134
        JSValue v = JSImmediate::from(i);
 
135
        *this = v ? v : jsNumberCell(exec, i);
 
136
    }
 
137
 
 
138
    inline JSValue::JSValue(ExecState* exec, long i)
 
139
    {
 
140
        JSValue v = JSImmediate::from(i);
 
141
        *this = v ? v : jsNumberCell(exec, i);
 
142
    }
 
143
 
 
144
    inline JSValue::JSValue(ExecState* exec, unsigned long i)
 
145
    {
 
146
        JSValue v = JSImmediate::from(i);
 
147
        *this = v ? v : jsNumberCell(exec, i);
 
148
    }
 
149
 
 
150
    inline JSValue::JSValue(ExecState* exec, long long i)
 
151
    {
 
152
        JSValue v = JSImmediate::from(i);
 
153
        *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
 
154
    }
 
155
 
 
156
    inline JSValue::JSValue(ExecState* exec, unsigned long long i)
 
157
    {
 
158
        JSValue v = JSImmediate::from(i);
 
159
        *this = v ? v : jsNumberCell(exec, static_cast<double>(i));
 
160
    }
 
161
 
 
162
    inline JSValue::JSValue(JSGlobalData* globalData, double d)
 
163
    {
 
164
        JSValue v = JSImmediate::from(d);
 
165
        *this = v ? v : jsNumberCell(globalData, d);
 
166
    }
 
167
 
 
168
    inline JSValue::JSValue(JSGlobalData* globalData, int i)
 
169
    {
 
170
        JSValue v = JSImmediate::from(i);
 
171
        *this = v ? v : jsNumberCell(globalData, i);
 
172
    }
 
173
 
 
174
    inline JSValue::JSValue(JSGlobalData* globalData, unsigned i)
 
175
    {
 
176
        JSValue v = JSImmediate::from(i);
 
177
        *this = v ? v : jsNumberCell(globalData, i);
 
178
    }
 
179
 
 
180
    inline bool JSValue::isDouble() const
 
181
    {
 
182
        return isNumberCell(asValue());
 
183
    }
 
184
 
 
185
    inline double JSValue::asDouble() const
 
186
    {
 
187
        return asNumberCell(asValue())->value();
 
188
    }
 
189
 
 
190
    inline bool JSValue::isNumber() const
 
191
    {
 
192
        return JSImmediate::isNumber(asValue()) || isDouble();
 
193
    }
 
194
 
 
195
    inline double JSValue::uncheckedGetNumber() const
 
196
    {
 
197
        ASSERT(isNumber());
 
198
        return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asDouble();
 
199
    }
 
200
 
 
201
#endif // USE(JSVALUE32)
 
202
 
 
203
#if USE(JSVALUE64)
 
204
    inline JSValue::JSValue(ExecState*, double d)
 
205
    {
 
206
        JSValue v = JSImmediate::from(d);
 
207
        ASSERT(v);
 
208
        *this = v;
 
209
    }
 
210
 
 
211
    inline JSValue::JSValue(ExecState*, int i)
 
212
    {
 
213
        JSValue v = JSImmediate::from(i);
 
214
        ASSERT(v);
 
215
        *this = v;
 
216
    }
 
217
 
 
218
    inline JSValue::JSValue(ExecState*, unsigned i)
 
219
    {
 
220
        JSValue v = JSImmediate::from(i);
 
221
        ASSERT(v);
 
222
        *this = v;
 
223
    }
 
224
 
 
225
    inline JSValue::JSValue(ExecState*, long i)
 
226
    {
 
227
        JSValue v = JSImmediate::from(i);
 
228
        ASSERT(v);
 
229
        *this = v;
 
230
    }
 
231
 
 
232
    inline JSValue::JSValue(ExecState*, unsigned long i)
 
233
    {
 
234
        JSValue v = JSImmediate::from(i);
 
235
        ASSERT(v);
 
236
        *this = v;
 
237
    }
 
238
 
 
239
    inline JSValue::JSValue(ExecState*, long long i)
 
240
    {
 
241
        JSValue v = JSImmediate::from(static_cast<double>(i));
 
242
        ASSERT(v);
 
243
        *this = v;
 
244
    }
 
245
 
 
246
    inline JSValue::JSValue(ExecState*, unsigned long long i)
 
247
    {
 
248
        JSValue v = JSImmediate::from(static_cast<double>(i));
 
249
        ASSERT(v);
 
250
        *this = v;
 
251
    }
 
252
 
 
253
    inline JSValue::JSValue(JSGlobalData*, double d)
 
254
    {
 
255
        JSValue v = JSImmediate::from(d);
 
256
        ASSERT(v);
 
257
        *this = v;
 
258
    }
 
259
 
 
260
    inline JSValue::JSValue(JSGlobalData*, int i)
 
261
    {
 
262
        JSValue v = JSImmediate::from(i);
 
263
        ASSERT(v);
 
264
        *this = v;
 
265
    }
 
266
 
 
267
    inline JSValue::JSValue(JSGlobalData*, unsigned i)
 
268
    {
 
269
        JSValue v = JSImmediate::from(i);
 
270
        ASSERT(v);
 
271
        *this = v;
 
272
    }
 
273
 
 
274
    inline bool JSValue::isDouble() const
 
275
    {
 
276
        return JSImmediate::isDouble(asValue());
 
277
    }
 
278
 
 
279
    inline double JSValue::asDouble() const
 
280
    {
 
281
        return JSImmediate::doubleValue(asValue());
 
282
    }
 
283
 
 
284
    inline bool JSValue::isNumber() const
 
285
    {
 
286
        return JSImmediate::isNumber(asValue());
 
287
    }
 
288
 
 
289
    inline double JSValue::uncheckedGetNumber() const
 
290
    {
 
291
        ASSERT(isNumber());
 
292
        return JSImmediate::toDouble(asValue());
 
293
    }
 
294
 
 
295
#endif // USE(JSVALUE64)
 
296
 
 
297
#if USE(JSVALUE32) || USE(JSVALUE64)
 
298
 
 
299
    inline JSValue::JSValue(ExecState*, char i)
 
300
    {
 
301
        ASSERT(JSImmediate::from(i));
 
302
        *this = JSImmediate::from(i);
 
303
    }
 
304
 
 
305
    inline JSValue::JSValue(ExecState*, unsigned char i)
 
306
    {
 
307
        ASSERT(JSImmediate::from(i));
 
308
        *this = JSImmediate::from(i);
 
309
    }
 
310
 
 
311
    inline JSValue::JSValue(ExecState*, short i)
 
312
    {
 
313
        ASSERT(JSImmediate::from(i));
 
314
        *this = JSImmediate::from(i);
 
315
    }
 
316
 
 
317
    inline JSValue::JSValue(ExecState*, unsigned short i)
 
318
    {
 
319
        ASSERT(JSImmediate::from(i));
 
320
        *this = JSImmediate::from(i);
 
321
    }
 
322
 
 
323
    inline JSValue jsNaN(ExecState* exec)
 
324
    {
 
325
        return jsNumber(exec, NaN);
 
326
    }
 
327
 
 
328
    inline JSValue jsNaN(JSGlobalData* globalData)
 
329
    {
 
330
        return jsNumber(globalData, NaN);
229
331
    }
230
332
 
231
333
    // --- JSValue inlines ----------------------------
232
334
 
233
 
    inline double JSValue::uncheckedGetNumber() const
234
 
    {
235
 
        ASSERT(JSImmediate::isImmediate(asValue()) || asCell()->isNumber());
236
 
        return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asNumberCell(asValue())->value();
237
 
    }
238
 
 
239
 
    inline int32_t JSNumberCell::toInt32() const
240
 
    {
241
 
        if (m_value >= -2147483648.0 && m_value < 2147483648.0)
242
 
            return static_cast<int32_t>(m_value);
243
 
        bool scratch;
244
 
        return JSC::toInt32SlowCase(m_value, scratch);
245
 
    }
246
 
 
247
 
    inline uint32_t JSNumberCell::toUInt32() const
248
 
    {
249
 
        if (m_value >= 0.0 && m_value < 4294967296.0)
250
 
            return static_cast<uint32_t>(m_value);
251
 
        bool scratch;
252
 
        return JSC::toUInt32SlowCase(m_value, scratch);
253
 
    }
254
 
 
255
 
    ALWAYS_INLINE JSValuePtr JSValue::toJSNumber(ExecState* exec) const
256
 
    {
257
 
        return JSImmediate::isNumber(asValue()) ? asValue() : jsNumber(exec, this->toNumber(exec));
258
 
    }
 
335
    ALWAYS_INLINE JSValue JSValue::toJSNumber(ExecState* exec) const
 
336
    {
 
337
        return isNumber() ? asValue() : jsNumber(exec, this->toNumber(exec));
 
338
    }
 
339
 
 
340
    inline bool JSValue::getNumber(double &result) const
 
341
    {
 
342
        if (isInt32())
 
343
            result = asInt32();
 
344
        else if (LIKELY(isDouble()))
 
345
            result = asDouble();
 
346
        else {
 
347
            ASSERT(!isNumber());
 
348
            return false;
 
349
        }
 
350
        return true;
 
351
    }
 
352
 
 
353
#endif // USE(JSVALUE32) || USE(JSVALUE64)
259
354
 
260
355
} // namespace JSC
261
356