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

Unified 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: Flatten generated code block 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/IDLExtendedAttributes.txt ('k') | Source/bindings/tests/idls/TestObject.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/code_generator_v8.pm
diff --git a/Source/bindings/scripts/code_generator_v8.pm b/Source/bindings/scripts/code_generator_v8.pm
index f48e2ec650bdf2aefc35951e60f93753d557ba01..843ad1bf9d84bb93a888d417fa95b5238c42c4b2 100644
--- a/Source/bindings/scripts/code_generator_v8.pm
+++ b/Source/bindings/scripts/code_generator_v8.pm
@@ -1504,8 +1504,14 @@ END
if ($reflect && !$url && InheritsInterface($interface, "Node") && $attrType eq "DOMString") {
# Generate super-compact call for regular attribute getter:
my ($functionName, @arguments) = GetterExpression($interfaceName, $attribute);
+ my $getterExpression = "imp->${functionName}(" . join(", ", @arguments) . ")";
$code .= " Element* imp = V8Element::toNative(info.Holder());\n";
- $code .= " v8SetReturnValueString(info, imp->${functionName}(" . join(", ", @arguments) . "), info.GetIsolate());\n";
+ if ($attribute->extendedAttributes->{"ReflectOnly"}) {
+ $code .= " String resultValue = ${getterExpression};\n";
+ $code .= GenerateReflectOnlyCheck($attribute->extendedAttributes->{"ReflectOnly"}, " ");
+ $getterExpression = "resultValue";
+ }
+ $code .= " v8SetReturnValueString(info, ${getterExpression}, info.GetIsolate());\n";
$code .= "}\n";
$code .= "#endif // ${conditionalString}\n" if $conditionalString;
$code .= "\n";
@@ -5696,6 +5702,13 @@ sub NativeToJSValue
return "$indent$receiver v8::Number::New($getIsolate, static_cast<double>($nativeValue));";
}
+ if ($type eq "DOMString" && $extendedAttributes->{"ReflectOnly"}) {
+ my $code = "${indent}String resultValue = ${nativeValue};\n";
+ $code .= GenerateReflectOnlyCheck($extendedAttributes->{"ReflectOnly"}, ${indent});
+ return "${code}${indent}v8SetReturnValueString(${getCallbackInfo}, resultValue, $getIsolate);" if $isReturnValue;
+ return "${code}$indent$receiver resultValue";
+ }
+
my $conv = $extendedAttributes->{"TreatReturnedNullStringAs"};
if (($type eq "DOMString" || IsEnumType($type)) && $isReturnValue) {
my $functionSuffix = "";
@@ -6243,6 +6256,35 @@ sub GenerateCompileTimeCheckForEnumsIfNeeded
return @checks;
}
+sub GenerateReflectOnlyCheck
+{
+ my $knownValueString = shift;
+ my $indent = shift;
+
+ my @knownValues = split(quotemeta("|"), $knownValueString);
+
+ # Attribute is limited to only known values: check that the attribute
+ # value is one of those..and if not, set it to the empty string.
+ # ( http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-values )
+ #
+ my @normalizeAttributeCode = ();
+ my $code = "";
+ foreach my $knownValue (@knownValues) {
+ push(@normalizeAttributeCode, "${indent}} else if (equalIgnoringCase(resultValue, \"$knownValue\")) {");
+ push(@normalizeAttributeCode, "${indent} resultValue = \"$knownValue\";");
+ }
+ my $normalizeAttributeValue = join("\n", @normalizeAttributeCode);
+ $code .= <<END;
+${indent}if (resultValue.isEmpty()) {
+${indent} ;
+${normalizeAttributeValue}
+${indent}} else {
+${indent} resultValue = "";
+${indent}}
+END
+ return "${code}";
+}
+
sub ExtendedAttributeContains
{
my $extendedAttributeValue = shift;
« 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