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

Side by Side Diff: src/builtins/builtins-typedarray.cc

Issue 2778623003: [typedarrays] Check detached buffer at start of typed array methods (Closed)
Patch Set: Created 3 years, 8 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 | src/js/typedarray.js » ('j') | src/js/typedarray.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/counters.h" 7 #include "src/counters.h"
8 #include "src/elements.h" 8 #include "src/elements.h"
9 #include "src/objects-inl.h" 9 #include "src/objects-inl.h"
10 10
(...skipping 29 matching lines...) Expand all
40 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum) 40 return relative < 0 ? std::max<int64_t>(relative + maximum, minimum)
41 : std::min<int64_t>(relative, maximum); 41 : std::min<int64_t>(relative, maximum);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 BUILTIN(TypedArrayPrototypeCopyWithin) { 46 BUILTIN(TypedArrayPrototypeCopyWithin) {
47 HandleScope scope(isolate); 47 HandleScope scope(isolate);
48 48
49 Handle<JSTypedArray> array; 49 Handle<JSTypedArray> array;
50 const char* method = "%TypedArray%.prototype.copyWithin"; 50 const char* method = "TypedArray.prototype.copyWithin";
adamk 2017/03/27 19:48:20 Why did this change? "%TypedArray%" is the spec na
Choongwoo Han 2017/03/28 09:50:58 Done.
51 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 51 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
52 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 52 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
53 53
54 if (V8_UNLIKELY(array->WasNeutered())) return *array;
55
56 int64_t len = array->length_value(); 54 int64_t len = array->length_value();
57 int64_t to = 0; 55 int64_t to = 0;
58 int64_t from = 0; 56 int64_t from = 0;
59 int64_t final = len; 57 int64_t final = len;
60 58
61 if (V8_LIKELY(args.length() > 1)) { 59 if (V8_LIKELY(args.length() > 1)) {
62 Handle<Object> num; 60 Handle<Object> num;
63 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 61 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
64 isolate, num, Object::ToInteger(isolate, args.at<Object>(1))); 62 isolate, num, Object::ToInteger(isolate, args.at<Object>(1)));
65 to = CapRelativeIndex(num, 0, len); 63 to = CapRelativeIndex(num, 0, len);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); 103 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr());
106 std::memmove(data + to, data + from, count); 104 std::memmove(data + to, data + from, count);
107 105
108 return *array; 106 return *array;
109 } 107 }
110 108
111 BUILTIN(TypedArrayPrototypeFill) { 109 BUILTIN(TypedArrayPrototypeFill) {
112 HandleScope scope(isolate); 110 HandleScope scope(isolate);
113 111
114 Handle<JSTypedArray> array; 112 Handle<JSTypedArray> array;
115 const char* method = "%TypedArray%.prototype.fill"; 113 const char* method = "TypedArray.prototype.fill";
116 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 114 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
117 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 115 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
118 116
119 if (V8_UNLIKELY(array->WasNeutered())) return *array;
120
121 int64_t len = array->length_value(); 117 int64_t len = array->length_value();
122 int64_t start = 0; 118 int64_t start = 0;
123 int64_t end = len; 119 int64_t end = len;
124 120
125 if (args.length() > 2) { 121 if (args.length() > 2) {
126 Handle<Object> num = args.atOrUndefined(isolate, 2); 122 Handle<Object> num = args.atOrUndefined(isolate, 2);
127 if (!num->IsUndefined(isolate)) { 123 if (!num->IsUndefined(isolate)) {
128 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 124 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
129 isolate, num, Object::ToInteger(isolate, num)); 125 isolate, num, Object::ToInteger(isolate, num));
130 start = CapRelativeIndex(num, 0, len); 126 start = CapRelativeIndex(num, 0, len);
(...skipping 23 matching lines...) Expand all
154 150
155 return array->GetElementsAccessor()->Fill(isolate, array, obj_value, 151 return array->GetElementsAccessor()->Fill(isolate, array, obj_value,
156 static_cast<uint32_t>(start), 152 static_cast<uint32_t>(start),
157 static_cast<uint32_t>(end)); 153 static_cast<uint32_t>(end));
158 } 154 }
159 155
160 BUILTIN(TypedArrayPrototypeIncludes) { 156 BUILTIN(TypedArrayPrototypeIncludes) {
161 HandleScope scope(isolate); 157 HandleScope scope(isolate);
162 158
163 Handle<JSTypedArray> array; 159 Handle<JSTypedArray> array;
164 const char* method = "%TypedArray%.prototype.includes"; 160 const char* method = "TypedArray.prototype.includes";
165 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 161 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
166 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 162 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
167 163
168 if (args.length() < 2) return isolate->heap()->false_value(); 164 if (args.length() < 2) return isolate->heap()->false_value();
169 165
170 int64_t len = array->length_value(); 166 int64_t len = array->length_value();
171 if (len == 0) return isolate->heap()->false_value(); 167 if (len == 0) return isolate->heap()->false_value();
172 168
173 int64_t index = 0; 169 int64_t index = 0;
174 if (args.length() > 2) { 170 if (args.length() > 2) {
(...skipping 12 matching lines...) Expand all
187 static_cast<uint32_t>(index), 183 static_cast<uint32_t>(index),
188 static_cast<uint32_t>(len)); 184 static_cast<uint32_t>(len));
189 MAYBE_RETURN(result, isolate->heap()->exception()); 185 MAYBE_RETURN(result, isolate->heap()->exception());
190 return *isolate->factory()->ToBoolean(result.FromJust()); 186 return *isolate->factory()->ToBoolean(result.FromJust());
191 } 187 }
192 188
193 BUILTIN(TypedArrayPrototypeIndexOf) { 189 BUILTIN(TypedArrayPrototypeIndexOf) {
194 HandleScope scope(isolate); 190 HandleScope scope(isolate);
195 191
196 Handle<JSTypedArray> array; 192 Handle<JSTypedArray> array;
197 const char* method = "%TypedArray%.prototype.indexOf"; 193 const char* method = "TypedArray.prototype.indexOf";
198 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 194 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
199 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 195 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
200 196
201 int64_t len = array->length_value(); 197 int64_t len = array->length_value();
202 if (len == 0) return Smi::FromInt(-1); 198 if (len == 0) return Smi::FromInt(-1);
203 199
204 int64_t index = 0; 200 int64_t index = 0;
205 if (args.length() > 2) { 201 if (args.length() > 2) {
206 Handle<Object> num; 202 Handle<Object> num;
207 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 203 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
(...skipping 10 matching lines...) Expand all
218 static_cast<uint32_t>(index), 214 static_cast<uint32_t>(index),
219 static_cast<uint32_t>(len)); 215 static_cast<uint32_t>(len));
220 MAYBE_RETURN(result, isolate->heap()->exception()); 216 MAYBE_RETURN(result, isolate->heap()->exception());
221 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); 217 return *isolate->factory()->NewNumberFromInt64(result.FromJust());
222 } 218 }
223 219
224 BUILTIN(TypedArrayPrototypeLastIndexOf) { 220 BUILTIN(TypedArrayPrototypeLastIndexOf) {
225 HandleScope scope(isolate); 221 HandleScope scope(isolate);
226 222
227 Handle<JSTypedArray> array; 223 Handle<JSTypedArray> array;
228 const char* method = "%TypedArray%.prototype.lastIndexOf"; 224 const char* method = "TypedArray.prototype.lastIndexOf";
229 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 225 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
230 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 226 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
231 227
232 int64_t len = array->length_value(); 228 int64_t len = array->length_value();
233 if (len == 0) return Smi::FromInt(-1); 229 if (len == 0) return Smi::FromInt(-1);
234 230
235 int64_t index = len - 1; 231 int64_t index = len - 1;
236 if (args.length() > 2) { 232 if (args.length() > 2) {
237 Handle<Object> num; 233 Handle<Object> num;
238 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 234 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
(...skipping 13 matching lines...) Expand all
252 Maybe<int64_t> result = elements->LastIndexOfValue( 248 Maybe<int64_t> result = elements->LastIndexOfValue(
253 isolate, array, search_element, static_cast<uint32_t>(index)); 249 isolate, array, search_element, static_cast<uint32_t>(index));
254 MAYBE_RETURN(result, isolate->heap()->exception()); 250 MAYBE_RETURN(result, isolate->heap()->exception());
255 return *isolate->factory()->NewNumberFromInt64(result.FromJust()); 251 return *isolate->factory()->NewNumberFromInt64(result.FromJust());
256 } 252 }
257 253
258 BUILTIN(TypedArrayPrototypeReverse) { 254 BUILTIN(TypedArrayPrototypeReverse) {
259 HandleScope scope(isolate); 255 HandleScope scope(isolate);
260 256
261 Handle<JSTypedArray> array; 257 Handle<JSTypedArray> array;
262 const char* method = "%TypedArray%.prototype.reverse"; 258 const char* method = "TypedArray.prototype.reverse";
263 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 259 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
264 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method)); 260 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
265 261
266 if (V8_UNLIKELY(array->WasNeutered())) return *array;
267
268 ElementsAccessor* elements = array->GetElementsAccessor(); 262 ElementsAccessor* elements = array->GetElementsAccessor();
269 elements->Reverse(*array); 263 elements->Reverse(*array);
270 return *array; 264 return *array;
271 } 265 }
272 266
273 } // namespace internal 267 } // namespace internal
274 } // namespace v8 268 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/js/typedarray.js » ('j') | src/js/typedarray.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698