Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1069)

Side by Side Diff: src/builtins.cc

Issue 200363002: Handlify callers of Object::GetElement. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 array->set_elements(new_elms); 500 array->set_elements(new_elms);
501 } 501 }
502 502
503 // Set the length. 503 // Set the length.
504 array->set_length(Smi::FromInt(new_length)); 504 array->set_length(Smi::FromInt(new_length));
505 return Smi::FromInt(new_length); 505 return Smi::FromInt(new_length);
506 } 506 }
507 } 507 }
508 508
509 509
510 static Handle<Object> ElementsAccessorSetLengthWrapper(
511 Isolate* isolate,
512 ElementsAccessor* accessor,
513 Handle<JSArray> array,
514 int new_length) {
515 CALL_HEAP_FUNCTION(isolate,
516 accessor->SetLength(*array, Smi::FromInt(new_length)),
517 Object);
518 }
519
520
510 BUILTIN(ArrayPop) { 521 BUILTIN(ArrayPop) {
511 Heap* heap = isolate->heap(); 522 Heap* heap = isolate->heap();
512 Object* receiver = *args.receiver(); 523 Object* receiver = *args.receiver();
513 FixedArrayBase* elms_obj; 524 FixedArrayBase* elms_obj;
514 MaybeObject* maybe_elms = 525 MaybeObject* maybe_elms =
515 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); 526 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
516 if (maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); 527 if (maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args);
517 if (!maybe_elms->To(&elms_obj)) return maybe_elms; 528 if (!maybe_elms->To(&elms_obj)) return maybe_elms;
518 529
519 JSArray* array = JSArray::cast(receiver); 530 JSArray* array = JSArray::cast(receiver);
520 ASSERT(!array->map()->is_observed()); 531 ASSERT(!array->map()->is_observed());
521 532
522 int len = Smi::cast(array->length())->value(); 533 int len = Smi::cast(array->length())->value();
523 if (len == 0) return heap->undefined_value(); 534 if (len == 0) return heap->undefined_value();
524 535
525 ElementsAccessor* accessor = array->GetElementsAccessor(); 536 ElementsAccessor* accessor = array->GetElementsAccessor();
526 int new_length = len - 1; 537 int new_length = len - 1;
527 MaybeObject* maybe_result;
528 if (accessor->HasElement(array, array, new_length, elms_obj)) { 538 if (accessor->HasElement(array, array, new_length, elms_obj)) {
529 maybe_result = accessor->Get(array, array, new_length, elms_obj); 539 MaybeObject* maybe_result =
540 accessor->Get(array, array, new_length, elms_obj);
541 if (maybe_result->IsFailure()) return maybe_result;
542 MaybeObject* maybe_failure =
543 accessor->SetLength(array, Smi::FromInt(new_length));
544 if (maybe_failure->IsFailure()) return maybe_failure;
545 return maybe_result;
530 } else { 546 } else {
531 maybe_result = array->GetPrototype()->GetElement(isolate, len - 1); 547 // TODO(yangguo): handlify all once ElementsAccessors are handlified.
548 HandleScope scope(isolate);
549 Handle<Object> proto(array->GetPrototype(), isolate);
550 Handle<Object> element = Object::GetElement(isolate, proto, len - 1);
551 RETURN_IF_EMPTY_HANDLE(isolate, element);
552 Handle<JSArray> array_handle(array, isolate);
553 RETURN_IF_EMPTY_HANDLE(isolate,
554 ElementsAccessorSetLengthWrapper(
555 isolate, accessor, array_handle, new_length));
556 return *element;
532 } 557 }
533 if (maybe_result->IsFailure()) return maybe_result;
534 MaybeObject* maybe_failure =
535 accessor->SetLength(array, Smi::FromInt(new_length));
536 if (maybe_failure->IsFailure()) return maybe_failure;
537 return maybe_result;
538 } 558 }
539 559
540 560
541 BUILTIN(ArrayShift) { 561 BUILTIN(ArrayShift) {
542 Heap* heap = isolate->heap(); 562 Heap* heap = isolate->heap();
543 Object* receiver = *args.receiver(); 563 Object* receiver = *args.receiver();
544 FixedArrayBase* elms_obj; 564 FixedArrayBase* elms_obj;
545 MaybeObject* maybe_elms_obj = 565 MaybeObject* maybe_elms_obj =
546 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); 566 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
547 if (maybe_elms_obj == NULL) 567 if (maybe_elms_obj == NULL)
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1758 }
1739 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1759 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1740 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1760 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1741 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1761 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1742 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1762 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1743 #undef DEFINE_BUILTIN_ACCESSOR_C 1763 #undef DEFINE_BUILTIN_ACCESSOR_C
1744 #undef DEFINE_BUILTIN_ACCESSOR_A 1764 #undef DEFINE_BUILTIN_ACCESSOR_A
1745 1765
1746 1766
1747 } } // namespace v8::internal 1767 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698