| OLD | NEW |
| 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/factory.h" | 8 #include "src/factory.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| 11 #include "src/runtime/runtime.h" | 11 #include "src/runtime/runtime.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { | 16 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { |
| 17 SealHandleScope shs(isolate); | 17 SealHandleScope shs(isolate); |
| 18 DCHECK(args.length() == 1); | 18 DCHECK_EQ(1, args.length()); |
| 19 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); | 19 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); |
| 20 return holder->byte_length(); | 20 return holder->byte_length(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 | 23 |
| 24 RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) { | 24 RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) { |
| 25 HandleScope scope(isolate); | 25 HandleScope scope(isolate); |
| 26 DCHECK(args.length() == 4); | 26 DCHECK_EQ(4, args.length()); |
| 27 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); | 27 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); |
| 28 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); | 28 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); |
| 29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(first, 2); | 29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(first, 2); |
| 30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); | 30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); |
| 31 | 31 |
| 32 if (source->was_neutered() || target->was_neutered()) { | 32 if (source->was_neutered() || target->was_neutered()) { |
| 33 THROW_NEW_ERROR_RETURN_FAILURE( | 33 THROW_NEW_ERROR_RETURN_FAILURE( |
| 34 isolate, NewTypeError(MessageTemplate::kDetachedOperation, | 34 isolate, NewTypeError(MessageTemplate::kDetachedOperation, |
| 35 isolate->factory()->NewStringFromAsciiChecked( | 35 isolate->factory()->NewStringFromAsciiChecked( |
| 36 "ArrayBuffer.prototype.slice"))); | 36 "ArrayBuffer.prototype.slice"))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 CHECK(source_byte_length - start >= target_length); | 49 CHECK(source_byte_length - start >= target_length); |
| 50 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 50 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
| 51 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 51 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
| 52 CopyBytes(target_data, source_data + start, target_length); | 52 CopyBytes(target_data, source_data + start, target_length); |
| 53 return isolate->heap()->undefined_value(); | 53 return isolate->heap()->undefined_value(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { | 57 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { |
| 58 HandleScope scope(isolate); | 58 HandleScope scope(isolate); |
| 59 DCHECK(args.length() == 1); | 59 DCHECK_EQ(1, args.length()); |
| 60 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); | 60 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); |
| 61 if (array_buffer->backing_store() == NULL) { | 61 if (array_buffer->backing_store() == NULL) { |
| 62 CHECK(Smi::kZero == array_buffer->byte_length()); | 62 CHECK(Smi::kZero == array_buffer->byte_length()); |
| 63 return isolate->heap()->undefined_value(); | 63 return isolate->heap()->undefined_value(); |
| 64 } | 64 } |
| 65 // Shared array buffers should never be neutered. | 65 // Shared array buffers should never be neutered. |
| 66 CHECK(!array_buffer->is_shared()); | 66 CHECK(!array_buffer->is_shared()); |
| 67 DCHECK(!array_buffer->is_external()); | 67 DCHECK(!array_buffer->is_external()); |
| 68 void* backing_store = array_buffer->backing_store(); | 68 void* backing_store = array_buffer->backing_store(); |
| 69 size_t byte_length = NumberToSize(array_buffer->byte_length()); | 69 size_t byte_length = NumberToSize(array_buffer->byte_length()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 #undef ARRAY_ID_CASE | 90 #undef ARRAY_ID_CASE |
| 91 | 91 |
| 92 default: | 92 default: |
| 93 UNREACHABLE(); | 93 UNREACHABLE(); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| 98 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { | 98 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { |
| 99 HandleScope scope(isolate); | 99 HandleScope scope(isolate); |
| 100 DCHECK(args.length() == 6); | 100 DCHECK_EQ(6, args.length()); |
| 101 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 101 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); |
| 102 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 102 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
| 103 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); | 103 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); |
| 104 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3); | 104 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3); |
| 105 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4); | 105 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4); |
| 106 CONVERT_BOOLEAN_ARG_CHECKED(initialize, 5); | 106 CONVERT_BOOLEAN_ARG_CHECKED(initialize, 5); |
| 107 | 107 |
| 108 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST && | 108 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST && |
| 109 arrayId <= Runtime::ARRAY_ID_LAST); | 109 arrayId <= Runtime::ARRAY_ID_LAST); |
| 110 | 110 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 | 174 |
| 175 // Initializes a typed array from an array-like object. | 175 // Initializes a typed array from an array-like object. |
| 176 // If an array-like object happens to be a typed array of the same type, | 176 // If an array-like object happens to be a typed array of the same type, |
| 177 // initializes backing store using memove. | 177 // initializes backing store using memove. |
| 178 // | 178 // |
| 179 // Returns true if backing store was initialized or false otherwise. | 179 // Returns true if backing store was initialized or false otherwise. |
| 180 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { | 180 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { |
| 181 HandleScope scope(isolate); | 181 HandleScope scope(isolate); |
| 182 DCHECK(args.length() == 4); | 182 DCHECK_EQ(4, args.length()); |
| 183 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 183 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); |
| 184 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 184 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
| 185 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); | 185 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); |
| 186 CONVERT_NUMBER_ARG_HANDLE_CHECKED(length_obj, 3); | 186 CONVERT_NUMBER_ARG_HANDLE_CHECKED(length_obj, 3); |
| 187 | 187 |
| 188 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST && | 188 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST && |
| 189 arrayId <= Runtime::ARRAY_ID_LAST); | 189 arrayId <= Runtime::ARRAY_ID_LAST); |
| 190 | 190 |
| 191 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. | 191 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. |
| 192 size_t element_size = 1; // Bogus initialization. | 192 size_t element_size = 1; // Bogus initialization. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING = 1, | 303 TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING = 1, |
| 304 // Set from typed array of the different type, non-overlapping. | 304 // Set from typed array of the different type, non-overlapping. |
| 305 TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING = 2, | 305 TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING = 2, |
| 306 // Set from non-typed array. | 306 // Set from non-typed array. |
| 307 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3 | 307 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3 |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 | 310 |
| 311 RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { | 311 RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { |
| 312 HandleScope scope(isolate); | 312 HandleScope scope(isolate); |
| 313 DCHECK(args.length() == 3); | 313 DCHECK_EQ(3, args.length()); |
| 314 if (!args[0]->IsJSTypedArray()) { | 314 if (!args[0]->IsJSTypedArray()) { |
| 315 THROW_NEW_ERROR_RETURN_FAILURE( | 315 THROW_NEW_ERROR_RETURN_FAILURE( |
| 316 isolate, NewTypeError(MessageTemplate::kNotTypedArray)); | 316 isolate, NewTypeError(MessageTemplate::kNotTypedArray)); |
| 317 } | 317 } |
| 318 | 318 |
| 319 if (!args[1]->IsJSTypedArray()) | 319 if (!args[1]->IsJSTypedArray()) |
| 320 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); | 320 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); |
| 321 | 321 |
| 322 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); | 322 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); |
| 323 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); | 323 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 DCHECK(target->GetBuffer()->backing_store() == | 362 DCHECK(target->GetBuffer()->backing_store() == |
| 363 source->GetBuffer()->backing_store()); | 363 source->GetBuffer()->backing_store()); |
| 364 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); | 364 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); |
| 365 } else { // Non-overlapping typed arrays | 365 } else { // Non-overlapping typed arrays |
| 366 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); | 366 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 | 370 |
| 371 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) { | 371 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) { |
| 372 DCHECK(args.length() == 0); | 372 DCHECK_EQ(0, args.length()); |
| 373 DCHECK_OBJECT_SIZE(FLAG_typed_array_max_size_in_heap + | 373 DCHECK_OBJECT_SIZE(FLAG_typed_array_max_size_in_heap + |
| 374 FixedTypedArrayBase::kDataOffset); | 374 FixedTypedArrayBase::kDataOffset); |
| 375 return Smi::FromInt(FLAG_typed_array_max_size_in_heap); | 375 return Smi::FromInt(FLAG_typed_array_max_size_in_heap); |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 RUNTIME_FUNCTION(Runtime_IsTypedArray) { | 379 RUNTIME_FUNCTION(Runtime_IsTypedArray) { |
| 380 HandleScope scope(isolate); | 380 HandleScope scope(isolate); |
| 381 DCHECK(args.length() == 1); | 381 DCHECK_EQ(1, args.length()); |
| 382 return isolate->heap()->ToBoolean(args[0]->IsJSTypedArray()); | 382 return isolate->heap()->ToBoolean(args[0]->IsJSTypedArray()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 | 385 |
| 386 RUNTIME_FUNCTION(Runtime_IsSharedTypedArray) { | 386 RUNTIME_FUNCTION(Runtime_IsSharedTypedArray) { |
| 387 HandleScope scope(isolate); | 387 HandleScope scope(isolate); |
| 388 DCHECK(args.length() == 1); | 388 DCHECK_EQ(1, args.length()); |
| 389 return isolate->heap()->ToBoolean( | 389 return isolate->heap()->ToBoolean( |
| 390 args[0]->IsJSTypedArray() && | 390 args[0]->IsJSTypedArray() && |
| 391 JSTypedArray::cast(args[0])->GetBuffer()->is_shared()); | 391 JSTypedArray::cast(args[0])->GetBuffer()->is_shared()); |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 RUNTIME_FUNCTION(Runtime_IsSharedIntegerTypedArray) { | 395 RUNTIME_FUNCTION(Runtime_IsSharedIntegerTypedArray) { |
| 396 HandleScope scope(isolate); | 396 HandleScope scope(isolate); |
| 397 DCHECK(args.length() == 1); | 397 DCHECK_EQ(1, args.length()); |
| 398 if (!args[0]->IsJSTypedArray()) { | 398 if (!args[0]->IsJSTypedArray()) { |
| 399 return isolate->heap()->false_value(); | 399 return isolate->heap()->false_value(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); | 402 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); |
| 403 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && | 403 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && |
| 404 obj->type() != kExternalFloat32Array && | 404 obj->type() != kExternalFloat32Array && |
| 405 obj->type() != kExternalFloat64Array && | 405 obj->type() != kExternalFloat64Array && |
| 406 obj->type() != kExternalUint8ClampedArray); | 406 obj->type() != kExternalUint8ClampedArray); |
| 407 } | 407 } |
| 408 | 408 |
| 409 | 409 |
| 410 RUNTIME_FUNCTION(Runtime_IsSharedInteger32TypedArray) { | 410 RUNTIME_FUNCTION(Runtime_IsSharedInteger32TypedArray) { |
| 411 HandleScope scope(isolate); | 411 HandleScope scope(isolate); |
| 412 DCHECK(args.length() == 1); | 412 DCHECK_EQ(1, args.length()); |
| 413 if (!args[0]->IsJSTypedArray()) { | 413 if (!args[0]->IsJSTypedArray()) { |
| 414 return isolate->heap()->false_value(); | 414 return isolate->heap()->false_value(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); | 417 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); |
| 418 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && | 418 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && |
| 419 obj->type() == kExternalInt32Array); | 419 obj->type() == kExternalInt32Array); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace internal | 422 } // namespace internal |
| 423 } // namespace v8 | 423 } // namespace v8 |
| OLD | NEW |