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

Side by Side Diff: src/ast/ast.cc

Issue 2043183003: Replace all remaining Oddball checks with new function (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: simplifying checks Created 4 years, 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 8
9 #include "src/ast/prettyprinter.h" 9 #include "src/ast/prettyprinter.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return IsLiteral() && AsLiteral()->value()->IsSmi(); 52 return IsLiteral() && AsLiteral()->value()->IsSmi();
53 } 53 }
54 54
55 55
56 bool Expression::IsStringLiteral() const { 56 bool Expression::IsStringLiteral() const {
57 return IsLiteral() && AsLiteral()->value()->IsString(); 57 return IsLiteral() && AsLiteral()->value()->IsString();
58 } 58 }
59 59
60 60
61 bool Expression::IsNullLiteral() const { 61 bool Expression::IsNullLiteral() const {
62 return IsLiteral() && AsLiteral()->value()->IsNull(); 62 if (!IsLiteral()) return false;
63 Handle<Object> value = AsLiteral()->value();
64 return !value->IsSmi() &&
65 value->IsNull(HeapObject::cast(*value)->GetIsolate());
63 } 66 }
64 67
65 bool Expression::IsUndefinedLiteral() const { 68 bool Expression::IsUndefinedLiteral() const {
66 if (IsLiteral() && AsLiteral()->value()->IsUndefined()) { 69 if (!IsLiteral()) return false;
70 Handle<Object> value = AsLiteral()->value();
71 if (!value->IsSmi() &&
72 value->IsUndefined(HeapObject::cast(*value)->GetIsolate())) {
67 return true; 73 return true;
68 } 74 }
69 75
70 const VariableProxy* var_proxy = AsVariableProxy(); 76 const VariableProxy* var_proxy = AsVariableProxy();
71 if (var_proxy == NULL) return false; 77 if (var_proxy == NULL) return false;
72 Variable* var = var_proxy->var(); 78 Variable* var = var_proxy->var();
73 // The global identifier "undefined" is immutable. Everything 79 // The global identifier "undefined" is immutable. Everything
74 // else could be reassigned. 80 // else could be reassigned.
75 return var != NULL && var->IsUnallocatedOrGlobalSlot() && 81 return var != NULL && var->IsUnallocatedOrGlobalSlot() &&
76 var_proxy->raw_name()->IsOneByteEqualTo("undefined"); 82 var_proxy->raw_name()->IsOneByteEqualTo("undefined");
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 386
381 ZoneAllocationPolicy allocator(zone); 387 ZoneAllocationPolicy allocator(zone);
382 388
383 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, 389 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity,
384 allocator); 390 allocator);
385 for (int i = properties()->length() - 1; i >= 0; i--) { 391 for (int i = properties()->length() - 1; i >= 0; i--) {
386 ObjectLiteral::Property* property = properties()->at(i); 392 ObjectLiteral::Property* property = properties()->at(i);
387 if (property->is_computed_name()) continue; 393 if (property->is_computed_name()) continue;
388 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) continue; 394 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) continue;
389 Literal* literal = property->key()->AsLiteral(); 395 Literal* literal = property->key()->AsLiteral();
390 DCHECK(!literal->value()->IsNull()); 396 DCHECK(!literal->IsNullLiteral());
391 397
392 // If there is an existing entry do not emit a store unless the previous 398 // If there is an existing entry do not emit a store unless the previous
393 // entry was also an accessor. 399 // entry was also an accessor.
394 uint32_t hash = literal->Hash(); 400 uint32_t hash = literal->Hash();
395 ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator); 401 ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator);
396 if (entry->value != NULL) { 402 if (entry->value != NULL) {
397 auto previous_kind = 403 auto previous_kind =
398 static_cast<ObjectLiteral::Property*>(entry->value)->kind(); 404 static_cast<ObjectLiteral::Property*>(entry->value)->kind();
399 if (!((property->kind() == GETTER && previous_kind == SETTER) || 405 if (!((property->kind() == GETTER && previous_kind == SETTER) ||
400 (property->kind() == SETTER && previous_kind == GETTER))) { 406 (property->kind() == SETTER && previous_kind == GETTER))) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // runtime. The enumeration order is maintained. 456 // runtime. The enumeration order is maintained.
451 Handle<Object> key = property->key()->AsLiteral()->value(); 457 Handle<Object> key = property->key()->AsLiteral()->value();
452 Handle<Object> value = GetBoilerplateValue(property->value(), isolate); 458 Handle<Object> value = GetBoilerplateValue(property->value(), isolate);
453 459
454 // Ensure objects that may, at any point in time, contain fields with double 460 // Ensure objects that may, at any point in time, contain fields with double
455 // representation are always treated as nested objects. This is true for 461 // representation are always treated as nested objects. This is true for
456 // computed fields (value is undefined), and smi and double literals 462 // computed fields (value is undefined), and smi and double literals
457 // (value->IsNumber()). 463 // (value->IsNumber()).
458 // TODO(verwaest): Remove once we can store them inline. 464 // TODO(verwaest): Remove once we can store them inline.
459 if (FLAG_track_double_fields && 465 if (FLAG_track_double_fields &&
460 (value->IsNumber() || value->IsUninitialized())) { 466 (value->IsNumber() || value->IsUninitialized(isolate))) {
461 may_store_doubles_ = true; 467 may_store_doubles_ = true;
462 } 468 }
463 469
464 is_simple = is_simple && !value->IsUninitialized(); 470 is_simple = is_simple && !value->IsUninitialized(isolate);
465 471
466 // Keep track of the number of elements in the object literal and 472 // Keep track of the number of elements in the object literal and
467 // the largest element index. If the largest element index is 473 // the largest element index. If the largest element index is
468 // much larger than the number of elements, creating an object 474 // much larger than the number of elements, creating an object
469 // literal with fast elements will be a waste of space. 475 // literal with fast elements will be a waste of space.
470 uint32_t element_index = 0; 476 uint32_t element_index = 0;
471 if (key->IsString() && String::cast(*key)->AsArrayIndex(&element_index)) { 477 if (key->IsString() && String::cast(*key)->AsArrayIndex(&element_index)) {
472 max_element_index = Max(element_index, max_element_index); 478 max_element_index = Max(element_index, max_element_index);
473 elements++; 479 elements++;
474 key = isolate->factory()->NewNumberFromUint(element_index); 480 key = isolate->factory()->NewNumberFromUint(element_index);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 528 }
523 529
524 // New handle scope here, needs to be after BuildContants(). 530 // New handle scope here, needs to be after BuildContants().
525 HandleScope scope(isolate); 531 HandleScope scope(isolate);
526 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); 532 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate);
527 if (boilerplate_value->IsTheHole(isolate)) { 533 if (boilerplate_value->IsTheHole(isolate)) {
528 is_holey = true; 534 is_holey = true;
529 continue; 535 continue;
530 } 536 }
531 537
532 if (boilerplate_value->IsUninitialized()) { 538 if (boilerplate_value->IsUninitialized(isolate)) {
533 boilerplate_value = handle(Smi::FromInt(0), isolate); 539 boilerplate_value = handle(Smi::FromInt(0), isolate);
534 is_simple = false; 540 is_simple = false;
535 } 541 }
536 542
537 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) 543 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE)
538 .Assert(); 544 .Assert();
539 } 545 }
540 546
541 JSObject::ValidateElements(array); 547 JSObject::ValidateElements(array);
542 Handle<FixedArrayBase> element_values(array->elements()); 548 Handle<FixedArrayBase> element_values(array->elements());
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 bool Literal::Match(void* literal1, void* literal2) { 1140 bool Literal::Match(void* literal1, void* literal2) {
1135 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1141 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1136 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1142 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1137 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 1143 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
1138 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1144 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1139 } 1145 }
1140 1146
1141 1147
1142 } // namespace internal 1148 } // namespace internal
1143 } // namespace v8 1149 } // namespace v8
OLDNEW
« no previous file with comments | « src/api-natives.cc ('k') | src/ast/prettyprinter.cc » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698