Changeset 37681 in webkit for trunk/JavaScriptCore/kjs/JSImmediate.h
- Timestamp:
- Oct 18, 2008, 4:08:12 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSImmediate.h
r36802 r37681 39 39 class UString; 40 40 41 inline JSValue* noValue() { return 0; } 42 inline void* asPointer(JSValue* value) { return value; } 43 41 44 /* 42 45 * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged … … 106 109 static ALWAYS_INLINE bool isImmediate(const JSValue* v) 107 110 { 108 return r einterpret_cast<uintptr_t>(v) & TagMask;111 return rawValue(v) & TagMask; 109 112 } 110 113 111 114 static ALWAYS_INLINE bool isNumber(const JSValue* v) 112 115 { 113 return r einterpret_cast<uintptr_t>(v) & TagBitTypeInteger;116 return rawValue(v) & TagBitTypeInteger; 114 117 } 115 118 … … 117 120 { 118 121 // A single mask to check for the sign bit and the number tag all at once. 119 return (r einterpret_cast<uintptr_t>(v) & (0x80000000 | TagBitTypeInteger)) == TagBitTypeInteger;122 return (rawValue(v) & (0x80000000 | TagBitTypeInteger)) == TagBitTypeInteger; 120 123 } 121 124 122 125 static ALWAYS_INLINE bool isBoolean(const JSValue* v) 123 126 { 124 return (r einterpret_cast<uintptr_t>(v) & FullTagTypeMask) == FullTagTypeBool;127 return (rawValue(v) & FullTagTypeMask) == FullTagTypeBool; 125 128 } 126 129 … … 128 131 { 129 132 // Undefined and null share the same value, bar the 'undefined' bit in the extended tag. 130 return (r einterpret_cast<uintptr_t>(v) & ~ExtendedTagBitUndefined) == FullTagTypeNull;133 return (rawValue(v) & ~ExtendedTagBitUndefined) == FullTagTypeNull; 131 134 } 132 135 … … 134 137 { 135 138 ASSERT(isNumber(v)); 136 return r einterpret_cast<uintptr_t>(v) & 0x80000000;139 return rawValue(v) & 0x80000000; 137 140 } 138 141 … … 152 155 static ALWAYS_INLINE bool isEitherImmediate(const JSValue* v1, const JSValue* v2) 153 156 { 154 return (r einterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2)) & TagMask;157 return (rawValue(v1) | rawValue(v2)) & TagMask; 155 158 } 156 159 157 160 static ALWAYS_INLINE bool isAnyImmediate(const JSValue* v1, const JSValue* v2, JSValue* v3) 158 161 { 159 return (r einterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2) | reinterpret_cast<uintptr_t>(v3)) & TagMask;162 return (rawValue(v1) | rawValue(v2) | rawValue(v3)) & TagMask; 160 163 } 161 164 … … 167 170 static ALWAYS_INLINE bool areBothImmediateNumbers(const JSValue* v1, const JSValue* v2) 168 171 { 169 return r einterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagBitTypeInteger;172 return rawValue(v1) & rawValue(v2) & TagBitTypeInteger; 170 173 } 171 174 … … 173 176 { 174 177 ASSERT(areBothImmediateNumbers(v1, v2)); 175 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2));178 return makeValue(rawValue(v1) & rawValue(v2)); 176 179 } 177 180 … … 179 182 { 180 183 ASSERT(areBothImmediateNumbers(v1, v2)); 181 return reinterpret_cast<JSValue*>((reinterpret_cast<uintptr_t>(v1) ^ reinterpret_cast<uintptr_t>(v2)) | TagBitTypeInteger);184 return makeValue((rawValue(v1) ^ rawValue(v2)) | TagBitTypeInteger); 182 185 } 183 186 … … 185 188 { 186 189 ASSERT(areBothImmediateNumbers(v1, v2)); 187 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) | reinterpret_cast<uintptr_t>(v2));190 return makeValue(rawValue(v1) | rawValue(v2)); 188 191 } 189 192 … … 191 194 { 192 195 ASSERT(areBothImmediateNumbers(val, shift)); 193 return reinterpret_cast<JSValue*>((reinterpret_cast<intptr_t>(val) >> ((reinterpret_cast<uintptr_t>(shift) >> IntegerPayloadShift) & 0x1f)) | TagBitTypeInteger);196 return makeValue((static_cast<intptr_t>(rawValue(val)) >> ((rawValue(shift) >> IntegerPayloadShift) & 0x1f)) | TagBitTypeInteger); 194 197 } 195 198 … … 198 201 // Number is non-negative and an operation involving two of these can't overflow. 199 202 // Checking for allowed negative numbers takes more time than it's worth on SunSpider. 200 return (r einterpret_cast<uintptr_t>(v) & (TagBitTypeInteger + (3u << 30))) == TagBitTypeInteger;203 return (rawValue(v) & (TagBitTypeInteger + (3u << 30))) == TagBitTypeInteger; 201 204 } 202 205 … … 205 208 ASSERT(canDoFastAdditiveOperations(v1)); 206 209 ASSERT(canDoFastAdditiveOperations(v2)); 207 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) + reinterpret_cast<uintptr_t>(v2) - TagBitTypeInteger);210 return makeValue(rawValue(v1) + rawValue(v2) - TagBitTypeInteger); 208 211 } 209 212 … … 212 215 ASSERT(canDoFastAdditiveOperations(v1)); 213 216 ASSERT(canDoFastAdditiveOperations(v2)); 214 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) - reinterpret_cast<uintptr_t>(v2) + TagBitTypeInteger);217 return makeValue(rawValue(v1) - rawValue(v2) + TagBitTypeInteger); 215 218 } 216 219 … … 218 221 { 219 222 ASSERT(canDoFastAdditiveOperations(v)); 220 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) + (1 << IntegerPayloadShift));223 return makeValue(rawValue(v) + (1 << IntegerPayloadShift)); 221 224 } 222 225 … … 224 227 { 225 228 ASSERT(canDoFastAdditiveOperations(v)); 226 return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v) - (1 << IntegerPayloadShift));229 return makeValue(rawValue(v) - (1 << IntegerPayloadShift)); 227 230 } 228 231 … … 254 257 static const int maxImmediateInt = INT_MAX >> IntegerPayloadShift; 255 258 static const unsigned maxImmediateUInt = maxImmediateInt; 256 259 260 static ALWAYS_INLINE JSValue* makeValue(uintptr_t integer) 261 { 262 return reinterpret_cast<JSValue*>(integer); 263 } 264 257 265 static ALWAYS_INLINE JSValue* makeInt(int32_t value) 258 266 { 259 return reinterpret_cast<JSValue*>((value << IntegerPayloadShift) | TagBitTypeInteger);267 return makeValue((value << IntegerPayloadShift) | TagBitTypeInteger); 260 268 } 261 269 262 270 static ALWAYS_INLINE JSValue* makeBool(bool b) 263 271 { 264 return reinterpret_cast<JSValue*>((static_cast<uintptr_t>(b) << ExtendedPayloadShift) | FullTagTypeBool);272 return makeValue((static_cast<uintptr_t>(b) << ExtendedPayloadShift) | FullTagTypeBool); 265 273 } 266 274 267 275 static ALWAYS_INLINE JSValue* makeUndefined() 268 276 { 269 return reinterpret_cast<JSValue*>(FullTagTypeUndefined);277 return makeValue(FullTagTypeUndefined); 270 278 } 271 279 272 280 static ALWAYS_INLINE JSValue* makeNull() 273 281 { 274 return reinterpret_cast<JSValue*>(FullTagTypeNull);282 return makeValue(FullTagTypeNull); 275 283 } 276 284 277 285 static ALWAYS_INLINE int32_t intValue(const JSValue* v) 278 286 { 279 return static_cast<int32_t>( reinterpret_cast<intptr_t>(v) >> IntegerPayloadShift);287 return static_cast<int32_t>(static_cast<intptr_t>(rawValue(v)) >> IntegerPayloadShift); 280 288 } 281 289 … … 306 314 307 315 // This value is impossible because 0x4 is not a valid pointer but a tag of 0 would indicate non-immediate 308 ALWAYS_INLINE JSValue* JSImmediate::impossibleValue() { return reinterpret_cast<JSValue*>(0x4); }316 ALWAYS_INLINE JSValue* JSImmediate::impossibleValue() { return makeValue(0x4); } 309 317 310 318 ALWAYS_INLINE bool JSImmediate::toBoolean(const JSValue* v) … … 351 359 { 352 360 if ((i < minImmediateInt) | (i > maxImmediateInt)) 353 return 0;361 return noValue(); 354 362 return makeInt(i); 355 363 } … … 358 366 { 359 367 if (i > maxImmediateUInt) 360 return 0;368 return noValue(); 361 369 return makeInt(i); 362 370 } … … 365 373 { 366 374 if ((i < minImmediateInt) | (i > maxImmediateInt)) 367 return 0;375 return noValue(); 368 376 return makeInt(i); 369 377 } … … 372 380 { 373 381 if (i > maxImmediateUInt) 374 return 0;382 return noValue(); 375 383 return makeInt(i); 376 384 } … … 379 387 { 380 388 if ((i < minImmediateInt) | (i > maxImmediateInt)) 381 return 0;389 return noValue(); 382 390 return makeInt(static_cast<uintptr_t>(i)); 383 391 } … … 386 394 { 387 395 if (i > maxImmediateUInt) 388 return 0;396 return noValue(); 389 397 return makeInt(static_cast<uintptr_t>(i)); 390 398 } … … 395 403 396 404 if ((intVal < minImmediateInt) | (intVal > maxImmediateInt)) 397 return 0;405 return noValue(); 398 406 399 407 // Check for data loss from conversion to int. 400 408 if (intVal != d || (!intVal && signbit(d))) 401 return 0;409 return noValue(); 402 410 403 411 return makeInt(intVal);
Note:
See TracChangeset
for help on using the changeset viewer.