Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: src/objects.cc

Issue 314603004: Parser: Delay internalizing strings and values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: oops, #include fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1714 }
1715 break; 1715 break;
1716 default: 1716 default:
1717 PrintF("Unknown type: %d\n", type); 1717 PrintF("Unknown type: %d\n", type);
1718 UNREACHABLE(); 1718 UNREACHABLE();
1719 } 1719 }
1720 } 1720 }
1721 1721
1722 1722
1723 bool HeapNumber::HeapNumberBooleanValue() { 1723 bool HeapNumber::HeapNumberBooleanValue() {
1724 // NaN, +0, and -0 should return the false object 1724 return DoubleToBoolean(value());
1725 #if __BYTE_ORDER == __LITTLE_ENDIAN
1726 union IeeeDoubleLittleEndianArchType u;
1727 #elif __BYTE_ORDER == __BIG_ENDIAN
1728 union IeeeDoubleBigEndianArchType u;
1729 #endif
1730 u.d = value();
1731 if (u.bits.exp == 2047) {
1732 // Detect NaN for IEEE double precision floating point.
1733 if ((u.bits.man_low | u.bits.man_high) != 0) return false;
1734 }
1735 if (u.bits.exp == 0) {
1736 // Detect +0, and -0 for IEEE double precision floating point.
1737 if ((u.bits.man_low | u.bits.man_high) == 0) return false;
1738 }
1739 return true;
1740 } 1725 }
1741 1726
1742 1727
1743 void HeapNumber::HeapNumberPrint(FILE* out) { 1728 void HeapNumber::HeapNumberPrint(FILE* out) {
1744 PrintF(out, "%.16g", Number()); 1729 PrintF(out, "%.16g", Number());
1745 } 1730 }
1746 1731
1747 1732
1748 void HeapNumber::HeapNumberPrint(StringStream* accumulator) { 1733 void HeapNumber::HeapNumberPrint(StringStream* accumulator) {
1749 // The Windows version of vsnprintf can allocate when printing a %g string 1734 // The Windows version of vsnprintf can allocate when printing a %g string
(...skipping 7716 matching lines...) Expand 10 before | Expand all | Expand 10 after
9466 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. 9451 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
9467 return result; 9452 return result;
9468 } 9453 }
9469 9454
9470 9455
9471 bool String::ComputeArrayIndex(uint32_t* index) { 9456 bool String::ComputeArrayIndex(uint32_t* index) {
9472 int length = this->length(); 9457 int length = this->length();
9473 if (length == 0 || length > kMaxArrayIndexSize) return false; 9458 if (length == 0 || length > kMaxArrayIndexSize) return false;
9474 ConsStringIteratorOp op; 9459 ConsStringIteratorOp op;
9475 StringCharacterStream stream(this, &op); 9460 StringCharacterStream stream(this, &op);
9476 uint16_t ch = stream.GetNext(); 9461 return StringToArrayIndex(&stream, index);
9477
9478 // If the string begins with a '0' character, it must only consist
9479 // of it to be a legal array index.
9480 if (ch == '0') {
9481 *index = 0;
9482 return length == 1;
9483 }
9484
9485 // Convert string to uint32 array index; character by character.
9486 int d = ch - '0';
9487 if (d < 0 || d > 9) return false;
9488 uint32_t result = d;
9489 while (stream.HasMore()) {
9490 d = stream.GetNext() - '0';
9491 if (d < 0 || d > 9) return false;
9492 // Check that the new result is below the 32 bit limit.
9493 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false;
9494 result = (result * 10) + d;
9495 }
9496
9497 *index = result;
9498 return true;
9499 } 9462 }
9500 9463
9501 9464
9502 bool String::SlowAsArrayIndex(uint32_t* index) { 9465 bool String::SlowAsArrayIndex(uint32_t* index) {
9503 if (length() <= kMaxCachedArrayIndexLength) { 9466 if (length() <= kMaxCachedArrayIndexLength) {
9504 Hash(); // force computation of hash code 9467 Hash(); // force computation of hash code
9505 uint32_t field = hash_field(); 9468 uint32_t field = hash_field();
9506 if ((field & kIsNotArrayIndexMask) != 0) return false; 9469 if ((field & kIsNotArrayIndexMask) != 0) return false;
9507 // Isolate the array index form the full hash field. 9470 // Isolate the array index form the full hash field.
9508 *index = ArrayIndexValueBits::decode(field); 9471 *index = ArrayIndexValueBits::decode(field);
(...skipping 7599 matching lines...) Expand 10 before | Expand all | Expand 10 after
17108 #define ERROR_MESSAGES_TEXTS(C, T) T, 17071 #define ERROR_MESSAGES_TEXTS(C, T) T,
17109 static const char* error_messages_[] = { 17072 static const char* error_messages_[] = {
17110 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17073 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17111 }; 17074 };
17112 #undef ERROR_MESSAGES_TEXTS 17075 #undef ERROR_MESSAGES_TEXTS
17113 return error_messages_[reason]; 17076 return error_messages_[reason];
17114 } 17077 }
17115 17078
17116 17079
17117 } } // namespace v8::internal 17080 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698