Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateObjectLiteral) { | 476 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateObjectLiteral) { |
| 477 HandleScope scope(isolate); | 477 HandleScope scope(isolate); |
| 478 ASSERT(args.length() == 4); | 478 ASSERT(args.length() == 4); |
| 479 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); | 479 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); |
| 480 CONVERT_SMI_ARG_CHECKED(literals_index, 1); | 480 CONVERT_SMI_ARG_CHECKED(literals_index, 1); |
| 481 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); | 481 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); |
| 482 CONVERT_SMI_ARG_CHECKED(flags, 3); | 482 CONVERT_SMI_ARG_CHECKED(flags, 3); |
| 483 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; | 483 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; |
| 484 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; | 484 bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0; |
| 485 | 485 |
| 486 RUNTIME_ASSERT(literals_index >= 0 && literals_index < literals->length()); | |
| 487 | |
| 486 // Check if boilerplate exists. If not, create it first. | 488 // Check if boilerplate exists. If not, create it first. |
| 487 Handle<Object> literal_site(literals->get(literals_index), isolate); | 489 Handle<Object> literal_site(literals->get(literals_index), isolate); |
| 488 Handle<AllocationSite> site; | 490 Handle<AllocationSite> site; |
| 489 Handle<JSObject> boilerplate; | 491 Handle<JSObject> boilerplate; |
| 490 if (*literal_site == isolate->heap()->undefined_value()) { | 492 if (*literal_site == isolate->heap()->undefined_value()) { |
| 491 Handle<Object> raw_boilerplate; | 493 Handle<Object> raw_boilerplate; |
| 492 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 494 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 493 isolate, raw_boilerplate, | 495 isolate, raw_boilerplate, |
| 494 CreateObjectLiteralBoilerplate( | 496 CreateObjectLiteralBoilerplate( |
| 495 isolate, | 497 isolate, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 | 555 |
| 554 return site; | 556 return site; |
| 555 } | 557 } |
| 556 | 558 |
| 557 | 559 |
| 558 static MaybeHandle<JSObject> CreateArrayLiteralImpl(Isolate* isolate, | 560 static MaybeHandle<JSObject> CreateArrayLiteralImpl(Isolate* isolate, |
| 559 Handle<FixedArray> literals, | 561 Handle<FixedArray> literals, |
| 560 int literals_index, | 562 int literals_index, |
| 561 Handle<FixedArray> elements, | 563 Handle<FixedArray> elements, |
| 562 int flags) { | 564 int flags) { |
| 565 RUNTIME_ASSERT(literals_index >= 0 && literals_index < literals->length()); | |
|
Jakob Kummerow
2014/04/15 15:27:31
Urgh. After rebasing, this doesn't compile any mor
| |
| 563 Handle<AllocationSite> site; | 566 Handle<AllocationSite> site; |
| 564 ASSIGN_RETURN_ON_EXCEPTION( | 567 ASSIGN_RETURN_ON_EXCEPTION( |
| 565 isolate, site, | 568 isolate, site, |
| 566 GetLiteralAllocationSite(isolate, literals, literals_index, elements), | 569 GetLiteralAllocationSite(isolate, literals, literals_index, elements), |
| 567 JSObject); | 570 JSObject); |
| 568 | 571 |
| 569 bool enable_mementos = (flags & ArrayLiteral::kDisableMementos) == 0; | 572 bool enable_mementos = (flags & ArrayLiteral::kDisableMementos) == 0; |
| 570 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); | 573 Handle<JSObject> boilerplate(JSObject::cast(site->transition_info())); |
| 571 AllocationSiteUsageContext usage_context(isolate, site, enable_mementos); | 574 AllocationSiteUsageContext usage_context(isolate, site, enable_mementos); |
| 572 usage_context.EnterNewScope(); | 575 usage_context.EnterNewScope(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 Handle<JSArrayBuffer> array_buffer, | 813 Handle<JSArrayBuffer> array_buffer, |
| 811 size_t allocated_length, | 814 size_t allocated_length, |
| 812 bool initialize) { | 815 bool initialize) { |
| 813 void* data; | 816 void* data; |
| 814 CHECK(V8::ArrayBufferAllocator() != NULL); | 817 CHECK(V8::ArrayBufferAllocator() != NULL); |
| 815 if (allocated_length != 0) { | 818 if (allocated_length != 0) { |
| 816 if (initialize) { | 819 if (initialize) { |
| 817 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); | 820 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); |
| 818 } else { | 821 } else { |
| 819 data = | 822 data = |
| 820 V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length); | 823 V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length); |
| 821 } | 824 } |
| 822 if (data == NULL) return false; | 825 if (data == NULL) return false; |
| 823 } else { | 826 } else { |
| 824 data = NULL; | 827 data = NULL; |
| 825 } | 828 } |
| 826 | 829 |
| 827 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); | 830 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
| 828 | 831 |
| 829 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 832 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
| 830 | 833 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 847 view_obj = handle(view->weak_next(), isolate); | 850 view_obj = handle(view->weak_next(), isolate); |
| 848 } | 851 } |
| 849 array_buffer->Neuter(); | 852 array_buffer->Neuter(); |
| 850 } | 853 } |
| 851 | 854 |
| 852 | 855 |
| 853 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { | 856 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { |
| 854 HandleScope scope(isolate); | 857 HandleScope scope(isolate); |
| 855 ASSERT(args.length() == 2); | 858 ASSERT(args.length() == 2); |
| 856 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 859 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); |
| 857 CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1); | 860 CONVERT_ARG_HANDLE_CHECKED(Number, byteLength, 1); |
| 858 size_t allocated_length; | 861 size_t allocated_length = 0; |
| 859 if (byteLength->IsSmi()) { | 862 if (byteLength->IsSmi()) { |
|
Jakob Kummerow
2014/04/15 15:27:31
Come to think of it, we can probably just call Num
| |
| 860 allocated_length = Smi::cast(*byteLength)->value(); | 863 int smi_value = Smi::cast(*byteLength)->value(); |
| 864 RUNTIME_ASSERT(smi_value >= 0); | |
| 865 allocated_length = smi_value; | |
| 861 } else { | 866 } else { |
| 862 ASSERT(byteLength->IsHeapNumber()); | 867 ASSERT(byteLength->IsHeapNumber()); |
| 863 double value = HeapNumber::cast(*byteLength)->value(); | 868 double value = HeapNumber::cast(*byteLength)->value(); |
| 864 | 869 if (value < 0 || value > std::numeric_limits<size_t>::max()) { |
| 865 ASSERT(value >= 0); | |
| 866 | |
| 867 if (value > std::numeric_limits<size_t>::max()) { | |
| 868 return isolate->Throw( | 870 return isolate->Throw( |
| 869 *isolate->factory()->NewRangeError("invalid_array_buffer_length", | 871 *isolate->factory()->NewRangeError("invalid_array_buffer_length", |
| 870 HandleVector<Object>(NULL, 0))); | 872 HandleVector<Object>(NULL, 0))); |
| 871 } | 873 } |
| 872 | |
| 873 allocated_length = static_cast<size_t>(value); | 874 allocated_length = static_cast<size_t>(value); |
| 874 } | 875 } |
| 875 | 876 |
| 876 if (!Runtime::SetupArrayBufferAllocatingData(isolate, | 877 if (!Runtime::SetupArrayBufferAllocatingData(isolate, |
| 877 holder, allocated_length)) { | 878 holder, allocated_length)) { |
| 878 return isolate->Throw(*isolate->factory()-> | 879 return isolate->Throw( |
| 879 NewRangeError("invalid_array_buffer_length", | 880 *isolate->factory()->NewRangeError("invalid_array_buffer_length", |
| 880 HandleVector<Object>(NULL, 0))); | 881 HandleVector<Object>(NULL, 0))); |
| 881 } | 882 } |
| 882 | 883 |
| 883 return *holder; | 884 return *holder; |
| 884 } | 885 } |
| 885 | 886 |
| 886 | 887 |
| 887 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferGetByteLength) { | 888 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferGetByteLength) { |
| 888 SealHandleScope shs(isolate); | 889 SealHandleScope shs(isolate); |
| 889 ASSERT(args.length() == 1); | 890 ASSERT(args.length() == 1); |
| 890 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); | 891 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); |
| 891 return holder->byte_length(); | 892 return holder->byte_length(); |
| 892 } | 893 } |
| 893 | 894 |
| 894 | 895 |
| 895 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { | 896 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { |
| 896 HandleScope scope(isolate); | 897 HandleScope scope(isolate); |
| 897 ASSERT(args.length() == 3); | 898 ASSERT(args.length() == 3); |
| 898 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); | 899 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); |
| 899 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); | 900 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); |
| 900 CONVERT_DOUBLE_ARG_CHECKED(first, 2); | 901 CONVERT_ARG_HANDLE_CHECKED(Number, first, 2); |
| 901 size_t start = static_cast<size_t>(first); | 902 size_t start = NumberToSize(isolate, first); |
|
Jakob Kummerow
2014/04/15 15:27:31
As discussed, we'll want to return an exception ra
| |
| 902 size_t target_length = NumberToSize(isolate, target->byte_length()); | 903 size_t target_length = NumberToSize(isolate, target->byte_length()); |
| 903 | 904 |
| 904 if (target_length == 0) return isolate->heap()->undefined_value(); | 905 if (target_length == 0) return isolate->heap()->undefined_value(); |
| 905 | 906 |
| 906 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); | 907 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); |
| 907 CHECK(start <= source_byte_length); | 908 RUNTIME_ASSERT(start <= source_byte_length); |
| 908 CHECK(source_byte_length - start >= target_length); | 909 RUNTIME_ASSERT(source_byte_length - start >= target_length); |
| 909 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 910 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
| 910 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 911 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
| 911 CopyBytes(target_data, source_data + start, target_length); | 912 CopyBytes(target_data, source_data + start, target_length); |
| 912 return isolate->heap()->undefined_value(); | 913 return isolate->heap()->undefined_value(); |
| 913 } | 914 } |
| 914 | 915 |
| 915 | 916 |
| 916 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) { | 917 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) { |
| 917 HandleScope scope(isolate); | 918 HandleScope scope(isolate); |
| 918 ASSERT(args.length() == 1); | 919 ASSERT(args.length() == 1); |
| 919 CONVERT_ARG_CHECKED(Object, object, 0); | 920 CONVERT_ARG_CHECKED(Object, object, 0); |
| 920 return object->IsJSArrayBufferView() | 921 return isolate->heap()->ToBoolean(object->IsJSArrayBufferView()); |
| 921 ? isolate->heap()->true_value() | |
| 922 : isolate->heap()->false_value(); | |
| 923 } | 922 } |
| 924 | 923 |
| 925 | 924 |
| 926 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferNeuter) { | 925 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferNeuter) { |
| 927 HandleScope scope(isolate); | 926 HandleScope scope(isolate); |
| 927 ASSERT(args.length() == 1); | |
| 928 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); | 928 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); |
| 929 if (array_buffer->backing_store() == NULL) { | 929 if (array_buffer->backing_store() == NULL) { |
| 930 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); | 930 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); |
| 931 return isolate->heap()->undefined_value(); | 931 return isolate->heap()->undefined_value(); |
| 932 } | 932 } |
| 933 ASSERT(!array_buffer->is_external()); | 933 ASSERT(!array_buffer->is_external()); |
| 934 void* backing_store = array_buffer->backing_store(); | 934 void* backing_store = array_buffer->backing_store(); |
| 935 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); | 935 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); |
| 936 array_buffer->set_is_external(true); | 936 array_buffer->set_is_external(true); |
| 937 Runtime::NeuterArrayBuffer(array_buffer); | 937 Runtime::NeuterArrayBuffer(array_buffer); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 963 } | 963 } |
| 964 } | 964 } |
| 965 | 965 |
| 966 | 966 |
| 967 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { | 967 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { |
| 968 HandleScope scope(isolate); | 968 HandleScope scope(isolate); |
| 969 ASSERT(args.length() == 5); | 969 ASSERT(args.length() == 5); |
| 970 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 970 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); |
| 971 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 971 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
| 972 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); | 972 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); |
| 973 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); | 973 CONVERT_ARG_HANDLE_CHECKED(Number, byte_offset_object, 3); |
| 974 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); | 974 CONVERT_ARG_HANDLE_CHECKED(Number, byte_length_object, 4); |
| 975 | 975 |
| 976 ASSERT(holder->GetInternalFieldCount() == | 976 ASSERT(holder->GetInternalFieldCount() == |
| 977 v8::ArrayBufferView::kInternalFieldCount); | 977 v8::ArrayBufferView::kInternalFieldCount); |
| 978 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 978 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 979 holder->SetInternalField(i, Smi::FromInt(0)); | 979 holder->SetInternalField(i, Smi::FromInt(0)); |
| 980 } | 980 } |
| 981 | 981 |
| 982 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. | 982 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. |
| 983 size_t element_size = 1; // Bogus initialization. | 983 size_t element_size = 1; // Bogus initialization. |
| 984 ElementsKind external_elements_kind = | 984 ElementsKind external_elements_kind = |
| 985 EXTERNAL_INT8_ELEMENTS; // Bogus initialization. | 985 EXTERNAL_INT8_ELEMENTS; // Bogus initialization. |
| 986 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. | 986 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. |
| 987 Runtime::ArrayIdToTypeAndSize(arrayId, | 987 Runtime::ArrayIdToTypeAndSize(arrayId, |
| 988 &array_type, | 988 &array_type, |
| 989 &external_elements_kind, | 989 &external_elements_kind, |
| 990 &fixed_elements_kind, | 990 &fixed_elements_kind, |
| 991 &element_size); | 991 &element_size); |
| 992 | 992 |
| 993 holder->set_byte_offset(*byte_offset_object); | 993 holder->set_byte_offset(*byte_offset_object); |
| 994 holder->set_byte_length(*byte_length_object); | 994 holder->set_byte_length(*byte_length_object); |
| 995 | 995 |
| 996 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 996 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
| 997 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 997 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
| 998 | 998 |
| 999 CHECK_EQ(0, static_cast<int>(byte_length % element_size)); | 999 CHECK_EQ(0, static_cast<int>(byte_length % element_size)); |
| 1000 size_t length = byte_length / element_size; | 1000 size_t length = byte_length / element_size; |
| 1001 | 1001 |
| 1002 if (length > static_cast<unsigned>(Smi::kMaxValue)) { | 1002 if (length > static_cast<unsigned>(Smi::kMaxValue)) { |
| 1003 return isolate->Throw(*isolate->factory()-> | 1003 return isolate->Throw( |
| 1004 NewRangeError("invalid_typed_array_length", | 1004 *isolate->factory()->NewRangeError("invalid_typed_array_length", |
| 1005 HandleVector<Object>(NULL, 0))); | 1005 HandleVector<Object>(NULL, 0))); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 1008 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| 1009 holder->set_length(*length_obj); | 1009 holder->set_length(*length_obj); |
| 1010 if (!maybe_buffer->IsNull()) { | 1010 if (!maybe_buffer->IsNull()) { |
| 1011 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(*maybe_buffer)); | 1011 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(*maybe_buffer)); |
| 1012 | 1012 |
| 1013 size_t array_buffer_byte_length = | 1013 size_t array_buffer_byte_length = |
| 1014 NumberToSize(isolate, buffer->byte_length()); | 1014 NumberToSize(isolate, buffer->byte_length()); |
| 1015 CHECK(byte_offset <= array_buffer_byte_length); | 1015 CHECK(byte_offset <= array_buffer_byte_length); |
| (...skipping 14061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15077 } | 15077 } |
| 15078 } | 15078 } |
| 15079 | 15079 |
| 15080 | 15080 |
| 15081 void Runtime::OutOfMemory() { | 15081 void Runtime::OutOfMemory() { |
| 15082 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); | 15082 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); |
| 15083 UNREACHABLE(); | 15083 UNREACHABLE(); |
| 15084 } | 15084 } |
| 15085 | 15085 |
| 15086 } } // namespace v8::internal | 15086 } } // namespace v8::internal |
| OLD | NEW |