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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
5 # Copyright (C) 2006 Apple Computer, Inc. 5 # Copyright (C) 2006 Apple Computer, Inc.
6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc. 6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 # Copyright (C) 2012 Ericsson AB. All rights reserved. 10 # Copyright (C) 2012 Ericsson AB. All rights reserved.
(...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 2132
2133 if ($raisesExceptions) { 2133 if ($raisesExceptions) {
2134 push(@implContentInternals, " fail:\n"); 2134 push(@implContentInternals, " fail:\n");
2135 push(@implContentInternals, " return setDOMException(ec, args.GetIsol ate());\n"); 2135 push(@implContentInternals, " return setDOMException(ec, args.GetIsol ate());\n");
2136 } 2136 }
2137 2137
2138 push(@implContentInternals, "}\n"); 2138 push(@implContentInternals, "}\n");
2139 push(@implContentInternals, "\n"); 2139 push(@implContentInternals, "\n");
2140 } 2140 }
2141 2141
2142 # The Web IDL specification states that Interface objects for interfaces MUST ha ve a property named
2143 # "length" that returns the length of the shortest argument list of the entries in the effective
2144 # overload set for constructors. In other words, use the lowest number of mandat ory arguments among
2145 # all constructors.
2146 sub GetInterfaceLength
2147 {
2148 my $interface = shift;
2149
2150 my $leastNumMandatoryParams = 0;
2151 if ($codeGenerator->IsConstructorTemplate($interface, "Event") || $codeGener ator->IsConstructorTemplate($interface, "TypedArray")) {
2152 $leastNumMandatoryParams = 1;
2153 } elsif ($interface->extendedAttributes->{"Constructor"} || $interface->exte ndedAttributes->{"CustomConstructor"}) {
2154 my @constructors = @{$interface->constructors};
2155 my @customConstructors = @{$interface->customConstructors};
2156 $leastNumMandatoryParams = 255;
2157 foreach my $constructor (@constructors, @customConstructors) {
2158 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParamet ersCheck($constructor);
2159 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryPara ms < $leastNumMandatoryParams);
2160 }
2161 }
2162
2163 return $leastNumMandatoryParams;
2164 }
2165
2142 sub GenerateConstructorCallback 2166 sub GenerateConstructorCallback
2143 { 2167 {
2144 my $interface = shift; 2168 my $interface = shift;
2145 2169
2146 my $interfaceName = $interface->name; 2170 my $interfaceName = $interface->name;
2147 push(@implContent, "v8::Handle<v8::Value> V8${interfaceName}::constructorCal lback(const v8::Arguments& args)\n"); 2171 push(@implContent, "v8::Handle<v8::Value> V8${interfaceName}::constructorCal lback(const v8::Arguments& args)\n");
2148 push(@implContent, "{\n"); 2172 push(@implContent, "{\n");
2149 push(@implContent, GenerateFeatureObservation($interface->extendedAttributes ->{"MeasureAs"})); 2173 push(@implContent, GenerateFeatureObservation($interface->extendedAttributes ->{"MeasureAs"}));
2150 push(@implContent, GenerateConstructorHeader()); 2174 push(@implContent, GenerateConstructorHeader());
2151 if (HasCustomConstructor($interface)) { 2175 if (HasCustomConstructor($interface)) {
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
3041 next if !IsStandardFunction($interface, $function); 3065 next if !IsStandardFunction($interface, $function);
3042 if (!$has_callbacks) { 3066 if (!$has_callbacks) {
3043 $has_callbacks = 1; 3067 $has_callbacks = 1;
3044 push(@implContent, "static const V8DOMConfiguration::BatchedMethod $ {v8InterfaceName}Methods[] = {\n"); 3068 push(@implContent, "static const V8DOMConfiguration::BatchedMethod $ {v8InterfaceName}Methods[] = {\n");
3045 } 3069 }
3046 my $name = $function->signature->name; 3070 my $name = $function->signature->name;
3047 my $methodForMainWorld = "0"; 3071 my $methodForMainWorld = "0";
3048 if ($function->signature->extendedAttributes->{"PerWorldBindings"}) { 3072 if ($function->signature->extendedAttributes->{"PerWorldBindings"}) {
3049 $methodForMainWorld = "${interfaceName}V8Internal::${name}MethodCall backForMainWorld"; 3073 $methodForMainWorld = "${interfaceName}V8Internal::${name}MethodCall backForMainWorld";
3050 } 3074 }
3075 # numMandatoryParams is used to set the "length" property of the Functio n object.
3076 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($function);
3051 my $conditionalString = $codeGenerator->GenerateConditionalString($funct ion->signature); 3077 my $conditionalString = $codeGenerator->GenerateConditionalString($funct ion->signature);
3052 push(@implContent, "#if ${conditionalString}\n") if $conditionalString; 3078 push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
3053 push(@implContent, <<END); 3079 push(@implContent, <<END);
3054 {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMain World}}, 3080 {"$name", ${interfaceName}V8Internal::${name}MethodCallback, ${methodForMain World}, ${numMandatoryParams}},
3055 END 3081 END
3056 push(@implContent, "#endif\n") if $conditionalString; 3082 push(@implContent, "#endif\n") if $conditionalString;
3057 $num_callbacks++; 3083 $num_callbacks++;
3058 } 3084 }
3059 push(@implContent, "};\n\n") if $has_callbacks; 3085 push(@implContent, "};\n\n") if $has_callbacks;
3060 3086
3061 # Setup constants 3087 # Setup constants
3062 my $has_constants = 0; 3088 my $has_constants = 0;
3063 my @constantsEnabledAtRuntime; 3089 my @constantsEnabledAtRuntime;
3064 if (@{$interface->constants}) { 3090 if (@{$interface->constants}) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 END 3205 END
3180 } 3206 }
3181 3207
3182 AddToImplIncludes("wtf/UnusedParam.h"); 3208 AddToImplIncludes("wtf/UnusedParam.h");
3183 push(@implContent, <<END); 3209 push(@implContent, <<END);
3184 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. 3210 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
3185 END 3211 END
3186 3212
3187 if (IsConstructable($interface)) { 3213 if (IsConstructable($interface)) {
3188 push(@implContent, " desc->SetCallHandler(${v8InterfaceName}::constru ctorCallback);\n"); 3214 push(@implContent, " desc->SetCallHandler(${v8InterfaceName}::constru ctorCallback);\n");
3215 my $interfaceLength = GetInterfaceLength($interface);
3216 push(@implContent, " desc->SetLength(${interfaceLength});\n");
3189 } 3217 }
3190 3218
3191 if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has _constants) { 3219 if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has _constants) {
3192 push(@implContent, <<END); 3220 push(@implContent, <<END);
3193 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); 3221 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
3194 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); 3222 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
3195 UNUSED_PARAM(instance); // In some cases, it will not be used. 3223 UNUSED_PARAM(instance); // In some cases, it will not be used.
3196 UNUSED_PARAM(proto); // In some cases, it will not be used. 3224 UNUSED_PARAM(proto); // In some cases, it will not be used.
3197 END 3225 END
3198 } 3226 }
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
4588 4616
4589 sub GetPassRefPtrType 4617 sub GetPassRefPtrType
4590 { 4618 {
4591 my $v8InterfaceName = shift; 4619 my $v8InterfaceName = shift;
4592 4620
4593 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : ""; 4621 my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : "";
4594 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>"; 4622 return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>";
4595 } 4623 }
4596 4624
4597 1; 4625 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698