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

Unified Diff: Source/bindings/templates/interface.cpp

Issue 1097773004: Sharing of SharedArrayBuffer via PostMessage transfer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update for non-split typedarray hierarchy Created 5 years, 6 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
Index: Source/bindings/templates/interface.cpp
diff --git a/Source/bindings/templates/interface.cpp b/Source/bindings/templates/interface.cpp
index c736a026d980b26815bb35978f8932c83643e13c..edac6aa1df80a81aa6098ae76d8b8088c54e3cf7 100644
--- a/Source/bindings/templates/interface.cpp
+++ b/Source/bindings/templates/interface.cpp
@@ -725,7 +725,33 @@ v8::Local<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Local<v8::V
// Transfer the ownership of the allocated memory to an ArrayBuffer without
// copying.
v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize();
- WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(), 0);
+ WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(), false, 0);
+ RefPtr<{{cpp_class}}> buffer = {{cpp_class}}::create(contents);
+ // Since this transfer doesn't allocate new memory, do not call
+ // DOMArrayBufferDeallocationObserver::blinkAllocatedMemory.
+ buffer->buffer()->setDeallocationObserverWithoutAllocationNotification(
+ DOMArrayBufferDeallocationObserver::instance());
+ buffer->associateWithWrapper(v8::Isolate::GetCurrent(), buffer->wrapperTypeInfo(), object);
+
+ return buffer.get();
+}
+
+{% elif interface_name == 'SharedArrayBuffer' %}
+{{cpp_class}}* V8SharedArrayBuffer::toImpl(v8::Local<v8::Object> object)
+{
+ ASSERT(object->IsSharedArrayBuffer());
+ v8::Local<v8::SharedArrayBuffer> v8buffer = object.As<v8::SharedArrayBuffer>();
+ if (v8buffer->IsExternal()) {
+ const WrapperTypeInfo* wrapperTypeInfo = toWrapperTypeInfo(object);
+ RELEASE_ASSERT(wrapperTypeInfo);
+ RELEASE_ASSERT(wrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink);
+ return toScriptWrappable(object)->toImpl<{{cpp_class}}>();
+ }
+
+ // Transfer the ownership of the allocated memory to a SharedArrayBuffer
+ // without copying.
+ v8::SharedArrayBuffer::Contents v8Contents = v8buffer->Externalize();
+ WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(), true, 0);
RefPtr<{{cpp_class}}> buffer = {{cpp_class}}::create(contents);
// Since this transfer doesn't allocate new memory, do not call
// DOMArrayBufferDeallocationObserver::blinkAllocatedMemory.
@@ -778,7 +804,19 @@ v8::Local<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Local<v8::V
return scriptWrappable->toImpl<{{cpp_class}}>();
v8::Local<v8::{{interface_name}}> v8View = object.As<v8::{{interface_name}}>();
- RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toImpl(v8View->Buffer()), v8View->ByteOffset(), v8View->{% if interface_name == 'DataView' %}Byte{% endif %}Length());
+{% if interface_name == 'DataView' %}
+ RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toImpl(v8View->Buffer()), v8View->ByteOffset(), v8View->ByteLength());
+{% else %}
+ v8::Local<v8::Object> arrayBuffer = v8View->Buffer();
+ RefPtr<{{cpp_class}}> typedArray;
+ if (arrayBuffer->IsArrayBuffer()) {
+ typedArray = {{cpp_class}}::create(V8ArrayBuffer::toImpl(arrayBuffer), v8View->ByteOffset(), v8View->Length());
+ } else if (arrayBuffer->IsSharedArrayBuffer()) {
+ typedArray = {{cpp_class}}::create(V8SharedArrayBuffer::toImpl(arrayBuffer), v8View->ByteOffset(), v8View->Length());
+ } else {
+ ASSERT_NOT_REACHED();
+ }
+{% endif %}
typedArray->associateWithWrapper(v8::Isolate::GetCurrent(), typedArray->wrapperTypeInfo(), object);
return typedArray->toImpl<{{cpp_class}}>();

Powered by Google App Engine
This is Rietveld 408576698