| 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 | 500 |
| 501 // TODO(ishell): Temporary wrapper until handlified. | 501 // TODO(ishell): Temporary wrapper until handlified. |
| 502 static bool ElementsAccessorHasElementWrapper( | 502 static bool ElementsAccessorHasElementWrapper( |
| 503 ElementsAccessor* accessor, | 503 ElementsAccessor* accessor, |
| 504 Handle<Object> receiver, | 504 Handle<Object> receiver, |
| 505 Handle<JSObject> holder, | 505 Handle<JSObject> holder, |
| 506 uint32_t key, | 506 uint32_t key, |
| 507 Handle<FixedArrayBase> backing_store = Handle<FixedArrayBase>::null()) { | 507 Handle<FixedArrayBase> backing_store = Handle<FixedArrayBase>::null()) { |
| 508 return accessor->HasElement(*receiver, *holder, key, | 508 return accessor->HasElement(*receiver, *holder, key, |
| 509 backing_store.is_null() ? *backing_store : NULL); | 509 backing_store.is_null() ? NULL : *backing_store); |
| 510 } | 510 } |
| 511 | 511 |
| 512 | 512 |
| 513 // TODO(ishell): Temporary wrapper until handlified. | |
| 514 static Handle<Object> ElementsAccessorGetWrapper( | |
| 515 Isolate* isolate, | |
| 516 ElementsAccessor* accessor, | |
| 517 Handle<Object> receiver, | |
| 518 Handle<JSObject> holder, | |
| 519 uint32_t key, | |
| 520 Handle<FixedArrayBase> backing_store = Handle<FixedArrayBase>::null()) { | |
| 521 CALL_HEAP_FUNCTION(isolate, | |
| 522 accessor->Get(*receiver, *holder, key, | |
| 523 backing_store.is_null() | |
| 524 ? *backing_store : NULL), | |
| 525 Object); | |
| 526 } | |
| 527 | |
| 528 | |
| 529 BUILTIN(ArrayPop) { | 513 BUILTIN(ArrayPop) { |
| 530 HandleScope scope(isolate); | 514 HandleScope scope(isolate); |
| 531 Handle<Object> receiver = args.receiver(); | 515 Handle<Object> receiver = args.receiver(); |
| 532 Handle<FixedArrayBase> elms_obj = | 516 Handle<FixedArrayBase> elms_obj = |
| 533 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); | 517 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); |
| 534 if (elms_obj.is_null()) return CallJsBuiltin(isolate, "ArrayPop", args); | 518 if (elms_obj.is_null()) return CallJsBuiltin(isolate, "ArrayPop", args); |
| 535 | 519 |
| 536 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 520 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 537 ASSERT(!array->map()->is_observed()); | 521 ASSERT(!array->map()->is_observed()); |
| 538 | 522 |
| 539 int len = Smi::cast(array->length())->value(); | 523 int len = Smi::cast(array->length())->value(); |
| 540 if (len == 0) return isolate->heap()->undefined_value(); | 524 if (len == 0) return isolate->heap()->undefined_value(); |
| 541 | 525 |
| 542 ElementsAccessor* accessor = array->GetElementsAccessor(); | 526 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 543 int new_length = len - 1; | 527 int new_length = len - 1; |
| 544 Handle<Object> element; | 528 Handle<Object> element; |
| 545 if (ElementsAccessorHasElementWrapper( | 529 if (ElementsAccessorHasElementWrapper( |
| 546 accessor, array, array, new_length, elms_obj)) { | 530 accessor, array, array, new_length, elms_obj)) { |
| 547 element = ElementsAccessorGetWrapper( | 531 element = accessor->Get( |
| 548 isolate, accessor, array, array, new_length, elms_obj); | 532 array, array, new_length, elms_obj); |
| 549 } else { | 533 } else { |
| 550 Handle<Object> proto(array->GetPrototype(), isolate); | 534 Handle<Object> proto(array->GetPrototype(), isolate); |
| 551 element = Object::GetElement(isolate, proto, len - 1); | 535 element = Object::GetElement(isolate, proto, len - 1); |
| 552 } | 536 } |
| 553 RETURN_IF_EMPTY_HANDLE(isolate, element); | 537 RETURN_IF_EMPTY_HANDLE(isolate, element); |
| 554 RETURN_IF_EMPTY_HANDLE(isolate, | 538 RETURN_IF_EMPTY_HANDLE(isolate, |
| 555 accessor->SetLength( | 539 accessor->SetLength( |
| 556 array, handle(Smi::FromInt(new_length), isolate))); | 540 array, handle(Smi::FromInt(new_length), isolate))); |
| 557 return *element; | 541 return *element; |
| 558 } | 542 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 571 } | 555 } |
| 572 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 556 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 573 ASSERT(!array->map()->is_observed()); | 557 ASSERT(!array->map()->is_observed()); |
| 574 | 558 |
| 575 int len = Smi::cast(array->length())->value(); | 559 int len = Smi::cast(array->length())->value(); |
| 576 if (len == 0) return heap->undefined_value(); | 560 if (len == 0) return heap->undefined_value(); |
| 577 | 561 |
| 578 // Get first element | 562 // Get first element |
| 579 ElementsAccessor* accessor = array->GetElementsAccessor(); | 563 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 580 Handle<Object> first = accessor->Get(receiver, array, 0, elms_obj); | 564 Handle<Object> first = accessor->Get(receiver, array, 0, elms_obj); |
| 565 RETURN_IF_EMPTY_HANDLE(isolate, first); |
| 581 if (first->IsTheHole()) { | 566 if (first->IsTheHole()) { |
| 582 first = isolate->factory()->undefined_value(); | 567 first = isolate->factory()->undefined_value(); |
| 583 } | 568 } |
| 584 | 569 |
| 585 if (!heap->lo_space()->Contains(*elms_obj)) { | 570 if (!heap->lo_space()->Contains(*elms_obj)) { |
| 586 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1)); | 571 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1)); |
| 587 } else { | 572 } else { |
| 588 // Shift the elements. | 573 // Shift the elements. |
| 589 if (elms_obj->IsFixedArray()) { | 574 if (elms_obj->IsFixedArray()) { |
| 590 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); | 575 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); |
| (...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 } | 1719 } |
| 1735 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1720 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1736 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1721 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1737 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1722 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 1738 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1723 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1739 #undef DEFINE_BUILTIN_ACCESSOR_C | 1724 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1740 #undef DEFINE_BUILTIN_ACCESSOR_A | 1725 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1741 | 1726 |
| 1742 | 1727 |
| 1743 } } // namespace v8::internal | 1728 } } // namespace v8::internal |
| OLD | NEW |