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

Unified Diff: src/api.cc

Issue 1136553006: Implement SharedArrayBuffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge master Created 5 years, 7 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 | « src/api.h ('k') | src/arraybuffer.js » ('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 9fe3759c5edaa3b9ca22984e4aedd208ac6dbc36..9caaa8caf742e958605f9ade20e1f2b089baa907 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2679,7 +2679,8 @@ bool Value::IsArray() const {
bool Value::IsArrayBuffer() const {
- return Utils::OpenHandle(this)->IsJSArrayBuffer();
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared();
}
@@ -2700,6 +2701,7 @@ bool Value::IsTypedArray() const {
i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
}
+
TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
#undef VALUE_IS_TYPED_ARRAY
@@ -2710,6 +2712,12 @@ bool Value::IsDataView() const {
}
+bool Value::IsSharedArrayBuffer() const {
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared();
+}
+
+
bool Value::IsObject() const {
return Utils::OpenHandle(this)->IsJSObject();
}
@@ -3086,9 +3094,9 @@ void v8::Promise::Resolver::CheckCast(Value* that) {
void v8::ArrayBuffer::CheckCast(Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
- Utils::ApiCheck(obj->IsJSArrayBuffer(),
- "v8::ArrayBuffer::Cast()",
- "Could not convert to ArrayBuffer");
+ Utils::ApiCheck(
+ obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(),
+ "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer");
}
@@ -3131,6 +3139,15 @@ void v8::DataView::CheckCast(Value* that) {
}
+void v8::SharedArrayBuffer::CheckCast(Value* that) {
+ i::Handle<i::Object> obj = Utils::OpenHandle(that);
+ Utils::ApiCheck(
+ obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(),
+ "v8::SharedArrayBuffer::Cast()",
+ "Could not convert to SharedArrayBuffer");
+}
+
+
void v8::Date::CheckCast(v8::Value* that) {
i::Handle<i::Object> obj = Utils::OpenHandle(that);
i::Isolate* isolate = NULL;
@@ -6277,7 +6294,7 @@ Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
- i_isolate->factory()->NewJSArrayBuffer();
+ i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
return Utils::ToLocal(obj);
}
@@ -6290,7 +6307,7 @@ Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
- i_isolate->factory()->NewJSArrayBuffer();
+ i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
i::Runtime::SetupArrayBuffer(i_isolate, obj,
mode == ArrayBufferCreationMode::kExternalized,
data, byte_length);
@@ -6396,6 +6413,66 @@ Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
}
+bool v8::SharedArrayBuffer::IsExternal() const {
+ return Utils::OpenHandle(this)->is_external();
+}
+
+
+v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() {
+ i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
+ i::Isolate* isolate = self->GetIsolate();
+ Utils::ApiCheck(!self->is_external(), "v8::SharedArrayBuffer::Externalize",
+ "SharedArrayBuffer already externalized");
+ self->set_is_external(true);
+ isolate->heap()->UnregisterArrayBuffer(self->backing_store());
+ return GetContents();
+}
+
+
+v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() {
+ i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
+ size_t byte_length = static_cast<size_t>(self->byte_length()->Number());
+ Contents contents;
+ contents.data_ = self->backing_store();
+ contents.byte_length_ = byte_length;
+ return contents;
+}
+
+
+size_t v8::SharedArrayBuffer::ByteLength() const {
+ i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
+ return static_cast<size_t>(obj->byte_length()->Number());
+}
+
+
+Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
+ size_t byte_length) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)");
+ ENTER_V8(i_isolate);
+ i::Handle<i::JSArrayBuffer> obj =
+ i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
+ i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true,
+ i::SharedFlag::kShared);
+ return Utils::ToLocalShared(obj);
+}
+
+
+Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
+ Isolate* isolate, void* data, size_t byte_length,
+ ArrayBufferCreationMode mode) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)");
+ ENTER_V8(i_isolate);
+ i::Handle<i::JSArrayBuffer> obj =
+ i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
+ i::Runtime::SetupArrayBuffer(i_isolate, obj,
+ mode == ArrayBufferCreationMode::kExternalized,
+ data, byte_length, i::SharedFlag::kShared);
+ return Utils::ToLocalShared(obj);
+}
+
+
Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, "Symbol::New()");
« no previous file with comments | « src/api.h ('k') | src/arraybuffer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698