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

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

Issue 124763002: Support IDL attributes limited to only known values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased + switched to using '|' as ReflectOnly separator Created 6 years, 11 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
« no previous file with comments | « Source/bindings/IDLExtendedAttributes.txt ('k') | Source/bindings/tests/idls/TestObject.idl » ('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 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 } 1497 }
1498 $code .= <<END; 1498 $code .= <<END;
1499 ${implClassName}* imp = ${v8ClassName}::toNative(holder); 1499 ${implClassName}* imp = ${v8ClassName}::toNative(holder);
1500 END 1500 END
1501 } else { 1501 } else {
1502 my $reflect = $attribute->extendedAttributes->{"Reflect"}; 1502 my $reflect = $attribute->extendedAttributes->{"Reflect"};
1503 my $url = $attribute->extendedAttributes->{"URL"}; 1503 my $url = $attribute->extendedAttributes->{"URL"};
1504 if ($reflect && !$url && InheritsInterface($interface, "Node") && $attrT ype eq "DOMString") { 1504 if ($reflect && !$url && InheritsInterface($interface, "Node") && $attrT ype eq "DOMString") {
1505 # Generate super-compact call for regular attribute getter: 1505 # Generate super-compact call for regular attribute getter:
1506 my ($functionName, @arguments) = GetterExpression($interfaceName, $a ttribute); 1506 my ($functionName, @arguments) = GetterExpression($interfaceName, $a ttribute);
1507 my $getterExpression = "imp->${functionName}(" . join(", ", @argumen ts) . ")";
1507 $code .= " Element* imp = V8Element::toNative(info.Holder());\n"; 1508 $code .= " Element* imp = V8Element::toNative(info.Holder());\n";
1508 $code .= " v8SetReturnValueString(info, imp->${functionName}(" . join(", ", @arguments) . "), info.GetIsolate());\n"; 1509 if ($attribute->extendedAttributes->{"ReflectOnly"}) {
1510 $code .= " String resultValue = ${getterExpression};\n";
1511 $code .= GenerateReflectOnlyCheck($attribute->extendedAttributes ->{"ReflectOnly"}, " ");
1512 $getterExpression = "resultValue";
1513 }
1514 $code .= " v8SetReturnValueString(info, ${getterExpression}, info .GetIsolate());\n";
1509 $code .= "}\n"; 1515 $code .= "}\n";
1510 $code .= "#endif // ${conditionalString}\n" if $conditionalString; 1516 $code .= "#endif // ${conditionalString}\n" if $conditionalString;
1511 $code .= "\n"; 1517 $code .= "\n";
1512 $implementation{nameSpaceInternal}->add($code); 1518 $implementation{nameSpaceInternal}->add($code);
1513 return; 1519 return;
1514 # Skip the rest of the function! 1520 # Skip the rest of the function!
1515 } 1521 }
1516 my $imp = 0; 1522 my $imp = 0;
1517 if ($attrCached) { 1523 if ($attrCached) {
1518 $imp = 1; 1524 $imp = 1;
(...skipping 4170 matching lines...) Expand 10 before | Expand all | Expand 10 after
5689 return "${indent}v8SetReturnValue(${getCallbackInfo}, v8DateOrNull($nati veValue, $getIsolate));" if $isReturnValue; 5695 return "${indent}v8SetReturnValue(${getCallbackInfo}, v8DateOrNull($nati veValue, $getIsolate));" if $isReturnValue;
5690 return "$indent$receiver v8DateOrNull($nativeValue, $getIsolate);" 5696 return "$indent$receiver v8DateOrNull($nativeValue, $getIsolate);"
5691 } 5697 }
5692 5698
5693 # long long and unsigned long long are not representable in ECMAScript. 5699 # long long and unsigned long long are not representable in ECMAScript.
5694 if ($type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTi meStamp") { 5700 if ($type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTi meStamp") {
5695 return "${indent}v8SetReturnValue(${getCallbackInfo}, static_cast<double >($nativeValue));" if $isReturnValue; 5701 return "${indent}v8SetReturnValue(${getCallbackInfo}, static_cast<double >($nativeValue));" if $isReturnValue;
5696 return "$indent$receiver v8::Number::New($getIsolate, static_cast<double >($nativeValue));"; 5702 return "$indent$receiver v8::Number::New($getIsolate, static_cast<double >($nativeValue));";
5697 } 5703 }
5698 5704
5705 if ($type eq "DOMString" && $extendedAttributes->{"ReflectOnly"}) {
5706 my $code = "${indent}String resultValue = ${nativeValue};\n";
5707 $code .= GenerateReflectOnlyCheck($extendedAttributes->{"ReflectOnly"}, ${indent});
5708 return "${code}${indent}v8SetReturnValueString(${getCallbackInfo}, resul tValue, $getIsolate);" if $isReturnValue;
5709 return "${code}$indent$receiver resultValue";
5710 }
5711
5699 my $conv = $extendedAttributes->{"TreatReturnedNullStringAs"}; 5712 my $conv = $extendedAttributes->{"TreatReturnedNullStringAs"};
5700 if (($type eq "DOMString" || IsEnumType($type)) && $isReturnValue) { 5713 if (($type eq "DOMString" || IsEnumType($type)) && $isReturnValue) {
5701 my $functionSuffix = ""; 5714 my $functionSuffix = "";
5702 if (defined $conv) { 5715 if (defined $conv) {
5703 if ($conv eq "Null") { 5716 if ($conv eq "Null") {
5704 $functionSuffix = "OrNull"; 5717 $functionSuffix = "OrNull";
5705 } elsif ($conv eq "Undefined") { 5718 } elsif ($conv eq "Undefined") {
5706 $functionSuffix = "OrUndefined"; 5719 $functionSuffix = "OrUndefined";
5707 } else { 5720 } else {
5708 die "Unknown value for TreatReturnedNullStringAs extended attrib ute"; 5721 die "Unknown value for TreatReturnedNullStringAs extended attrib ute";
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
6236 my $implementedByImplName = GetImplNameFromImplementedBy($consta nt->extendedAttributes->{"ImplementedBy"}); 6249 my $implementedByImplName = GetImplNameFromImplementedBy($consta nt->extendedAttributes->{"ImplementedBy"});
6237 push(@checks, " COMPILE_ASSERT($value == " . $implementedByIm plName . "::$name, TheValueOf${implClassName}_${name}DoesntMatchWithImplementati on);\n"); 6250 push(@checks, " COMPILE_ASSERT($value == " . $implementedByIm plName . "::$name, TheValueOf${implClassName}_${name}DoesntMatchWithImplementati on);\n");
6238 } else { 6251 } else {
6239 push(@checks, " COMPILE_ASSERT($value == ${implClassName}::$n ame, TheValueOf${implClassName}_${name}DoesntMatchWithImplementation);\n"); 6252 push(@checks, " COMPILE_ASSERT($value == ${implClassName}::$n ame, TheValueOf${implClassName}_${name}DoesntMatchWithImplementation);\n");
6240 } 6253 }
6241 } 6254 }
6242 } 6255 }
6243 return @checks; 6256 return @checks;
6244 } 6257 }
6245 6258
6259 sub GenerateReflectOnlyCheck
6260 {
6261 my $knownValueString = shift;
6262 my $indent = shift;
6263
6264 my @knownValues = split(quotemeta("|"), $knownValueString);
6265
6266 # Attribute is limited to only known values: check that the attribute
6267 # value is one of those..and if not, set it to the empty string.
6268 # ( http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known -values )
6269 #
6270 AddToImplIncludes("wtf/text/WTFString.h");
haraken 2014/01/06 13:13:02 This won't be needed.
sof 2014/01/06 13:45:33 Done.
6271 my @normalizeAttributeCode = ();
6272 my $code = "";
6273 my $prefix = "";
6274 foreach my $knownValue (@knownValues) {
6275 push(@normalizeAttributeCode, "${indent}${prefix}if (equalIgnoringCase(r esultValue, \"$knownValue\")) {");
6276 push(@normalizeAttributeCode, "${indent} resultValue = \"$knownVa lue\";");
6277 if (!$prefix) {
6278 $prefix = " } else ";
6279 }
6280 }
6281 my $normalizeAttributeValue = join("\n", @normalizeAttributeCode);
6282 $code .= <<END;
6283 ${indent}if (!resultValue.isEmpty()) {
haraken 2014/01/06 13:13:02 This empty check won't be needed.
sof 2014/01/06 13:15:56 It is useful to check for early though (rather tha
sof 2014/01/06 13:45:33 Done.
6284 ${indent}${normalizeAttributeValue}
6285 ${indent} } else {
6286 ${indent} resultValue = "";
6287 ${indent} }
6288 ${indent}}
6289 END
6290 return "${code}";
6291 }
6292
6246 sub ExtendedAttributeContains 6293 sub ExtendedAttributeContains
6247 { 6294 {
6248 my $extendedAttributeValue = shift; 6295 my $extendedAttributeValue = shift;
6249 return 0 unless $extendedAttributeValue; 6296 return 0 unless $extendedAttributeValue;
6250 my $keyword = shift; 6297 my $keyword = shift;
6251 6298
6252 my @extendedAttributeValues = split /\s*(\&|\|)\s*/, $extendedAttributeValue ; 6299 my @extendedAttributeValues = split /\s*(\&|\|)\s*/, $extendedAttributeValue ;
6253 return grep { $_ eq $keyword } @extendedAttributeValues; 6300 return grep { $_ eq $keyword } @extendedAttributeValues;
6254 } 6301 }
6255 6302
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6307 6354
6308 foreach my $parameter (@{$function->parameters}) { 6355 foreach my $parameter (@{$function->parameters}) {
6309 if ($parameter->type eq "SerializedScriptValue") { 6356 if ($parameter->type eq "SerializedScriptValue") {
6310 return 1; 6357 return 1;
6311 } 6358 }
6312 } 6359 }
6313 return 0; 6360 return 0;
6314 } 6361 }
6315 6362
6316 1; 6363 1;
OLDNEW
« no previous file with comments | « Source/bindings/IDLExtendedAttributes.txt ('k') | Source/bindings/tests/idls/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698