OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 HInstruction* elements = Add<HArgumentsElements>(false); | 735 HInstruction* elements = Add<HArgumentsElements>(false); |
736 HInstruction* argument = Add<HAccessArgumentsAt>( | 736 HInstruction* argument = Add<HAccessArgumentsAt>( |
737 elements, constant_one, constant_zero); | 737 elements, constant_one, constant_zero); |
738 | 738 |
739 return BuildAllocateArrayFromLength(array_builder, argument); | 739 return BuildAllocateArrayFromLength(array_builder, argument); |
740 } | 740 } |
741 | 741 |
742 | 742 |
743 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( | 743 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( |
744 JSArrayBuilder* array_builder, ElementsKind kind) { | 744 JSArrayBuilder* array_builder, ElementsKind kind) { |
| 745 // Insert a bounds check because the number of arguments might exceed |
| 746 // the kInitialMaxFastElementArray limit. This cannot happen for code |
| 747 // that was parsed, but calling via Array.apply(thisArg, [...]) might |
| 748 // trigger it. |
| 749 HValue* length = GetArgumentsLength(); |
| 750 HConstant* max_alloc_length = |
| 751 Add<HConstant>(JSObject::kInitialMaxFastElementArray); |
| 752 HValue* checked_length = Add<HBoundsCheck>(length, max_alloc_length); |
| 753 |
745 // We need to fill with the hole if it's a smi array in the multi-argument | 754 // We need to fill with the hole if it's a smi array in the multi-argument |
746 // case because we might have to bail out while copying arguments into | 755 // case because we might have to bail out while copying arguments into |
747 // the array because they aren't compatible with a smi array. | 756 // the array because they aren't compatible with a smi array. |
748 // If it's a double array, no problem, and if it's fast then no | 757 // If it's a double array, no problem, and if it's fast then no |
749 // problem either because doubles are boxed. | 758 // problem either because doubles are boxed. |
750 // | 759 // |
751 // TODO(mvstanton): consider an instruction to memset fill the array | 760 // TODO(mvstanton): consider an instruction to memset fill the array |
752 // with zero in this case instead. | 761 // with zero in this case instead. |
753 HValue* length = GetArgumentsLength(); | |
754 JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind) | 762 JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind) |
755 ? JSArrayBuilder::FILL_WITH_HOLE | 763 ? JSArrayBuilder::FILL_WITH_HOLE |
756 : JSArrayBuilder::DONT_FILL_WITH_HOLE; | 764 : JSArrayBuilder::DONT_FILL_WITH_HOLE; |
757 HValue* new_object = array_builder->AllocateArray(length, | 765 HValue* new_object = array_builder->AllocateArray(checked_length, |
758 length, | 766 checked_length, |
759 fill_mode); | 767 fill_mode); |
760 HValue* elements = array_builder->GetElementsLocation(); | 768 HValue* elements = array_builder->GetElementsLocation(); |
761 ASSERT(elements != NULL); | 769 ASSERT(elements != NULL); |
762 | 770 |
763 // Now populate the elements correctly. | 771 // Now populate the elements correctly. |
764 LoopBuilder builder(this, | 772 LoopBuilder builder(this, |
765 context(), | 773 context(), |
766 LoopBuilder::kPostIncrement); | 774 LoopBuilder::kPostIncrement); |
767 HValue* start = graph()->GetConstant0(); | 775 HValue* start = graph()->GetConstant0(); |
768 HValue* key = builder.BeginBody(start, length, Token::LT); | 776 HValue* key = builder.BeginBody(start, checked_length, Token::LT); |
769 HInstruction* argument_elements = Add<HArgumentsElements>(false); | 777 HInstruction* argument_elements = Add<HArgumentsElements>(false); |
770 HInstruction* argument = Add<HAccessArgumentsAt>( | 778 HInstruction* argument = Add<HAccessArgumentsAt>( |
771 argument_elements, length, key); | 779 argument_elements, checked_length, key); |
772 | 780 |
773 Add<HStoreKeyed>(elements, key, argument, kind); | 781 Add<HStoreKeyed>(elements, key, argument, kind); |
774 builder.EndBody(); | 782 builder.EndBody(); |
775 return new_object; | 783 return new_object; |
776 } | 784 } |
777 | 785 |
778 | 786 |
779 template <> | 787 template <> |
780 HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { | 788 HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { |
781 ElementsKind kind = casted_stub()->elements_kind(); | 789 ElementsKind kind = casted_stub()->elements_kind(); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 return BuildUncheckedDictionaryElementLoad(receiver, key); | 1331 return BuildUncheckedDictionaryElementLoad(receiver, key); |
1324 } | 1332 } |
1325 | 1333 |
1326 | 1334 |
1327 Handle<Code> KeyedLoadDictionaryElementStub::GenerateCode(Isolate* isolate) { | 1335 Handle<Code> KeyedLoadDictionaryElementStub::GenerateCode(Isolate* isolate) { |
1328 return DoGenerateCode(isolate, this); | 1336 return DoGenerateCode(isolate, this); |
1329 } | 1337 } |
1330 | 1338 |
1331 | 1339 |
1332 } } // namespace v8::internal | 1340 } } // namespace v8::internal |
OLD | NEW |