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/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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 #undef ARRAY_ID_CASE | 173 #undef ARRAY_ID_CASE |
174 | 174 |
175 default: | 175 default: |
176 UNREACHABLE(); | 176 UNREACHABLE(); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { | 181 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { |
182 HandleScope scope(isolate); | 182 HandleScope scope(isolate); |
183 DCHECK(args.length() == 5); | 183 DCHECK(args.length() == 6); |
184 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | 184 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); |
185 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | 185 CONVERT_SMI_ARG_CHECKED(arrayId, 1); |
186 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); | 186 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); |
187 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3); | 187 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3); |
188 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4); | 188 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4); |
| 189 CONVERT_BOOLEAN_ARG_CHECKED(initialize, 5); |
189 | 190 |
190 RUNTIME_ASSERT(arrayId >= Runtime::ARRAY_ID_FIRST && | 191 RUNTIME_ASSERT(arrayId >= Runtime::ARRAY_ID_FIRST && |
191 arrayId <= Runtime::ARRAY_ID_LAST); | 192 arrayId <= Runtime::ARRAY_ID_LAST); |
192 | 193 |
193 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. | 194 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. |
194 size_t element_size = 1; // Bogus initialization. | 195 size_t element_size = 1; // Bogus initialization. |
195 ElementsKind external_elements_kind = | 196 ElementsKind external_elements_kind = |
196 EXTERNAL_INT8_ELEMENTS; // Bogus initialization. | 197 EXTERNAL_INT8_ELEMENTS; // Bogus initialization. |
197 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. | 198 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. |
198 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind, | 199 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &external_elements_kind, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 JSObject::GetElementsTransitionMap(holder, external_elements_kind); | 246 JSObject::GetElementsTransitionMap(holder, external_elements_kind); |
246 JSObject::SetMapAndElements(holder, map, elements); | 247 JSObject::SetMapAndElements(holder, map, elements); |
247 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); | 248 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); |
248 } else { | 249 } else { |
249 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 250 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
250 Runtime::SetupArrayBuffer(isolate, buffer, true, NULL, byte_length, | 251 Runtime::SetupArrayBuffer(isolate, buffer, true, NULL, byte_length, |
251 SharedFlag::kNotShared); | 252 SharedFlag::kNotShared); |
252 holder->set_buffer(*buffer); | 253 holder->set_buffer(*buffer); |
253 Handle<FixedTypedArrayBase> elements = | 254 Handle<FixedTypedArrayBase> elements = |
254 isolate->factory()->NewFixedTypedArray(static_cast<int>(length), | 255 isolate->factory()->NewFixedTypedArray(static_cast<int>(length), |
255 array_type); | 256 array_type, initialize); |
256 holder->set_elements(*elements); | 257 holder->set_elements(*elements); |
257 } | 258 } |
258 return isolate->heap()->undefined_value(); | 259 return isolate->heap()->undefined_value(); |
259 } | 260 } |
260 | 261 |
261 | 262 |
262 // Initializes a typed array from an array-like object. | 263 // Initializes a typed array from an array-like object. |
263 // If an array-like object happens to be a typed array of the same type, | 264 // If an array-like object happens to be a typed array of the same type, |
264 // initializes backing store using memove. | 265 // initializes backing store using memove. |
265 // | 266 // |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 DATA_VIEW_SETTER(Uint16, uint16_t) | 722 DATA_VIEW_SETTER(Uint16, uint16_t) |
722 DATA_VIEW_SETTER(Int16, int16_t) | 723 DATA_VIEW_SETTER(Int16, int16_t) |
723 DATA_VIEW_SETTER(Uint32, uint32_t) | 724 DATA_VIEW_SETTER(Uint32, uint32_t) |
724 DATA_VIEW_SETTER(Int32, int32_t) | 725 DATA_VIEW_SETTER(Int32, int32_t) |
725 DATA_VIEW_SETTER(Float32, float) | 726 DATA_VIEW_SETTER(Float32, float) |
726 DATA_VIEW_SETTER(Float64, double) | 727 DATA_VIEW_SETTER(Float64, double) |
727 | 728 |
728 #undef DATA_VIEW_SETTER | 729 #undef DATA_VIEW_SETTER |
729 } // namespace internal | 730 } // namespace internal |
730 } // namespace v8 | 731 } // namespace v8 |
OLD | NEW |