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

Side by Side Diff: src/api.cc

Issue 1095083002: Allow for accessing an ArrayBuffer contents without externalizing it (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/test-typedarrays.cc » ('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 6358 matching lines...) Expand 10 before | Expand all | Expand 10 after
6369 return Utils::OpenHandle(this)->is_external(); 6369 return Utils::OpenHandle(this)->is_external();
6370 } 6370 }
6371 6371
6372 6372
6373 bool v8::ArrayBuffer::IsNeuterable() const { 6373 bool v8::ArrayBuffer::IsNeuterable() const {
6374 return Utils::OpenHandle(this)->is_neuterable(); 6374 return Utils::OpenHandle(this)->is_neuterable();
6375 } 6375 }
6376 6376
6377 6377
6378 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { 6378 v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
6379 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6379 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
6380 Utils::ApiCheck(!obj->is_external(), 6380 Utils::ApiCheck(!self->is_external(), "v8::ArrayBuffer::Externalize",
6381 "v8::ArrayBuffer::Externalize",
6382 "ArrayBuffer already externalized"); 6381 "ArrayBuffer already externalized");
6383 obj->set_is_external(true); 6382 self->set_is_external(true);
6384 size_t byte_length = static_cast<size_t>(obj->byte_length()->Number()); 6383 return GetContents();
6384 }
6385
6386
6387 v8::ArrayBuffer::Contents v8::ArrayBuffer::GetContents() {
6388 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
6389 size_t byte_length = static_cast<size_t>(self->byte_length()->Number());
6385 Contents contents; 6390 Contents contents;
6386 contents.data_ = obj->backing_store(); 6391 contents.data_ = self->backing_store();
6387 contents.byte_length_ = byte_length; 6392 contents.byte_length_ = byte_length;
6388 return contents; 6393 return contents;
6389 } 6394 }
6390 6395
6391 6396
6392 void v8::ArrayBuffer::Neuter() { 6397 void v8::ArrayBuffer::Neuter() {
6393 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6398 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6394 i::Isolate* isolate = obj->GetIsolate(); 6399 i::Isolate* isolate = obj->GetIsolate();
6395 Utils::ApiCheck(obj->is_external(), 6400 Utils::ApiCheck(obj->is_external(),
6396 "v8::ArrayBuffer::Neuter", 6401 "v8::ArrayBuffer::Neuter",
(...skipping 17 matching lines...) Expand all
6414 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)"); 6419 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
6415 ENTER_V8(i_isolate); 6420 ENTER_V8(i_isolate);
6416 i::Handle<i::JSArrayBuffer> obj = 6421 i::Handle<i::JSArrayBuffer> obj =
6417 i_isolate->factory()->NewJSArrayBuffer(); 6422 i_isolate->factory()->NewJSArrayBuffer();
6418 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length); 6423 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
6419 return Utils::ToLocal(obj); 6424 return Utils::ToLocal(obj);
6420 } 6425 }
6421 6426
6422 6427
6423 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, 6428 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
6424 size_t byte_length) { 6429 size_t byte_length,
6430 ArrayBufferCreationMode mode) {
6425 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6431 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6426 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6432 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
6427 ENTER_V8(i_isolate); 6433 ENTER_V8(i_isolate);
6428 i::Handle<i::JSArrayBuffer> obj = 6434 i::Handle<i::JSArrayBuffer> obj =
6429 i_isolate->factory()->NewJSArrayBuffer(); 6435 i_isolate->factory()->NewJSArrayBuffer();
6430 i::Runtime::SetupArrayBuffer(i_isolate, obj, true, data, byte_length); 6436 i::Runtime::SetupArrayBuffer(i_isolate, obj,
6437 mode == ArrayBufferCreationMode::kExternalized,
6438 data, byte_length);
6431 return Utils::ToLocal(obj); 6439 return Utils::ToLocal(obj);
6432 } 6440 }
6433 6441
6434 6442
6435 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { 6443 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
6436 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); 6444 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6437 i::Handle<i::JSArrayBuffer> buffer; 6445 i::Handle<i::JSArrayBuffer> buffer;
6438 if (obj->IsJSDataView()) { 6446 if (obj->IsJSDataView()) {
6439 i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj)); 6447 i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
6440 DCHECK(data_view->buffer()->IsJSArrayBuffer()); 6448 DCHECK(data_view->buffer()->IsJSArrayBuffer());
(...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after
8143 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8151 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8144 Address callback_address = 8152 Address callback_address =
8145 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8153 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8146 VMState<EXTERNAL> state(isolate); 8154 VMState<EXTERNAL> state(isolate);
8147 ExternalCallbackScope call_scope(isolate, callback_address); 8155 ExternalCallbackScope call_scope(isolate, callback_address);
8148 callback(info); 8156 callback(info);
8149 } 8157 }
8150 8158
8151 8159
8152 } } // namespace v8::internal 8160 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-typedarrays.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698