OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 } | 1709 } |
1710 break; | 1710 break; |
1711 default: | 1711 default: |
1712 PrintF("Unknown type: %d\n", type); | 1712 PrintF("Unknown type: %d\n", type); |
1713 UNREACHABLE(); | 1713 UNREACHABLE(); |
1714 } | 1714 } |
1715 } | 1715 } |
1716 | 1716 |
1717 | 1717 |
1718 bool HeapNumber::HeapNumberBooleanValue() { | 1718 bool HeapNumber::HeapNumberBooleanValue() { |
1719 return DoubleToBoolean(value()); | 1719 // NaN, +0, and -0 should return the false object |
| 1720 #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 1721 union IeeeDoubleLittleEndianArchType u; |
| 1722 #elif __BYTE_ORDER == __BIG_ENDIAN |
| 1723 union IeeeDoubleBigEndianArchType u; |
| 1724 #endif |
| 1725 u.d = value(); |
| 1726 if (u.bits.exp == 2047) { |
| 1727 // Detect NaN for IEEE double precision floating point. |
| 1728 if ((u.bits.man_low | u.bits.man_high) != 0) return false; |
| 1729 } |
| 1730 if (u.bits.exp == 0) { |
| 1731 // Detect +0, and -0 for IEEE double precision floating point. |
| 1732 if ((u.bits.man_low | u.bits.man_high) == 0) return false; |
| 1733 } |
| 1734 return true; |
1720 } | 1735 } |
1721 | 1736 |
1722 | 1737 |
1723 void HeapNumber::HeapNumberPrint(FILE* out) { | 1738 void HeapNumber::HeapNumberPrint(FILE* out) { |
1724 PrintF(out, "%.16g", Number()); | 1739 PrintF(out, "%.16g", Number()); |
1725 } | 1740 } |
1726 | 1741 |
1727 | 1742 |
1728 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { | 1743 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { |
1729 // The Windows version of vsnprintf can allocate when printing a %g string | 1744 // The Windows version of vsnprintf can allocate when printing a %g string |
(...skipping 7600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9330 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 9345 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
9331 return result; | 9346 return result; |
9332 } | 9347 } |
9333 | 9348 |
9334 | 9349 |
9335 bool String::ComputeArrayIndex(uint32_t* index) { | 9350 bool String::ComputeArrayIndex(uint32_t* index) { |
9336 int length = this->length(); | 9351 int length = this->length(); |
9337 if (length == 0 || length > kMaxArrayIndexSize) return false; | 9352 if (length == 0 || length > kMaxArrayIndexSize) return false; |
9338 ConsStringIteratorOp op; | 9353 ConsStringIteratorOp op; |
9339 StringCharacterStream stream(this, &op); | 9354 StringCharacterStream stream(this, &op); |
9340 return StringToArrayIndex(&stream, index); | 9355 uint16_t ch = stream.GetNext(); |
| 9356 |
| 9357 // If the string begins with a '0' character, it must only consist |
| 9358 // of it to be a legal array index. |
| 9359 if (ch == '0') { |
| 9360 *index = 0; |
| 9361 return length == 1; |
| 9362 } |
| 9363 |
| 9364 // Convert string to uint32 array index; character by character. |
| 9365 int d = ch - '0'; |
| 9366 if (d < 0 || d > 9) return false; |
| 9367 uint32_t result = d; |
| 9368 while (stream.HasMore()) { |
| 9369 d = stream.GetNext() - '0'; |
| 9370 if (d < 0 || d > 9) return false; |
| 9371 // Check that the new result is below the 32 bit limit. |
| 9372 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; |
| 9373 result = (result * 10) + d; |
| 9374 } |
| 9375 |
| 9376 *index = result; |
| 9377 return true; |
9341 } | 9378 } |
9342 | 9379 |
9343 | 9380 |
9344 bool String::SlowAsArrayIndex(uint32_t* index) { | 9381 bool String::SlowAsArrayIndex(uint32_t* index) { |
9345 if (length() <= kMaxCachedArrayIndexLength) { | 9382 if (length() <= kMaxCachedArrayIndexLength) { |
9346 Hash(); // force computation of hash code | 9383 Hash(); // force computation of hash code |
9347 uint32_t field = hash_field(); | 9384 uint32_t field = hash_field(); |
9348 if ((field & kIsNotArrayIndexMask) != 0) return false; | 9385 if ((field & kIsNotArrayIndexMask) != 0) return false; |
9349 // Isolate the array index form the full hash field. | 9386 // Isolate the array index form the full hash field. |
9350 *index = ArrayIndexValueBits::decode(field); | 9387 *index = ArrayIndexValueBits::decode(field); |
(...skipping 7612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16963 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17000 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16964 static const char* error_messages_[] = { | 17001 static const char* error_messages_[] = { |
16965 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17002 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16966 }; | 17003 }; |
16967 #undef ERROR_MESSAGES_TEXTS | 17004 #undef ERROR_MESSAGES_TEXTS |
16968 return error_messages_[reason]; | 17005 return error_messages_[reason]; |
16969 } | 17006 } |
16970 | 17007 |
16971 | 17008 |
16972 } } // namespace v8::internal | 17009 } } // namespace v8::internal |
OLD | NEW |