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 7625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9355 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 9340 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
9356 return result; | 9341 return result; |
9357 } | 9342 } |
9358 | 9343 |
9359 | 9344 |
9360 bool String::ComputeArrayIndex(uint32_t* index) { | 9345 bool String::ComputeArrayIndex(uint32_t* index) { |
9361 int length = this->length(); | 9346 int length = this->length(); |
9362 if (length == 0 || length > kMaxArrayIndexSize) return false; | 9347 if (length == 0 || length > kMaxArrayIndexSize) return false; |
9363 ConsStringIteratorOp op; | 9348 ConsStringIteratorOp op; |
9364 StringCharacterStream stream(this, &op); | 9349 StringCharacterStream stream(this, &op); |
9365 uint16_t ch = stream.GetNext(); | 9350 return StringToArrayIndex(&stream, index); |
9366 | |
9367 // If the string begins with a '0' character, it must only consist | |
9368 // of it to be a legal array index. | |
9369 if (ch == '0') { | |
9370 *index = 0; | |
9371 return length == 1; | |
9372 } | |
9373 | |
9374 // Convert string to uint32 array index; character by character. | |
9375 int d = ch - '0'; | |
9376 if (d < 0 || d > 9) return false; | |
9377 uint32_t result = d; | |
9378 while (stream.HasMore()) { | |
9379 d = stream.GetNext() - '0'; | |
9380 if (d < 0 || d > 9) return false; | |
9381 // Check that the new result is below the 32 bit limit. | |
9382 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; | |
9383 result = (result * 10) + d; | |
9384 } | |
9385 | |
9386 *index = result; | |
9387 return true; | |
9388 } | 9351 } |
9389 | 9352 |
9390 | 9353 |
9391 bool String::SlowAsArrayIndex(uint32_t* index) { | 9354 bool String::SlowAsArrayIndex(uint32_t* index) { |
9392 if (length() <= kMaxCachedArrayIndexLength) { | 9355 if (length() <= kMaxCachedArrayIndexLength) { |
9393 Hash(); // force computation of hash code | 9356 Hash(); // force computation of hash code |
9394 uint32_t field = hash_field(); | 9357 uint32_t field = hash_field(); |
9395 if ((field & kIsNotArrayIndexMask) != 0) return false; | 9358 if ((field & kIsNotArrayIndexMask) != 0) return false; |
9396 // Isolate the array index form the full hash field. | 9359 // Isolate the array index form the full hash field. |
9397 *index = ArrayIndexValueBits::decode(field); | 9360 *index = ArrayIndexValueBits::decode(field); |
(...skipping 7592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16990 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16953 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16991 static const char* error_messages_[] = { | 16954 static const char* error_messages_[] = { |
16992 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16955 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16993 }; | 16956 }; |
16994 #undef ERROR_MESSAGES_TEXTS | 16957 #undef ERROR_MESSAGES_TEXTS |
16995 return error_messages_[reason]; | 16958 return error_messages_[reason]; |
16996 } | 16959 } |
16997 | 16960 |
16998 | 16961 |
16999 } } // namespace v8::internal | 16962 } } // namespace v8::internal |
OLD | NEW |