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

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: Replace [Optional] by optional 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
« no previous file with comments | « LayoutTests/fast/js/function-length-expected.txt ('k') | Source/bindings/scripts/IDLParser.pm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/CodeGeneratorV8.pm
diff --git a/Source/bindings/scripts/CodeGeneratorV8.pm b/Source/bindings/scripts/CodeGeneratorV8.pm
index 4b2fba9bcb8f636dbbde4691ee16de1d73d6e015..ed4c8c670077e801299d17abadf00a99ea9e851a 100644
--- a/Source/bindings/scripts/CodeGeneratorV8.pm
+++ b/Source/bindings/scripts/CodeGeneratorV8.pm
@@ -2203,6 +2203,30 @@ END
AddToImplContentInternals($code);
}
+# 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;
@@ -3180,10 +3204,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);
$code .= "#if ${conditionalString}\n" if $conditionalString;
$code .= <<END;
- {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMainWorld}},
+ {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMainWorld}, ${numMandatoryParams}},
END
$code .= "#endif\n" if $conditionalString;
$num_callbacks++;
@@ -3321,6 +3347,8 @@ END
if (IsConstructable($interface)) {
$code .= " desc->SetCallHandler(${v8InterfaceName}::constructorCallback);\n";
+ my $interfaceLength = GetInterfaceLength($interface);
+ $code .= " desc->SetLength(${interfaceLength});\n";
}
if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has_constants) {
« no previous file with comments | « LayoutTests/fast/js/function-length-expected.txt ('k') | Source/bindings/scripts/IDLParser.pm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698