| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 uint32_t index; | 142 uint32_t index; |
| 143 return !string_->AsArrayIndex(&index); | 143 return !string_->AsArrayIndex(&index); |
| 144 } | 144 } |
| 145 return false; | 145 return false; |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 bool AstValue::BooleanValue() const { | 149 bool AstValue::BooleanValue() const { |
| 150 switch (type_) { | 150 switch (type_) { |
| 151 case STRING: | 151 case STRING: |
| 152 ASSERT(string_ != NULL); | 152 DCHECK(string_ != NULL); |
| 153 return !string_->IsEmpty(); | 153 return !string_->IsEmpty(); |
| 154 case SYMBOL: | 154 case SYMBOL: |
| 155 UNREACHABLE(); | 155 UNREACHABLE(); |
| 156 break; | 156 break; |
| 157 case NUMBER: | 157 case NUMBER: |
| 158 return DoubleToBoolean(number_); | 158 return DoubleToBoolean(number_); |
| 159 case SMI: | 159 case SMI: |
| 160 return smi_ != 0; | 160 return smi_ != 0; |
| 161 case STRING_ARRAY: | 161 case STRING_ARRAY: |
| 162 UNREACHABLE(); | 162 UNREACHABLE(); |
| 163 break; | 163 break; |
| 164 case BOOLEAN: | 164 case BOOLEAN: |
| 165 return bool_; | 165 return bool_; |
| 166 case NULL_TYPE: | 166 case NULL_TYPE: |
| 167 return false; | 167 return false; |
| 168 case THE_HOLE: | 168 case THE_HOLE: |
| 169 UNREACHABLE(); | 169 UNREACHABLE(); |
| 170 break; | 170 break; |
| 171 case UNDEFINED: | 171 case UNDEFINED: |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 UNREACHABLE(); | 174 UNREACHABLE(); |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 void AstValue::Internalize(Isolate* isolate) { | 179 void AstValue::Internalize(Isolate* isolate) { |
| 180 switch (type_) { | 180 switch (type_) { |
| 181 case STRING: | 181 case STRING: |
| 182 ASSERT(string_ != NULL); | 182 DCHECK(string_ != NULL); |
| 183 // Strings are already internalized. | 183 // Strings are already internalized. |
| 184 ASSERT(!string_->string().is_null()); | 184 DCHECK(!string_->string().is_null()); |
| 185 break; | 185 break; |
| 186 case SYMBOL: | 186 case SYMBOL: |
| 187 value_ = Object::GetProperty( | 187 value_ = Object::GetProperty( |
| 188 isolate, handle(isolate->native_context()->builtins()), | 188 isolate, handle(isolate->native_context()->builtins()), |
| 189 symbol_name_).ToHandleChecked(); | 189 symbol_name_).ToHandleChecked(); |
| 190 break; | 190 break; |
| 191 case NUMBER: | 191 case NUMBER: |
| 192 value_ = isolate->factory()->NewNumber(number_, TENURED); | 192 value_ = isolate->factory()->NewNumber(number_, TENURED); |
| 193 break; | 193 break; |
| 194 case SMI: | 194 case SMI: |
| 195 value_ = handle(Smi::FromInt(smi_), isolate); | 195 value_ = handle(Smi::FromInt(smi_), isolate); |
| 196 break; | 196 break; |
| 197 case BOOLEAN: | 197 case BOOLEAN: |
| 198 if (bool_) { | 198 if (bool_) { |
| 199 value_ = isolate->factory()->true_value(); | 199 value_ = isolate->factory()->true_value(); |
| 200 } else { | 200 } else { |
| 201 value_ = isolate->factory()->false_value(); | 201 value_ = isolate->factory()->false_value(); |
| 202 } | 202 } |
| 203 break; | 203 break; |
| 204 case STRING_ARRAY: { | 204 case STRING_ARRAY: { |
| 205 ASSERT(strings_ != NULL); | 205 DCHECK(strings_ != NULL); |
| 206 Factory* factory = isolate->factory(); | 206 Factory* factory = isolate->factory(); |
| 207 int len = strings_->length(); | 207 int len = strings_->length(); |
| 208 Handle<FixedArray> elements = factory->NewFixedArray(len, TENURED); | 208 Handle<FixedArray> elements = factory->NewFixedArray(len, TENURED); |
| 209 for (int i = 0; i < len; i++) { | 209 for (int i = 0; i < len; i++) { |
| 210 const AstRawString* string = (*strings_)[i]; | 210 const AstRawString* string = (*strings_)[i]; |
| 211 Handle<Object> element = string->string(); | 211 Handle<Object> element = string->string(); |
| 212 // Strings are already internalized. | 212 // Strings are already internalized. |
| 213 ASSERT(!element.is_null()); | 213 DCHECK(!element.is_null()); |
| 214 elements->set(i, *element); | 214 elements->set(i, *element); |
| 215 } | 215 } |
| 216 value_ = | 216 value_ = |
| 217 factory->NewJSArrayWithElements(elements, FAST_ELEMENTS, TENURED); | 217 factory->NewJSArrayWithElements(elements, FAST_ELEMENTS, TENURED); |
| 218 break; | 218 break; |
| 219 } | 219 } |
| 220 case NULL_TYPE: | 220 case NULL_TYPE: |
| 221 value_ = isolate->factory()->null_value(); | 221 value_ = isolate->factory()->null_value(); |
| 222 break; | 222 break; |
| 223 case THE_HOLE: | 223 case THE_HOLE: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 245 return GetString(hash, false, Vector<const byte>::cast(literal)); | 245 return GetString(hash, false, Vector<const byte>::cast(literal)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 | 248 |
| 249 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { | 249 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { |
| 250 DisallowHeapAllocation no_gc; | 250 DisallowHeapAllocation no_gc; |
| 251 String::FlatContent content = literal->GetFlatContent(); | 251 String::FlatContent content = literal->GetFlatContent(); |
| 252 if (content.IsAscii()) { | 252 if (content.IsAscii()) { |
| 253 return GetOneByteString(content.ToOneByteVector()); | 253 return GetOneByteString(content.ToOneByteVector()); |
| 254 } | 254 } |
| 255 ASSERT(content.IsTwoByte()); | 255 DCHECK(content.IsTwoByte()); |
| 256 return GetTwoByteString(content.ToUC16Vector()); | 256 return GetTwoByteString(content.ToUC16Vector()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 | 259 |
| 260 const AstConsString* AstValueFactory::NewConsString( | 260 const AstConsString* AstValueFactory::NewConsString( |
| 261 const AstString* left, const AstString* right) { | 261 const AstString* left, const AstString* right) { |
| 262 // This Vector will be valid as long as the Collector is alive (meaning that | 262 // This Vector will be valid as long as the Collector is alive (meaning that |
| 263 // the AstRawString will not be moved). | 263 // the AstRawString will not be moved). |
| 264 AstConsString* new_string = new (zone_) AstConsString(left, right); | 264 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 265 strings_.Add(new_string); | 265 strings_.Add(new_string); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 282 } | 282 } |
| 283 for (int i = 0; i < values_.length(); ++i) { | 283 for (int i = 0; i < values_.length(); ++i) { |
| 284 values_[i]->Internalize(isolate); | 284 values_[i]->Internalize(isolate); |
| 285 } | 285 } |
| 286 isolate_ = isolate; | 286 isolate_ = isolate; |
| 287 } | 287 } |
| 288 | 288 |
| 289 | 289 |
| 290 const AstValue* AstValueFactory::NewString(const AstRawString* string) { | 290 const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
| 291 AstValue* value = new (zone_) AstValue(string); | 291 AstValue* value = new (zone_) AstValue(string); |
| 292 ASSERT(string != NULL); | 292 DCHECK(string != NULL); |
| 293 if (isolate_) { | 293 if (isolate_) { |
| 294 value->Internalize(isolate_); | 294 value->Internalize(isolate_); |
| 295 } | 295 } |
| 296 values_.Add(value); | 296 values_.Add(value); |
| 297 return value; | 297 return value; |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 const AstValue* AstValueFactory::NewSymbol(const char* name) { | 301 const AstValue* AstValueFactory::NewSymbol(const char* name) { |
| 302 AstValue* value = new (zone_) AstValue(name); | 302 AstValue* value = new (zone_) AstValue(name); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (isolate_) { | 400 if (isolate_) { |
| 401 new_string->Internalize(isolate_); | 401 new_string->Internalize(isolate_); |
| 402 } | 402 } |
| 403 entry->value = reinterpret_cast<void*>(1); | 403 entry->value = reinterpret_cast<void*>(1); |
| 404 } | 404 } |
| 405 return reinterpret_cast<AstRawString*>(entry->key); | 405 return reinterpret_cast<AstRawString*>(entry->key); |
| 406 } | 406 } |
| 407 | 407 |
| 408 | 408 |
| 409 } } // namespace v8::internal | 409 } } // namespace v8::internal |
| OLD | NEW |