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 6407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6418 DCHECK(data_view->buffer()->IsJSArrayBuffer()); | 6418 DCHECK(data_view->buffer()->IsJSArrayBuffer()); |
6419 buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer())); | 6419 buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer())); |
6420 } else { | 6420 } else { |
6421 DCHECK(obj->IsJSTypedArray()); | 6421 DCHECK(obj->IsJSTypedArray()); |
6422 buffer = i::JSTypedArray::cast(*obj)->GetBuffer(); | 6422 buffer = i::JSTypedArray::cast(*obj)->GetBuffer(); |
6423 } | 6423 } |
6424 return Utils::ToLocal(buffer); | 6424 return Utils::ToLocal(buffer); |
6425 } | 6425 } |
6426 | 6426 |
6427 | 6427 |
6428 size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) { | |
6429 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | |
6430 size_t byte_offset = static_cast<size_t>(obj->byte_offset()->Number()); | |
Dmitry Lomov (no reviews)
2015/04/01 08:48:57
Use NumberToSize function
| |
6431 size_t bytes_to_copy = | |
6432 i::Min(byte_length, static_cast<size_t>(obj->byte_length()->Number())); | |
Dmitry Lomov (no reviews)
2015/04/01 08:48:57
Use NumberToSize function
| |
6433 if (bytes_to_copy) { | |
6434 const char* source = nullptr; | |
Dmitry Lomov (no reviews)
2015/04/01 08:48:57
Since you operate with raw pointers into V8 heap,
| |
6435 if (obj->IsJSDataView()) { | |
6436 i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj)); | |
6437 i::Handle<i::JSArrayBuffer> buffer( | |
6438 i::JSArrayBuffer::cast(data_view->buffer())); | |
6439 source = reinterpret_cast<char*>(buffer->backing_store()); | |
6440 } else { | |
6441 DCHECK(obj->IsJSTypedArray()); | |
6442 i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj)); | |
6443 if (typed_array->buffer()->IsSmi()) { | |
6444 i::Handle<i::FixedTypedArrayBase> fixed_array( | |
6445 i::FixedTypedArrayBase::cast(typed_array->elements())); | |
6446 source = reinterpret_cast<char*>(fixed_array->DataPtr()); | |
6447 } else { | |
6448 i::Handle<i::JSArrayBuffer> buffer( | |
6449 i::JSArrayBuffer::cast(typed_array->buffer())); | |
6450 source = reinterpret_cast<char*>(buffer->backing_store()); | |
6451 } | |
6452 } | |
6453 memcpy(dest, source + byte_offset, bytes_to_copy); | |
6454 } | |
6455 return bytes_to_copy; | |
6456 } | |
6457 | |
6458 | |
6428 size_t v8::ArrayBufferView::ByteOffset() { | 6459 size_t v8::ArrayBufferView::ByteOffset() { |
6429 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6460 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
6430 return static_cast<size_t>(obj->byte_offset()->Number()); | 6461 return static_cast<size_t>(obj->byte_offset()->Number()); |
6431 } | 6462 } |
6432 | 6463 |
6433 | 6464 |
6434 size_t v8::ArrayBufferView::ByteLength() { | 6465 size_t v8::ArrayBufferView::ByteLength() { |
6435 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6466 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
6436 return static_cast<size_t>(obj->byte_length()->Number()); | 6467 return static_cast<size_t>(obj->byte_length()->Number()); |
6437 } | 6468 } |
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8054 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8085 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8055 Address callback_address = | 8086 Address callback_address = |
8056 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8087 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8057 VMState<EXTERNAL> state(isolate); | 8088 VMState<EXTERNAL> state(isolate); |
8058 ExternalCallbackScope call_scope(isolate, callback_address); | 8089 ExternalCallbackScope call_scope(isolate, callback_address); |
8059 callback(info); | 8090 callback(info); |
8060 } | 8091 } |
8061 | 8092 |
8062 | 8093 |
8063 } } // namespace v8::internal | 8094 } } // namespace v8::internal |
OLD | NEW |