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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 } | 346 } |
347 if (target_kind != origin_kind) { | 347 if (target_kind != origin_kind) { |
348 MaybeObject* maybe_failure = array->TransitionElementsKind(target_kind); | 348 MaybeObject* maybe_failure = array->TransitionElementsKind(target_kind); |
349 if (maybe_failure->IsFailure()) return maybe_failure; | 349 if (maybe_failure->IsFailure()) return maybe_failure; |
350 return array->elements(); | 350 return array->elements(); |
351 } | 351 } |
352 return elms; | 352 return elms; |
353 } | 353 } |
354 | 354 |
355 | 355 |
356 // TODO(ishell): Temporary wrapper until handlified. | |
357 MUST_USE_RESULT | |
358 static inline Handle<Object> EnsureJSArrayWithWritableFastElementsWrapper( | |
359 Isolate* isolate, | |
360 Handle<Object> receiver, | |
361 Arguments* args, | |
362 int first_added_arg) { | |
363 CALL_HEAP_FUNCTION(isolate, | |
364 EnsureJSArrayWithWritableFastElements( | |
365 isolate->heap(), *receiver, args, first_added_arg), | |
366 Object); | |
367 } | |
368 | |
369 | |
356 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 370 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
357 JSArray* receiver) { | 371 JSArray* receiver) { |
358 if (!FLAG_clever_optimizations) return false; | 372 if (!FLAG_clever_optimizations) return false; |
359 Context* native_context = heap->isolate()->context()->native_context(); | 373 Context* native_context = heap->isolate()->context()->native_context(); |
360 JSObject* array_proto = | 374 JSObject* array_proto = |
361 JSObject::cast(native_context->array_function()->prototype()); | 375 JSObject::cast(native_context->array_function()->prototype()); |
362 return receiver->GetPrototype() == array_proto && | 376 return receiver->GetPrototype() == array_proto && |
363 ArrayPrototypeHasNoElements(heap, native_context, array_proto); | 377 ArrayPrototypeHasNoElements(heap, native_context, array_proto); |
364 } | 378 } |
365 | 379 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 array->set_elements(new_elms); | 513 array->set_elements(new_elms); |
500 } | 514 } |
501 | 515 |
502 // Set the length. | 516 // Set the length. |
503 array->set_length(Smi::FromInt(new_length)); | 517 array->set_length(Smi::FromInt(new_length)); |
504 return Smi::FromInt(new_length); | 518 return Smi::FromInt(new_length); |
505 } | 519 } |
506 } | 520 } |
507 | 521 |
508 | 522 |
523 // TODO(ishell): Temporary wrapper until handlified. | |
524 static bool ElementsAccessorHasElementWrapper( | |
525 ElementsAccessor* accessor, | |
526 Handle<Object> receiver, | |
527 Handle<JSObject> holder, | |
528 uint32_t key, | |
529 Handle<FixedArrayBase> backing_store = Handle<FixedArrayBase>::null()) { | |
530 return accessor->HasElement(*receiver, *holder, key, | |
531 backing_store.is_null() ? *backing_store : NULL); | |
532 } | |
533 | |
534 | |
535 // TODO(ishell): Temporary wrapper until handlified. | |
536 static Handle<Object> ElementsAccessorGetWrapper( | |
537 Isolate* isolate, | |
538 ElementsAccessor* accessor, | |
539 Handle<Object> receiver, | |
540 Handle<JSObject> holder, | |
541 uint32_t key, | |
542 Handle<FixedArrayBase> backing_store = Handle<FixedArrayBase>::null()) { | |
543 CALL_HEAP_FUNCTION(isolate, | |
544 accessor->Get(*receiver, *holder, key, | |
545 backing_store.is_null() | |
546 ? *backing_store : NULL), | |
547 Object); | |
548 } | |
549 | |
550 | |
551 // TODO(ishell): Temporary wrapper until handlified. | |
509 static Handle<Object> ElementsAccessorSetLengthWrapper( | 552 static Handle<Object> ElementsAccessorSetLengthWrapper( |
510 Isolate* isolate, | 553 Isolate* isolate, |
511 ElementsAccessor* accessor, | 554 ElementsAccessor* accessor, |
512 Handle<JSArray> array, | 555 Handle<JSArray> array, |
513 int new_length) { | 556 int new_length) { |
514 CALL_HEAP_FUNCTION(isolate, | 557 CALL_HEAP_FUNCTION(isolate, |
515 accessor->SetLength(*array, Smi::FromInt(new_length)), | 558 accessor->SetLength(*array, Smi::FromInt(new_length)), |
516 Object); | 559 Object); |
517 } | 560 } |
518 | 561 |
519 | 562 |
520 BUILTIN(ArrayPop) { | 563 BUILTIN(ArrayPop) { |
521 Heap* heap = isolate->heap(); | 564 HandleScope scope(isolate); |
522 Object* receiver = *args.receiver(); | 565 Handle<Object> receiver = args.receiver(); |
523 FixedArrayBase* elms_obj; | 566 Handle<Object> maybe_elms = |
Yang
2014/03/19 15:06:30
name is confusing. It's not a MaybeObject.
| |
524 MaybeObject* maybe_elms = | 567 EnsureJSArrayWithWritableFastElementsWrapper(isolate, receiver, NULL, 0); |
525 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 568 RETURN_IF_EMPTY_HANDLE(isolate, maybe_elms); |
526 if (maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); | 569 if (*maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); |
527 if (!maybe_elms->To(&elms_obj)) return maybe_elms; | |
528 | 570 |
529 JSArray* array = JSArray::cast(receiver); | 571 Handle<FixedArrayBase> elms_obj = Handle<FixedArrayBase>::cast(maybe_elms); |
572 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | |
530 ASSERT(!array->map()->is_observed()); | 573 ASSERT(!array->map()->is_observed()); |
531 | 574 |
532 int len = Smi::cast(array->length())->value(); | 575 int len = Smi::cast(array->length())->value(); |
533 if (len == 0) return heap->undefined_value(); | 576 if (len == 0) return isolate->heap()->undefined_value(); |
534 | 577 |
535 ElementsAccessor* accessor = array->GetElementsAccessor(); | 578 ElementsAccessor* accessor = array->GetElementsAccessor(); |
536 int new_length = len - 1; | 579 int new_length = len - 1; |
537 if (accessor->HasElement(array, array, new_length, elms_obj)) { | 580 Handle<Object> element; |
538 MaybeObject* maybe_result = | 581 if (ElementsAccessorHasElementWrapper( |
539 accessor->Get(array, array, new_length, elms_obj); | 582 accessor, array, array, new_length, elms_obj)) { |
540 if (maybe_result->IsFailure()) return maybe_result; | 583 element = ElementsAccessorGetWrapper( |
541 MaybeObject* maybe_failure = | 584 isolate, accessor, array, array, new_length, elms_obj); |
542 accessor->SetLength(array, Smi::FromInt(new_length)); | |
543 if (maybe_failure->IsFailure()) return maybe_failure; | |
544 return maybe_result; | |
545 } else { | 585 } else { |
546 // TODO(yangguo): handlify all once ElementsAccessors are handlified. | |
547 HandleScope scope(isolate); | |
548 Handle<Object> proto(array->GetPrototype(), isolate); | 586 Handle<Object> proto(array->GetPrototype(), isolate); |
549 Handle<Object> element = Object::GetElement(isolate, proto, len - 1); | 587 element = Object::GetElement(isolate, proto, len - 1); |
550 RETURN_IF_EMPTY_HANDLE(isolate, element); | |
551 Handle<JSArray> array_handle(array, isolate); | |
552 RETURN_IF_EMPTY_HANDLE(isolate, | |
553 ElementsAccessorSetLengthWrapper( | |
554 isolate, accessor, array_handle, new_length)); | |
555 return *element; | |
556 } | 588 } |
589 RETURN_IF_EMPTY_HANDLE(isolate, element); | |
590 RETURN_IF_EMPTY_HANDLE(isolate, | |
591 ElementsAccessorSetLengthWrapper( | |
592 isolate, accessor, array, new_length)); | |
593 return *element; | |
557 } | 594 } |
558 | 595 |
559 | 596 |
560 BUILTIN(ArrayShift) { | 597 BUILTIN(ArrayShift) { |
561 Heap* heap = isolate->heap(); | 598 Heap* heap = isolate->heap(); |
562 Object* receiver = *args.receiver(); | 599 Object* receiver = *args.receiver(); |
563 FixedArrayBase* elms_obj; | 600 FixedArrayBase* elms_obj; |
564 MaybeObject* maybe_elms_obj = | 601 MaybeObject* maybe_elms_obj = |
565 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 602 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); |
566 if (maybe_elms_obj == NULL) | 603 if (maybe_elms_obj == NULL) |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1757 } | 1794 } |
1758 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1795 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1759 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1796 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1760 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1797 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
1761 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1798 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1762 #undef DEFINE_BUILTIN_ACCESSOR_C | 1799 #undef DEFINE_BUILTIN_ACCESSOR_C |
1763 #undef DEFINE_BUILTIN_ACCESSOR_A | 1800 #undef DEFINE_BUILTIN_ACCESSOR_A |
1764 | 1801 |
1765 | 1802 |
1766 } } // namespace v8::internal | 1803 } } // namespace v8::internal |
OLD | NEW |