OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 6318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6329 buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer())); | 6329 buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer())); |
6330 } else { | 6330 } else { |
6331 DCHECK(obj->IsJSTypedArray()); | 6331 DCHECK(obj->IsJSTypedArray()); |
6332 buffer = i::JSTypedArray::cast(*obj)->GetBuffer(); | 6332 buffer = i::JSTypedArray::cast(*obj)->GetBuffer(); |
6333 } | 6333 } |
6334 return Utils::ToLocal(buffer); | 6334 return Utils::ToLocal(buffer); |
6335 } | 6335 } |
6336 | 6336 |
6337 | 6337 |
6338 size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) { | 6338 size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) { |
6339 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6339 i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this); |
6340 i::Isolate* isolate = obj->GetIsolate(); | 6340 i::Isolate* isolate = self->GetIsolate(); |
6341 size_t byte_offset = i::NumberToSize(isolate, obj->byte_offset()); | 6341 size_t byte_offset = i::NumberToSize(isolate, self->byte_offset()); |
6342 size_t bytes_to_copy = | 6342 size_t bytes_to_copy = |
6343 i::Min(byte_length, i::NumberToSize(isolate, obj->byte_length())); | 6343 i::Min(byte_length, i::NumberToSize(isolate, self->byte_length())); |
6344 if (bytes_to_copy) { | 6344 if (bytes_to_copy) { |
6345 i::DisallowHeapAllocation no_gc; | 6345 i::DisallowHeapAllocation no_gc; |
6346 const char* source = nullptr; | 6346 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer())); |
6347 if (obj->IsJSDataView()) { | 6347 const char* source = reinterpret_cast<char*>(buffer->backing_store()); |
6348 i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj)); | 6348 if (source == nullptr) { |
6349 i::Handle<i::JSArrayBuffer> buffer( | 6349 DCHECK(self->IsJSTypedArray()); |
6350 i::JSArrayBuffer::cast(data_view->buffer())); | 6350 i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*self)); |
6351 source = reinterpret_cast<char*>(buffer->backing_store()); | 6351 i::Handle<i::FixedTypedArrayBase> fixed_array( |
6352 } else { | 6352 i::FixedTypedArrayBase::cast(typed_array->elements())); |
6353 DCHECK(obj->IsJSTypedArray()); | 6353 source = reinterpret_cast<char*>(fixed_array->DataPtr()); |
6354 i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj)); | |
6355 if (typed_array->buffer()->IsSmi()) { | |
6356 i::Handle<i::FixedTypedArrayBase> fixed_array( | |
6357 i::FixedTypedArrayBase::cast(typed_array->elements())); | |
6358 source = reinterpret_cast<char*>(fixed_array->DataPtr()); | |
6359 } else { | |
6360 i::Handle<i::JSArrayBuffer> buffer( | |
6361 i::JSArrayBuffer::cast(typed_array->buffer())); | |
6362 source = reinterpret_cast<char*>(buffer->backing_store()); | |
6363 } | |
6364 } | 6354 } |
6365 memcpy(dest, source + byte_offset, bytes_to_copy); | 6355 memcpy(dest, source + byte_offset, bytes_to_copy); |
6366 } | 6356 } |
6367 return bytes_to_copy; | 6357 return bytes_to_copy; |
6368 } | 6358 } |
6369 | 6359 |
6370 | 6360 |
6371 bool v8::ArrayBufferView::HasBuffer() const { | 6361 bool v8::ArrayBufferView::HasBuffer() const { |
6372 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6362 i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this); |
6373 if (obj->IsJSDataView()) return true; | 6363 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer())); |
6374 DCHECK(obj->IsJSTypedArray()); | 6364 return buffer->backing_store() != nullptr; |
6375 i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj)); | |
6376 return !typed_array->buffer()->IsSmi(); | |
6377 } | 6365 } |
6378 | 6366 |
6379 | 6367 |
6380 size_t v8::ArrayBufferView::ByteOffset() { | 6368 size_t v8::ArrayBufferView::ByteOffset() { |
6381 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6369 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
6382 return static_cast<size_t>(obj->byte_offset()->Number()); | 6370 return static_cast<size_t>(obj->byte_offset()->Number()); |
6383 } | 6371 } |
6384 | 6372 |
6385 | 6373 |
6386 size_t v8::ArrayBufferView::ByteLength() { | 6374 size_t v8::ArrayBufferView::ByteLength() { |
(...skipping 1656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8043 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8031 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8044 Address callback_address = | 8032 Address callback_address = |
8045 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8033 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8046 VMState<EXTERNAL> state(isolate); | 8034 VMState<EXTERNAL> state(isolate); |
8047 ExternalCallbackScope call_scope(isolate, callback_address); | 8035 ExternalCallbackScope call_scope(isolate, callback_address); |
8048 callback(info); | 8036 callback(info); |
8049 } | 8037 } |
8050 | 8038 |
8051 | 8039 |
8052 } } // namespace v8::internal | 8040 } } // namespace v8::internal |
OLD | NEW |