~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to JavaScriptCore/runtime/JSImmediate.h

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090515183058-50q5exjo9b1kxy9s
Tags: 1.1.7-1
* New upstream release
* debian/libwebkit-1.0-2.symbols:
- updated with the new symbols in 1.1.7
* debian/libwebkit-dev.install, debian/libwebkit-dev.links,
  debian/rules:
- Build, and ship gtk-doc documentation (Closes: #526683)
* debian/copyright:
- updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    class JSObject;
43
43
    class UString;
44
44
 
45
 
    JSValuePtr js0();
46
 
    JSValuePtr jsNull();
47
 
    JSValuePtr jsBoolean(bool b);
48
 
    JSValuePtr jsUndefined();
49
 
    JSValuePtr jsImpossibleValue();
50
 
    JSValuePtr jsNumber(ExecState* exec, double d);
51
 
    JSValuePtr jsNumber(ExecState*, char i);
52
 
    JSValuePtr jsNumber(ExecState*, unsigned char i);
53
 
    JSValuePtr jsNumber(ExecState*, short i);
54
 
    JSValuePtr jsNumber(ExecState*, unsigned short i);
55
 
    JSValuePtr jsNumber(ExecState* exec, int i);
56
 
    JSValuePtr jsNumber(ExecState* exec, unsigned i);
57
 
    JSValuePtr jsNumber(ExecState* exec, long i);
58
 
    JSValuePtr jsNumber(ExecState* exec, unsigned long i);
59
 
    JSValuePtr jsNumber(ExecState* exec, long long i);
60
 
    JSValuePtr jsNumber(ExecState* exec, unsigned long long i);
61
 
    JSValuePtr jsNumber(JSGlobalData* globalData, double d);
62
 
    JSValuePtr jsNumber(JSGlobalData* globalData, short i);
63
 
    JSValuePtr jsNumber(JSGlobalData* globalData, unsigned short i);
64
 
    JSValuePtr jsNumber(JSGlobalData* globalData, int i);
65
 
    JSValuePtr jsNumber(JSGlobalData* globalData, unsigned i);
66
 
    JSValuePtr jsNumber(JSGlobalData* globalData, long i);
67
 
    JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long i);
68
 
    JSValuePtr jsNumber(JSGlobalData* globalData, long long i);
69
 
    JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long long i);
70
 
 
71
45
#if USE(ALTERNATE_JSIMMEDIATE)
72
46
    inline intptr_t reinterpretDoubleToIntptr(double value)
73
47
    {
158
132
    class JSImmediate {
159
133
    private:
160
134
        friend class JIT;
161
 
        friend class JSValuePtr;
 
135
        friend class JSValue;
162
136
        friend class JSFastMath;
163
 
        friend JSValuePtr js0();
164
 
        friend JSValuePtr jsNull();
165
 
        friend JSValuePtr jsBoolean(bool b);
166
 
        friend JSValuePtr jsUndefined();
167
 
        friend JSValuePtr jsImpossibleValue();
168
 
        friend JSValuePtr jsNumber(ExecState* exec, double d);
169
 
        friend JSValuePtr jsNumber(ExecState*, char i);
170
 
        friend JSValuePtr jsNumber(ExecState*, unsigned char i);
171
 
        friend JSValuePtr jsNumber(ExecState*, short i);
172
 
        friend JSValuePtr jsNumber(ExecState*, unsigned short i);
173
 
        friend JSValuePtr jsNumber(ExecState* exec, int i);
174
 
        friend JSValuePtr jsNumber(ExecState* exec, unsigned i);
175
 
        friend JSValuePtr jsNumber(ExecState* exec, long i);
176
 
        friend JSValuePtr jsNumber(ExecState* exec, unsigned long i);
177
 
        friend JSValuePtr jsNumber(ExecState* exec, long long i);
178
 
        friend JSValuePtr jsNumber(ExecState* exec, unsigned long long i);
179
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, double d);
180
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, short i);
181
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, unsigned short i);
182
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, int i);
183
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, unsigned i);
184
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, long i);
185
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long i);
186
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, long long i);
187
 
        friend JSValuePtr jsNumber(JSGlobalData* globalData, unsigned long long i);
 
137
        friend JSValue jsNumber(ExecState* exec, double d);
 
138
        friend JSValue jsNumber(ExecState*, char i);
 
139
        friend JSValue jsNumber(ExecState*, unsigned char i);
 
140
        friend JSValue jsNumber(ExecState*, short i);
 
141
        friend JSValue jsNumber(ExecState*, unsigned short i);
 
142
        friend JSValue jsNumber(ExecState* exec, int i);
 
143
        friend JSValue jsNumber(ExecState* exec, unsigned i);
 
144
        friend JSValue jsNumber(ExecState* exec, long i);
 
145
        friend JSValue jsNumber(ExecState* exec, unsigned long i);
 
146
        friend JSValue jsNumber(ExecState* exec, long long i);
 
147
        friend JSValue jsNumber(ExecState* exec, unsigned long long i);
 
148
        friend JSValue jsNumber(JSGlobalData* globalData, double d);
 
149
        friend JSValue jsNumber(JSGlobalData* globalData, short i);
 
150
        friend JSValue jsNumber(JSGlobalData* globalData, unsigned short i);
 
151
        friend JSValue jsNumber(JSGlobalData* globalData, int i);
 
152
        friend JSValue jsNumber(JSGlobalData* globalData, unsigned i);
 
153
        friend JSValue jsNumber(JSGlobalData* globalData, long i);
 
154
        friend JSValue jsNumber(JSGlobalData* globalData, unsigned long i);
 
155
        friend JSValue jsNumber(JSGlobalData* globalData, long long i);
 
156
        friend JSValue jsNumber(JSGlobalData* globalData, unsigned long long i);
188
157
 
189
158
#if USE(ALTERNATE_JSIMMEDIATE)
190
159
        // If all bits in the mask are set, this indicates an integer number,
219
188
 
220
189
        static const int32_t signBit = 0x80000000;
221
190
 
222
 
        static ALWAYS_INLINE bool isImmediate(JSValuePtr v)
 
191
        static ALWAYS_INLINE bool isImmediate(JSValue v)
223
192
        {
224
193
            return rawValue(v) & TagMask;
225
194
        }
226
195
        
227
 
        static ALWAYS_INLINE bool isNumber(JSValuePtr v)
 
196
        static ALWAYS_INLINE bool isNumber(JSValue v)
228
197
        {
229
198
            return rawValue(v) & TagTypeNumber;
230
199
        }
231
200
 
232
 
        static ALWAYS_INLINE bool isIntegerNumber(JSValuePtr v)
 
201
        static ALWAYS_INLINE bool isIntegerNumber(JSValue v)
233
202
        {
234
203
#if USE(ALTERNATE_JSIMMEDIATE)
235
204
            return (rawValue(v) & TagTypeNumber) == TagTypeNumber;
239
208
        }
240
209
 
241
210
#if USE(ALTERNATE_JSIMMEDIATE)
242
 
        static ALWAYS_INLINE bool isDoubleNumber(JSValuePtr v)
 
211
        static ALWAYS_INLINE bool isDoubleNumber(JSValue v)
243
212
        {
244
213
            return isNumber(v) && !isIntegerNumber(v);
245
214
        }
246
215
#endif
247
216
 
248
 
        static ALWAYS_INLINE bool isPositiveIntegerNumber(JSValuePtr v)
 
217
        static ALWAYS_INLINE bool isPositiveIntegerNumber(JSValue v)
249
218
        {
250
219
            // A single mask to check for the sign bit and the number tag all at once.
251
220
            return (rawValue(v) & (signBit | TagTypeNumber)) == TagTypeNumber;
252
221
        }
253
222
        
254
 
        static ALWAYS_INLINE bool isBoolean(JSValuePtr v)
 
223
        static ALWAYS_INLINE bool isBoolean(JSValue v)
255
224
        {
256
225
            return (rawValue(v) & FullTagTypeMask) == FullTagTypeBool;
257
226
        }
258
227
        
259
 
        static ALWAYS_INLINE bool isUndefinedOrNull(JSValuePtr v)
 
228
        static ALWAYS_INLINE bool isUndefinedOrNull(JSValue v)
260
229
        {
261
230
            // Undefined and null share the same value, bar the 'undefined' bit in the extended tag.
262
231
            return (rawValue(v) & ~ExtendedTagBitUndefined) == FullTagTypeNull;
263
232
        }
264
233
 
265
 
        static JSValuePtr from(char);
266
 
        static JSValuePtr from(signed char);
267
 
        static JSValuePtr from(unsigned char);
268
 
        static JSValuePtr from(short);
269
 
        static JSValuePtr from(unsigned short);
270
 
        static JSValuePtr from(int);
271
 
        static JSValuePtr from(unsigned);
272
 
        static JSValuePtr from(long);
273
 
        static JSValuePtr from(unsigned long);
274
 
        static JSValuePtr from(long long);
275
 
        static JSValuePtr from(unsigned long long);
276
 
        static JSValuePtr from(double);
 
234
        static JSValue from(char);
 
235
        static JSValue from(signed char);
 
236
        static JSValue from(unsigned char);
 
237
        static JSValue from(short);
 
238
        static JSValue from(unsigned short);
 
239
        static JSValue from(int);
 
240
        static JSValue from(unsigned);
 
241
        static JSValue from(long);
 
242
        static JSValue from(unsigned long);
 
243
        static JSValue from(long long);
 
244
        static JSValue from(unsigned long long);
 
245
        static JSValue from(double);
277
246
 
278
 
        static ALWAYS_INLINE bool isEitherImmediate(JSValuePtr v1, JSValuePtr v2)
 
247
        static ALWAYS_INLINE bool isEitherImmediate(JSValue v1, JSValue v2)
279
248
        {
280
249
            return (rawValue(v1) | rawValue(v2)) & TagMask;
281
250
        }
282
251
 
283
 
        static ALWAYS_INLINE bool areBothImmediate(JSValuePtr v1, JSValuePtr v2)
 
252
        static ALWAYS_INLINE bool areBothImmediate(JSValue v1, JSValue v2)
284
253
        {
285
254
            return isImmediate(v1) & isImmediate(v2);
286
255
        }
287
256
 
288
 
        static ALWAYS_INLINE bool areBothImmediateIntegerNumbers(JSValuePtr v1, JSValuePtr v2)
 
257
        static ALWAYS_INLINE bool areBothImmediateIntegerNumbers(JSValue v1, JSValue v2)
289
258
        {
290
259
#if USE(ALTERNATE_JSIMMEDIATE)
291
260
            return (rawValue(v1) & rawValue(v2) & TagTypeNumber) == TagTypeNumber;
294
263
#endif
295
264
        }
296
265
 
297
 
        static double toDouble(JSValuePtr);
298
 
        static bool toBoolean(JSValuePtr);
299
 
        static JSObject* toObject(JSValuePtr, ExecState*);
300
 
        static JSObject* toThisObject(JSValuePtr, ExecState*);
301
 
        static UString toString(JSValuePtr);
302
 
 
303
 
        static bool getUInt32(JSValuePtr, uint32_t&);
304
 
        static bool getTruncatedInt32(JSValuePtr, int32_t&);
305
 
        static bool getTruncatedUInt32(JSValuePtr, uint32_t&);
306
 
 
307
 
        static int32_t getTruncatedInt32(JSValuePtr);
308
 
        static uint32_t getTruncatedUInt32(JSValuePtr);
309
 
 
310
 
        static JSValuePtr trueImmediate();
311
 
        static JSValuePtr falseImmediate();
312
 
        static JSValuePtr undefinedImmediate();
313
 
        static JSValuePtr nullImmediate();
314
 
        static JSValuePtr zeroImmediate();
315
 
        static JSValuePtr oneImmediate();
316
 
 
317
 
        static JSValuePtr impossibleValue();
318
 
        
319
 
        static JSObject* prototype(JSValuePtr, ExecState*);
 
266
        static double toDouble(JSValue);
 
267
        static bool toBoolean(JSValue);
 
268
        static JSObject* toObject(JSValue, ExecState*);
 
269
        static JSObject* toThisObject(JSValue, ExecState*);
 
270
        static UString toString(JSValue);
 
271
 
 
272
        static bool getUInt32(JSValue, uint32_t&);
 
273
        static bool getTruncatedInt32(JSValue, int32_t&);
 
274
        static bool getTruncatedUInt32(JSValue, uint32_t&);
 
275
 
 
276
        static int32_t getTruncatedInt32(JSValue);
 
277
        static uint32_t getTruncatedUInt32(JSValue);
 
278
 
 
279
        static JSValue trueImmediate();
 
280
        static JSValue falseImmediate();
 
281
        static JSValue undefinedImmediate();
 
282
        static JSValue nullImmediate();
 
283
        static JSValue zeroImmediate();
 
284
        static JSValue oneImmediate();
 
285
 
 
286
        static JSObject* prototype(JSValue, ExecState*);
320
287
 
321
288
    private:
322
289
#if USE(ALTERNATE_JSIMMEDIATE)
328
295
#endif
329
296
        static const unsigned maxImmediateUInt = maxImmediateInt;
330
297
 
331
 
        static ALWAYS_INLINE JSValuePtr makeValue(intptr_t integer)
 
298
        static ALWAYS_INLINE JSValue makeValue(intptr_t integer)
332
299
        {
333
 
            return JSValuePtr::makeImmediate(integer);
 
300
            return JSValue::makeImmediate(integer);
334
301
        }
335
302
 
336
303
        // With USE(ALTERNATE_JSIMMEDIATE) we want the argument to be zero extended, so the
337
304
        // integer doesn't interfere with the tag bits in the upper word.  In the default encoding,
338
305
        // if intptr_t id larger then int32_t we sign extend the value through the upper word.
339
306
#if USE(ALTERNATE_JSIMMEDIATE)
340
 
        static ALWAYS_INLINE JSValuePtr makeInt(uint32_t value)
 
307
        static ALWAYS_INLINE JSValue makeInt(uint32_t value)
341
308
#else
342
 
        static ALWAYS_INLINE JSValuePtr makeInt(int32_t value)
 
309
        static ALWAYS_INLINE JSValue makeInt(int32_t value)
343
310
#endif
344
311
        {
345
312
            return makeValue((static_cast<intptr_t>(value) << IntegerPayloadShift) | TagTypeNumber);
346
313
        }
347
314
        
348
315
#if USE(ALTERNATE_JSIMMEDIATE)
349
 
        static ALWAYS_INLINE JSValuePtr makeDouble(double value)
 
316
        static ALWAYS_INLINE JSValue makeDouble(double value)
350
317
        {
351
318
            return makeValue(reinterpretDoubleToIntptr(value) + DoubleEncodeOffset);
352
319
        }
353
320
#endif
354
321
        
355
 
        static ALWAYS_INLINE JSValuePtr makeBool(bool b)
 
322
        static ALWAYS_INLINE JSValue makeBool(bool b)
356
323
        {
357
324
            return makeValue((static_cast<intptr_t>(b) << ExtendedPayloadShift) | FullTagTypeBool);
358
325
        }
359
326
        
360
 
        static ALWAYS_INLINE JSValuePtr makeUndefined()
 
327
        static ALWAYS_INLINE JSValue makeUndefined()
361
328
        {
362
329
            return makeValue(FullTagTypeUndefined);
363
330
        }
364
331
        
365
 
        static ALWAYS_INLINE JSValuePtr makeNull()
 
332
        static ALWAYS_INLINE JSValue makeNull()
366
333
        {
367
334
            return makeValue(FullTagTypeNull);
368
335
        }
369
336
 
370
337
        template<typename T>
371
 
        static JSValuePtr fromNumberOutsideIntegerRange(T);
 
338
        static JSValue fromNumberOutsideIntegerRange(T);
372
339
 
373
340
#if USE(ALTERNATE_JSIMMEDIATE)
374
 
        static ALWAYS_INLINE double doubleValue(JSValuePtr v)
 
341
        static ALWAYS_INLINE double doubleValue(JSValue v)
375
342
        {
376
343
            return reinterpretIntptrToDouble(rawValue(v) - DoubleEncodeOffset);
377
344
        }
378
345
#endif
379
346
 
380
 
        static ALWAYS_INLINE int32_t intValue(JSValuePtr v)
 
347
        static ALWAYS_INLINE int32_t intValue(JSValue v)
381
348
        {
382
349
            return static_cast<int32_t>(rawValue(v) >> IntegerPayloadShift);
383
350
        }
384
351
        
385
 
        static ALWAYS_INLINE uint32_t uintValue(JSValuePtr v)
 
352
        static ALWAYS_INLINE uint32_t uintValue(JSValue v)
386
353
        {
387
354
            return static_cast<uint32_t>(rawValue(v) >> IntegerPayloadShift);
388
355
        }
389
356
        
390
 
        static ALWAYS_INLINE bool boolValue(JSValuePtr v)
 
357
        static ALWAYS_INLINE bool boolValue(JSValue v)
391
358
        {
392
359
            return rawValue(v) & ExtendedPayloadBitBoolValue;
393
360
        }
394
361
        
395
 
        static ALWAYS_INLINE intptr_t rawValue(JSValuePtr v)
 
362
        static ALWAYS_INLINE intptr_t rawValue(JSValue v)
396
363
        {
397
364
            return v.immediateValue();
398
365
        }
400
367
        static double nonInlineNaN();
401
368
    };
402
369
 
403
 
    ALWAYS_INLINE JSValuePtr JSImmediate::trueImmediate() { return makeBool(true); }
404
 
    ALWAYS_INLINE JSValuePtr JSImmediate::falseImmediate() { return makeBool(false); }
405
 
    ALWAYS_INLINE JSValuePtr JSImmediate::undefinedImmediate() { return makeUndefined(); }
406
 
    ALWAYS_INLINE JSValuePtr JSImmediate::nullImmediate() { return makeNull(); }
407
 
    ALWAYS_INLINE JSValuePtr JSImmediate::zeroImmediate() { return makeInt(0); }
408
 
    ALWAYS_INLINE JSValuePtr JSImmediate::oneImmediate() { return makeInt(1); }
409
 
 
410
 
    // This value is impossible because 0x4 is not a valid pointer but a tag of 0 would indicate non-immediate
411
 
    ALWAYS_INLINE JSValuePtr JSImmediate::impossibleValue() { return makeValue(0x4); }
 
370
    ALWAYS_INLINE JSValue JSImmediate::trueImmediate() { return makeBool(true); }
 
371
    ALWAYS_INLINE JSValue JSImmediate::falseImmediate() { return makeBool(false); }
 
372
    ALWAYS_INLINE JSValue JSImmediate::undefinedImmediate() { return makeUndefined(); }
 
373
    ALWAYS_INLINE JSValue JSImmediate::nullImmediate() { return makeNull(); }
 
374
    ALWAYS_INLINE JSValue JSImmediate::zeroImmediate() { return makeInt(0); }
 
375
    ALWAYS_INLINE JSValue JSImmediate::oneImmediate() { return makeInt(1); }
412
376
 
413
377
#if USE(ALTERNATE_JSIMMEDIATE)
414
378
    inline bool doubleToBoolean(double value)
416
380
        return value < 0.0 || value > 0.0;
417
381
    }
418
382
 
419
 
    ALWAYS_INLINE bool JSImmediate::toBoolean(JSValuePtr v)
 
383
    ALWAYS_INLINE bool JSImmediate::toBoolean(JSValue v)
420
384
    {
421
385
        ASSERT(isImmediate(v));
422
386
        return isNumber(v) ? isIntegerNumber(v) ? v != zeroImmediate()
423
387
            : doubleToBoolean(doubleValue(v)) : v == trueImmediate();
424
388
    }
425
389
#else
426
 
    ALWAYS_INLINE bool JSImmediate::toBoolean(JSValuePtr v)
 
390
    ALWAYS_INLINE bool JSImmediate::toBoolean(JSValue v)
427
391
    {
428
392
        ASSERT(isImmediate(v));
429
393
        return isIntegerNumber(v) ? v != zeroImmediate() : v == trueImmediate();
430
394
    }
431
395
#endif
432
396
 
433
 
    ALWAYS_INLINE uint32_t JSImmediate::getTruncatedUInt32(JSValuePtr v)
 
397
    ALWAYS_INLINE uint32_t JSImmediate::getTruncatedUInt32(JSValue v)
434
398
    {
435
399
        // FIXME: should probably be asserting isPositiveIntegerNumber here.
436
400
        ASSERT(isIntegerNumber(v));
439
403
 
440
404
#if USE(ALTERNATE_JSIMMEDIATE)
441
405
    template<typename T>
442
 
    inline JSValuePtr JSImmediate::fromNumberOutsideIntegerRange(T value)
 
406
    inline JSValue JSImmediate::fromNumberOutsideIntegerRange(T value)
443
407
    {
444
408
        return makeDouble(static_cast<double>(value));
445
409
    }
446
410
#else
447
411
    template<typename T>
448
 
    inline JSValuePtr JSImmediate::fromNumberOutsideIntegerRange(T)
 
412
    inline JSValue JSImmediate::fromNumberOutsideIntegerRange(T)
449
413
    {
450
 
        return noValue();
 
414
        return JSValue();
451
415
    }
452
416
#endif
453
417
 
454
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(char i)
455
 
    {
456
 
        return makeInt(i);
457
 
    }
458
 
 
459
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(signed char i)
460
 
    {
461
 
        return makeInt(i);
462
 
    }
463
 
 
464
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(unsigned char i)
465
 
    {
466
 
        return makeInt(i);
467
 
    }
468
 
 
469
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(short i)
470
 
    {
471
 
        return makeInt(i);
472
 
    }
473
 
 
474
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(unsigned short i)
475
 
    {
476
 
        return makeInt(i);
477
 
    }
478
 
 
479
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(int i)
 
418
    ALWAYS_INLINE JSValue JSImmediate::from(char i)
 
419
    {
 
420
        return makeInt(i);
 
421
    }
 
422
 
 
423
    ALWAYS_INLINE JSValue JSImmediate::from(signed char i)
 
424
    {
 
425
        return makeInt(i);
 
426
    }
 
427
 
 
428
    ALWAYS_INLINE JSValue JSImmediate::from(unsigned char i)
 
429
    {
 
430
        return makeInt(i);
 
431
    }
 
432
 
 
433
    ALWAYS_INLINE JSValue JSImmediate::from(short i)
 
434
    {
 
435
        return makeInt(i);
 
436
    }
 
437
 
 
438
    ALWAYS_INLINE JSValue JSImmediate::from(unsigned short i)
 
439
    {
 
440
        return makeInt(i);
 
441
    }
 
442
 
 
443
    ALWAYS_INLINE JSValue JSImmediate::from(int i)
480
444
    {
481
445
#if !USE(ALTERNATE_JSIMMEDIATE)
482
446
        if ((i < minImmediateInt) | (i > maxImmediateInt))
485
449
        return makeInt(i);
486
450
    }
487
451
 
488
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(unsigned i)
489
 
    {
490
 
        if (i > maxImmediateUInt)
491
 
            return fromNumberOutsideIntegerRange(i);
492
 
        return makeInt(i);
493
 
    }
494
 
 
495
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(long i)
496
 
    {
497
 
        if ((i < minImmediateInt) | (i > maxImmediateInt))
498
 
            return fromNumberOutsideIntegerRange(i);
499
 
        return makeInt(i);
500
 
    }
501
 
 
502
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(unsigned long i)
503
 
    {
504
 
        if (i > maxImmediateUInt)
505
 
            return fromNumberOutsideIntegerRange(i);
506
 
        return makeInt(i);
507
 
    }
508
 
 
509
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(long long i)
510
 
    {
511
 
        if ((i < minImmediateInt) | (i > maxImmediateInt))
512
 
            return noValue();
513
 
        return makeInt(static_cast<intptr_t>(i));
514
 
    }
515
 
 
516
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(unsigned long long i)
517
 
    {
518
 
        if (i > maxImmediateUInt)
519
 
            return fromNumberOutsideIntegerRange(i);
520
 
        return makeInt(static_cast<intptr_t>(i));
521
 
    }
522
 
 
523
 
    ALWAYS_INLINE JSValuePtr JSImmediate::from(double d)
 
452
    ALWAYS_INLINE JSValue JSImmediate::from(unsigned i)
 
453
    {
 
454
        if (i > maxImmediateUInt)
 
455
            return fromNumberOutsideIntegerRange(i);
 
456
        return makeInt(i);
 
457
    }
 
458
 
 
459
    ALWAYS_INLINE JSValue JSImmediate::from(long i)
 
460
    {
 
461
        if ((i < minImmediateInt) | (i > maxImmediateInt))
 
462
            return fromNumberOutsideIntegerRange(i);
 
463
        return makeInt(i);
 
464
    }
 
465
 
 
466
    ALWAYS_INLINE JSValue JSImmediate::from(unsigned long i)
 
467
    {
 
468
        if (i > maxImmediateUInt)
 
469
            return fromNumberOutsideIntegerRange(i);
 
470
        return makeInt(i);
 
471
    }
 
472
 
 
473
    ALWAYS_INLINE JSValue JSImmediate::from(long long i)
 
474
    {
 
475
        if ((i < minImmediateInt) | (i > maxImmediateInt))
 
476
            return JSValue();
 
477
        return makeInt(static_cast<intptr_t>(i));
 
478
    }
 
479
 
 
480
    ALWAYS_INLINE JSValue JSImmediate::from(unsigned long long i)
 
481
    {
 
482
        if (i > maxImmediateUInt)
 
483
            return fromNumberOutsideIntegerRange(i);
 
484
        return makeInt(static_cast<intptr_t>(i));
 
485
    }
 
486
 
 
487
    ALWAYS_INLINE JSValue JSImmediate::from(double d)
524
488
    {
525
489
        const int intVal = static_cast<int>(d);
526
490
 
531
495
        return from(intVal);
532
496
    }
533
497
 
534
 
    ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(JSValuePtr v)
 
498
    ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(JSValue v)
535
499
    {
536
500
        ASSERT(isIntegerNumber(v));
537
501
        return intValue(v);
538
502
    }
539
503
 
540
 
    ALWAYS_INLINE double JSImmediate::toDouble(JSValuePtr v)
 
504
    ALWAYS_INLINE double JSImmediate::toDouble(JSValue v)
541
505
    {
542
506
        ASSERT(isImmediate(v));
543
507
 
560
524
        return rawValue(v) >> ExtendedPayloadShift;
561
525
    }
562
526
 
563
 
    ALWAYS_INLINE bool JSImmediate::getUInt32(JSValuePtr v, uint32_t& i)
 
527
    ALWAYS_INLINE bool JSImmediate::getUInt32(JSValue v, uint32_t& i)
564
528
    {
565
529
        i = uintValue(v);
566
530
        return isPositiveIntegerNumber(v);
567
531
    }
568
532
 
569
 
    ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(JSValuePtr v, int32_t& i)
 
533
    ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(JSValue v, int32_t& i)
570
534
    {
571
535
        i = intValue(v);
572
536
        return isIntegerNumber(v);
573
537
    }
574
538
 
575
 
    ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(JSValuePtr v, uint32_t& i)
 
539
    ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(JSValue v, uint32_t& i)
576
540
    {
577
541
        return getUInt32(v, i);
578
542
    }
579
543
 
580
 
    inline JSValuePtr js0()
581
 
    {
582
 
        return JSImmediate::zeroImmediate();
583
 
    }
584
 
 
585
 
    inline JSValuePtr jsNull()
586
 
    {
587
 
        return JSImmediate::nullImmediate();
588
 
    }
589
 
 
590
 
    inline JSValuePtr jsBoolean(bool b)
591
 
    {
592
 
        return b ? JSImmediate::trueImmediate() : JSImmediate::falseImmediate();
593
 
    }
594
 
 
595
 
    inline JSValuePtr jsUndefined()
596
 
    {
597
 
        return JSImmediate::undefinedImmediate();
598
 
    }
599
 
 
600
 
    inline JSValuePtr jsImpossibleValue()
601
 
    {
602
 
        return JSImmediate::impossibleValue();
603
 
    }
604
 
 
605
544
    // These are identical logic to the JSValue functions above, and faster than jsNumber(number).toInt32().
606
545
    int32_t toInt32(double);
607
546
    uint32_t toUInt32(double);
608
547
    int32_t toInt32SlowCase(double, bool& ok);
609
548
    uint32_t toUInt32SlowCase(double, bool& ok);
610
549
 
611
 
    inline bool JSValuePtr::isUndefined() const
612
 
    {
613
 
        return asValue() == jsUndefined();
614
 
    }
615
 
 
616
 
    inline bool JSValuePtr::isNull() const
617
 
    {
618
 
        return asValue() == jsNull();
619
 
    }
620
 
 
621
 
    inline bool JSValuePtr::isUndefinedOrNull() const
 
550
    inline JSValue::JSValue(JSNullTag)
 
551
    {
 
552
        *this = JSImmediate::nullImmediate();
 
553
    }
 
554
    
 
555
    inline JSValue::JSValue(JSUndefinedTag)
 
556
    {
 
557
        *this = JSImmediate::undefinedImmediate();
 
558
    }
 
559
 
 
560
    inline JSValue::JSValue(JSTrueTag)
 
561
    {
 
562
        *this = JSImmediate::trueImmediate();
 
563
    }
 
564
 
 
565
    inline JSValue::JSValue(JSFalseTag)
 
566
    {
 
567
        *this = JSImmediate::falseImmediate();
 
568
    }
 
569
 
 
570
    inline bool JSValue::isUndefinedOrNull() const
622
571
    {
623
572
        return JSImmediate::isUndefinedOrNull(asValue());
624
573
    }
625
574
 
626
 
    inline bool JSValuePtr::isBoolean() const
 
575
    inline bool JSValue::isBoolean() const
627
576
    {
628
577
        return JSImmediate::isBoolean(asValue());
629
578
    }
630
579
 
631
 
    inline bool JSValuePtr::getBoolean(bool& v) const
 
580
    inline bool JSValue::getBoolean(bool& v) const
632
581
    {
633
582
        if (JSImmediate::isBoolean(asValue())) {
634
583
            v = JSImmediate::toBoolean(asValue());
638
587
        return false;
639
588
    }
640
589
 
641
 
    inline bool JSValuePtr::getBoolean() const
 
590
    inline bool JSValue::getBoolean() const
642
591
    {
643
592
        return asValue() == jsBoolean(true);
644
593
    }
645
594
 
646
 
    ALWAYS_INLINE int32_t JSValuePtr::toInt32(ExecState* exec) const
 
595
    ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
647
596
    {
648
597
        int32_t i;
649
598
        if (getTruncatedInt32(i))
652
601
        return toInt32SlowCase(toNumber(exec), ignored);
653
602
    }
654
603
 
655
 
    inline uint32_t JSValuePtr::toUInt32(ExecState* exec) const
 
604
    inline uint32_t JSValue::toUInt32(ExecState* exec) const
656
605
    {
657
606
        uint32_t i;
658
607
        if (getTruncatedUInt32(i))
679
628
        return static_cast<uint32_t>(val);
680
629
    }
681
630
 
682
 
    inline int32_t JSValuePtr::toInt32(ExecState* exec, bool& ok) const
 
631
    inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
683
632
    {
684
633
        int32_t i;
685
634
        if (getTruncatedInt32(i)) {
689
638
        return toInt32SlowCase(toNumber(exec), ok);
690
639
    }
691
640
 
692
 
    inline uint32_t JSValuePtr::toUInt32(ExecState* exec, bool& ok) const
 
641
    inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
693
642
    {
694
643
        uint32_t i;
695
644
        if (getTruncatedUInt32(i)) {
699
648
        return toUInt32SlowCase(toNumber(exec), ok);
700
649
    }
701
650
 
702
 
    inline bool JSValuePtr::isCell() const
 
651
    inline bool JSValue::isCell() const
703
652
    {
704
653
        return !JSImmediate::isImmediate(asValue());
705
654
    }
706
655
 
707
 
    inline bool JSValuePtr::isInt32Fast() const
 
656
    inline bool JSValue::isInt32Fast() const
708
657
    {
709
658
        return JSImmediate::isIntegerNumber(asValue());
710
659
    }
711
660
 
712
 
    inline int32_t JSValuePtr::getInt32Fast() const
 
661
    inline int32_t JSValue::getInt32Fast() const
713
662
    {
714
663
        ASSERT(isInt32Fast());
715
664
        return JSImmediate::getTruncatedInt32(asValue());
716
665
    }
717
666
 
718
 
    inline bool JSValuePtr::isUInt32Fast() const
 
667
    inline bool JSValue::isUInt32Fast() const
719
668
    {
720
669
        return JSImmediate::isPositiveIntegerNumber(asValue());
721
670
    }
722
671
 
723
 
    inline uint32_t JSValuePtr::getUInt32Fast() const
 
672
    inline uint32_t JSValue::getUInt32Fast() const
724
673
    {
725
674
        ASSERT(isUInt32Fast());
726
675
        return JSImmediate::getTruncatedUInt32(asValue());
727
676
    }
728
677
 
729
 
    inline JSValuePtr JSValuePtr::makeInt32Fast(int32_t i)
 
678
    inline JSValue JSValue::makeInt32Fast(int32_t i)
730
679
    {
731
680
        return JSImmediate::from(i);
732
681
    }
733
682
 
734
 
    inline bool JSValuePtr::areBothInt32Fast(JSValuePtr v1, JSValuePtr v2)
 
683
    inline bool JSValue::areBothInt32Fast(JSValue v1, JSValue v2)
735
684
    {
736
685
        return JSImmediate::areBothImmediateIntegerNumbers(v1, v2);
737
686
    }
738
687
 
739
688
    class JSFastMath {
740
689
    public:
741
 
        static ALWAYS_INLINE bool canDoFastBitwiseOperations(JSValuePtr v1, JSValuePtr v2)
 
690
        static ALWAYS_INLINE bool canDoFastBitwiseOperations(JSValue v1, JSValue v2)
742
691
        {
743
692
            return JSImmediate::areBothImmediateIntegerNumbers(v1, v2);
744
693
        }
745
694
 
746
 
        static ALWAYS_INLINE JSValuePtr equal(JSValuePtr v1, JSValuePtr v2)
 
695
        static ALWAYS_INLINE JSValue equal(JSValue v1, JSValue v2)
747
696
        {
748
697
            ASSERT(canDoFastBitwiseOperations(v1, v2));
749
698
            return jsBoolean(v1 == v2);
750
699
        }
751
700
 
752
 
        static ALWAYS_INLINE JSValuePtr notEqual(JSValuePtr v1, JSValuePtr v2)
 
701
        static ALWAYS_INLINE JSValue notEqual(JSValue v1, JSValue v2)
753
702
        {
754
703
            ASSERT(canDoFastBitwiseOperations(v1, v2));
755
704
            return jsBoolean(v1 != v2);
756
705
        }
757
706
 
758
 
        static ALWAYS_INLINE JSValuePtr andImmediateNumbers(JSValuePtr v1, JSValuePtr v2)
 
707
        static ALWAYS_INLINE JSValue andImmediateNumbers(JSValue v1, JSValue v2)
759
708
        {
760
709
            ASSERT(canDoFastBitwiseOperations(v1, v2));
761
710
            return JSImmediate::makeValue(JSImmediate::rawValue(v1) & JSImmediate::rawValue(v2));
762
711
        }
763
712
 
764
 
        static ALWAYS_INLINE JSValuePtr xorImmediateNumbers(JSValuePtr v1, JSValuePtr v2)
 
713
        static ALWAYS_INLINE JSValue xorImmediateNumbers(JSValue v1, JSValue v2)
765
714
        {
766
715
            ASSERT(canDoFastBitwiseOperations(v1, v2));
767
716
            return JSImmediate::makeValue((JSImmediate::rawValue(v1) ^ JSImmediate::rawValue(v2)) | JSImmediate::TagTypeNumber);
768
717
        }
769
718
 
770
 
        static ALWAYS_INLINE JSValuePtr orImmediateNumbers(JSValuePtr v1, JSValuePtr v2)
 
719
        static ALWAYS_INLINE JSValue orImmediateNumbers(JSValue v1, JSValue v2)
771
720
        {
772
721
            ASSERT(canDoFastBitwiseOperations(v1, v2));
773
722
            return JSImmediate::makeValue(JSImmediate::rawValue(v1) | JSImmediate::rawValue(v2));
774
723
        }
775
724
 
776
 
        static ALWAYS_INLINE bool canDoFastRshift(JSValuePtr v1, JSValuePtr v2)
 
725
        static ALWAYS_INLINE bool canDoFastRshift(JSValue v1, JSValue v2)
777
726
        {
778
727
            return JSImmediate::areBothImmediateIntegerNumbers(v1, v2);
779
728
        }
780
729
 
781
 
        static ALWAYS_INLINE bool canDoFastUrshift(JSValuePtr v1, JSValuePtr v2)
 
730
        static ALWAYS_INLINE bool canDoFastUrshift(JSValue v1, JSValue v2)
782
731
        {
783
732
            return JSImmediate::areBothImmediateIntegerNumbers(v1, v2) && !(JSImmediate::rawValue(v1) & JSImmediate::signBit);
784
733
        }
785
734
 
786
 
        static ALWAYS_INLINE JSValuePtr rightShiftImmediateNumbers(JSValuePtr val, JSValuePtr shift)
 
735
        static ALWAYS_INLINE JSValue rightShiftImmediateNumbers(JSValue val, JSValue shift)
787
736
        {
788
737
            ASSERT(canDoFastRshift(val, shift) || canDoFastUrshift(val, shift));
789
738
#if USE(ALTERNATE_JSIMMEDIATE)
793
742
#endif
794
743
        }
795
744
 
796
 
        static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValuePtr v)
 
745
        static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValue v)
797
746
        {
798
747
            // Number is non-negative and an operation involving two of these can't overflow.
799
748
            // Checking for allowed negative numbers takes more time than it's worth on SunSpider.
800
749
            return (JSImmediate::rawValue(v) & (JSImmediate::TagTypeNumber + (JSImmediate::signBit | (JSImmediate::signBit >> 1)))) == JSImmediate::TagTypeNumber;
801
750
        }
802
751
 
803
 
        static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValuePtr v1, JSValuePtr v2)
 
752
        static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValue v1, JSValue v2)
804
753
        {
805
754
            // Number is non-negative and an operation involving two of these can't overflow.
806
755
            // Checking for allowed negative numbers takes more time than it's worth on SunSpider.
807
756
            return canDoFastAdditiveOperations(v1) && canDoFastAdditiveOperations(v2);
808
757
        }
809
758
 
810
 
        static ALWAYS_INLINE JSValuePtr addImmediateNumbers(JSValuePtr v1, JSValuePtr v2)
 
759
        static ALWAYS_INLINE JSValue addImmediateNumbers(JSValue v1, JSValue v2)
811
760
        {
812
761
            ASSERT(canDoFastAdditiveOperations(v1, v2));
813
762
            return JSImmediate::makeValue(JSImmediate::rawValue(v1) + JSImmediate::rawValue(v2) - JSImmediate::TagTypeNumber);
814
763
        }
815
764
 
816
 
        static ALWAYS_INLINE JSValuePtr subImmediateNumbers(JSValuePtr v1, JSValuePtr v2)
 
765
        static ALWAYS_INLINE JSValue subImmediateNumbers(JSValue v1, JSValue v2)
817
766
        {
818
767
            ASSERT(canDoFastAdditiveOperations(v1, v2));
819
768
            return JSImmediate::makeValue(JSImmediate::rawValue(v1) - JSImmediate::rawValue(v2) + JSImmediate::TagTypeNumber);
820
769
        }
821
770
 
822
 
        static ALWAYS_INLINE JSValuePtr incImmediateNumber(JSValuePtr v)
 
771
        static ALWAYS_INLINE JSValue incImmediateNumber(JSValue v)
823
772
        {
824
773
            ASSERT(canDoFastAdditiveOperations(v));
825
774
            return JSImmediate::makeValue(JSImmediate::rawValue(v) + (1 << JSImmediate::IntegerPayloadShift));
826
775
        }
827
776
 
828
 
        static ALWAYS_INLINE JSValuePtr decImmediateNumber(JSValuePtr v)
 
777
        static ALWAYS_INLINE JSValue decImmediateNumber(JSValue v)
829
778
        {
830
779
            ASSERT(canDoFastAdditiveOperations(v));
831
780
            return JSImmediate::makeValue(JSImmediate::rawValue(v) - (1 << JSImmediate::IntegerPayloadShift));