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

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: 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 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..ae97318c5327fe5d8c24292ac0567cc18501820e 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,40 @@ 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 )
+ #
+ 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.
+ my @normalizeAttributeCode = ();
+ my $code = "";
+ my $prefix = "";
+ foreach my $knownValue (@knownValues) {
+ push(@normalizeAttributeCode, "${indent}${prefix}if (equalIgnoringCase(resultValue, \"$knownValue\")) {");
+ push(@normalizeAttributeCode, "${indent} resultValue = \"$knownValue\";");
+ if (!$prefix) {
+ $prefix = " } else ";
+ }
+ }
+ my $normalizeAttributeValue = join("\n", @normalizeAttributeCode);
+ $code .= <<END;
+${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.
+${indent}${normalizeAttributeValue}
+${indent} } else {
+${indent} resultValue = "";
+${indent} }
+${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