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

Side by Side Diff: src/elements.cc

Issue 2714793004: Merged: [elements] Check if the backing store has been neutered for indexOf (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-691323.js » ('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 // 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/elements.h" 5 #include "src/elements.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 } 2758 }
2759 2759
2760 static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder, 2760 static uint32_t GetEntryForIndexImpl(Isolate* isolate, JSObject* holder,
2761 FixedArrayBase* backing_store, 2761 FixedArrayBase* backing_store,
2762 uint32_t index, PropertyFilter filter) { 2762 uint32_t index, PropertyFilter filter) {
2763 return index < AccessorClass::GetCapacityImpl(holder, backing_store) 2763 return index < AccessorClass::GetCapacityImpl(holder, backing_store)
2764 ? index 2764 ? index
2765 : kMaxUInt32; 2765 : kMaxUInt32;
2766 } 2766 }
2767 2767
2768 static bool WasNeutered(JSObject* holder) {
2769 JSArrayBufferView* view = JSArrayBufferView::cast(holder);
2770 return view->WasNeutered();
2771 }
2772
2768 static uint32_t GetCapacityImpl(JSObject* holder, 2773 static uint32_t GetCapacityImpl(JSObject* holder,
2769 FixedArrayBase* backing_store) { 2774 FixedArrayBase* backing_store) {
2770 JSArrayBufferView* view = JSArrayBufferView::cast(holder); 2775 if (WasNeutered(holder)) return 0;
2771 if (view->WasNeutered()) return 0;
2772 return backing_store->length(); 2776 return backing_store->length();
2773 } 2777 }
2774 2778
2775 static uint32_t NumberOfElementsImpl(JSObject* receiver, 2779 static uint32_t NumberOfElementsImpl(JSObject* receiver,
2776 FixedArrayBase* backing_store) { 2780 FixedArrayBase* backing_store) {
2777 return AccessorClass::GetCapacityImpl(receiver, backing_store); 2781 return AccessorClass::GetCapacityImpl(receiver, backing_store);
2778 } 2782 }
2779 2783
2780 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, 2784 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
2781 KeyAccumulator* accumulator, 2785 KeyAccumulator* accumulator,
(...skipping 28 matching lines...) Expand all
2810 return Just(true); 2814 return Just(true);
2811 } 2815 }
2812 2816
2813 static Maybe<bool> IncludesValueImpl(Isolate* isolate, 2817 static Maybe<bool> IncludesValueImpl(Isolate* isolate,
2814 Handle<JSObject> receiver, 2818 Handle<JSObject> receiver,
2815 Handle<Object> value, 2819 Handle<Object> value,
2816 uint32_t start_from, uint32_t length) { 2820 uint32_t start_from, uint32_t length) {
2817 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); 2821 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
2818 DisallowHeapAllocation no_gc; 2822 DisallowHeapAllocation no_gc;
2819 2823
2824 // TODO(caitp): return Just(false) here when implementing strict throwing on
2825 // neutered views.
2826 if (WasNeutered(*receiver)) {
2827 return Just(value->IsUndefined(isolate) && length > start_from);
2828 }
2829
2820 BackingStore* elements = BackingStore::cast(receiver->elements()); 2830 BackingStore* elements = BackingStore::cast(receiver->elements());
2821 if (value->IsUndefined(isolate) && 2831 if (value->IsUndefined(isolate) &&
2822 length > static_cast<uint32_t>(elements->length())) { 2832 length > static_cast<uint32_t>(elements->length())) {
2823 return Just(true); 2833 return Just(true);
2824 } 2834 }
2825 if (!value->IsNumber()) return Just(false); 2835 if (!value->IsNumber()) return Just(false);
2826 2836
2827 double search_value = value->Number(); 2837 double search_value = value->Number();
2828 2838
2829 if (!std::isfinite(search_value)) { 2839 if (!std::isfinite(search_value)) {
(...skipping 29 matching lines...) Expand all
2859 } 2869 }
2860 } 2870 }
2861 2871
2862 static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate, 2872 static Maybe<int64_t> IndexOfValueImpl(Isolate* isolate,
2863 Handle<JSObject> receiver, 2873 Handle<JSObject> receiver,
2864 Handle<Object> value, 2874 Handle<Object> value,
2865 uint32_t start_from, uint32_t length) { 2875 uint32_t start_from, uint32_t length) {
2866 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver)); 2876 DCHECK(JSObject::PrototypeHasNoElements(isolate, *receiver));
2867 DisallowHeapAllocation no_gc; 2877 DisallowHeapAllocation no_gc;
2868 2878
2879 if (WasNeutered(*receiver)) return Just<int64_t>(-1);
2880
2869 BackingStore* elements = BackingStore::cast(receiver->elements()); 2881 BackingStore* elements = BackingStore::cast(receiver->elements());
2870 if (!value->IsNumber()) return Just<int64_t>(-1); 2882 if (!value->IsNumber()) return Just<int64_t>(-1);
2871 2883
2872 double search_value = value->Number(); 2884 double search_value = value->Number();
2873 2885
2874 if (!std::isfinite(search_value)) { 2886 if (!std::isfinite(search_value)) {
2875 // Integral types cannot represent +Inf or NaN. 2887 // Integral types cannot represent +Inf or NaN.
2876 if (AccessorClass::kind() < FLOAT32_ELEMENTS || 2888 if (AccessorClass::kind() < FLOAT32_ELEMENTS ||
2877 AccessorClass::kind() > FLOAT64_ELEMENTS) { 2889 AccessorClass::kind() > FLOAT64_ELEMENTS) {
2878 return Just<int64_t>(-1); 2890 return Just<int64_t>(-1);
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
3852 insertion_index += len; 3864 insertion_index += len;
3853 } 3865 }
3854 3866
3855 DCHECK_EQ(insertion_index, result_len); 3867 DCHECK_EQ(insertion_index, result_len);
3856 return result_array; 3868 return result_array;
3857 } 3869 }
3858 3870
3859 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 3871 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
3860 } // namespace internal 3872 } // namespace internal
3861 } // namespace v8 3873 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-crbug-691323.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698