| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void AstRawString::Internalize(Isolate* isolate) { | 99 void AstRawString::Internalize(Isolate* isolate) { |
| 100 if (!string_.is_null()) return; | 100 if (!string_.is_null()) return; |
| 101 if (literal_bytes_.length() == 0) { | 101 if (literal_bytes_.length() == 0) { |
| 102 string_ = isolate->factory()->empty_string(); | 102 string_ = isolate->factory()->empty_string(); |
| 103 } else { | 103 } else { |
| 104 AstRawStringInternalizationKey key(this); | 104 AstRawStringInternalizationKey key(this); |
| 105 string_ = StringTable::LookupKey(isolate, &key); | 105 string_ = StringTable::LookupKey(isolate, &key); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 bool AstRawString::AsArrayIndex(uint32_t* index, |
| 110 bool AstRawString::AsArrayIndex(uint32_t* index) const { | 110 HandleDereferenceMode deref_mode) const { |
| 111 if (!string_.is_null()) | 111 if (deref_mode == HandleDereferenceMode::kAllowed && !string_.is_null()) |
| 112 return string_->AsArrayIndex(index); | 112 return string_->AsArrayIndex(index); |
| 113 if (!is_one_byte() || literal_bytes_.length() == 0 || | 113 if (!is_one_byte() || literal_bytes_.length() == 0 || |
| 114 literal_bytes_.length() > String::kMaxArrayIndexSize) | 114 literal_bytes_.length() > String::kMaxArrayIndexSize) |
| 115 return false; | 115 return false; |
| 116 OneByteStringStream stream(literal_bytes_); | 116 OneByteStringStream stream(literal_bytes_); |
| 117 return StringToArrayIndex(&stream, index); | 117 return StringToArrayIndex(&stream, index); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 bool AstRawString::IsOneByteEqualTo(const char* data) const { | 121 bool AstRawString::IsOneByteEqualTo(const char* data) const { |
| 122 int length = static_cast<int>(strlen(data)); | 122 int length = static_cast<int>(strlen(data)); |
| 123 if (is_one_byte() && literal_bytes_.length() == length) { | 123 if (is_one_byte() && literal_bytes_.length() == length) { |
| 124 const char* token = reinterpret_cast<const char*>(literal_bytes_.start()); | 124 const char* token = reinterpret_cast<const char*>(literal_bytes_.start()); |
| 125 return !strncmp(token, data, length); | 125 return !strncmp(token, data, length); |
| 126 } | 126 } |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 void AstConsString::Internalize(Isolate* isolate) { | 131 void AstConsString::Internalize(Isolate* isolate) { |
| 132 // AstRawStrings are internalized before AstConsStrings so left and right are | 132 // AstRawStrings are internalized before AstConsStrings so left and right are |
| 133 // already internalized. | 133 // already internalized. |
| 134 string_ = isolate->factory() | 134 string_ = isolate->factory() |
| 135 ->NewConsString(left_->string(), right_->string()) | 135 ->NewConsString(left_->string(), right_->string()) |
| 136 .ToHandleChecked(); | 136 .ToHandleChecked(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 bool AstValue::IsPropertyName(HandleDereferenceMode deref_mode) const { |
| 140 bool AstValue::IsPropertyName() const { | |
| 141 if (type_ == STRING) { | 140 if (type_ == STRING) { |
| 142 uint32_t index; | 141 uint32_t index; |
| 143 return !string_->AsArrayIndex(&index); | 142 return !string_->AsArrayIndex(&index, deref_mode); |
| 144 } | 143 } |
| 145 return false; | 144 return false; |
| 146 } | 145 } |
| 147 | 146 |
| 148 | 147 |
| 149 bool AstValue::BooleanValue() const { | 148 bool AstValue::BooleanValue() const { |
| 150 switch (type_) { | 149 switch (type_) { |
| 151 case STRING: | 150 case STRING: |
| 152 DCHECK(string_ != NULL); | 151 DCHECK(string_ != NULL); |
| 153 return !string_->IsEmpty(); | 152 return !string_->IsEmpty(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 268 } |
| 270 return new_string; | 269 return new_string; |
| 271 } | 270 } |
| 272 | 271 |
| 273 | 272 |
| 274 void AstValueFactory::Internalize(Isolate* isolate) { | 273 void AstValueFactory::Internalize(Isolate* isolate) { |
| 275 if (isolate_) { | 274 if (isolate_) { |
| 276 // Everything is already internalized. | 275 // Everything is already internalized. |
| 277 return; | 276 return; |
| 278 } | 277 } |
| 278 |
| 279 // Strings need to be internalized before values, because values refer to | 279 // Strings need to be internalized before values, because values refer to |
| 280 // strings. | 280 // strings. |
| 281 for (int i = 0; i < strings_.length(); ++i) { | 281 for (int i = 0; i < strings_.length(); ++i) { |
| 282 strings_[i]->Internalize(isolate); | 282 strings_[i]->Internalize(isolate); |
| 283 } | 283 } |
| 284 for (int i = 0; i < values_.length(); ++i) { | 284 for (int i = 0; i < values_.length(); ++i) { |
| 285 values_[i]->Internalize(isolate); | 285 values_[i]->Internalize(isolate); |
| 286 } | 286 } |
| 287 isolate_ = isolate; | 287 isolate_ = isolate; |
| 288 } | 288 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 length) == 0; | 419 length) == 0; |
| 420 } else { | 420 } else { |
| 421 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), | 421 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
| 422 reinterpret_cast<const uint16_t*>(r), | 422 reinterpret_cast<const uint16_t*>(r), |
| 423 length) == 0; | 423 length) == 0; |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 } // namespace internal | 427 } // namespace internal |
| 428 } // namespace v8 | 428 } // namespace v8 |
| OLD | NEW |