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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 379 |
380 // Allocate a fixed array to hold all the object literals. | 380 // Allocate a fixed array to hold all the object literals. |
381 Handle<JSArray> array = | 381 Handle<JSArray> array = |
382 isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); | 382 isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); |
383 JSArray::Expand(array, values()->length()); | 383 JSArray::Expand(array, values()->length()); |
384 | 384 |
385 // Fill in the literals. | 385 // Fill in the literals. |
386 bool is_simple = true; | 386 bool is_simple = true; |
387 int depth_acc = 1; | 387 int depth_acc = 1; |
388 bool is_holey = false; | 388 bool is_holey = false; |
389 for (int i = 0, n = values()->length(); i < n; i++) { | 389 int array_index = 0; |
390 Expression* element = values()->at(i); | 390 for (int n = values()->length(); array_index < n; array_index++) { |
| 391 Expression* element = values()->at(array_index); |
| 392 if (element->IsSpread()) break; |
391 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); | 393 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); |
392 if (m_literal != NULL) { | 394 if (m_literal != NULL) { |
393 m_literal->BuildConstants(isolate); | 395 m_literal->BuildConstants(isolate); |
394 if (m_literal->depth() + 1 > depth_acc) { | 396 if (m_literal->depth() + 1 > depth_acc) { |
395 depth_acc = m_literal->depth() + 1; | 397 depth_acc = m_literal->depth() + 1; |
396 } | 398 } |
397 } | 399 } |
398 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); | 400 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); |
399 if (boilerplate_value->IsTheHole()) { | 401 if (boilerplate_value->IsTheHole()) { |
400 is_holey = true; | 402 is_holey = true; |
401 } else if (boilerplate_value->IsUninitialized()) { | 403 } else if (boilerplate_value->IsUninitialized()) { |
402 is_simple = false; | 404 is_simple = false; |
403 JSObject::SetOwnElement( | 405 JSObject::SetOwnElement(array, array_index, |
404 array, i, handle(Smi::FromInt(0), isolate), SLOPPY).Assert(); | 406 handle(Smi::FromInt(0), isolate), |
| 407 SLOPPY).Assert(); |
405 } else { | 408 } else { |
406 JSObject::SetOwnElement(array, i, boilerplate_value, SLOPPY).Assert(); | 409 JSObject::SetOwnElement(array, array_index, boilerplate_value, SLOPPY) |
| 410 .Assert(); |
407 } | 411 } |
408 } | 412 } |
409 | 413 |
| 414 if (array_index != values()->length()) { |
| 415 JSArray::SetElementsLength( |
| 416 array, handle(Smi::FromInt(array_index), isolate)).Assert(); |
| 417 } |
410 Handle<FixedArrayBase> element_values(array->elements()); | 418 Handle<FixedArrayBase> element_values(array->elements()); |
411 | 419 |
412 // Simple and shallow arrays can be lazily copied, we transform the | 420 // Simple and shallow arrays can be lazily copied, we transform the |
413 // elements array to a copy-on-write array. | 421 // elements array to a copy-on-write array. |
414 if (is_simple && depth_acc == 1 && values()->length() > 0 && | 422 if (is_simple && depth_acc == 1 && array_index > 0 && |
415 array->HasFastSmiOrObjectElements()) { | 423 array->HasFastSmiOrObjectElements()) { |
416 element_values->set_map(isolate->heap()->fixed_cow_array_map()); | 424 element_values->set_map(isolate->heap()->fixed_cow_array_map()); |
417 } | 425 } |
418 | 426 |
419 // Remember both the literal's constant values as well as the ElementsKind | 427 // Remember both the literal's constant values as well as the ElementsKind |
420 // in a 2-element FixedArray. | 428 // in a 2-element FixedArray. |
421 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); | 429 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); |
422 | 430 |
423 ElementsKind kind = array->GetElementsKind(); | 431 ElementsKind kind = array->GetElementsKind(); |
424 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind); | 432 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 // static | 1011 // static |
1004 bool Literal::Match(void* literal1, void* literal2) { | 1012 bool Literal::Match(void* literal1, void* literal2) { |
1005 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1013 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
1006 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1014 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
1007 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || | 1015 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || |
1008 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1016 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
1009 } | 1017 } |
1010 | 1018 |
1011 | 1019 |
1012 } } // namespace v8::internal | 1020 } } // namespace v8::internal |
OLD | NEW |