Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/api.cc

Issue 1041403003: Expose an API on ArrayBufferView to copy out content w/o changing the buffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 i::Isolate* isolate = obj->GetIsolate();
6431 size_t byte_offset = i::NumberToSize(isolate, obj->byte_offset());
6432 size_t bytes_to_copy =
6433 i::Min(byte_length, i::NumberToSize(isolate, obj->byte_length()));
6434 if (bytes_to_copy) {
6435 i::DisallowHeapAllocation no_gc;
6436 const char* source = nullptr;
6437 if (obj->IsJSDataView()) {
6438 i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
6439 i::Handle<i::JSArrayBuffer> buffer(
6440 i::JSArrayBuffer::cast(data_view->buffer()));
6441 source = reinterpret_cast<char*>(buffer->backing_store());
6442 } else {
6443 DCHECK(obj->IsJSTypedArray());
6444 i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj));
6445 if (typed_array->buffer()->IsSmi()) {
6446 i::Handle<i::FixedTypedArrayBase> fixed_array(
6447 i::FixedTypedArrayBase::cast(typed_array->elements()));
6448 source = reinterpret_cast<char*>(fixed_array->DataPtr());
6449 } else {
6450 i::Handle<i::JSArrayBuffer> buffer(
6451 i::JSArrayBuffer::cast(typed_array->buffer()));
6452 source = reinterpret_cast<char*>(buffer->backing_store());
6453 }
6454 }
6455 memcpy(dest, source + byte_offset, bytes_to_copy);
6456 }
6457 return bytes_to_copy;
6458 }
6459
6460
6428 size_t v8::ArrayBufferView::ByteOffset() { 6461 size_t v8::ArrayBufferView::ByteOffset() {
6429 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); 6462 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6430 return static_cast<size_t>(obj->byte_offset()->Number()); 6463 return static_cast<size_t>(obj->byte_offset()->Number());
6431 } 6464 }
6432 6465
6433 6466
6434 size_t v8::ArrayBufferView::ByteLength() { 6467 size_t v8::ArrayBufferView::ByteLength() {
6435 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); 6468 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6436 return static_cast<size_t>(obj->byte_length()->Number()); 6469 return static_cast<size_t>(obj->byte_length()->Number());
6437 } 6470 }
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
8054 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8087 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8055 Address callback_address = 8088 Address callback_address =
8056 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8089 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8057 VMState<EXTERNAL> state(isolate); 8090 VMState<EXTERNAL> state(isolate);
8058 ExternalCallbackScope call_scope(isolate, callback_address); 8091 ExternalCallbackScope call_scope(isolate, callback_address);
8059 callback(info); 8092 callback(info);
8060 } 8093 }
8061 8094
8062 8095
8063 } } // namespace v8::internal 8096 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698