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 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 } | 1694 } |
1695 break; | 1695 break; |
1696 default: | 1696 default: |
1697 PrintF("Unknown type: %d\n", type); | 1697 PrintF("Unknown type: %d\n", type); |
1698 UNREACHABLE(); | 1698 UNREACHABLE(); |
1699 } | 1699 } |
1700 } | 1700 } |
1701 | 1701 |
1702 | 1702 |
1703 bool HeapNumber::HeapNumberBooleanValue() { | 1703 bool HeapNumber::HeapNumberBooleanValue() { |
1704 // NaN, +0, and -0 should return the false object | 1704 return DoubleToBoolean(value()); |
1705 #if __BYTE_ORDER == __LITTLE_ENDIAN | |
1706 union IeeeDoubleLittleEndianArchType u; | |
1707 #elif __BYTE_ORDER == __BIG_ENDIAN | |
1708 union IeeeDoubleBigEndianArchType u; | |
1709 #endif | |
1710 u.d = value(); | |
1711 if (u.bits.exp == 2047) { | |
1712 // Detect NaN for IEEE double precision floating point. | |
1713 if ((u.bits.man_low | u.bits.man_high) != 0) return false; | |
1714 } | |
1715 if (u.bits.exp == 0) { | |
1716 // Detect +0, and -0 for IEEE double precision floating point. | |
1717 if ((u.bits.man_low | u.bits.man_high) == 0) return false; | |
1718 } | |
1719 return true; | |
1720 } | 1705 } |
1721 | 1706 |
1722 | 1707 |
1723 void HeapNumber::HeapNumberPrint(FILE* out) { | 1708 void HeapNumber::HeapNumberPrint(FILE* out) { |
1724 PrintF(out, "%.16g", Number()); | 1709 PrintF(out, "%.16g", Number()); |
1725 } | 1710 } |
1726 | 1711 |
1727 | 1712 |
1728 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { | 1713 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { |
1729 // The Windows version of vsnprintf can allocate when printing a %g string | 1714 // The Windows version of vsnprintf can allocate when printing a %g string |
(...skipping 7593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9323 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 9308 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
9324 return result; | 9309 return result; |
9325 } | 9310 } |
9326 | 9311 |
9327 | 9312 |
9328 bool String::ComputeArrayIndex(uint32_t* index) { | 9313 bool String::ComputeArrayIndex(uint32_t* index) { |
9329 int length = this->length(); | 9314 int length = this->length(); |
9330 if (length == 0 || length > kMaxArrayIndexSize) return false; | 9315 if (length == 0 || length > kMaxArrayIndexSize) return false; |
9331 ConsStringIteratorOp op; | 9316 ConsStringIteratorOp op; |
9332 StringCharacterStream stream(this, &op); | 9317 StringCharacterStream stream(this, &op); |
9333 uint16_t ch = stream.GetNext(); | 9318 return StringToArrayIndex(&stream, index); |
9334 | |
9335 // If the string begins with a '0' character, it must only consist | |
9336 // of it to be a legal array index. | |
9337 if (ch == '0') { | |
9338 *index = 0; | |
9339 return length == 1; | |
9340 } | |
9341 | |
9342 // Convert string to uint32 array index; character by character. | |
9343 int d = ch - '0'; | |
9344 if (d < 0 || d > 9) return false; | |
9345 uint32_t result = d; | |
9346 while (stream.HasMore()) { | |
9347 d = stream.GetNext() - '0'; | |
9348 if (d < 0 || d > 9) return false; | |
9349 // Check that the new result is below the 32 bit limit. | |
9350 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; | |
9351 result = (result * 10) + d; | |
9352 } | |
9353 | |
9354 *index = result; | |
9355 return true; | |
9356 } | 9319 } |
9357 | 9320 |
9358 | 9321 |
9359 bool String::SlowAsArrayIndex(uint32_t* index) { | 9322 bool String::SlowAsArrayIndex(uint32_t* index) { |
9360 if (length() <= kMaxCachedArrayIndexLength) { | 9323 if (length() <= kMaxCachedArrayIndexLength) { |
9361 Hash(); // force computation of hash code | 9324 Hash(); // force computation of hash code |
9362 uint32_t field = hash_field(); | 9325 uint32_t field = hash_field(); |
9363 if ((field & kIsNotArrayIndexMask) != 0) return false; | 9326 if ((field & kIsNotArrayIndexMask) != 0) return false; |
9364 // Isolate the array index form the full hash field. | 9327 // Isolate the array index form the full hash field. |
9365 *index = ArrayIndexValueBits::decode(field); | 9328 *index = ArrayIndexValueBits::decode(field); |
(...skipping 7592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16958 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16921 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16959 static const char* error_messages_[] = { | 16922 static const char* error_messages_[] = { |
16960 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16923 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16961 }; | 16924 }; |
16962 #undef ERROR_MESSAGES_TEXTS | 16925 #undef ERROR_MESSAGES_TEXTS |
16963 return error_messages_[reason]; | 16926 return error_messages_[reason]; |
16964 } | 16927 } |
16965 | 16928 |
16966 | 16929 |
16967 } } // namespace v8::internal | 16930 } } // namespace v8::internal |
OLD | NEW |