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/elements.h" | 5 #include "src/elements.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 length = fixed_array_base->length(); | 508 length = fixed_array_base->length(); |
509 } | 509 } |
510 ElementsAccessorSubclass::ValidateContents(holder, length); | 510 ElementsAccessorSubclass::ValidateContents(holder, length); |
511 } | 511 } |
512 | 512 |
513 void Validate(Handle<JSObject> holder) final { | 513 void Validate(Handle<JSObject> holder) final { |
514 DisallowHeapAllocation no_gc; | 514 DisallowHeapAllocation no_gc; |
515 ElementsAccessorSubclass::ValidateImpl(holder); | 515 ElementsAccessorSubclass::ValidateImpl(holder); |
516 } | 516 } |
517 | 517 |
| 518 virtual bool IsPacked(Handle<JSObject> holder, |
| 519 Handle<FixedArrayBase> backing_store, uint32_t start, |
| 520 uint32_t end) final { |
| 521 return ElementsAccessorSubclass::IsPackedImpl(holder, backing_store, start, |
| 522 end); |
| 523 } |
| 524 |
| 525 static bool IsPackedImpl(Handle<JSObject> holder, |
| 526 Handle<FixedArrayBase> backing_store, uint32_t start, |
| 527 uint32_t end) { |
| 528 if (IsFastPackedElementsKind(kind())) return true; |
| 529 for (uint32_t i = start; i < end; i++) { |
| 530 if (!ElementsAccessorSubclass::HasElementImpl(holder, i, backing_store)) { |
| 531 return false; |
| 532 } |
| 533 } |
| 534 return true; |
| 535 } |
| 536 |
518 virtual bool HasElement(Handle<JSObject> holder, uint32_t index, | 537 virtual bool HasElement(Handle<JSObject> holder, uint32_t index, |
519 Handle<FixedArrayBase> backing_store) final { | 538 Handle<FixedArrayBase> backing_store) final { |
| 539 return ElementsAccessorSubclass::HasElementImpl(holder, index, |
| 540 backing_store); |
| 541 } |
| 542 |
| 543 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, |
| 544 Handle<FixedArrayBase> backing_store) { |
520 return ElementsAccessorSubclass::GetEntryForIndexImpl( | 545 return ElementsAccessorSubclass::GetEntryForIndexImpl( |
521 *holder, *backing_store, index) != kMaxUInt32; | 546 *holder, *backing_store, index) != kMaxUInt32; |
522 } | 547 } |
523 | 548 |
524 virtual Handle<Object> Get(Handle<FixedArrayBase> backing_store, | 549 virtual Handle<Object> Get(Handle<FixedArrayBase> backing_store, |
525 uint32_t entry) final { | 550 uint32_t entry) final { |
526 return ElementsAccessorSubclass::GetImpl(backing_store, entry); | 551 return ElementsAccessorSubclass::GetImpl(backing_store, entry); |
527 } | 552 } |
528 | 553 |
529 static Handle<Object> GetImpl(Handle<FixedArrayBase> backing_store, | 554 static Handle<Object> GetImpl(Handle<FixedArrayBase> backing_store, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 590 } |
566 | 591 |
567 static void AddImpl(Handle<JSObject> object, uint32_t index, | 592 static void AddImpl(Handle<JSObject> object, uint32_t index, |
568 Handle<Object> value, PropertyAttributes attributes, | 593 Handle<Object> value, PropertyAttributes attributes, |
569 uint32_t new_capacity) { | 594 uint32_t new_capacity) { |
570 UNREACHABLE(); | 595 UNREACHABLE(); |
571 } | 596 } |
572 | 597 |
573 virtual uint32_t Push(Handle<JSArray> receiver, | 598 virtual uint32_t Push(Handle<JSArray> receiver, |
574 Handle<FixedArrayBase> backing_store, Object** objects, | 599 Handle<FixedArrayBase> backing_store, Object** objects, |
575 uint32_t push_size, int direction) { | 600 uint32_t push_size, int direction) final { |
576 return ElementsAccessorSubclass::PushImpl(receiver, backing_store, objects, | 601 return ElementsAccessorSubclass::PushImpl(receiver, backing_store, objects, |
577 push_size, direction); | 602 push_size, direction); |
578 } | 603 } |
579 | 604 |
580 static uint32_t PushImpl(Handle<JSArray> receiver, | 605 static uint32_t PushImpl(Handle<JSArray> receiver, |
581 Handle<FixedArrayBase> elms_obj, Object** objects, | 606 Handle<FixedArrayBase> elms_obj, Object** objects, |
582 uint32_t push_size, int direction) { | 607 uint32_t push_size, int direction) { |
583 UNREACHABLE(); | 608 UNREACHABLE(); |
584 return 0; | 609 return 0; |
585 } | 610 } |
586 | 611 |
| 612 virtual Handle<JSArray> Slice(Handle<JSObject> receiver, |
| 613 Handle<FixedArrayBase> backing_store, |
| 614 uint32_t start, uint32_t end) final { |
| 615 return ElementsAccessorSubclass::SliceImpl(receiver, backing_store, start, |
| 616 end); |
| 617 } |
| 618 |
| 619 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
| 620 Handle<FixedArrayBase> backing_store, |
| 621 uint32_t start, uint32_t end) { |
| 622 UNREACHABLE(); |
| 623 return Handle<JSArray>(); |
| 624 } |
| 625 |
587 virtual Handle<JSArray> Splice(Handle<JSArray> receiver, | 626 virtual Handle<JSArray> Splice(Handle<JSArray> receiver, |
588 Handle<FixedArrayBase> backing_store, | 627 Handle<FixedArrayBase> backing_store, |
589 uint32_t start, uint32_t delete_count, | 628 uint32_t start, uint32_t delete_count, |
590 Arguments args, uint32_t add_count) { | 629 Arguments args, uint32_t add_count) final { |
591 return ElementsAccessorSubclass::SpliceImpl(receiver, backing_store, start, | 630 return ElementsAccessorSubclass::SpliceImpl(receiver, backing_store, start, |
592 delete_count, args, add_count); | 631 delete_count, args, add_count); |
593 } | 632 } |
594 | 633 |
595 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, | 634 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
596 Handle<FixedArrayBase> backing_store, | 635 Handle<FixedArrayBase> backing_store, |
597 uint32_t start, uint32_t delete_count, | 636 uint32_t start, uint32_t delete_count, |
598 Arguments args, uint32_t add_count) { | 637 Arguments args, uint32_t add_count) { |
599 UNREACHABLE(); | 638 UNREACHABLE(); |
600 return Handle<JSArray>(); | 639 return Handle<JSArray>(); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 receiver->set_length(Smi::FromInt(new_length)); | 1264 receiver->set_length(Smi::FromInt(new_length)); |
1226 return new_length; | 1265 return new_length; |
1227 } | 1266 } |
1228 | 1267 |
1229 static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store, | 1268 static void MoveElements(Heap* heap, Handle<FixedArrayBase> backing_store, |
1230 int dst_index, int src_index, int len, | 1269 int dst_index, int src_index, int len, |
1231 int hole_start, int hole_end) { | 1270 int hole_start, int hole_end) { |
1232 UNREACHABLE(); | 1271 UNREACHABLE(); |
1233 } | 1272 } |
1234 | 1273 |
| 1274 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
| 1275 Handle<FixedArrayBase> backing_store, |
| 1276 uint32_t start, uint32_t end) { |
| 1277 Isolate* isolate = receiver->GetIsolate(); |
| 1278 if (end <= start) { |
| 1279 return isolate->factory()->NewJSArray(KindTraits::Kind, 0, 0); |
| 1280 } |
| 1281 int result_len = end - start; |
| 1282 Handle<JSArray> result_array = isolate->factory()->NewJSArray( |
| 1283 KindTraits::Kind, result_len, result_len); |
| 1284 DisallowHeapAllocation no_gc; |
| 1285 FastElementsAccessorSubclass::CopyElementsImpl( |
| 1286 *backing_store, start, result_array->elements(), KindTraits::Kind, 0, |
| 1287 kPackedSizeNotKnown, result_len); |
| 1288 return result_array; |
| 1289 } |
| 1290 |
1235 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, | 1291 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
1236 Handle<FixedArrayBase> backing_store, | 1292 Handle<FixedArrayBase> backing_store, |
1237 uint32_t start, uint32_t delete_count, | 1293 uint32_t start, uint32_t delete_count, |
1238 Arguments args, uint32_t add_count) { | 1294 Arguments args, uint32_t add_count) { |
1239 Isolate* isolate = receiver->GetIsolate(); | 1295 Isolate* isolate = receiver->GetIsolate(); |
1240 Heap* heap = isolate->heap(); | 1296 Heap* heap = isolate->heap(); |
1241 const uint32_t len = Smi::cast(receiver->length())->value(); | 1297 uint32_t len = Smi::cast(receiver->length())->value(); |
1242 const uint32_t new_length = len - delete_count + add_count; | 1298 uint32_t new_length = len - delete_count + add_count; |
1243 | 1299 |
1244 if (new_length == 0) { | 1300 if (new_length == 0) { |
1245 receiver->set_elements(heap->empty_fixed_array()); | 1301 receiver->set_elements(heap->empty_fixed_array()); |
1246 receiver->set_length(Smi::FromInt(0)); | 1302 receiver->set_length(Smi::FromInt(0)); |
1247 return isolate->factory()->NewJSArrayWithElements( | 1303 return isolate->factory()->NewJSArrayWithElements( |
1248 backing_store, KindTraits::Kind, delete_count); | 1304 backing_store, KindTraits::Kind, delete_count); |
1249 } | 1305 } |
1250 | 1306 |
1251 // construct the result array which holds the deleted elements | 1307 // construct the result array which holds the deleted elements |
1252 Handle<JSArray> deleted_elements = isolate->factory()->NewJSArray( | 1308 Handle<JSArray> deleted_elements = isolate->factory()->NewJSArray( |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; | 2196 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; |
2141 ELEMENTS_LIST(ACCESSOR_DELETE) | 2197 ELEMENTS_LIST(ACCESSOR_DELETE) |
2142 #undef ACCESSOR_DELETE | 2198 #undef ACCESSOR_DELETE |
2143 elements_accessors_ = NULL; | 2199 elements_accessors_ = NULL; |
2144 } | 2200 } |
2145 | 2201 |
2146 | 2202 |
2147 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 2203 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
2148 } // namespace internal | 2204 } // namespace internal |
2149 } // namespace v8 | 2205 } // namespace v8 |
OLD | NEW |