| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "src/utils.h" | 32 #include "src/utils.h" |
| 33 | 33 |
| 34 namespace v8 { | 34 namespace v8 { |
| 35 namespace internal { | 35 namespace internal { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // For using StringToArrayIndex. | 39 // For using StringToArrayIndex. |
| 40 class OneByteStringStream { | 40 class OneByteStringStream { |
| 41 public: | 41 public: |
| 42 explicit OneByteStringStream(Vector<const byte> lb) : | 42 explicit OneByteStringStream(Vector<const byte> lb) |
| 43 literal_bytes_(lb), pos_(0) {} | 43 : literal_bytes_(lb), pos_(0) {} |
| 44 | 44 |
| 45 bool HasMore() { return pos_ < literal_bytes_.length(); } | 45 bool HasMore() { return pos_ < literal_bytes_.length(); } |
| 46 uint16_t GetNext() { return literal_bytes_[pos_++]; } | 46 uint16_t GetNext() { return literal_bytes_[pos_++]; } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 Vector<const byte> literal_bytes_; | 49 Vector<const byte> literal_bytes_; |
| 50 int pos_; | 50 int pos_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (literal_bytes_.length() == 0) { | 88 if (literal_bytes_.length() == 0) { |
| 89 string_ = isolate->factory()->empty_string(); | 89 string_ = isolate->factory()->empty_string(); |
| 90 } else { | 90 } else { |
| 91 AstRawStringInternalizationKey key(this); | 91 AstRawStringInternalizationKey key(this); |
| 92 string_ = StringTable::LookupKey(isolate, &key); | 92 string_ = StringTable::LookupKey(isolate, &key); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 bool AstRawString::AsArrayIndex(uint32_t* index) const { | 97 bool AstRawString::AsArrayIndex(uint32_t* index) const { |
| 98 if (!string_.is_null()) | 98 if (!string_.is_null()) return string_->AsArrayIndex(index); |
| 99 return string_->AsArrayIndex(index); | |
| 100 if (!is_one_byte_ || literal_bytes_.length() == 0 || | 99 if (!is_one_byte_ || literal_bytes_.length() == 0 || |
| 101 literal_bytes_.length() > String::kMaxArrayIndexSize) | 100 literal_bytes_.length() > String::kMaxArrayIndexSize) |
| 102 return false; | 101 return false; |
| 103 OneByteStringStream stream(literal_bytes_); | 102 OneByteStringStream stream(literal_bytes_); |
| 104 return StringToArrayIndex(&stream, index); | 103 return StringToArrayIndex(&stream, index); |
| 105 } | 104 } |
| 106 | 105 |
| 107 | 106 |
| 108 bool AstRawString::IsOneByteEqualTo(const char* data) const { | 107 bool AstRawString::IsOneByteEqualTo(const char* data) const { |
| 109 int length = static_cast<int>(strlen(data)); | 108 int length = static_cast<int>(strlen(data)); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 DCHECK(content.IsTwoByte()); | 234 DCHECK(content.IsTwoByte()); |
| 236 result = GetTwoByteStringInternal(content.ToUC16Vector()); | 235 result = GetTwoByteStringInternal(content.ToUC16Vector()); |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 isolate_ = saved_isolate; | 238 isolate_ = saved_isolate; |
| 240 if (isolate_) result->Internalize(isolate_); | 239 if (isolate_) result->Internalize(isolate_); |
| 241 return result; | 240 return result; |
| 242 } | 241 } |
| 243 | 242 |
| 244 | 243 |
| 245 const AstConsString* AstValueFactory::NewConsString( | 244 const AstConsString* AstValueFactory::NewConsString(const AstString* left, |
| 246 const AstString* left, const AstString* right) { | 245 const AstString* right) { |
| 247 // This Vector will be valid as long as the Collector is alive (meaning that | 246 // This Vector will be valid as long as the Collector is alive (meaning that |
| 248 // the AstRawString will not be moved). | 247 // the AstRawString will not be moved). |
| 249 AstConsString* new_string = new (zone_) AstConsString(left, right); | 248 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 250 strings_.Add(new_string); | 249 strings_.Add(new_string); |
| 251 if (isolate_) { | 250 if (isolate_) { |
| 252 new_string->Internalize(isolate_); | 251 new_string->Internalize(isolate_); |
| 253 } | 252 } |
| 254 return new_string; | 253 return new_string; |
| 255 } | 254 } |
| 256 | 255 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 AstValue* value = new (zone_) AstValue(number, with_dot); | 296 AstValue* value = new (zone_) AstValue(number, with_dot); |
| 298 if (isolate_) { | 297 if (isolate_) { |
| 299 value->Internalize(isolate_); | 298 value->Internalize(isolate_); |
| 300 } | 299 } |
| 301 values_.Add(value); | 300 values_.Add(value); |
| 302 return value; | 301 return value; |
| 303 } | 302 } |
| 304 | 303 |
| 305 | 304 |
| 306 const AstValue* AstValueFactory::NewSmi(int number) { | 305 const AstValue* AstValueFactory::NewSmi(int number) { |
| 307 AstValue* value = | 306 AstValue* value = new (zone_) AstValue(AstValue::SMI, number); |
| 308 new (zone_) AstValue(AstValue::SMI, number); | |
| 309 if (isolate_) { | 307 if (isolate_) { |
| 310 value->Internalize(isolate_); | 308 value->Internalize(isolate_); |
| 311 } | 309 } |
| 312 values_.Add(value); | 310 values_.Add(value); |
| 313 return value; | 311 return value; |
| 314 } | 312 } |
| 315 | 313 |
| 316 | 314 |
| 317 #define GENERATE_VALUE_GETTER(value, initializer) \ | 315 #define GENERATE_VALUE_GETTER(value, initializer) \ |
| 318 if (!value) { \ | 316 if (!value) { \ |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 length) == 0; | 400 length) == 0; |
| 403 } else { | 401 } else { |
| 404 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), | 402 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
| 405 reinterpret_cast<const uint16_t*>(r), | 403 reinterpret_cast<const uint16_t*>(r), |
| 406 length) == 0; | 404 length) == 0; |
| 407 } | 405 } |
| 408 } | 406 } |
| 409 } | 407 } |
| 410 } // namespace internal | 408 } // namespace internal |
| 411 } // namespace v8 | 409 } // namespace v8 |
| OLD | NEW |