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 85263002: Improve handling of dictionary conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have conversion methods take a context argument; elaborate error msgs further. Created 7 years, 1 month 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
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 1f38d7fa439d5c5700fc55d0e031d6f1f6f6d393..faf104d7d74dd442dcf0a5c8bb23d3ad59c3b9e5 100644
--- a/Source/bindings/scripts/code_generator_v8.pm
+++ b/Source/bindings/scripts/code_generator_v8.pm
@@ -169,6 +169,16 @@ my %primitiveTypeHash = ("Date" => 1,
"double" => 1,
);
+my %integerTypeHash = ("byte" => 1,
+ "octet" => 1,
+ "short" => 1,
+ "long" => 1,
+ "long long" => 1,
+ "unsigned short" => 1,
+ "unsigned long" => 1,
+ "unsigned long long" => 1,
+ );
+
my %nonWrapperTypes = ("CompareHow" => 1,
"Dictionary" => 1,
"EventListener" => 1,
@@ -1019,7 +1029,7 @@ inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<${
END
if (IsConstructorTemplate($interface, "Event")) {
- $header{nameSpaceWebCore}->add("bool fill${implClassName}Init(${implClassName}Init&, const Dictionary&);\n\n");
+ $header{nameSpaceWebCore}->add("bool fill${implClassName}Init(${implClassName}Init&, const Dictionary&, ExceptionState&, const String& = \"\");\n\n");
}
}
@@ -2863,6 +2873,8 @@ sub GenerateEventConstructor
my $implClassName = GetImplName($interface);
my $v8ClassName = GetV8ClassName($interface);
+ my $constructorRaisesException = $interface->extendedAttributes->{"RaisesException"} && $interface->extendedAttributes->{"RaisesException"} eq "Constructor";
+
my @anyAttributeNames;
my @serializableAnyAttributeNames;
foreach my $attribute (@{$interface->attributes}) {
@@ -2895,8 +2907,11 @@ END
${implClassName}Init eventInit;
if (info.Length() >= 2) {
V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate()));
- if (!fill${implClassName}Init(eventInit, options))
+ ExceptionState exceptionState(info.Holder(), info.GetIsolate());
+ if (!fill${implClassName}Init(eventInit, options, exceptionState)) {
+ exceptionState.throwIfNeeded();
return;
+ }
END
# Store 'any'-typed properties on the wrapper to avoid leaking them between isolated worlds.
@@ -2910,10 +2925,27 @@ END
$implementation{nameSpaceInternal}->add(<<END);
}
+END
- RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit);
+ my $exceptionStateArgument = "";
+ if ($constructorRaisesException) {
+ ${exceptionStateArgument} = ", exceptionState";
+ $implementation{nameSpaceInternal}->add(<<END);
+ ExceptionState exceptionState(info.Holder(), info.GetIsolate());
+END
+ }
+
+ $implementation{nameSpaceInternal}->add(<<END);
+ RefPtr<${implClassName}> event = ${implClassName}::create(type, eventInit${exceptionStateArgument});
END
+ if ($constructorRaisesException) {
+ $implementation{nameSpaceInternal}->add(<<END);
+ if (exceptionState.throwIfNeeded())
+ return;
+END
+ }
+
if (@serializableAnyAttributeNames) {
# If we're in an isolated world, create a SerializedScriptValue and store it in the event for
# later cloning if the property is accessed from another world.
@@ -2939,14 +2971,15 @@ END
my $code = "";
$code .= <<END;
-bool fill${implClassName}Init(${implClassName}Init& eventInit, const Dictionary& options)
+bool fill${implClassName}Init(${implClassName}Init& eventInit, const Dictionary& options, ExceptionState& exceptionState, const String& forEventName)
{
+ Dictionary::ConversionContext conversionContext(forEventName.isEmpty() ? String("${interfaceName}") : forEventName, "", exceptionState);
END
if ($interface->parent) {
my $interfaceBase = $interface->parent;
$code .= <<END;
- if (!fill${interfaceBase}Init(eventInit, options))
+ if (!fill${interfaceBase}Init(eventInit, options, exceptionState, forEventName.isEmpty() ? String("${interfaceName}") : forEventName))
return false;
END
@@ -2958,12 +2991,40 @@ END
my $attributeName = $attribute->name;
my $attributeImplName = GetImplName($attribute);
my $deprecation = $attribute->extendedAttributes->{"DeprecateAs"};
- my $dictionaryGetter = "options.get(\"$attributeName\", eventInit.$attributeImplName)";
+
+ # Construct the arguments to the corresponding Dictionary.convert() method.
+ my @convertArguments = ();
+ if ($attribute->extendedAttributes->{"EnforceRange"}) {
+ push(@convertArguments, "EnforceRange");
+ } elsif ($attribute->extendedAttributes->{"Clamp"}) {
+ push(@convertArguments, "Clamp");
+ } elsif (IsIntegerType($attribute->type)) {
+ push(@convertArguments, "NormalConversion");
+ } elsif ($attribute->type eq "boolean" || $attribute->type eq "double") {
+ ;
+ } elsif ($attribute->type eq "DOMString" || IsEnumType($attribute->type) || IsCallbackFunctionType($attribute->type)) {
+ ;
+ } elsif ($attribute->type ne "object") {
+ push(@convertArguments, "\"" . $attribute->type . "\"");
+ }
+
+ my $withPropertyAttributes = "";
+ if (@convertArguments || $attribute->isNullable) {
+ unshift(@convertArguments, $attribute->isNullable ? "true" : "false");
+ $withPropertyAttributes = ".withAttributes(" . join(", ", @convertArguments) . ")";
+ }
+
+ my $dictionaryGetter = "options.convert(conversionContext${withPropertyAttributes}, \"$attributeName\", eventInit.$attributeImplName)";
if ($attribute->extendedAttributes->{"DeprecateAs"}) {
- $code .= " if ($dictionaryGetter)\n";
- $code .= " " . GenerateDeprecationNotification($attribute->extendedAttributes->{"DeprecateAs"});
+ $code .= " if ($dictionaryGetter) {\n";
+ $code .= " if (options.hasProperty(\"$attributeName\"))\n";
+ $code .= " " . GenerateDeprecationNotification($attribute->extendedAttributes->{"DeprecateAs"});
+ $code .= " } else {\n";
+ $code .= " return false;\n";
+ $code .= " }\n";
} else {
- $code .= " $dictionaryGetter;\n";
+ $code .= " if (!$dictionaryGetter)\n";
+ $code .= " return false;\n";
}
}
}
@@ -5942,6 +6003,14 @@ sub IsPrimitiveType
return 0;
}
+sub IsIntegerType
+{
+ my $type = shift;
+
+ return 1 if $integerTypeHash{$type};
+ return 0;
+}
+
sub IsCallbackFunctionType
{
my $type = shift;

Powered by Google App Engine
This is Rietveld 408576698