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

Side by Side Diff: src/ast/ast-value-factory.cc

Issue 2156513002: AstValueFactory: Add paranoid null checks for debugging. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (isolate_) result->Internalize(isolate_); 242 if (isolate_) result->Internalize(isolate_);
243 return result; 243 return result;
244 } 244 }
245 245
246 246
247 const AstConsString* AstValueFactory::NewConsString( 247 const AstConsString* AstValueFactory::NewConsString(
248 const AstString* left, const AstString* right) { 248 const AstString* left, const AstString* right) {
249 // This Vector will be valid as long as the Collector is alive (meaning that 249 // This Vector will be valid as long as the Collector is alive (meaning that
250 // the AstRawString will not be moved). 250 // the AstRawString will not be moved).
251 AstConsString* new_string = new (zone_) AstConsString(left, right); 251 AstConsString* new_string = new (zone_) AstConsString(left, right);
252 CHECK(new_string != nullptr);
252 strings_.Add(new_string); 253 strings_.Add(new_string);
253 if (isolate_) { 254 if (isolate_) {
254 new_string->Internalize(isolate_); 255 new_string->Internalize(isolate_);
255 } 256 }
256 return new_string; 257 return new_string;
257 } 258 }
258 259
259 260
260 void AstValueFactory::Internalize(Isolate* isolate) { 261 void AstValueFactory::Internalize(Isolate* isolate) {
261 if (isolate_) { 262 if (isolate_) {
262 // Everything is already internalized. 263 // Everything is already internalized.
263 return; 264 return;
264 } 265 }
265 // Strings need to be internalized before values, because values refer to 266 // Strings need to be internalized before values, because values refer to
266 // strings. 267 // strings.
267 for (int i = 0; i < strings_.length(); ++i) { 268 for (int i = 0; i < strings_.length(); ++i) {
268 strings_[i]->Internalize(isolate); 269 strings_[i]->Internalize(isolate);
269 } 270 }
270 for (int i = 0; i < values_.length(); ++i) { 271 for (int i = 0; i < values_.length(); ++i) {
271 values_[i]->Internalize(isolate); 272 values_[i]->Internalize(isolate);
272 } 273 }
273 isolate_ = isolate; 274 isolate_ = isolate;
274 } 275 }
275 276
276 277
277 const AstValue* AstValueFactory::NewString(const AstRawString* string) { 278 const AstValue* AstValueFactory::NewString(const AstRawString* string) {
278 AstValue* value = new (zone_) AstValue(string); 279 AstValue* value = new (zone_) AstValue(string);
279 DCHECK(string != NULL); 280 CHECK(string != nullptr);
280 if (isolate_) { 281 if (isolate_) {
281 value->Internalize(isolate_); 282 value->Internalize(isolate_);
282 } 283 }
283 values_.Add(value); 284 values_.Add(value);
284 return value; 285 return value;
285 } 286 }
286 287
287 288
288 const AstValue* AstValueFactory::NewSymbol(const char* name) { 289 const AstValue* AstValueFactory::NewSymbol(const char* name) {
289 AstValue* value = new (zone_) AstValue(name); 290 AstValue* value = new (zone_) AstValue(name);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // return this AstRawString. 362 // return this AstRawString.
362 AstRawString key(is_one_byte, literal_bytes, hash); 363 AstRawString key(is_one_byte, literal_bytes, hash);
363 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash); 364 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash);
364 if (entry->value == NULL) { 365 if (entry->value == NULL) {
365 // Copy literal contents for later comparison. 366 // Copy literal contents for later comparison.
366 int length = literal_bytes.length(); 367 int length = literal_bytes.length();
367 byte* new_literal_bytes = zone_->NewArray<byte>(length); 368 byte* new_literal_bytes = zone_->NewArray<byte>(length);
368 memcpy(new_literal_bytes, literal_bytes.start(), length); 369 memcpy(new_literal_bytes, literal_bytes.start(), length);
369 AstRawString* new_string = new (zone_) AstRawString( 370 AstRawString* new_string = new (zone_) AstRawString(
370 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); 371 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash);
372 CHECK(new_string != nullptr);
371 entry->key = new_string; 373 entry->key = new_string;
372 strings_.Add(new_string); 374 strings_.Add(new_string);
373 if (isolate_) { 375 if (isolate_) {
374 new_string->Internalize(isolate_); 376 new_string->Internalize(isolate_);
375 } 377 }
376 entry->value = reinterpret_cast<void*>(1); 378 entry->value = reinterpret_cast<void*>(1);
377 } 379 }
378 return reinterpret_cast<AstRawString*>(entry->key); 380 return reinterpret_cast<AstRawString*>(entry->key);
379 } 381 }
380 382
(...skipping 23 matching lines...) Expand all
404 length) == 0; 406 length) == 0;
405 } else { 407 } else {
406 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), 408 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
407 reinterpret_cast<const uint16_t*>(r), 409 reinterpret_cast<const uint16_t*>(r),
408 length) == 0; 410 length) == 0;
409 } 411 }
410 } 412 }
411 } 413 }
412 } // namespace internal 414 } // namespace internal
413 } // namespace v8 415 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698