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

Side by Side Diff: Source/bindings/templates/interface.cpp

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 2 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 | Annotate | Revision Log
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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 720 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
721 static const V8DOMConfiguration::AttributeConfiguration {{method.name}}OriginSaf eAttributeConfiguration = { 721 static const V8DOMConfiguration::AttributeConfiguration {{method.name}}OriginSaf eAttributeConfiguration = {
722 "{{method.name}}", {{getter_callback}}, {{setter_callback}}, {{getter_callba ck_for_main_world}}, {{setter_callback_for_main_world}}, &{{v8_class}}::wrapperT ypeInfo, v8::ALL_CAN_READ, {{property_attribute}}, {{only_exposed_to_private_scr ipt}}, V8DOMConfiguration::OnInstance, 722 "{{method.name}}", {{getter_callback}}, {{setter_callback}}, {{getter_callba ck_for_main_world}}, {{setter_callback_for_main_world}}, &{{v8_class}}::wrapperT ypeInfo, v8::ALL_CAN_READ, {{property_attribute}}, {{only_exposed_to_private_scr ipt}}, V8DOMConfiguration::OnInstance,
723 }; 723 };
724 V8DOMConfiguration::installAttribute({{method.function_template}}, v8::Handle<v8 ::ObjectTemplate>(), {{method.name}}OriginSafeAttributeConfiguration, isolate); 724 V8DOMConfiguration::installAttribute({{method.function_template}}, v8::Handle<v8 ::ObjectTemplate>(), {{method.name}}OriginSafeAttributeConfiguration, isolate);
725 {%- endmacro %} 725 {%- endmacro %}
726 726
727 727
728 {##############################################################################} 728 {##############################################################################}
729 {% block get_dom_template %} 729 {% block get_dom_template %}
730 {% if is_v8object %}
730 v8::Handle<v8::FunctionTemplate> {{v8_class}}::domTemplate(v8::Isolate* isolate) 731 v8::Handle<v8::FunctionTemplate> {{v8_class}}::domTemplate(v8::Isolate* isolate)
731 { 732 {
732 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeI nfo*>(&wrapperTypeInfo), install{{v8_class}}Template); 733 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeI nfo*>(&wrapperTypeInfo), install{{v8_class}}Template);
733 } 734 }
734 735
736 {% endif %}
735 {% endblock %} 737 {% endblock %}
736 738
737 739
738 {##############################################################################} 740 {##############################################################################}
739 {% block has_instance %} 741 {% block has_instance %}
740 bool {{v8_class}}::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isola te) 742 bool {{v8_class}}::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isola te)
741 { 743 {
744 {% if is_v8object %}
742 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Valu e); 745 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Valu e);
746 {% else %}
747 return v8Value->Is{{interface_name}}();
748 {% endif %}
743 } 749 }
744 750
751 {% if is_v8object %}
745 v8::Handle<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Handle<v8: :Value> v8Value, v8::Isolate* isolate) 752 v8::Handle<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Handle<v8: :Value> v8Value, v8::Isolate* isolate)
746 { 753 {
747 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrappe rTypeInfo, v8Value); 754 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrappe rTypeInfo, v8Value);
748 } 755 }
749 756
757 {% endif %}
750 {% endblock %} 758 {% endblock %}
751 759
752 760
761 {##############################################################################}
762 {% block to_impl %}
763 {% if interface_name == 'ArrayBuffer' %}
764 DOMArrayBuffer* V8ArrayBuffer::toImpl(v8::Handle<v8::Object> object)
765 {
766 ASSERT(object->IsArrayBuffer());
767 v8::Local<v8::ArrayBuffer> v8buffer = object.As<v8::ArrayBuffer>();
768 if (v8buffer->IsExternal()) {
769 RELEASE_ASSERT(toWrapperTypeInfo(object)->ginEmbedder == gin::kEmbedderB link);
770 return blink::toScriptWrappableBase(object)->toImpl<DOMArrayBuffer>();
771 }
772
773 v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize();
774 WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength() , 0);
775 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(contents);
776 buffer->associateWithWrapper(buffer->wrapperTypeInfo(), object, v8::Isolate: :GetCurrent());
777
778 return blink::toScriptWrappableBase(object)->toImpl<DOMArrayBuffer>();
779 }
780 {% elif interface_name == 'ArrayBufferView' %}
781 DOMArrayBufferView* V8ArrayBufferView::toImpl(v8::Handle<v8::Object> object)
782 {
783 ASSERT(object->IsArrayBufferView());
784 ScriptWrappableBase* internalPointer = blink::toScriptWrappableBase(object);
785 if (internalPointer)
haraken 2014/10/16 05:41:41 BTW, let's rename internalPointer to scriptWrappab
Yuki 2014/10/16 14:21:50 Will do.
786 return internalPointer->toImpl<DOMArrayBufferView>();
787
788 if (object->IsInt8Array())
789 return V8Int8Array::toImpl(object);
790 if (object->IsInt16Array())
791 return V8Int16Array::toImpl(object);
792 if (object->IsInt32Array())
793 return V8Int32Array::toImpl(object);
794 if (object->IsUint8Array())
795 return V8Uint8Array::toImpl(object);
796 if (object->IsUint8ClampedArray())
797 return V8Uint8ClampedArray::toImpl(object);
798 if (object->IsUint16Array())
799 return V8Uint16Array::toImpl(object);
800 if (object->IsUint32Array())
801 return V8Uint32Array::toImpl(object);
802 if (object->IsFloat32Array())
803 return V8Float32Array::toImpl(object);
804 if (object->IsFloat64Array())
805 return V8Float64Array::toImpl(object);
806 if (object->IsDataView())
807 return V8DataView::toImpl(object);
808
809 ASSERT_NOT_REACHED();
810 return 0;
811 }
812 {% elif is_array_type %}
813 {{cpp_class}}* {{v8_class}}::toImpl(v8::Handle<v8::Object> object)
814 {
815 ASSERT(object->Is{{interface_name}}());
816 ScriptWrappableBase* internalPointer = blink::toScriptWrappableBase(object);
817 if (internalPointer)
haraken 2014/10/16 05:41:41 We have the internalPointer check both in V8ArrayB
Yuki 2014/10/16 14:21:50 It's a matter of the speed performance. Obviously
818 return internalPointer->toImpl<{{cpp_class}}>();
819
820 v8::Handle<v8::{{interface_name}}> v8View = object.As<v8::{{interface_name}} >();
821 RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toIm pl(v8View->Buffer()), v8View->ByteOffset(), v8View->{% if interface_name == 'Dat aView' %}Byte{% endif %}Length());
822 typedArray->associateWithWrapper(typedArray->wrapperTypeInfo(), object, v8:: Isolate::GetCurrent());
823
824 internalPointer = blink::toScriptWrappableBase(object);
825 ASSERT(internalPointer);
haraken 2014/10/16 05:41:41 ASSERT(internalPointer == typedArray) ?
Yuki 2014/10/16 14:21:50 Done.
826 return internalPointer->toImpl<{{cpp_class}}>();
haraken 2014/10/16 05:41:41 Actually it's redundant to get an internalPointer
Yuki 2014/10/16 14:21:50 Done.
827 }
828 {% endif %}
829 {% endblock %}
830
831
753 {##############################################################################} 832 {##############################################################################}
754 {% block to_impl_with_type_check %} 833 {% block to_impl_with_type_check %}
755 {{cpp_class}}* {{v8_class}}::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handl e<v8::Value> value) 834 {{cpp_class}}* {{v8_class}}::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handl e<v8::Value> value)
756 { 835 {
757 return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle <v8::Object>::Cast(value))->toImpl<{{cpp_class}}>() : 0; 836 return hasInstance(value, isolate) ? toImpl(v8::Handle<v8::Object>::Cast(val ue)) : 0;
758 } 837 }
759 838
760 {% endblock %} 839 {% endblock %}
761 840
762 841
763 {##############################################################################} 842 {##############################################################################}
764 {% block to_active_dom_object %} 843 {% block to_active_dom_object %}
765 {% if is_active_dom_object %} 844 {% if is_active_dom_object %}
766 ActiveDOMObject* {{v8_class}}::toActiveDOMObject(v8::Handle<v8::Object> wrapper) 845 ActiveDOMObject* {{v8_class}}::toActiveDOMObject(v8::Handle<v8::Object> wrapper)
767 { 846 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 {% endif %} 974 {% endif %}
896 } 975 }
897 976
898 template<> 977 template<>
899 v8::Handle<v8::Value> toV8NoInline({{cpp_class}}* impl, v8::Handle<v8::Object> c reationContext, v8::Isolate* isolate) 978 v8::Handle<v8::Value> toV8NoInline({{cpp_class}}* impl, v8::Handle<v8::Object> c reationContext, v8::Isolate* isolate)
900 { 979 {
901 return toV8(impl, creationContext, isolate); 980 return toV8(impl, creationContext, isolate);
902 } 981 }
903 982
904 {% endblock %} 983 {% endblock %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698