Changeset 67825 in webkit for trunk/JavaScriptCore/runtime/JSValue.h
- Timestamp:
- Sep 19, 2010, 6:23:33 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSValue.h
r66318 r67825 57 57 58 58 double nonInlineNaN(); 59 int32_t toInt32SlowCase(double, bool& ok); 60 uint32_t toUInt32SlowCase(double, bool& ok); 59 60 // This implements ToInt32, defined in ECMA-262 9.5. 61 int32_t toInt32(double); 62 63 // This implements ToUInt32, defined in ECMA-262 9.6. 64 inline uint32_t toUInt32(double number) 65 { 66 // As commented in the spec, the operation of ToInt32 and ToUint32 only differ 67 // in how the result is interpreted; see NOTEs in sections 9.5 and 9.6. 68 return toInt32(number); 69 } 61 70 62 71 class JSValue { … … 164 173 double toIntegerPreserveNaN(ExecState*) const; 165 174 int32_t toInt32(ExecState*) const; 166 int32_t toInt32(ExecState*, bool& ok) const;167 175 uint32_t toUInt32(ExecState*) const; 168 uint32_t toUInt32(ExecState*, bool& ok) const;169 176 170 177 #if ENABLE(JSC_ZOMBIES) … … 368 375 inline bool operator!=(const JSCell* a, const JSValue b) { return JSValue(a) != b; } 369 376 370 inline int32_t toInt32(double val)371 {372 if (!(val >= -2147483648.0 && val < 2147483648.0)) {373 bool ignored;374 return toInt32SlowCase(val, ignored);375 }376 return static_cast<int32_t>(val);377 }378 379 inline uint32_t toUInt32(double val)380 {381 if (!(val >= 0.0 && val < 4294967296.0)) {382 bool ignored;383 return toUInt32SlowCase(val, ignored);384 }385 return static_cast<uint32_t>(val);386 }387 388 377 // FIXME: We should deprecate this and just use JSValue::asCell() instead. 389 378 JSCell* asCell(JSValue); … … 398 387 if (isInt32()) 399 388 return asInt32(); 400 401 double val = toNumber(exec); 402 403 if (val >= -2147483648.0 && val < 2147483648.0) 404 return static_cast<int32_t>(val); 405 406 bool ignored; 407 return toInt32SlowCase(val, ignored); 389 return JSC::toInt32(toNumber(exec)); 408 390 } 409 391 410 392 inline uint32_t JSValue::toUInt32(ExecState* exec) const 411 393 { 412 if (isUInt32()) 413 return asUInt32(); 414 415 double val = toNumber(exec); 416 417 if (val >= 0.0 && val < 4294967296.0) 418 return static_cast<uint32_t>(val); 419 420 bool ignored; 421 return toUInt32SlowCase(val, ignored); 422 } 423 424 inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const 425 { 426 if (isInt32()) { 427 ok = true; 428 return asInt32(); 429 } 430 431 double val = toNumber(exec); 432 433 if (val >= -2147483648.0 && val < 2147483648.0) { 434 ok = true; 435 return static_cast<int32_t>(val); 436 } 437 438 return toInt32SlowCase(val, ok); 439 } 440 441 inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const 442 { 443 if (isUInt32()) { 444 ok = true; 445 return asInt32(); 446 } 447 448 double val = toNumber(exec); 449 450 if (val >= 0.0 && val < 4294967296.0) { 451 ok = true; 452 return static_cast<uint32_t>(val); 453 } 454 455 return toUInt32SlowCase(val, ok); 394 // See comment on JSC::toUInt32, above. 395 return toInt32(exec); 456 396 } 457 397
Note:
See TracChangeset
for help on using the changeset viewer.