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

Side by Side Diff: src/builtins.cc

Issue 11417006: Set length only after retrieving the element succeeded (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Micro optimization Created 8 years, 1 month 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 | no next file » | 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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 666
667 if (FLAG_harmony_observation && array->map()->is_observed()) { 667 if (FLAG_harmony_observation && array->map()->is_observed()) {
668 return CallJsBuiltin(isolate, "ArrayPop", args); 668 return CallJsBuiltin(isolate, "ArrayPop", args);
669 } 669 }
670 670
671 int len = Smi::cast(array->length())->value(); 671 int len = Smi::cast(array->length())->value();
672 if (len == 0) return heap->undefined_value(); 672 if (len == 0) return heap->undefined_value();
673 673
674 ElementsAccessor* accessor = array->GetElementsAccessor(); 674 ElementsAccessor* accessor = array->GetElementsAccessor();
675 int new_length = len - 1; 675 int new_length = len - 1;
676 Object* result; 676 MaybeObject* maybe_result;
677 MaybeObject* maybe_result = accessor->Get(array, array, new_length); 677 if (accessor->HasElement(array, array, new_length, elms_obj)) {
678 if (!maybe_result->To(&result)) return maybe_result; 678 maybe_result = accessor->Get(array, array, new_length, elms_obj);
679 } else {
680 maybe_result = array->GetPrototype()->GetElement(len - 1);
681 }
682 if (maybe_result->IsFailure()) return maybe_result;
679 MaybeObject* maybe_failure = 683 MaybeObject* maybe_failure =
680 accessor->SetLength(array, Smi::FromInt(new_length)); 684 accessor->SetLength(array, Smi::FromInt(new_length));
681 if (maybe_failure->IsFailure()) return maybe_failure; 685 if (maybe_failure->IsFailure()) return maybe_failure;
682 if (!result->IsTheHole()) return result; 686 return maybe_result;
683 return array->GetPrototype()->GetElement(len - 1);
684 } 687 }
685 688
686 689
687 BUILTIN(ArrayShift) { 690 BUILTIN(ArrayShift) {
688 Heap* heap = isolate->heap(); 691 Heap* heap = isolate->heap();
689 Object* receiver = *args.receiver(); 692 Object* receiver = *args.receiver();
690 FixedArrayBase* elms_obj; 693 FixedArrayBase* elms_obj;
691 MaybeObject* maybe_elms_obj = 694 MaybeObject* maybe_elms_obj =
692 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); 695 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0);
693 if (maybe_elms_obj == NULL) 696 if (maybe_elms_obj == NULL)
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 return Handle<Code>(code_address); \ 1918 return Handle<Code>(code_address); \
1916 } 1919 }
1917 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1920 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1918 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1921 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1919 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1922 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1920 #undef DEFINE_BUILTIN_ACCESSOR_C 1923 #undef DEFINE_BUILTIN_ACCESSOR_C
1921 #undef DEFINE_BUILTIN_ACCESSOR_A 1924 #undef DEFINE_BUILTIN_ACCESSOR_A
1922 1925
1923 1926
1924 } } // namespace v8::internal 1927 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698