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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index f6398aedf5ea50100398db2b73a20edb5984c9b8..c76f826ae9eb4ff76387732b74d3e0bc012fd21a 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6425,6 +6425,39 @@ Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
}
+size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) {
+ i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
+ i::Isolate* isolate = obj->GetIsolate();
+ size_t byte_offset = i::NumberToSize(isolate, obj->byte_offset());
+ size_t bytes_to_copy =
+ i::Min(byte_length, i::NumberToSize(isolate, obj->byte_length()));
+ if (bytes_to_copy) {
+ i::DisallowHeapAllocation no_gc;
+ const char* source = nullptr;
+ if (obj->IsJSDataView()) {
+ i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
+ i::Handle<i::JSArrayBuffer> buffer(
+ i::JSArrayBuffer::cast(data_view->buffer()));
+ source = reinterpret_cast<char*>(buffer->backing_store());
+ } else {
+ DCHECK(obj->IsJSTypedArray());
+ i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*obj));
+ if (typed_array->buffer()->IsSmi()) {
+ i::Handle<i::FixedTypedArrayBase> fixed_array(
+ i::FixedTypedArrayBase::cast(typed_array->elements()));
+ source = reinterpret_cast<char*>(fixed_array->DataPtr());
+ } else {
+ i::Handle<i::JSArrayBuffer> buffer(
+ i::JSArrayBuffer::cast(typed_array->buffer()));
+ source = reinterpret_cast<char*>(buffer->backing_store());
+ }
+ }
+ memcpy(dest, source + byte_offset, bytes_to_copy);
+ }
+ return bytes_to_copy;
+}
+
+
size_t v8::ArrayBufferView::ByteOffset() {
i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
return static_cast<size_t>(obj->byte_offset()->Number());
« 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