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

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: Created 5 years, 7 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 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 size_t element_size = 1; // Bogus initialization. 271 size_t element_size = 1; // Bogus initialization.
272 ElementsKind external_elements_kind = 272 ElementsKind external_elements_kind =
273 EXTERNAL_INT8_ELEMENTS; // Bogus intialization. 273 EXTERNAL_INT8_ELEMENTS; // Bogus intialization.
274 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 274 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
275 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind, 275 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind,
276 &fixed_elements_kind, &element_size); 276 &fixed_elements_kind, &element_size);
277 277
278 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind); 278 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind);
279 279
280 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 280 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
281 size_t length = 0;
281 if (source->IsJSTypedArray() && 282 if (source->IsJSTypedArray() &&
282 JSTypedArray::cast(*source)->type() == array_type) { 283 JSTypedArray::cast(*source)->type() == array_type) {
283 length_obj = Handle<Object>(JSTypedArray::cast(*source)->length(), isolate); 284 length_obj = handle(JSTypedArray::cast(*source)->length(), isolate);
285 length = JSTypedArray::cast(*source)->length_value();
286 } else {
287 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length));
284 } 288 }
285 size_t length = 0;
286 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length));
287 289
288 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 290 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
289 (length > (kMaxInt / element_size))) { 291 (length > (kMaxInt / element_size))) {
290 THROW_NEW_ERROR_RETURN_FAILURE( 292 THROW_NEW_ERROR_RETURN_FAILURE(
291 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 293 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
292 } 294 }
293 size_t byte_length = length * element_size; 295 size_t byte_length = length * element_size;
294 296
295 DCHECK(holder->GetInternalFieldCount() == 297 DCHECK(holder->GetInternalFieldCount() ==
296 v8::ArrayBufferView::kInternalFieldCount); 298 v8::ArrayBufferView::kInternalFieldCount);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 350 }
349 } 351 }
350 352
351 return isolate->heap()->false_value(); 353 return isolate->heap()->false_value();
352 } 354 }
353 355
354 356
355 #define BUFFER_VIEW_GETTER(Type, getter, accessor) \ 357 #define BUFFER_VIEW_GETTER(Type, getter, accessor) \
356 RUNTIME_FUNCTION(Runtime_##Type##Get##getter) { \ 358 RUNTIME_FUNCTION(Runtime_##Type##Get##getter) { \
357 HandleScope scope(isolate); \ 359 HandleScope scope(isolate); \
358 DCHECK(args.length() == 1); \ 360 DCHECK_EQ(1, args.length()); \
359 CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \ 361 CONVERT_ARG_HANDLE_CHECKED(JS##Type, holder, 0); \
360 return holder->accessor(); \ 362 return holder->accessor(); \
361 } 363 }
362 364
363 BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length) 365 BUFFER_VIEW_GETTER(ArrayBufferView, ByteLength, byte_length)
364 BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset) 366 BUFFER_VIEW_GETTER(ArrayBufferView, ByteOffset, byte_offset)
365 BUFFER_VIEW_GETTER(TypedArray, Length, length) 367 BUFFER_VIEW_GETTER(TypedArray, Length, length)
366 BUFFER_VIEW_GETTER(DataView, Buffer, buffer) 368 BUFFER_VIEW_GETTER(DataView, Buffer, buffer)
367 369
368 #undef BUFFER_VIEW_GETTER 370 #undef BUFFER_VIEW_GETTER
369 371
370 RUNTIME_FUNCTION(Runtime_TypedArrayGetBuffer) { 372 RUNTIME_FUNCTION(Runtime_TypedArrayGetBuffer) {
371 HandleScope scope(isolate); 373 HandleScope scope(isolate);
372 DCHECK(args.length() == 1); 374 DCHECK_EQ(1, args.length());
373 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 375 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
374 return *holder->GetBuffer(); 376 return *holder->GetBuffer();
375 } 377 }
376 378
377 379
378 // Return codes for Runtime_TypedArraySetFastCases. 380 // Return codes for Runtime_TypedArraySetFastCases.
379 // Should be synchronized with typedarray.js natives. 381 // Should be synchronized with typedarray.js natives.
380 enum TypedArraySetResultCodes { 382 enum TypedArraySetResultCodes {
381 // Set from typed array of the same type. 383 // Set from typed array of the same type.
382 // This is processed by TypedArraySetFastCases 384 // This is processed by TypedArraySetFastCases
(...skipping 19 matching lines...) Expand all
402 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); 404 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY);
403 405
404 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); 406 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0);
405 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); 407 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1);
406 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2); 408 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2);
407 409
408 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); 410 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
409 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); 411 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
410 size_t offset = 0; 412 size_t offset = 0;
411 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset)); 413 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset));
412 size_t target_length = NumberToSize(isolate, target->length()); 414 size_t target_length = target->length_value();
413 size_t source_length = NumberToSize(isolate, source->length()); 415 size_t source_length = source->length_value();
414 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); 416 size_t target_byte_length = NumberToSize(isolate, target->byte_length());
415 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 417 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
416 if (offset > target_length || offset + source_length > target_length || 418 if (offset > target_length || offset + source_length > target_length ||
417 offset + source_length < offset) { // overflow 419 offset + source_length < offset) { // overflow
418 THROW_NEW_ERROR_RETURN_FAILURE( 420 THROW_NEW_ERROR_RETURN_FAILURE(
419 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge)); 421 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge));
420 } 422 }
421 423
422 size_t target_offset = NumberToSize(isolate, target->byte_offset()); 424 size_t target_offset = NumberToSize(isolate, target->byte_offset());
423 size_t source_offset = NumberToSize(isolate, source->byte_offset()); 425 size_t source_offset = NumberToSize(isolate, source->byte_offset());
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 DATA_VIEW_SETTER(Uint16, uint16_t) 715 DATA_VIEW_SETTER(Uint16, uint16_t)
714 DATA_VIEW_SETTER(Int16, int16_t) 716 DATA_VIEW_SETTER(Int16, int16_t)
715 DATA_VIEW_SETTER(Uint32, uint32_t) 717 DATA_VIEW_SETTER(Uint32, uint32_t)
716 DATA_VIEW_SETTER(Int32, int32_t) 718 DATA_VIEW_SETTER(Int32, int32_t)
717 DATA_VIEW_SETTER(Float32, float) 719 DATA_VIEW_SETTER(Float32, float)
718 DATA_VIEW_SETTER(Float64, double) 720 DATA_VIEW_SETTER(Float64, double)
719 721
720 #undef DATA_VIEW_SETTER 722 #undef DATA_VIEW_SETTER
721 } // namespace internal 723 } // namespace internal
722 } // namespace v8 724 } // namespace v8
OLDNEW
« src/objects-inl.h ('K') | « src/runtime/runtime-debug.cc ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698