OLD | NEW |
---|---|
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.h" | 5 #include "src/ast.h" |
6 | 6 |
7 #include <cmath> // For isfinite. | 7 #include <cmath> // For isfinite. |
8 #include "src/builtins.h" | 8 #include "src/builtins.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 (max_element_index <= 32) || ((2 * elements) >= max_element_index); | 498 (max_element_index <= 32) || ((2 * elements) >= max_element_index); |
499 has_elements_ = elements > 0; | 499 has_elements_ = elements > 0; |
500 set_is_simple(is_simple); | 500 set_is_simple(is_simple); |
501 set_depth(depth_acc); | 501 set_depth(depth_acc); |
502 } | 502 } |
503 | 503 |
504 | 504 |
505 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { | 505 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
506 if (!constant_elements_.is_null()) return; | 506 if (!constant_elements_.is_null()) return; |
507 | 507 |
508 // Find the first spread; everything before that is part of | |
509 // the constant elements. | |
510 // TODO(adamk): Store constant length in the AST. | |
511 int constants_length = values()->length(); | |
512 for (int i = 0; i < values()->length(); i++) { | |
513 if (values()->at(i)->IsSpread()) { | |
514 constants_length = i; | |
caitp (gmail)
2015/07/14 05:49:03
Looks like you just need a `break` here to make th
caitp (gmail)
2015/07/14 05:49:53
Otherwise if there are multiple spread elements, i
adamk
2015/07/14 16:04:55
Oops, indeed, I refactored this from a different a
| |
515 } | |
516 } | |
517 | |
508 // Allocate a fixed array to hold all the object literals. | 518 // Allocate a fixed array to hold all the object literals. |
509 Handle<JSArray> array = isolate->factory()->NewJSArray( | 519 Handle<JSArray> array = isolate->factory()->NewJSArray( |
510 FAST_HOLEY_SMI_ELEMENTS, values()->length(), values()->length(), | 520 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length, |
511 Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | 521 Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
512 | 522 |
513 // Fill in the literals. | 523 // Fill in the literals. |
514 bool is_simple = true; | 524 bool is_simple = true; |
515 int depth_acc = 1; | 525 int depth_acc = 1; |
516 bool is_holey = false; | 526 bool is_holey = false; |
517 int array_index = 0; | 527 int array_index = 0; |
518 for (int n = values()->length(); array_index < n; array_index++) { | 528 for (; array_index < constants_length; array_index++) { |
519 Expression* element = values()->at(array_index); | 529 Expression* element = values()->at(array_index); |
520 if (element->IsSpread()) break; | 530 DCHECK(!element->IsSpread()); |
521 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); | 531 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); |
522 if (m_literal != NULL) { | 532 if (m_literal != NULL) { |
523 m_literal->BuildConstants(isolate); | 533 m_literal->BuildConstants(isolate); |
524 if (m_literal->depth() + 1 > depth_acc) { | 534 if (m_literal->depth() + 1 > depth_acc) { |
525 depth_acc = m_literal->depth() + 1; | 535 depth_acc = m_literal->depth() + 1; |
526 } | 536 } |
527 } | 537 } |
528 | 538 |
529 // New handle scope here, needs to be after BuildContants(). | 539 // New handle scope here, needs to be after BuildContants(). |
530 HandleScope scope(isolate); | 540 HandleScope scope(isolate); |
531 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); | 541 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); |
532 if (boilerplate_value->IsTheHole()) { | 542 if (boilerplate_value->IsTheHole()) { |
533 is_holey = true; | 543 is_holey = true; |
534 continue; | 544 continue; |
535 } | 545 } |
536 | 546 |
537 if (boilerplate_value->IsUninitialized()) { | 547 if (boilerplate_value->IsUninitialized()) { |
538 boilerplate_value = handle(Smi::FromInt(0), isolate); | 548 boilerplate_value = handle(Smi::FromInt(0), isolate); |
539 is_simple = false; | 549 is_simple = false; |
540 } | 550 } |
541 | 551 |
542 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) | 552 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) |
543 .Assert(); | 553 .Assert(); |
544 } | 554 } |
545 | 555 |
546 if (array_index != values()->length()) { | |
547 JSArray::SetLength(array, array_index); | |
548 } | |
549 JSObject::ValidateElements(array); | 556 JSObject::ValidateElements(array); |
550 Handle<FixedArrayBase> element_values(array->elements()); | 557 Handle<FixedArrayBase> element_values(array->elements()); |
551 | 558 |
552 // Simple and shallow arrays can be lazily copied, we transform the | 559 // Simple and shallow arrays can be lazily copied, we transform the |
553 // elements array to a copy-on-write array. | 560 // elements array to a copy-on-write array. |
554 if (is_simple && depth_acc == 1 && array_index > 0 && | 561 if (is_simple && depth_acc == 1 && array_index > 0 && |
555 array->HasFastSmiOrObjectElements()) { | 562 array->HasFastSmiOrObjectElements()) { |
556 element_values->set_map(isolate->heap()->fixed_cow_array_map()); | 563 element_values->set_map(isolate->heap()->fixed_cow_array_map()); |
557 } | 564 } |
558 | 565 |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 bool Literal::Match(void* literal1, void* literal2) { | 1152 bool Literal::Match(void* literal1, void* literal2) { |
1146 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1153 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
1147 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1154 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
1148 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1155 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
1149 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1156 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
1150 } | 1157 } |
1151 | 1158 |
1152 | 1159 |
1153 } // namespace internal | 1160 } // namespace internal |
1154 } // namespace v8 | 1161 } // namespace v8 |
OLD | NEW |