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

Side by Side Diff: Source/bindings/scripts/CodeGeneratorV8.pm

Issue 13933014: Gen index getter by unified way instead of using several helper function in some special cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: refined Created 7 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
OLDNEW
1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
5 # Copyright (C) 2006 Apple Computer, Inc. 5 # Copyright (C) 2006 Apple Computer, Inc.
6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc. 6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 # Copyright (C) 2012 Ericsson AB. All rights reserved. 10 # Copyright (C) 2012 Ericsson AB. All rights reserved.
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 "Storage" => 1, 710 "Storage" => 1,
711 "HTMLAppletElement" => 1, 711 "HTMLAppletElement" => 1,
712 "HTMLEmbedElement" => 1, 712 "HTMLEmbedElement" => 1,
713 "HTMLObjectElement" => 1 713 "HTMLObjectElement" => 1
714 ); 714 );
715 715
716 sub GenerateHeaderNamedAndIndexedPropertyAccessors 716 sub GenerateHeaderNamedAndIndexedPropertyAccessors
717 { 717 {
718 my $interface = shift; 718 my $interface = shift;
719 my $interfaceName = $interface->name; 719 my $interfaceName = $interface->name;
720 my $hasCustomIndexedGetter = $interface->extendedAttributes->{"IndexedGetter "} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; 720 my $hasIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomIndexedGetter"};
721 my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexed Setter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"}; 721 my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexed Setter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"};
722 my $hasCustomNamedGetter = $interface->extendedAttributes->{"NamedGetter"} | | $interface->extendedAttributes->{"CustomNamedGetter"} || $interface->extendedA ttributes->{"CustomGetOwnPropertySlot"}; 722 my $hasCustomNamedGetter = $interface->extendedAttributes->{"NamedGetter"} | | $interface->extendedAttributes->{"CustomNamedGetter"} || $interface->extendedA ttributes->{"CustomGetOwnPropertySlot"};
723 my $hasCustomNamedSetter = $interface->extendedAttributes->{"CustomNamedSett er"}; 723 my $hasCustomNamedSetter = $interface->extendedAttributes->{"CustomNamedSett er"};
724 my $hasCustomDeleters = $interface->extendedAttributes->{"CustomDeleteProper ty"}; 724 my $hasCustomDeleters = $interface->extendedAttributes->{"CustomDeleteProper ty"};
725 my $hasCustomEnumerator = $interface->extendedAttributes->{"CustomEnumerateP roperty"}; 725 my $hasCustomEnumerator = $interface->extendedAttributes->{"CustomEnumerateP roperty"};
726 if ($interfaceName eq "HTMLOptionsCollection") { 726 if ($interfaceName eq "HTMLOptionsCollection") {
727 $interfaceName = "HTMLCollection"; 727 $interfaceName = "HTMLCollection";
728 $hasCustomIndexedGetter = 1; 728 $hasIndexedGetter = 1;
729 $hasCustomNamedGetter = 1; 729 $hasCustomNamedGetter = 1;
730 } 730 }
731 if ($interfaceName eq "DOMWindow") { 731 if ($interfaceName eq "DOMWindow") {
732 $hasCustomDeleters = 0; 732 $hasCustomDeleters = 0;
733 $hasCustomEnumerator = 0; 733 $hasCustomEnumerator = 0;
734 } 734 }
735 if ($interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedEle ment" || $interfaceName eq "HTMLObjectElement") { 735 if ($interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedEle ment" || $interfaceName eq "HTMLObjectElement") {
736 $hasCustomNamedGetter = 1; 736 $hasCustomNamedGetter = 1;
737 } 737 }
738 if ($interfaceName eq "HTMLDocument") { 738 if ($interfaceName eq "HTMLDocument") {
739 $hasCustomNamedGetter = 0; 739 $hasCustomNamedGetter = 0;
740 $hasCustomIndexedGetter = 0; 740 $hasIndexedGetter = 0;
741 } 741 }
742 my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName}; 742 my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName};
743 if ($isIndexerSpecialCase) {
744 $hasIndexedGetter = 1;
745 $hasCustomIndexedSetter = 1;
746 }
743 747
744 if ($hasCustomIndexedGetter || $isIndexerSpecialCase) { 748 if ($hasIndexedGetter) {
745 AddToHeader(<<END); 749 AddToHeader(<<END);
746 static v8::Handle<v8::Value> indexedPropertyGetter(uint32_t, const v8::Acces sorInfo&); 750 static v8::Handle<v8::Value> indexedPropertyGetter(uint32_t, const v8::Acces sorInfo&);
747 END 751 END
748 } 752 }
749 753
750 if ($isIndexerSpecialCase || $hasCustomIndexedSetter) { 754 if ($hasCustomIndexedSetter) {
751 AddToHeader(<<END); 755 AddToHeader(<<END);
752 static v8::Handle<v8::Value> indexedPropertySetter(uint32_t, v8::Local<v8::V alue>, const v8::AccessorInfo&); 756 static v8::Handle<v8::Value> indexedPropertySetter(uint32_t, v8::Local<v8::V alue>, const v8::AccessorInfo&);
753 END 757 END
754 } 758 }
755 if ($hasCustomDeleters) { 759 if ($hasCustomDeleters) {
756 AddToHeader(<<END); 760 AddToHeader(<<END);
757 static v8::Handle<v8::Boolean> indexedPropertyDeleter(uint32_t, const v8::Ac cessorInfo&); 761 static v8::Handle<v8::Boolean> indexedPropertyDeleter(uint32_t, const v8::Ac cessorInfo&);
758 END 762 END
759 } 763 }
760 if ($hasCustomNamedGetter) { 764 if ($hasCustomNamedGetter) {
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 $code .= " } else {\n"; 2678 $code .= " } else {\n";
2675 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$ name\"), v8::FunctionTemplate::New(${interfaceName}V8Internal::${name}MethodCall back, v8Undefined(), ${signature})$property_attributes);\n"; 2679 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$ name\"), v8::FunctionTemplate::New(${interfaceName}V8Internal::${name}MethodCall back, v8Undefined(), ${signature})$property_attributes);\n";
2676 $code .= " }\n"; 2680 $code .= " }\n";
2677 } else { 2681 } else {
2678 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$name \"), v8::FunctionTemplate::New(${interfaceName}V8Internal::${name}MethodCallback , v8Undefined(), ${signature})$property_attributes);\n"; 2682 $code .= " ${conditional}$template->Set(v8::String::NewSymbol(\"$name \"), v8::FunctionTemplate::New(${interfaceName}V8Internal::${name}MethodCallback , v8Undefined(), ${signature})$property_attributes);\n";
2679 } 2683 }
2680 $code .= "#endif // ${conditionalString}\n" if $conditionalString; 2684 $code .= "#endif // ${conditionalString}\n" if $conditionalString;
2681 return $code; 2685 return $code;
2682 } 2686 }
2683 2687
2684 sub GenerateImplementationIndexer 2688 sub GenerateImplementationIndexedProperty
2685 { 2689 {
2686 my $interface = shift; 2690 my $interface = shift;
2687 my $indexer = shift; 2691 my $indexer = shift;
2688 my $code = "";
2689
2690 my $interfaceName = $interface->name; 2692 my $interfaceName = $interface->name;
2691 my $v8InterfaceName = "V8$interfaceName"; 2693 my $v8InterfaceName = "V8$interfaceName";
2692 2694
2693 # FIXME: Figure out what NumericIndexedGetter is really supposed to do. Righ t now, it's only set on WebGL-related files. 2695 # FIXME: Figure out what NumericIndexedGetter is really supposed to do. Righ t now, it's only set on WebGL-related files.
2694 my $hasCustomSetter = $interface->extendedAttributes->{"CustomIndexedSetter" } && !$interface->extendedAttributes->{"NumericIndexedGetter"}; 2696 my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexed Setter"};
2695 my $hasGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interf ace->extendedAttributes->{"CustomGetOwnPropertySlot"}; 2697 my $hasIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomIndexedGetter"};
2696 2698
2697 # FIXME: Investigate and remove this nastinesss. In V8, named property handl ing and indexer handling are apparently decoupled, 2699 # FIXME: Investigate and remove this nastinesss. In V8, named property handl ing and indexer handling are apparently decoupled,
2698 # which means that object[X] where X is a number doesn't reach named propert y indexer. So we need to provide 2700 # which means that object[X] where X is a number doesn't reach named propert y indexer. So we need to provide
2699 # simplistic, mirrored indexer handling in addition to named property handli ng. 2701 # simplistic, mirrored indexer handling in addition to named property handli ng.
2700 my $isSpecialCase = exists $indexerSpecialCases{$interfaceName}; 2702 my $isSpecialCase = exists $indexerSpecialCases{$interfaceName};
2701 if ($isSpecialCase) { 2703 if ($isSpecialCase) {
2702 $hasGetter = 1; 2704 $hasIndexedGetter = 1;
2703 if ($interface->extendedAttributes->{"CustomNamedSetter"}) { 2705 if ($interface->extendedAttributes->{"CustomNamedSetter"}) {
2704 $hasCustomSetter = 1; 2706 $hasCustomIndexedSetter = 1;
2705 } 2707 }
2706 } 2708 }
2707 2709
2710 # FIXME: Remove the special cases. Interfaces that have indexedPropertyGette r should have indexedPropertyEnumerator.
2708 my $hasEnumerator = !$isSpecialCase && $codeGenerator->InheritsInterface($in terface, "Node"); 2711 my $hasEnumerator = !$isSpecialCase && $codeGenerator->InheritsInterface($in terface, "Node");
2709 2712
2710 # FIXME: Find a way to not have to special-case HTMLOptionsCollection. 2713 # FIXME: Find a way to not have to special-case HTMLOptionsCollection.
2711 if ($interfaceName eq "HTMLOptionsCollection") { 2714 if ($interfaceName eq "HTMLOptionsCollection") {
2712 $hasEnumerator = 1; 2715 $hasEnumerator = 1;
2713 $hasGetter = 1; 2716 $hasIndexedGetter = 1;
2714 } 2717 }
2715 2718
2716 if (!$hasGetter) { 2719 if (!$hasIndexedGetter) {
2717 return ""; 2720 return "";
2718 } 2721 }
2719 2722
2720 AddToImplIncludes("V8Collection.h"); 2723 AddToImplIncludes("V8Collection.h");
2721 2724
2722 if (!$indexer) { 2725 if (!$indexer) {
2723 $indexer = $codeGenerator->FindSuperMethod($interface, "item"); 2726 $indexer = $codeGenerator->FindSuperMethod($interface, "item");
2724 } 2727 }
2725 2728
2726 my $indexerType = $indexer ? $indexer->type : 0; 2729 my $indexerType = $indexer ? $indexer->type : 0;
2727 2730
2728 # FIXME: Remove this once toV8 helper methods are implemented (see https://b ugs.webkit.org/show_bug.cgi?id=32563). 2731 if ($indexerType && !$hasCustomIndexedSetter) {
2729 if ($interfaceName eq "WebKitCSSKeyframesRule") { 2732 $hasEnumerator = 1;
2730 $indexerType = "WebKitCSSKeyframeRule";
2731 }
2732
2733 if ($indexerType && !$hasCustomSetter) {
2734 if ($indexerType eq "DOMString") {
2735 my $conversion = $indexer->extendedAttributes->{"TreatReturnedNullSt ringAs"};
2736 if ($conversion && $conversion eq "Null") {
2737 $code .= <<END;
2738 setCollectionStringOrUndefinedIndexedGetter<${interfaceName}>(desc);
2739 END
2740 } else {
2741 $code .= <<END;
2742 setCollectionStringIndexedGetter<${interfaceName}>(desc);
2743 END
2744 }
2745 } else {
2746 $code .= <<END;
2747 setCollectionIndexedGetter<${interfaceName}, ${indexerType}>(desc);
2748 END
2749 # Include the header for this indexer type, because setCollectionInd exedGetter() requires toV8() for this type.
2750 AddToImplIncludes("V8${indexerType}.h");
2751 }
2752
2753 return $code;
2754 } 2733 }
2755 2734
2756 my $hasDeleter = $interface->extendedAttributes->{"CustomDeleteProperty"}; 2735 my $hasDeleter = $interface->extendedAttributes->{"CustomDeleteProperty"};
2757 my $setOn = "Instance"; 2736 my $setOn = "Instance";
2758 2737
2759 # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallba cks) and it's used on DOMWindow 2738 # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallba cks) and it's used on DOMWindow
2760 # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to 2739 # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to
2761 # get implementation straight out of the DOMWindow prototype regardless of w hat prototype is actually set 2740 # get implementation straight out of the DOMWindow prototype regardless of w hat prototype is actually set
2762 # on the object. 2741 # on the object.
2763 if ($interfaceName eq "DOMWindow") { 2742 if ($interfaceName eq "DOMWindow") {
2764 $setOn = "Prototype"; 2743 $setOn = "Prototype";
2765 $hasDeleter = 0; 2744 $hasDeleter = 0;
2766 } 2745 }
2746 # FIXME: Implement V8DataTransferItemList::indexedPropertyDeleter
2747 if ($interfaceName eq "DataTransferItemList") {
2748 $hasDeleter = 0;
2749 }
2767 2750
2751 my $code = "";
2768 $code .= " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8Interf aceName}::indexedPropertyGetter"; 2752 $code .= " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8Interf aceName}::indexedPropertyGetter";
2769 $code .= $hasCustomSetter ? ", ${v8InterfaceName}::indexedPropertySetter" : ", 0"; 2753 $code .= $hasCustomIndexedSetter ? ", ${v8InterfaceName}::indexedPropertySet ter" : ", 0";
2770 $code .= ", 0"; # IndexedPropertyQuery -- not being used at the moment. 2754 $code .= ", 0"; # IndexedPropertyQuery -- not being used at the moment.
2771 $code .= $hasDeleter ? ", ${v8InterfaceName}::indexedPropertyDeleter" : ", 0 "; 2755 $code .= $hasDeleter ? ", ${v8InterfaceName}::indexedPropertyDeleter" : ", 0 ";
2772 $code .= ", nodeCollectionIndexedPropertyEnumerator<${interfaceName}>" if $h asEnumerator; 2756 $code .= ", nodeCollectionIndexedPropertyEnumerator<${interfaceName}>" if $h asEnumerator;
2773 $code .= ");\n"; 2757 $code .= ");\n";
2758
2759 if($interface->extendedAttributes->{"IndexedGetter"}) {
2760 # FIXME: add item() method to WebKitCSSKeyframesRule.idl or remove [Inde xedGetter] from WebKitCSSKeyframesRule.idl
2761 # Currently indexer type is hard coded because it can not be obtained fr om IDL.
2762 if ($interfaceName eq "WebKitCSSKeyframesRule") {
2763 $indexerType = "WebKitCSSKeyframeRule";
2764 }
2765 my $jsValue = "";
2766 my $nativeType = GetNativeType($indexerType);
2767 my $isNull = "";
2768
2769 if ($codeGenerator->IsRefPtrType($indexerType)) {
2770 $isNull = "!element";
2771 if ($interfaceName eq "WebKitCSSKeyframesRule") {
2772 $jsValue = "toV8(element.release(), info.Holder(), info.GetIsola te())";
2773 } else {
2774 $jsValue = NativeToJSValue($indexer, "element.release()", "info. Holder()", "info.GetIsolate()");
2775 }
2776 } else {
2777 $isNull = "element.isNull()";
2778 $jsValue = NativeToJSValue($indexer, "element", "info.Holder()", "in fo.GetIsolate()");
2779 }
2780
2781 AddToImplContent(<<END);
2782 v8::Handle<v8::Value> ${v8InterfaceName}::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
2783 {
2784 ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
2785 ${interfaceName}* collection = toNative(info.Holder());
2786 $nativeType element = collection->item(index);
2787 if ($isNull)
2788 return v8Undefined();
2789 return $jsValue;
2790 }
2791 END
2792 }
2774 return $code; 2793 return $code;
2775 } 2794 }
2776 2795
2777 sub GenerateImplementationNamedPropertyGetter 2796 sub GenerateImplementationNamedPropertyGetter
2778 { 2797 {
2779 my $interface = shift; 2798 my $interface = shift;
2780 my $namedPropertyGetter = shift; 2799 my $namedPropertyGetter = shift;
2781 my $subCode = ""; 2800 my $subCode = "";
2782 2801
2783 my $interfaceName = $interface->name; 2802 my $interfaceName = $interface->name;
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
3341 $code .= "\n#if ${conditionalString}\n" if $conditionalString; 3360 $code .= "\n#if ${conditionalString}\n" if $conditionalString;
3342 $code .= " if (${enable_function}()) {\n"; 3361 $code .= " if (${enable_function}()) {\n";
3343 $code .= <<END; 3362 $code .= <<END;
3344 static const V8DOMConfiguration::BatchedConstant constData = {"${name}", static_cast<signed int>(${value})}; 3363 static const V8DOMConfiguration::BatchedConstant constData = {"${name}", static_cast<signed int>(${value})};
3345 V8DOMConfiguration::batchConfigureConstants(desc, proto, &constData, 1, isolate); 3364 V8DOMConfiguration::batchConfigureConstants(desc, proto, &constData, 1, isolate);
3346 END 3365 END
3347 $code .= " }\n"; 3366 $code .= " }\n";
3348 $code .= "\n#endif // ${conditionalString}\n" if $conditionalString; 3367 $code .= "\n#endif // ${conditionalString}\n" if $conditionalString;
3349 } 3368 }
3350 3369
3351 $code .= GenerateImplementationIndexer($interface, $indexer); 3370 $code .= GenerateImplementationIndexedProperty($interface, $indexer);
3352 3371 $code .= GenerateImplementationNamedPropertyGetter($interface, $namedPropert yGetter);
3353 my $tmplConfig = GenerateImplementationNamedPropertyGetter($interface, $name dPropertyGetter);
3354 $code .= $tmplConfig;
3355 $code .= GenerateImplementationCustomCall($interface); 3372 $code .= GenerateImplementationCustomCall($interface);
3356 $code .= GenerateImplementationMasqueradesAsUndefined($interface); 3373 $code .= GenerateImplementationMasqueradesAsUndefined($interface);
3357 3374
3358 # Define our functions with Set() or SetAccessor() 3375 # Define our functions with Set() or SetAccessor()
3359 my $total_functions = 0; 3376 my $total_functions = 0;
3360 foreach my $function (@normalFunctions) { 3377 foreach my $function (@normalFunctions) {
3361 # Only one accessor is needed for overloaded methods: 3378 # Only one accessor is needed for overloaded methods:
3362 next if $function->{overloadIndex} > 1; 3379 next if $function->{overloadIndex} > 1;
3363 3380
3364 $total_functions++; 3381 $total_functions++;
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
4714 4731
4715 sub GetPassRefPtrType 4732 sub GetPassRefPtrType
4716 { 4733 {
4717 my $v8InterfaceName = shift; 4734 my $v8InterfaceName = shift;
4718 4735
4719 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : ""; 4736 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : "";
4720 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>"; 4737 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>";
4721 } 4738 }
4722 4739
4723 1; 4740 1;
OLDNEW
« no previous file with comments | « LayoutTests/gamepad/gamepad-polling-access-expected.txt ('k') | Source/bindings/tests/results/V8TestEventTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698