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

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

Issue 25675003: IDL compiler: remove nop return from end of getters and setters (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 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
« no previous file with comments | « no previous file | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 ${implClassName}* imp = ${v8ClassName}::toNative(holder); 1405 ${implClassName}* imp = ${v8ClassName}::toNative(holder);
1406 END 1406 END
1407 } else { 1407 } else {
1408 my $reflect = $attribute->extendedAttributes->{"Reflect"}; 1408 my $reflect = $attribute->extendedAttributes->{"Reflect"};
1409 my $url = $attribute->extendedAttributes->{"URL"}; 1409 my $url = $attribute->extendedAttributes->{"URL"};
1410 if ($reflect && !$url && InheritsInterface($interface, "Node") && $attrT ype eq "DOMString") { 1410 if ($reflect && !$url && InheritsInterface($interface, "Node") && $attrT ype eq "DOMString") {
1411 # Generate super-compact call for regular attribute getter: 1411 # Generate super-compact call for regular attribute getter:
1412 my ($functionName, @arguments) = GetterExpression($interfaceName, $a ttribute); 1412 my ($functionName, @arguments) = GetterExpression($interfaceName, $a ttribute);
1413 $code .= " Element* imp = V8Element::toNative(info.Holder());\n"; 1413 $code .= " Element* imp = V8Element::toNative(info.Holder());\n";
1414 $code .= " v8SetReturnValueString(info, imp->${functionName}(" . join(", ", @arguments) . "), info.GetIsolate());\n"; 1414 $code .= " v8SetReturnValueString(info, imp->${functionName}(" . join(", ", @arguments) . "), info.GetIsolate());\n";
1415 $code .= " return;\n";
1416 $code .= "}\n\n"; 1415 $code .= "}\n\n";
1417 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 1416 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
1418 $implementation{nameSpaceInternal}->add($code); 1417 $implementation{nameSpaceInternal}->add($code);
1419 return; 1418 return;
1420 # Skip the rest of the function! 1419 # Skip the rest of the function!
1421 } 1420 }
1422 my $imp = 0; 1421 my $imp = 0;
1423 if ($attrCached) { 1422 if ($attrCached) {
1424 $imp = 1; 1423 $imp = 1;
1425 $code .= <<END; 1424 $code .= <<END;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 $expression = $getterString; 1525 $expression = $getterString;
1527 # Fix amigious conversion problem, by casting to the base type first ($g etterString returns a type that inherits from SVGAnimatedEnumeration, not the ba se class directly). 1526 # Fix amigious conversion problem, by casting to the base type first ($g etterString returns a type that inherits from SVGAnimatedEnumeration, not the ba se class directly).
1528 $expression = "static_pointer_cast<SVGAnimatedEnumeration>($expression)" if $returnType eq "SVGAnimatedEnumeration"; 1527 $expression = "static_pointer_cast<SVGAnimatedEnumeration>($expression)" if $returnType eq "SVGAnimatedEnumeration";
1529 } 1528 }
1530 1529
1531 if (ShouldKeepAttributeAlive($interface, $attribute, $returnType)) { 1530 if (ShouldKeepAttributeAlive($interface, $attribute, $returnType)) {
1532 my $arrayType = GetArrayType($returnType); 1531 my $arrayType = GetArrayType($returnType);
1533 if ($arrayType) { 1532 if ($arrayType) {
1534 AddIncludeForType("V8$arrayType.h"); 1533 AddIncludeForType("V8$arrayType.h");
1535 $code .= " v8SetReturnValue(info, v8Array(${getterString}, info.G etIsolate()));\n"; 1534 $code .= " v8SetReturnValue(info, v8Array(${getterString}, info.G etIsolate()));\n";
1536 $code .= " return;\n";
1537 $code .= "}\n\n"; 1535 $code .= "}\n\n";
1538 $implementation{nameSpaceInternal}->add($code); 1536 $implementation{nameSpaceInternal}->add($code);
1539 return; 1537 return;
1540 } 1538 }
1541 1539
1542 AddIncludesForType($returnType); 1540 AddIncludesForType($returnType);
1543 AddToImplIncludes("bindings/v8/V8HiddenPropertyName.h"); 1541 AddToImplIncludes("bindings/v8/V8HiddenPropertyName.h");
1544 # Check for a wrapper in the wrapper cache. If there is one, we know tha t a hidden reference has already 1542 # Check for a wrapper in the wrapper cache. If there is one, we know tha t a hidden reference has already
1545 # been created. If we don't find a wrapper, we create both a wrapper and a hidden reference. 1543 # been created. If we don't find a wrapper, we create both a wrapper and a hidden reference.
1546 my $nativeReturnType = GetNativeType($returnType); 1544 my $nativeReturnType = GetNativeType($returnType);
1547 my $v8ReturnType = "V8" . $returnType; 1545 my $v8ReturnType = "V8" . $returnType;
1548 $code .= " $nativeReturnType result = ${getterString};\n"; 1546 $code .= " $nativeReturnType result = ${getterString};\n";
1549 if ($forMainWorldSuffix) { 1547 if ($forMainWorldSuffix) {
1550 $code .= " if (result.get() && DOMDataStore::setReturnValueFromWr apper${forMainWorldSuffix}<${v8ReturnType}>(info.GetReturnValue(), result.get()) )\n"; 1548 $code .= " if (result.get() && DOMDataStore::setReturnValueFromWr apper${forMainWorldSuffix}<${v8ReturnType}>(info.GetReturnValue(), result.get()) )\n";
1551 } else { 1549 } else {
1552 $code .= " if (result.get() && DOMDataStore::setReturnValueFromWr apper<${v8ReturnType}>(info.GetReturnValue(), result.get()))\n"; 1550 $code .= " if (result.get() && DOMDataStore::setReturnValueFromWr apper<${v8ReturnType}>(info.GetReturnValue(), result.get()))\n";
1553 } 1551 }
1554 $code .= " return;\n"; 1552 $code .= " return;\n";
1555 $code .= " v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Ho lder(), info.GetIsolate());\n"; 1553 $code .= " v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Ho lder(), info.GetIsolate());\n";
1556 $code .= " if (!wrapper.IsEmpty()) {\n"; 1554 $code .= " if (!wrapper.IsEmpty()) {\n";
1557 $code .= " V8HiddenPropertyName::setNamedHiddenReference(info.Hol der(), \"${attrName}\", wrapper);\n"; 1555 $code .= " V8HiddenPropertyName::setNamedHiddenReference(info.Hol der(), \"${attrName}\", wrapper);\n";
1558 $code .= " v8SetReturnValue(info, wrapper);\n"; 1556 $code .= " v8SetReturnValue(info, wrapper);\n";
1559 $code .= " }\n"; 1557 $code .= " }\n";
1560 $code .= " return;\n";
1561 $code .= "}\n\n"; 1558 $code .= "}\n\n";
1562 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 1559 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
1563 $implementation{nameSpaceInternal}->add($code); 1560 $implementation{nameSpaceInternal}->add($code);
1564 return; 1561 return;
1565 } 1562 }
1566 1563
1567 if ((IsSVGAnimatedType($interfaceName) or $interfaceName eq "SVGViewSpec") a nd IsSVGTypeNeedingTearOff($attrType)) { 1564 if ((IsSVGAnimatedType($interfaceName) or $interfaceName eq "SVGViewSpec") a nd IsSVGTypeNeedingTearOff($attrType)) {
1568 AddToImplIncludes("V8$attrType.h"); 1565 AddToImplIncludes("V8$attrType.h");
1569 my $svgNativeType = GetSVGTypeNeedingTearOff($attrType); 1566 my $svgNativeType = GetSVGTypeNeedingTearOff($attrType);
1570 # Convert from abstract SVGProperty to real type, so the right toJS() me thod can be invoked. 1567 # Convert from abstract SVGProperty to real type, so the right toJS() me thod can be invoked.
1571 if ($forMainWorldSuffix eq "ForMainWorld") { 1568 if ($forMainWorldSuffix eq "ForMainWorld") {
1572 $code .= " v8SetReturnValueForMainWorld(info, static_cast<$svgNat iveType*>($expression), info.Holder());\n"; 1569 $code .= " v8SetReturnValueForMainWorld(info, static_cast<$svgNat iveType*>($expression), info.Holder());\n";
1573 } else { 1570 } else {
1574 $code .= " v8SetReturnValueFast(info, static_cast<$svgNativeType* >($expression), imp);\n"; 1571 $code .= " v8SetReturnValueFast(info, static_cast<$svgNativeType* >($expression), imp);\n";
1575 } 1572 }
1576 $code .= " return;\n";
1577 } elsif (IsSVGTypeNeedingTearOff($attrType) and not $interfaceName =~ /List$ /) { 1573 } elsif (IsSVGTypeNeedingTearOff($attrType) and not $interfaceName =~ /List$ /) {
1578 AddToImplIncludes("V8$attrType.h"); 1574 AddToImplIncludes("V8$attrType.h");
1579 AddToImplIncludes("core/svg/properties/SVGPropertyTearOff.h"); 1575 AddToImplIncludes("core/svg/properties/SVGPropertyTearOff.h");
1580 my $tearOffType = GetSVGTypeNeedingTearOff($attrType); 1576 my $tearOffType = GetSVGTypeNeedingTearOff($attrType);
1581 my $wrappedValue; 1577 my $wrappedValue;
1582 if (IsSVGTypeWithWritablePropertiesNeedingTearOff($attrType) and not def ined $attribute->extendedAttributes->{"Immutable"}) { 1578 if (IsSVGTypeWithWritablePropertiesNeedingTearOff($attrType) and not def ined $attribute->extendedAttributes->{"Immutable"}) {
1583 my $getter = $expression; 1579 my $getter = $expression;
1584 $getter =~ s/imp->//; 1580 $getter =~ s/imp->//;
1585 $getter =~ s/\(\)//; 1581 $getter =~ s/\(\)//;
1586 1582
(...skipping 15 matching lines...) Expand all
1602 } elsif ($tearOffType =~ /SVG(Point|PathSeg)List/) { 1598 } elsif ($tearOffType =~ /SVG(Point|PathSeg)List/) {
1603 $wrappedValue = "WTF::getPtr($expression)"; 1599 $wrappedValue = "WTF::getPtr($expression)";
1604 } else { 1600 } else {
1605 $wrappedValue = "WTF::getPtr(${tearOffType}::create($expression) )"; 1601 $wrappedValue = "WTF::getPtr(${tearOffType}::create($expression) )";
1606 } 1602 }
1607 if ($forMainWorldSuffix eq "ForMainWorld") { 1603 if ($forMainWorldSuffix eq "ForMainWorld") {
1608 $code .= " v8SetReturnValueForMainWorld(info, $wrappedValue, info .Holder());\n"; 1604 $code .= " v8SetReturnValueForMainWorld(info, $wrappedValue, info .Holder());\n";
1609 } else { 1605 } else {
1610 $code .= " v8SetReturnValueFast(info, $wrappedValue, imp);\n"; 1606 $code .= " v8SetReturnValueFast(info, $wrappedValue, imp);\n";
1611 } 1607 }
1612 $code .= " return;\n";
1613 } elsif ($attrCached) { 1608 } elsif ($attrCached) {
1614 if ($attribute->type eq "SerializedScriptValue") { 1609 if ($attribute->type eq "SerializedScriptValue") {
1615 $code .= " RefPtr<SerializedScriptValue> serialized = $getterStri ng;\n"; 1610 $code .= " RefPtr<SerializedScriptValue> serialized = $getterStri ng;\n";
1616 $code .= " value = serialized ? serialized->deserialize() : v8::H andle<v8::Value>(v8::Null(info.GetIsolate()));\n"; 1611 $code .= " value = serialized ? serialized->deserialize() : v8::H andle<v8::Value>(v8::Null(info.GetIsolate()));\n";
1617 } else { 1612 } else {
1618 $code .= " value = $getterString.v8Value();\n"; 1613 $code .= " value = $getterString.v8Value();\n";
1619 } 1614 }
1620 $code .= <<END; 1615 $code .= <<END;
1621 info.Holder()->SetHiddenValue(propertyName, value); 1616 info.Holder()->SetHiddenValue(propertyName, value);
1622 v8SetReturnValue(info, value); 1617 v8SetReturnValue(info, value);
1623 return;
1624 END 1618 END
1625 } elsif ($attribute->type eq "EventHandler") { 1619 } elsif ($attribute->type eq "EventHandler") {
1626 AddToImplIncludes("bindings/v8/V8AbstractEventListener.h"); 1620 AddToImplIncludes("bindings/v8/V8AbstractEventListener.h");
1627 my $getterFunc = ToMethodName($attribute->name); 1621 my $getterFunc = ToMethodName($attribute->name);
1628 # FIXME: Pass the main world ID for main-world-only getters. 1622 # FIXME: Pass the main world ID for main-world-only getters.
1629 $code .= " EventListener* listener = imp->${getterFunc}(isolatedWorld ForIsolate(info.GetIsolate()));\n"; 1623 $code .= " EventListener* listener = imp->${getterFunc}(isolatedWorld ForIsolate(info.GetIsolate()));\n";
1630 $code .= " v8SetReturnValue(info, listener ? v8::Handle<v8::Value>(V8 AbstractEventListener::cast(listener)->getListenerObject(imp->scriptExecutionCon text())) : v8::Handle<v8::Value>(v8::Null(info.GetIsolate())));\n"; 1624 $code .= " v8SetReturnValue(info, listener ? v8::Handle<v8::Value>(V8 AbstractEventListener::cast(listener)->getListenerObject(imp->scriptExecutionCon text())) : v8::Handle<v8::Value>(v8::Null(info.GetIsolate())));\n";
1631 $code .= " return;\n";
1632 } else { 1625 } else {
1633 my $nativeValue = NativeToJSValue($attribute->type, $attribute->extended Attributes, $expression, " ", "", "info.Holder()", "info.GetIsolate()", "info ", "imp", $forMainWorldSuffix, "return"); 1626 my $nativeValue = NativeToJSValue($attribute->type, $attribute->extended Attributes, $expression, " ", "", "info.Holder()", "info.GetIsolate()", "info ", "imp", $forMainWorldSuffix, "return");
1634 $code .= "${nativeValue}\n"; 1627 $code .= "${nativeValue}\n";
1635 $code .= " return;\n";
1636 } 1628 }
1637 1629
1638 $code .= "}\n\n"; # end of getter 1630 $code .= "}\n\n"; # end of getter
1639 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 1631 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
1640 $implementation{nameSpaceInternal}->add($code); 1632 $implementation{nameSpaceInternal}->add($code);
1641 } 1633 }
1642 1634
1643 sub ShouldKeepAttributeAlive 1635 sub ShouldKeepAttributeAlive
1644 { 1636 {
1645 my ($interface, $attribute, $returnType) = @_; 1637 my ($interface, $attribute, $returnType) = @_;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 $code .= " wrapper->commitChange();\n"; 1955 $code .= " wrapper->commitChange();\n";
1964 } 1956 }
1965 } 1957 }
1966 1958
1967 if ($attrCached) { 1959 if ($attrCached) {
1968 $code .= <<END; 1960 $code .= <<END;
1969 info.Holder()->DeleteHiddenValue(v8::String::NewSymbol("${attrName}")); // I nvalidate the cached value. 1961 info.Holder()->DeleteHiddenValue(v8::String::NewSymbol("${attrName}")); // I nvalidate the cached value.
1970 END 1962 END
1971 } 1963 }
1972 1964
1973 $code .= " return;\n";
1974 $code .= "}\n\n"; # end of setter 1965 $code .= "}\n\n"; # end of setter
1975 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 1966 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
1976 $implementation{nameSpaceInternal}->add($code); 1967 $implementation{nameSpaceInternal}->add($code);
1977 } 1968 }
1978 1969
1979 sub GenerateParametersCheckExpression 1970 sub GenerateParametersCheckExpression
1980 { 1971 {
1981 my $numParameters = shift; 1972 my $numParameters = shift;
1982 my $function = shift; 1973 my $function = shift;
1983 1974
(...skipping 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after
6121 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { 6112 if ($currentInterface->extendedAttributes->{$extendedAttribute}) {
6122 $found = 1; 6113 $found = 1;
6123 } 6114 }
6124 return 1 if $found; 6115 return 1 if $found;
6125 }, 0); 6116 }, 0);
6126 6117
6127 return $found; 6118 return $found;
6128 } 6119 }
6129 6120
6130 1; 6121 1;
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698