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

Side by Side Diff: src/builtins.cc

Issue 1814933002: Throw the right exceptions from setting elements in Array.prototype.concat (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
OLDNEW
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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/api-natives.h" 9 #include "src/api-natives.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 711
712 if (i >= JSObject::kMaxElementCount - index_offset_) { 712 if (i >= JSObject::kMaxElementCount - index_offset_) {
713 set_exceeds_array_limit(true); 713 set_exceeds_array_limit(true);
714 // Exception hasn't been thrown at this point. Return true to 714 // Exception hasn't been thrown at this point. Return true to
715 // break out, and caller will throw. !visit would imply that 715 // break out, and caller will throw. !visit would imply that
716 // there is already a pending exception. 716 // there is already a pending exception.
717 return true; 717 return true;
718 } 718 }
719 719
720 if (!is_fixed_array()) { 720 if (!is_fixed_array()) {
721 Handle<Object> element_value; 721 LookupIterator it(isolate_, storage_, index, LookupIterator::OWN);
722 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 722 Maybe<bool> success = JSReceiver::CreateDataProperty(
723 isolate_, element_value, 723 &it, elm, AbstractCode::ShouldThrow::THROW_ON_ERROR);
adamk 2016/03/17 19:22:21 "Object::THROW_ON_ERROR" is the usual way of namin
Dan Ehrenberg 2016/03/17 20:26:33 Done
724 Object::SetElement(isolate_, storage_, index, elm, STRICT), false); 724 if (!success.IsJust()) return false;
725 DCHECK(success.FromJust());
adamk 2016/03/17 19:22:21 I agree that this ought to be the case, but I'm no
Dan Ehrenberg 2016/03/17 20:26:33 For this patch, I just fixed it on this side, WDYT
adamk 2016/03/17 20:33:59 I'd prefer it be fixed properly, the CreateDataPro
adamk 2016/03/17 20:39:54 I do think it would make sense to do the CreateDat
Dan Ehrenberg 2016/03/17 21:15:53 This new version depends on https://codereview.chr
725 return true; 726 return true;
726 } 727 }
727 728
728 if (fast_elements()) { 729 if (fast_elements()) {
729 if (index < static_cast<uint32_t>(storage_fixed_array()->length())) { 730 if (index < static_cast<uint32_t>(storage_fixed_array()->length())) {
730 storage_fixed_array()->set(index, *elm); 731 storage_fixed_array()->set(index, *elm);
731 return true; 732 return true;
732 } 733 }
733 // Our initial estimate of length was foiled, possibly by 734 // Our initial estimate of length was foiled, possibly by
734 // getters on the arrays increasing the length of later arrays 735 // getters on the arrays increasing the length of later arrays
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 if (!new_storage.is_identical_to(slow_storage)) { 817 if (!new_storage.is_identical_to(slow_storage)) {
817 slow_storage = loop_scope.CloseAndEscape(new_storage); 818 slow_storage = loop_scope.CloseAndEscape(new_storage);
818 } 819 }
819 } 820 }
820 } 821 }
821 clear_storage(); 822 clear_storage();
822 set_storage(*slow_storage); 823 set_storage(*slow_storage);
823 set_fast_elements(false); 824 set_fast_elements(false);
824 } 825 }
825 826
826 inline void clear_storage() { 827 inline void clear_storage() { GlobalHandles::Destroy(storage_.location()); }
827 GlobalHandles::Destroy(Handle<Object>::cast(storage_).location());
828 }
829 828
830 inline void set_storage(FixedArray* storage) { 829 inline void set_storage(FixedArray* storage) {
831 DCHECK(is_fixed_array()); 830 DCHECK(is_fixed_array());
832 storage_ = isolate_->global_handles()->Create(storage); 831 storage_ = isolate_->global_handles()->Create(storage);
833 } 832 }
834 833
835 class FastElementsField : public BitField<bool, 0, 1> {}; 834 class FastElementsField : public BitField<bool, 0, 1> {};
836 class ExceedsLimitField : public BitField<bool, 1, 1> {}; 835 class ExceedsLimitField : public BitField<bool, 1, 1> {};
837 class IsFixedArrayField : public BitField<bool, 2, 1> {}; 836 class IsFixedArrayField : public BitField<bool, 2, 1> {};
838 837
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 for (int i = 0; i < argument_count; i++) { 1401 for (int i = 0; i < argument_count; i++) {
1403 Handle<Object> obj((*args)[i], isolate); 1402 Handle<Object> obj((*args)[i], isolate);
1404 Maybe<bool> spreadable = IsConcatSpreadable(isolate, obj); 1403 Maybe<bool> spreadable = IsConcatSpreadable(isolate, obj);
1405 MAYBE_RETURN(spreadable, isolate->heap()->exception()); 1404 MAYBE_RETURN(spreadable, isolate->heap()->exception());
1406 if (spreadable.FromJust()) { 1405 if (spreadable.FromJust()) {
1407 Handle<JSReceiver> object = Handle<JSReceiver>::cast(obj); 1406 Handle<JSReceiver> object = Handle<JSReceiver>::cast(obj);
1408 if (!IterateElements(isolate, object, &visitor)) { 1407 if (!IterateElements(isolate, object, &visitor)) {
1409 return isolate->heap()->exception(); 1408 return isolate->heap()->exception();
1410 } 1409 }
1411 } else { 1410 } else {
1412 visitor.visit(0, obj); 1411 bool success = visitor.visit(0, obj);
1412 DCHECK_EQ(success, !isolate->has_pending_exception());
1413 if (isolate->has_pending_exception()) return isolate->heap()->exception();
1413 visitor.increase_index_offset(1); 1414 visitor.increase_index_offset(1);
1414 } 1415 }
1415 } 1416 }
1416 1417
1417 if (visitor.exceeds_array_limit()) { 1418 if (visitor.exceeds_array_limit()) {
1418 THROW_NEW_ERROR_RETURN_FAILURE( 1419 THROW_NEW_ERROR_RETURN_FAILURE(
1419 isolate, NewRangeError(MessageTemplate::kInvalidArrayLength)); 1420 isolate, NewRangeError(MessageTemplate::kInvalidArrayLength));
1420 } 1421 }
1421 1422
1422 if (is_array_species) { 1423 if (is_array_species) {
(...skipping 3123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4546 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4547 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4547 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4548 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4548 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4549 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4549 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4550 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4550 #undef DEFINE_BUILTIN_ACCESSOR_C 4551 #undef DEFINE_BUILTIN_ACCESSOR_C
4551 #undef DEFINE_BUILTIN_ACCESSOR_A 4552 #undef DEFINE_BUILTIN_ACCESSOR_A
4552 4553
4553 4554
4554 } // namespace internal 4555 } // namespace internal
4555 } // namespace v8 4556 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-595319.js » ('j') | test/mjsunit/regress/regress-595319.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698