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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (content.IsOneByte()) { | 234 if (content.IsOneByte()) { |
235 return GetOneByteString(content.ToOneByteVector()); | 235 return GetOneByteString(content.ToOneByteVector()); |
236 } | 236 } |
237 DCHECK(content.IsTwoByte()); | 237 DCHECK(content.IsTwoByte()); |
238 return GetTwoByteString(content.ToUC16Vector()); | 238 return GetTwoByteString(content.ToUC16Vector()); |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 const AstConsString* AstValueFactory::NewConsString( | 242 const AstConsString* AstValueFactory::NewConsString( |
243 const AstString* left, const AstString* right) { | 243 const AstString* left, const AstString* right) { |
| 244 // This Vector will be valid as long as the Collector is alive (meaning that |
| 245 // the AstRawString will not be moved). |
244 AstConsString* new_string = new (zone_) AstConsString(left, right); | 246 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 247 strings_.Add(new_string); |
245 if (isolate_) { | 248 if (isolate_) { |
246 new_string->Internalize(isolate_); | 249 new_string->Internalize(isolate_); |
247 } else { | |
248 strings_.Add(new_string); | |
249 } | 250 } |
250 return new_string; | 251 return new_string; |
251 } | 252 } |
252 | 253 |
253 | 254 |
254 void AstValueFactory::Internalize(Isolate* isolate) { | 255 void AstValueFactory::Internalize(Isolate* isolate) { |
255 if (isolate_) { | 256 if (isolate_) { |
256 // Everything is already internalized. | 257 // Everything is already internalized. |
257 return; | 258 return; |
258 } | 259 } |
259 // Strings need to be internalized before values, because values refer to | 260 // Strings need to be internalized before values, because values refer to |
260 // strings. | 261 // strings. |
261 for (int i = 0; i < strings_.length(); ++i) { | 262 for (int i = 0; i < strings_.length(); ++i) { |
262 strings_[i]->Internalize(isolate); | 263 strings_[i]->Internalize(isolate); |
263 } | 264 } |
264 for (int i = 0; i < values_.length(); ++i) { | 265 for (int i = 0; i < values_.length(); ++i) { |
265 values_[i]->Internalize(isolate); | 266 values_[i]->Internalize(isolate); |
266 } | 267 } |
267 isolate_ = isolate; | 268 isolate_ = isolate; |
268 } | 269 } |
269 | 270 |
270 | 271 |
271 const AstValue* AstValueFactory::NewString(const AstRawString* string) { | 272 const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
272 AstValue* value = new (zone_) AstValue(string); | 273 AstValue* value = new (zone_) AstValue(string); |
273 DCHECK(string != NULL); | 274 DCHECK(string != NULL); |
274 if (isolate_) { | 275 if (isolate_) { |
275 // If we're creating immediately-internalized AstValues, the underlying | 276 value->Internalize(isolate_); |
276 // strings must already be internalized at this point. | |
277 DCHECK(!string->string_.is_null()); | |
278 } | 277 } |
279 // These AstValues don't need to be added to values_, since the AstRawStrings | 278 values_.Add(value); |
280 // will be insternalized separately. | |
281 return value; | 279 return value; |
282 } | 280 } |
283 | 281 |
284 | 282 |
285 const AstValue* AstValueFactory::NewSymbol(const char* name) { | 283 const AstValue* AstValueFactory::NewSymbol(const char* name) { |
286 AstValue* value = new (zone_) AstValue(name); | 284 AstValue* value = new (zone_) AstValue(name); |
287 if (isolate_) { | 285 if (isolate_) { |
288 value->Internalize(isolate_); | 286 value->Internalize(isolate_); |
289 } else { | |
290 values_.Add(value); | |
291 } | 287 } |
| 288 values_.Add(value); |
292 return value; | 289 return value; |
293 } | 290 } |
294 | 291 |
295 | 292 |
296 const AstValue* AstValueFactory::NewNumber(double number) { | 293 const AstValue* AstValueFactory::NewNumber(double number) { |
297 AstValue* value = new (zone_) AstValue(number); | 294 AstValue* value = new (zone_) AstValue(number); |
298 if (isolate_) { | 295 if (isolate_) { |
299 value->Internalize(isolate_); | 296 value->Internalize(isolate_); |
300 } else { | |
301 values_.Add(value); | |
302 } | 297 } |
| 298 values_.Add(value); |
303 return value; | 299 return value; |
304 } | 300 } |
305 | 301 |
306 | 302 |
307 const AstValue* AstValueFactory::NewSmi(int number) { | 303 const AstValue* AstValueFactory::NewSmi(int number) { |
308 AstValue* value = | 304 AstValue* value = |
309 new (zone_) AstValue(AstValue::SMI, number); | 305 new (zone_) AstValue(AstValue::SMI, number); |
310 if (isolate_) { | 306 if (isolate_) { |
311 value->Internalize(isolate_); | 307 value->Internalize(isolate_); |
312 } else { | |
313 values_.Add(value); | |
314 } | 308 } |
| 309 values_.Add(value); |
315 return value; | 310 return value; |
316 } | 311 } |
317 | 312 |
318 | 313 |
319 #define GENERATE_VALUE_GETTER(value, initializer) \ | 314 #define GENERATE_VALUE_GETTER(value, initializer) \ |
320 if (!value) { \ | 315 if (!value) { \ |
321 value = new (zone_) AstValue(initializer); \ | 316 value = new (zone_) AstValue(initializer); \ |
322 if (isolate_) { \ | 317 if (isolate_) { \ |
323 value->Internalize(isolate_); \ | 318 value->Internalize(isolate_); \ |
324 } else { \ | |
325 values_.Add(value); \ | |
326 } \ | 319 } \ |
| 320 values_.Add(value); \ |
327 } \ | 321 } \ |
328 return value; | 322 return value; |
329 | 323 |
330 | 324 |
331 const AstValue* AstValueFactory::NewBoolean(bool b) { | 325 const AstValue* AstValueFactory::NewBoolean(bool b) { |
332 if (b) { | 326 if (b) { |
333 GENERATE_VALUE_GETTER(true_value_, true); | 327 GENERATE_VALUE_GETTER(true_value_, true); |
334 } else { | 328 } else { |
335 GENERATE_VALUE_GETTER(false_value_, false); | 329 GENERATE_VALUE_GETTER(false_value_, false); |
336 } | 330 } |
(...skipping 26 matching lines...) Expand all Loading... |
363 AstRawString key(is_one_byte, literal_bytes, hash); | 357 AstRawString key(is_one_byte, literal_bytes, hash); |
364 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 358 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); |
365 if (entry->value == NULL) { | 359 if (entry->value == NULL) { |
366 // Copy literal contents for later comparison. | 360 // Copy literal contents for later comparison. |
367 int length = literal_bytes.length(); | 361 int length = literal_bytes.length(); |
368 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 362 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
369 memcpy(new_literal_bytes, literal_bytes.start(), length); | 363 memcpy(new_literal_bytes, literal_bytes.start(), length); |
370 AstRawString* new_string = new (zone_) AstRawString( | 364 AstRawString* new_string = new (zone_) AstRawString( |
371 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
372 entry->key = new_string; | 366 entry->key = new_string; |
| 367 strings_.Add(new_string); |
373 if (isolate_) { | 368 if (isolate_) { |
374 new_string->Internalize(isolate_); | 369 new_string->Internalize(isolate_); |
375 } else { | |
376 strings_.Add(new_string); | |
377 } | 370 } |
378 entry->value = reinterpret_cast<void*>(1); | 371 entry->value = reinterpret_cast<void*>(1); |
379 } | 372 } |
380 return reinterpret_cast<AstRawString*>(entry->key); | 373 return reinterpret_cast<AstRawString*>(entry->key); |
381 } | 374 } |
382 | 375 |
383 | 376 |
384 } } // namespace v8::internal | 377 } } // namespace v8::internal |
OLD | NEW |