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/runtime/runtime.h" | 8 #include "src/runtime/runtime.h" |
9 #include "src/runtime/runtime-utils.h" | 9 #include "src/runtime/runtime-utils.h" |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 reinterpret_cast<v8::Isolate*>(isolate) | 82 reinterpret_cast<v8::Isolate*>(isolate) |
83 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 83 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
84 | 84 |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 | 88 |
89 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) { | 89 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) { |
90 Isolate* isolate = array_buffer->GetIsolate(); | 90 Isolate* isolate = array_buffer->GetIsolate(); |
| 91 // Firstly, iterate over the views which are referenced directly by the array |
| 92 // buffer. |
91 for (Handle<Object> view_obj(array_buffer->weak_first_view(), isolate); | 93 for (Handle<Object> view_obj(array_buffer->weak_first_view(), isolate); |
92 !view_obj->IsUndefined();) { | 94 !view_obj->IsUndefined();) { |
93 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj)); | 95 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj)); |
94 if (view->IsJSTypedArray()) { | 96 if (view->IsJSTypedArray()) { |
95 JSTypedArray::cast(*view)->Neuter(); | 97 JSTypedArray::cast(*view)->Neuter(); |
96 } else if (view->IsJSDataView()) { | 98 } else if (view->IsJSDataView()) { |
97 JSDataView::cast(*view)->Neuter(); | 99 JSDataView::cast(*view)->Neuter(); |
98 } else { | 100 } else { |
99 UNREACHABLE(); | 101 UNREACHABLE(); |
100 } | 102 } |
101 view_obj = handle(view->weak_next(), isolate); | 103 view_obj = handle(view->weak_next(), isolate); |
102 } | 104 } |
| 105 |
| 106 // Secondly, iterate over the global list of new space views to find views |
| 107 // that belong to the neutered array buffer. |
| 108 Heap* heap = isolate->heap(); |
| 109 for (Handle<Object> view_obj(heap->new_array_buffer_views_list(), isolate); |
| 110 !view_obj->IsUndefined();) { |
| 111 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj)); |
| 112 if (view->buffer() == *array_buffer) { |
| 113 if (view->IsJSTypedArray()) { |
| 114 JSTypedArray::cast(*view)->Neuter(); |
| 115 } else if (view->IsJSDataView()) { |
| 116 JSDataView::cast(*view)->Neuter(); |
| 117 } else { |
| 118 UNREACHABLE(); |
| 119 } |
| 120 } |
| 121 view_obj = handle(view->weak_next(), isolate); |
| 122 } |
103 array_buffer->Neuter(); | 123 array_buffer->Neuter(); |
104 } | 124 } |
105 | 125 |
106 | 126 |
107 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { | 127 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { |
108 HandleScope scope(isolate); | 128 HandleScope scope(isolate); |
109 DCHECK(args.length() == 2); | 129 DCHECK(args.length() == 2); |
110 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 130 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); |
111 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); | 131 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); |
112 if (!holder->byte_length()->IsUndefined()) { | 132 if (!holder->byte_length()->IsUndefined()) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DCHECK(holder->GetInternalFieldCount() == | 278 DCHECK(holder->GetInternalFieldCount() == |
259 v8::ArrayBufferView::kInternalFieldCount); | 279 v8::ArrayBufferView::kInternalFieldCount); |
260 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 280 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
261 holder->SetInternalField(i, Smi::FromInt(0)); | 281 holder->SetInternalField(i, Smi::FromInt(0)); |
262 } | 282 } |
263 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 283 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
264 holder->set_length(*length_obj); | 284 holder->set_length(*length_obj); |
265 holder->set_byte_offset(*byte_offset_object); | 285 holder->set_byte_offset(*byte_offset_object); |
266 holder->set_byte_length(*byte_length_object); | 286 holder->set_byte_length(*byte_length_object); |
267 | 287 |
| 288 Heap* heap = isolate->heap(); |
268 if (!maybe_buffer->IsNull()) { | 289 if (!maybe_buffer->IsNull()) { |
269 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); | 290 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); |
270 holder->set_buffer(*buffer); | 291 holder->set_buffer(*buffer); |
271 holder->set_weak_next(buffer->weak_first_view()); | 292 |
272 buffer->set_weak_first_view(*holder); | 293 if (heap->InNewSpace(*holder)) { |
| 294 holder->set_weak_next(heap->new_array_buffer_views_list()); |
| 295 heap->set_new_array_buffer_views_list(*holder); |
| 296 } else { |
| 297 holder->set_weak_next(buffer->weak_first_view()); |
| 298 buffer->set_weak_first_view(*holder); |
| 299 } |
273 | 300 |
274 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( | 301 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( |
275 static_cast<int>(length), array_type, | 302 static_cast<int>(length), array_type, |
276 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 303 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
277 Handle<Map> map = | 304 Handle<Map> map = |
278 JSObject::GetElementsTransitionMap(holder, external_elements_kind); | 305 JSObject::GetElementsTransitionMap(holder, external_elements_kind); |
279 JSObject::SetMapAndElements(holder, map, elements); | 306 JSObject::SetMapAndElements(holder, map, elements); |
280 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); | 307 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); |
281 } else { | 308 } else { |
282 holder->set_buffer(Smi::FromInt(0)); | 309 holder->set_buffer(Smi::FromInt(0)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 isolate, NewRangeError("invalid_array_buffer_length", | 387 isolate, NewRangeError("invalid_array_buffer_length", |
361 HandleVector<Object>(NULL, 0))); | 388 HandleVector<Object>(NULL, 0))); |
362 } | 389 } |
363 | 390 |
364 holder->set_buffer(*buffer); | 391 holder->set_buffer(*buffer); |
365 holder->set_byte_offset(Smi::FromInt(0)); | 392 holder->set_byte_offset(Smi::FromInt(0)); |
366 Handle<Object> byte_length_obj( | 393 Handle<Object> byte_length_obj( |
367 isolate->factory()->NewNumberFromSize(byte_length)); | 394 isolate->factory()->NewNumberFromSize(byte_length)); |
368 holder->set_byte_length(*byte_length_obj); | 395 holder->set_byte_length(*byte_length_obj); |
369 holder->set_length(*length_obj); | 396 holder->set_length(*length_obj); |
370 holder->set_weak_next(buffer->weak_first_view()); | 397 |
371 buffer->set_weak_first_view(*holder); | 398 Heap* heap = isolate->heap(); |
| 399 if (heap->InNewSpace(*holder)) { |
| 400 holder->set_weak_next(heap->new_array_buffer_views_list()); |
| 401 heap->set_new_array_buffer_views_list(*holder); |
| 402 } else { |
| 403 holder->set_weak_next(buffer->weak_first_view()); |
| 404 buffer->set_weak_first_view(*holder); |
| 405 } |
372 | 406 |
373 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( | 407 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( |
374 static_cast<int>(length), array_type, | 408 static_cast<int>(length), array_type, |
375 static_cast<uint8_t*>(buffer->backing_store())); | 409 static_cast<uint8_t*>(buffer->backing_store())); |
376 Handle<Map> map = | 410 Handle<Map> map = |
377 JSObject::GetElementsTransitionMap(holder, external_elements_kind); | 411 JSObject::GetElementsTransitionMap(holder, external_elements_kind); |
378 JSObject::SetMapAndElements(holder, map, elements); | 412 JSObject::SetMapAndElements(holder, map, elements); |
379 | 413 |
380 if (source->IsJSTypedArray()) { | 414 if (source->IsJSTypedArray()) { |
381 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); | 415 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Entire range [offset, offset + length] must be in bounds. | 569 // Entire range [offset, offset + length] must be in bounds. |
536 RUNTIME_ASSERT(offset <= buffer_length); | 570 RUNTIME_ASSERT(offset <= buffer_length); |
537 RUNTIME_ASSERT(offset + length <= buffer_length); | 571 RUNTIME_ASSERT(offset + length <= buffer_length); |
538 // No overflow. | 572 // No overflow. |
539 RUNTIME_ASSERT(offset + length >= offset); | 573 RUNTIME_ASSERT(offset + length >= offset); |
540 | 574 |
541 holder->set_buffer(*buffer); | 575 holder->set_buffer(*buffer); |
542 holder->set_byte_offset(*byte_offset); | 576 holder->set_byte_offset(*byte_offset); |
543 holder->set_byte_length(*byte_length); | 577 holder->set_byte_length(*byte_length); |
544 | 578 |
545 holder->set_weak_next(buffer->weak_first_view()); | 579 Heap* heap = isolate->heap(); |
546 buffer->set_weak_first_view(*holder); | 580 if (heap->InNewSpace(*holder)) { |
| 581 holder->set_weak_next(heap->new_array_buffer_views_list()); |
| 582 heap->set_new_array_buffer_views_list(*holder); |
| 583 } else { |
| 584 holder->set_weak_next(buffer->weak_first_view()); |
| 585 buffer->set_weak_first_view(*holder); |
| 586 } |
547 | 587 |
548 return isolate->heap()->undefined_value(); | 588 return isolate->heap()->undefined_value(); |
549 } | 589 } |
550 | 590 |
551 | 591 |
552 inline static bool NeedToFlipBytes(bool is_little_endian) { | 592 inline static bool NeedToFlipBytes(bool is_little_endian) { |
553 #ifdef V8_TARGET_LITTLE_ENDIAN | 593 #ifdef V8_TARGET_LITTLE_ENDIAN |
554 return !is_little_endian; | 594 return !is_little_endian; |
555 #else | 595 #else |
556 return is_little_endian; | 596 return is_little_endian; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 DATA_VIEW_SETTER(Uint16, uint16_t) | 801 DATA_VIEW_SETTER(Uint16, uint16_t) |
762 DATA_VIEW_SETTER(Int16, int16_t) | 802 DATA_VIEW_SETTER(Int16, int16_t) |
763 DATA_VIEW_SETTER(Uint32, uint32_t) | 803 DATA_VIEW_SETTER(Uint32, uint32_t) |
764 DATA_VIEW_SETTER(Int32, int32_t) | 804 DATA_VIEW_SETTER(Int32, int32_t) |
765 DATA_VIEW_SETTER(Float32, float) | 805 DATA_VIEW_SETTER(Float32, float) |
766 DATA_VIEW_SETTER(Float64, double) | 806 DATA_VIEW_SETTER(Float64, double) |
767 | 807 |
768 #undef DATA_VIEW_SETTER | 808 #undef DATA_VIEW_SETTER |
769 } | 809 } |
770 } // namespace v8::internal | 810 } // namespace v8::internal |
OLD | NEW |