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

Side by Side 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: . 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 unified diff | Download patch
OLDNEW
1 {% extends 'interface_base.cpp' %} 1 {% extends 'interface_base.cpp' %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% block indexed_property_getter %} 5 {% block indexed_property_getter %}
6 {% if indexed_property_getter and not indexed_property_getter.is_custom %} 6 {% if indexed_property_getter and not indexed_property_getter.is_custom %}
7 {% set getter = indexed_property_getter %} 7 {% set getter = indexed_property_getter %}
8 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo <v8::Value>& info) 8 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo <v8::Value>& info)
9 { 9 {
10 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 10 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 if (v8buffer->IsExternal()) { 813 if (v8buffer->IsExternal()) {
814 const WrapperTypeInfo* wrapperTypeInfo = toWrapperTypeInfo(object); 814 const WrapperTypeInfo* wrapperTypeInfo = toWrapperTypeInfo(object);
815 RELEASE_ASSERT(wrapperTypeInfo); 815 RELEASE_ASSERT(wrapperTypeInfo);
816 RELEASE_ASSERT(wrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink); 816 RELEASE_ASSERT(wrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink);
817 return toScriptWrappable(object)->toImpl<{{cpp_class}}>(); 817 return toScriptWrappable(object)->toImpl<{{cpp_class}}>();
818 } 818 }
819 819
820 // Transfer the ownership of the allocated memory to an ArrayBuffer without 820 // Transfer the ownership of the allocated memory to an ArrayBuffer without
821 // copying. 821 // copying.
822 v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize(); 822 v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize();
823 WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength() , 0); 823 WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength() , WTF::ArrayBufferContents::NotShared, 0);
824 RefPtr<{{cpp_class}}> buffer = {{cpp_class}}::create(contents); 824 RefPtr<{{cpp_class}}> buffer = {{cpp_class}}::create(contents);
825 // Since this transfer doesn't allocate new memory, do not call 825 // Since this transfer doesn't allocate new memory, do not call
826 // DOMArrayBufferDeallocationObserver::blinkAllocatedMemory. 826 // DOMArrayBufferDeallocationObserver::blinkAllocatedMemory.
827 buffer->buffer()->setDeallocationObserverWithoutAllocationNotification(
828 DOMArrayBufferDeallocationObserver::instance());
829 buffer->associateWithWrapper(v8::Isolate::GetCurrent(), buffer->wrapperTypeI nfo(), object);
830
831 return buffer.get();
832 }
833
834 {% elif interface_name == 'SharedArrayBuffer' %}
835 {{cpp_class}}* V8SharedArrayBuffer::toImpl(v8::Local<v8::Object> object)
836 {
837 ASSERT(object->IsSharedArrayBuffer());
838 v8::Local<v8::SharedArrayBuffer> v8buffer = object.As<v8::SharedArrayBuffer> ();
839 if (v8buffer->IsExternal()) {
840 const WrapperTypeInfo* wrapperTypeInfo = toWrapperTypeInfo(object);
841 RELEASE_ASSERT(wrapperTypeInfo);
842 RELEASE_ASSERT(wrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink);
843 return toScriptWrappable(object)->toImpl<{{cpp_class}}>();
844 }
845
846 // Transfer the ownership of the allocated memory to a SharedArrayBuffer
847 // without copying.
848 v8::SharedArrayBuffer::Contents v8Contents = v8buffer->Externalize();
849 WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength() , WTF::ArrayBufferContents::Shared, 0);
850 RefPtr<{{cpp_class}}> buffer = {{cpp_class}}::create(contents);
851 // Since this transfer doesn't allocate new memory, do not call
852 // DOMArrayBufferDeallocationObserver::blinkAllocatedMemory.
827 buffer->buffer()->setDeallocationObserverWithoutAllocationNotification( 853 buffer->buffer()->setDeallocationObserverWithoutAllocationNotification(
828 DOMArrayBufferDeallocationObserver::instance()); 854 DOMArrayBufferDeallocationObserver::instance());
829 buffer->associateWithWrapper(v8::Isolate::GetCurrent(), buffer->wrapperTypeI nfo(), object); 855 buffer->associateWithWrapper(v8::Isolate::GetCurrent(), buffer->wrapperTypeI nfo(), object);
830 856
831 return buffer.get(); 857 return buffer.get();
832 } 858 }
833 859
834 {% elif interface_name == 'ArrayBufferView' %} 860 {% elif interface_name == 'ArrayBufferView' %}
835 {{cpp_class}}* V8ArrayBufferView::toImpl(v8::Local<v8::Object> object) 861 {{cpp_class}}* V8ArrayBufferView::toImpl(v8::Local<v8::Object> object)
836 { 862 {
(...skipping 29 matching lines...) Expand all
866 892
867 {% elif is_array_buffer_or_view %} 893 {% elif is_array_buffer_or_view %}
868 {{cpp_class}}* {{v8_class}}::toImpl(v8::Local<v8::Object> object) 894 {{cpp_class}}* {{v8_class}}::toImpl(v8::Local<v8::Object> object)
869 { 895 {
870 ASSERT(object->Is{{interface_name}}()); 896 ASSERT(object->Is{{interface_name}}());
871 ScriptWrappable* scriptWrappable = toScriptWrappable(object); 897 ScriptWrappable* scriptWrappable = toScriptWrappable(object);
872 if (scriptWrappable) 898 if (scriptWrappable)
873 return scriptWrappable->toImpl<{{cpp_class}}>(); 899 return scriptWrappable->toImpl<{{cpp_class}}>();
874 900
875 v8::Local<v8::{{interface_name}}> v8View = object.As<v8::{{interface_name}}> (); 901 v8::Local<v8::{{interface_name}}> v8View = object.As<v8::{{interface_name}}> ();
876 RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toIm pl(v8View->Buffer()), v8View->ByteOffset(), v8View->{% if interface_name == 'Dat aView' %}Byte{% endif %}Length()); 902 {% if interface_name == 'DataView' %}
903 RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toIm pl(v8View->Buffer()), v8View->ByteOffset(), v8View->ByteLength());
904 {% else %}
905 v8::Local<v8::Object> arrayBuffer = v8View->Buffer();
906 RefPtr<{{cpp_class}}> typedArray;
907 if (arrayBuffer->IsArrayBuffer()) {
908 typedArray = {{cpp_class}}::create(V8ArrayBuffer::toImpl(arrayBuffer), v 8View->ByteOffset(), v8View->Length());
909 } else if (arrayBuffer->IsSharedArrayBuffer()) {
910 typedArray = {{cpp_class}}::create(V8SharedArrayBuffer::toImpl(arrayBuff er), v8View->ByteOffset(), v8View->Length());
911 } else {
912 ASSERT_NOT_REACHED();
913 }
914 {% endif %}
877 typedArray->associateWithWrapper(v8::Isolate::GetCurrent(), typedArray->wrap perTypeInfo(), object); 915 typedArray->associateWithWrapper(v8::Isolate::GetCurrent(), typedArray->wrap perTypeInfo(), object);
878 916
879 return typedArray->toImpl<{{cpp_class}}>(); 917 return typedArray->toImpl<{{cpp_class}}>();
880 } 918 }
881 919
882 {% endif %} 920 {% endif %}
883 {% endblock %} 921 {% endblock %}
884 922
885 923
886 {##############################################################################} 924 {##############################################################################}
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 } 1076 }
1039 1077
1040 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} 1078 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %}
1041 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) 1079 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&))
1042 { 1080 {
1043 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; 1081 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method;
1044 } 1082 }
1045 {% endfor %} 1083 {% endfor %}
1046 {% endif %} 1084 {% endif %}
1047 {% endblock %} 1085 {% endblock %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698