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

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

Issue 14244017: Make length property return useful values for DOM bindings functions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Make length property return useful values for DOM bindings functions and interfaces Created 7 years, 8 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
Index: Source/bindings/scripts/CodeGeneratorV8.pm
diff --git a/Source/bindings/scripts/CodeGeneratorV8.pm b/Source/bindings/scripts/CodeGeneratorV8.pm
index dbb1c56a26978f9f8378e0c343b7f91931113a41..d444f6621c34d2820676cfb6dd9574abe87a9574 100644
--- a/Source/bindings/scripts/CodeGeneratorV8.pm
+++ b/Source/bindings/scripts/CodeGeneratorV8.pm
@@ -2139,6 +2139,30 @@ END
push(@implContentInternals, "\n");
}
+# The Web IDL specification states that Interface objects for interfaces MUST have a property named
+# "length" that returns the length of the shortest argument list of the entries in the effective
+# overload set for constructors. In other words, use the lowest number of mandatory arguments among
+# all constructors.
+sub GetInterfaceLength
+{
+ my $interface = shift;
+
+ my $leastNumMandatoryParams = 0;
+ if ($codeGenerator->IsConstructorTemplate($interface, "Event") || $codeGenerator->IsConstructorTemplate($interface, "TypedArray")) {
+ $leastNumMandatoryParams = 1;
+ } elsif ($interface->extendedAttributes->{"Constructor"} || $interface->extendedAttributes->{"CustomConstructor"}) {
+ my @constructors = @{$interface->constructors};
+ my @customConstructors = @{$interface->customConstructors};
+ $leastNumMandatoryParams = 255;
+ foreach my $constructor (@constructors, @customConstructors) {
+ my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersCheck($constructor);
+ $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
+ }
+ }
+
+ return $leastNumMandatoryParams;
+}
+
sub GenerateConstructorCallback
{
my $interface = shift;
@@ -3048,10 +3072,12 @@ END
if ($function->signature->extendedAttributes->{"PerWorldBindings"}) {
$methodForMainWorld = "${interfaceName}V8Internal::${name}MethodCallbackForMainWorld";
}
+ # numMandatoryParams is used to set the "length" property of the Function object.
+ my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersCheck($function);
my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature);
push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
push(@implContent, <<END);
- {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMainWorld}},
+ {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMainWorld}, ${numMandatoryParams}},
END
push(@implContent, "#endif\n") if $conditionalString;
$num_callbacks++;
@@ -3186,6 +3212,8 @@ END
if (IsConstructable($interface)) {
push(@implContent, " desc->SetCallHandler(${v8InterfaceName}::constructorCallback);\n");
+ my $interfaceLength = GetInterfaceLength($interface);
+ push(@implContent, " desc->SetLength(${interfaceLength});\n");
}
if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has_constants) {

Powered by Google App Engine
This is Rietveld 408576698