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

Unified Diff: Source/bindings/scripts/code_generator_v8.pm

Issue 98033003: Support missing and invalid defaults for reflected attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use same idiom for looking up value in array 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 671aae9aac94b806cbf22f93d6253c6a150f9abd..6f073e9837106799d60164e5f8a8810fa4acaf51 100644
--- a/Source/bindings/scripts/code_generator_v8.pm
+++ b/Source/bindings/scripts/code_generator_v8.pm
@@ -1508,7 +1508,7 @@ END
$code .= " Element* imp = V8Element::toNative(info.Holder());\n";
if ($attribute->extendedAttributes->{"ReflectOnly"}) {
$code .= " String resultValue = ${getterExpression};\n";
- $code .= GenerateReflectOnlyCheck($attribute->extendedAttributes->{"ReflectOnly"}, " ");
+ $code .= GenerateReflectOnlyCheck($attribute->extendedAttributes, " ");
$getterExpression = "resultValue";
}
$code .= " v8SetReturnValueString(info, ${getterExpression}, info.GetIsolate());\n";
@@ -5704,7 +5704,7 @@ sub NativeToJSValue
if ($type eq "DOMString" && $extendedAttributes->{"ReflectOnly"}) {
my $code = "${indent}String resultValue = ${nativeValue};\n";
- $code .= GenerateReflectOnlyCheck($extendedAttributes->{"ReflectOnly"}, ${indent});
+ $code .= GenerateReflectOnlyCheck($extendedAttributes, ${indent});
return "${code}${indent}v8SetReturnValueString(${getCallbackInfo}, resultValue, $getIsolate);" if $isReturnValue;
return "${code}$indent$receiver resultValue";
}
@@ -6258,11 +6258,32 @@ sub GenerateCompileTimeCheckForEnumsIfNeeded
sub GenerateReflectOnlyCheck
{
- my $knownValueString = shift;
+ my $extendedAttributes = shift;
my $indent = shift;
+ my $knownValueString = $extendedAttributes->{"ReflectOnly"};
my @knownValues = split(quotemeta("|"), $knownValueString);
+ my $missingValueDefault = $extendedAttributes->{"ReflectMissing"};
+ if ($missingValueDefault) {
+ if (!grep { $_ eq $missingValueDefault } @knownValues) {
+ die "Missing attribute value is not a known value " . $missingValueDefault;
+ }
+ $missingValueDefault = "resultValue = \"${missingValueDefault}\"";
+ } else {
+ $missingValueDefault = "";
+ }
+
+ my $invalidValueDefault = $extendedAttributes->{"ReflectInvalid"};
+ if ($invalidValueDefault) {
+ if (!grep { $_ eq $invalidValueDefault } @knownValues) {
+ die "Invalid attribute value is not a known value " . $invalidValueDefault;
+ }
+ $invalidValueDefault = "\"${invalidValueDefault}\"";
+ } else {
+ $invalidValueDefault = "\"\"";
+ }
+
# 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 )
@@ -6276,10 +6297,10 @@ sub GenerateReflectOnlyCheck
my $normalizeAttributeValue = join("\n", @normalizeAttributeCode);
$code .= <<END;
${indent}if (resultValue.isEmpty()) {
-${indent} ;
+${indent} $missingValueDefault;
${normalizeAttributeValue}
${indent}} else {
-${indent} resultValue = "";
+${indent} resultValue = $invalidValueDefault;
${indent}}
END
return "${code}";
« 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