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

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

Issue 1159433003: Use GetProperty for getting elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 6 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 | « src/runtime/runtime-debug.cc ('k') | src/utils.h » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/messages.h" 8 #include "src/messages.h"
9 #include "src/runtime/runtime.h" 9 #include "src/runtime/runtime.h"
10 #include "src/runtime/runtime-utils.h" 10 #include "src/runtime/runtime-utils.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 size_t element_size = 1; // Bogus initialization. 279 size_t element_size = 1; // Bogus initialization.
280 ElementsKind external_elements_kind = 280 ElementsKind external_elements_kind =
281 EXTERNAL_INT8_ELEMENTS; // Bogus intialization. 281 EXTERNAL_INT8_ELEMENTS; // Bogus intialization.
282 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 282 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
283 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind, 283 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind,
284 &fixed_elements_kind, &element_size); 284 &fixed_elements_kind, &element_size);
285 285
286 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind); 286 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind);
287 287
288 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 288 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
289 size_t length = 0;
289 if (source->IsJSTypedArray() && 290 if (source->IsJSTypedArray() &&
290 JSTypedArray::cast(*source)->type() == array_type) { 291 JSTypedArray::cast(*source)->type() == array_type) {
291 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); 292 length_obj = handle(JSTypedArray::cast(*source)->length(), isolate);
293 length = JSTypedArray::cast(*source)->length_value();
294 } else {
295 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length));
292 } 296 }
293 size_t length = 0;
294 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length));
295 297
296 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 298 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
297 (length > (kMaxInt / element_size))) { 299 (length > (kMaxInt / element_size))) {
298 THROW_NEW_ERROR_RETURN_FAILURE( 300 THROW_NEW_ERROR_RETURN_FAILURE(
299 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 301 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
300 } 302 }
301 size_t byte_length = length * element_size; 303 size_t byte_length = length * element_size;
302 304
303 DCHECK(holder->GetInternalFieldCount() == 305 DCHECK(holder->GetInternalFieldCount() ==
304 v8::ArrayBufferView::kInternalFieldCount); 306 v8::ArrayBufferView::kInternalFieldCount);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 358 }
357 } 359 }
358 360
359 return isolate->heap()->false_value(); 361 return isolate->heap()->false_value();
360 } 362 }
361 363
362 364
363 #define BUFFER_VIEW_GETTER(Type, getter, accessor) \ 365 #define BUFFER_VIEW_GETTER(Type, getter, accessor) \
364 RUNTIME_FUNCTION(Runtime_##Type##Get##getter) { \ 366 RUNTIME_FUNCTION(Runtime_##Type##Get##getter) { \
365 HandleScope scope(isolate); \ 367 HandleScope scope(isolate); \
366 DCHECK(args.length() == 1); \ 368 DCHECK_EQ(1, args.length()); \
367 CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \ 369 CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \
368 return holder->accessor(); \ 370 return holder->accessor(); \
369 } 371 }
370 372
371 BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length) 373 BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length)
372 BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset) 374 BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset)
373 BUFFER_VIEW_GETTER(TypedArray, Length, length) 375 BUFFER_VIEW_GETTER(TypedArray, Length, length)
374 BUFFER_VIEW_GETTER(DataView, Buffer, buffer) 376 BUFFER_VIEW_GETTER(DataView, Buffer, buffer)
375 377
376 #undef BUFFER_VIEW_GETTER 378 #undef BUFFER_VIEW_GETTER
377 379
378 RUNTIME_FUNCTION(Runtime_TypedArrayGetBuffer) { 380 RUNTIME_FUNCTION(Runtime_TypedArrayGetBuffer) {
379 HandleScope scope(isolate); 381 HandleScope scope(isolate);
380 DCHECK(args.length() == 1); 382 DCHECK_EQ(1, args.length());
381 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 383 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
382 return *holder->GetBuffer(); 384 return *holder->GetBuffer();
383 } 385 }
384 386
385 387
386 // Return codes for Runtime_TypedArraySetFastCases. 388 // Return codes for Runtime_TypedArraySetFastCases.
387 // Should be synchronized with typedarray.js natives. 389 // Should be synchronized with typedarray.js natives.
388 enum TypedArraySetResultCodes { 390 enum TypedArraySetResultCodes {
389 // Set from typed array of the same type. 391 // Set from typed array of the same type.
390 // This is processed by TypedArraySetFastCases 392 // This is processed by TypedArraySetFastCases
(...skipping 19 matching lines...) Expand all
410 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); 412 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY);
411 413
412 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); 414 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0);
413 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); 415 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1);
414 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2); 416 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2);
415 417
416 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); 418 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
417 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); 419 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
418 size_t offset = 0; 420 size_t offset = 0;
419 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset)); 421 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset));
420 size_t target_length = NumberToSize(isolate, target->length()); 422 size_t target_length = target->length_value();
421 size_t source_length = NumberToSize(isolate, source->length()); 423 size_t source_length = source->length_value();
422 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); 424 size_t target_byte_length = NumberToSize(isolate, target->byte_length());
423 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 425 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
424 if (offset > target_length || offset + source_length > target_length || 426 if (offset > target_length || offset + source_length > target_length ||
425 offset + source_length < offset) { // overflow 427 offset + source_length < offset) { // overflow
426 THROW_NEW_ERROR_RETURN_FAILURE( 428 THROW_NEW_ERROR_RETURN_FAILURE(
427 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge)); 429 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge));
428 } 430 }
429 431
430 size_t target_offset = NumberToSize(isolate, target->byte_offset()); 432 size_t target_offset = NumberToSize(isolate, target->byte_offset());
431 size_t source_offset = NumberToSize(isolate, source->byte_offset()); 433 size_t source_offset = NumberToSize(isolate, source->byte_offset());
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 DATA_VIEW_SETTER(Uint16, uint16_t) 723 DATA_VIEW_SETTER(Uint16, uint16_t)
722 DATA_VIEW_SETTER(Int16, int16_t) 724 DATA_VIEW_SETTER(Int16, int16_t)
723 DATA_VIEW_SETTER(Uint32, uint32_t) 725 DATA_VIEW_SETTER(Uint32, uint32_t)
724 DATA_VIEW_SETTER(Int32, int32_t) 726 DATA_VIEW_SETTER(Int32, int32_t)
725 DATA_VIEW_SETTER(Float32, float) 727 DATA_VIEW_SETTER(Float32, float)
726 DATA_VIEW_SETTER(Float64, double) 728 DATA_VIEW_SETTER(Float64, double)
727 729
728 #undef DATA_VIEW_SETTER 730 #undef DATA_VIEW_SETTER
729 } // namespace internal 731 } // namespace internal
730 } // namespace v8 732 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698