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 // NaN, +0, and -0 should return the false object | 1719 return DoubleToBoolean(value()); |
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; | |
1735 } | 1720 } |
1736 | 1721 |
1737 | 1722 |
1738 void HeapNumber::HeapNumberPrint(FILE* out) { | 1723 void HeapNumber::HeapNumberPrint(FILE* out) { |
1739 PrintF(out, "%.16g", Number()); | 1724 PrintF(out, "%.16g", Number()); |
1740 } | 1725 } |
1741 | 1726 |
1742 | 1727 |
1743 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { | 1728 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { |
1744 // The Windows version of vsnprintf can allocate when printing a %g string | 1729 // The Windows version of vsnprintf can allocate when printing a %g string |
(...skipping 7647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9392 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 9377 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
9393 return result; | 9378 return result; |
9394 } | 9379 } |
9395 | 9380 |
9396 | 9381 |
9397 bool String::ComputeArrayIndex(uint32_t* index) { | 9382 bool String::ComputeArrayIndex(uint32_t* index) { |
9398 int length = this->length(); | 9383 int length = this->length(); |
9399 if (length == 0 || length > kMaxArrayIndexSize) return false; | 9384 if (length == 0 || length > kMaxArrayIndexSize) return false; |
9400 ConsStringIteratorOp op; | 9385 ConsStringIteratorOp op; |
9401 StringCharacterStream stream(this, &op); | 9386 StringCharacterStream stream(this, &op); |
9402 uint16_t ch = stream.GetNext(); | 9387 return StringToArrayIndex(&stream, index); |
9403 | |
9404 // If the string begins with a '0' character, it must only consist | |
9405 // of it to be a legal array index. | |
9406 if (ch == '0') { | |
9407 *index = 0; | |
9408 return length == 1; | |
9409 } | |
9410 | |
9411 // Convert string to uint32 array index; character by character. | |
9412 int d = ch - '0'; | |
9413 if (d < 0 || d > 9) return false; | |
9414 uint32_t result = d; | |
9415 while (stream.HasMore()) { | |
9416 d = stream.GetNext() - '0'; | |
9417 if (d < 0 || d > 9) return false; | |
9418 // Check that the new result is below the 32 bit limit. | |
9419 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; | |
9420 result = (result * 10) + d; | |
9421 } | |
9422 | |
9423 *index = result; | |
9424 return true; | |
9425 } | 9388 } |
9426 | 9389 |
9427 | 9390 |
9428 bool String::SlowAsArrayIndex(uint32_t* index) { | 9391 bool String::SlowAsArrayIndex(uint32_t* index) { |
9429 if (length() <= kMaxCachedArrayIndexLength) { | 9392 if (length() <= kMaxCachedArrayIndexLength) { |
9430 Hash(); // force computation of hash code | 9393 Hash(); // force computation of hash code |
9431 uint32_t field = hash_field(); | 9394 uint32_t field = hash_field(); |
9432 if ((field & kIsNotArrayIndexMask) != 0) return false; | 9395 if ((field & kIsNotArrayIndexMask) != 0) return false; |
9433 // Isolate the array index form the full hash field. | 9396 // Isolate the array index form the full hash field. |
9434 *index = ArrayIndexValueBits::decode(field); | 9397 *index = ArrayIndexValueBits::decode(field); |
(...skipping 7603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17038 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17001 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17039 static const char* error_messages_[] = { | 17002 static const char* error_messages_[] = { |
17040 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17003 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17041 }; | 17004 }; |
17042 #undef ERROR_MESSAGES_TEXTS | 17005 #undef ERROR_MESSAGES_TEXTS |
17043 return error_messages_[reason]; | 17006 return error_messages_[reason]; |
17044 } | 17007 } |
17045 | 17008 |
17046 | 17009 |
17047 } } // namespace v8::internal | 17010 } } // namespace v8::internal |
OLD | NEW |