Changeset 447 for trunk/JavaScriptCore/kjs/JSImmediate.h
- Timestamp:
- 08/20/08 13:23:52 (5 months ago)
- Files:
-
- trunk/JavaScriptCore/kjs/JSImmediate.h (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/JavaScriptCore/kjs/JSImmediate.h
r440 r447 1 1 /* 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 4 * … … 23 23 #define KJS_JS_IMMEDIATE_H 24 24 25 #include "JSType.h"26 25 #include <wtf/Assertions.h> 27 26 #include <wtf/AlwaysInline.h> … … 41 40 42 41 /* 43 * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged42 * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged 44 43 * value masquerading as a pointer). The low two bits in a JSValue* are available for type tagging 45 44 * because allocator alignment guarantees they will be 00 in cell pointers. … … 83 82 84 83 class JSImmediate { 84 private: 85 85 static const uintptr_t TagMask = 0x3u; // primary tag is 2 bits long 86 static const uintptr_t TagBitTypeInteger = 0x1u; // bottom bit set indicates int , this dominates the following bit86 static const uintptr_t TagBitTypeInteger = 0x1u; // bottom bit set indicates integer, this dominates the following bit 87 87 static const uintptr_t TagBitTypeOther = 0x2u; // second bit set indicates immediate other than an integer 88 88 … … 104 104 static ALWAYS_INLINE bool isImmediate(const JSValue* v) 105 105 { 106 return (reinterpret_cast<uintptr_t>(v) & TagMask);106 return reinterpret_cast<uintptr_t>(v) & TagMask; 107 107 } 108 108 109 109 static ALWAYS_INLINE bool isNumber(const JSValue* v) 110 110 { 111 return (reinterpret_cast<uintptr_t>(v) & TagBitTypeInteger);111 return reinterpret_cast<uintptr_t>(v) & TagBitTypeInteger; 112 112 } 113 113 … … 120 120 static ALWAYS_INLINE bool isBoolean(const JSValue* v) 121 121 { 122 return ( (reinterpret_cast<uintptr_t>(v) & FullTagTypeMask) == FullTagTypeBool);122 return (reinterpret_cast<uintptr_t>(v) & FullTagTypeMask) == FullTagTypeBool; 123 123 } 124 124 … … 126 126 { 127 127 // Undefined and null share the same value, bar the 'undefined' bit in the extended tag. 128 return ( (reinterpret_cast<uintptr_t>(v) & ~ExtendedTagBitUndefined) == FullTagTypeNull);128 return (reinterpret_cast<uintptr_t>(v) & ~ExtendedTagBitUndefined) == FullTagTypeNull; 129 129 } 130 130 … … 148 148 static JSValue* from(double); 149 149 150 static ALWAYS_INLINE bool isEitherImmediate(const JSValue* v1, const JSValue* v2) 151 { 152 return (reinterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2)) & TagMask; 153 } 154 150 155 static ALWAYS_INLINE bool areBothImmediateNumbers(const JSValue* v1, const JSValue* v2) 151 156 { 152 return (reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagBitTypeInteger);157 return reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagBitTypeInteger; 153 158 } 154 159 … … 214 219 static JSObject* toObject(const JSValue*, ExecState*); 215 220 static UString toString(const JSValue*); 216 static uint32_t toTruncatedUInt32(const JSValue*);217 static JSType type(const JSValue*);218 221 219 222 static bool getUInt32(const JSValue*, uint32_t&); … … 222 225 223 226 static int32_t getTruncatedInt32(const JSValue*); 227 static uint32_t getTruncatedUInt32(const JSValue*); 224 228 225 229 static JSValue* trueImmediate(); … … 233 237 234 238 private: 235 // Immediate values are restricted to a 30 bit signed value.236 239 static const int minImmediateInt = ((-INT_MAX) - 1) >> IntegerPayloadShift; 237 240 static const int maxImmediateInt = INT_MAX >> IntegerPayloadShift; … … 270 273 static ALWAYS_INLINE bool boolValue(const JSValue* v) 271 274 { 272 return (rawValue(v) & ExtendedPayloadBitBoolValue) != 0;275 return rawValue(v) & ExtendedPayloadBitBoolValue; 273 276 } 274 277 … … 291 294 ASSERT(isImmediate(v)); 292 295 uintptr_t bits = rawValue(v); 293 return 294 (bits & TagBitTypeInteger) ? (bits != TagBitTypeInteger) :// !0 ints295 (bits == (FullTagTypeBool | ExtendedPayloadBitBoolValue)); // bool true296 } 297 298 ALWAYS_INLINE uint32_t JSImmediate:: toTruncatedUInt32(const JSValue* v)296 return (bits & TagBitTypeInteger) 297 ? bits != TagBitTypeInteger // !0 ints 298 : bits == (FullTagTypeBool | ExtendedPayloadBitBoolValue); // bool true 299 } 300 301 ALWAYS_INLINE uint32_t JSImmediate::getTruncatedUInt32(const JSValue* v) 299 302 { 300 303 ASSERT(isNumber(v)); … … 377 380 378 381 // Check for data loss from conversion to int. 379 if ( (intVal != d)|| (!intVal && signbit(d)))382 if (intVal != d || (!intVal && signbit(d))) 380 383 return 0; 381 384 … … 418 421 } 419 422 420 ALWAYS_INLINE JSType JSImmediate::type(const JSValue* v)421 {422 ASSERT(isImmediate(v));423 424 if (isNumber(v))425 return NumberType;426 if (isBoolean(v))427 return BooleanType;428 if (v != undefinedImmediate())429 return NullType;430 return UndefinedType;431 }432 433 423 ALWAYS_INLINE JSValue* jsUndefined() 434 424 {
