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

Side by Side Diff: Source/bindings/scripts/deprecated_code_generator_v8.pm

Issue 23471005: Use UNLIKELY() macro in generated bindings for minimum argument count checks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/tests/results/V8Float64Array.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 foreach my $overload (@{$function->{overloads}}) { 2078 foreach my $overload (@{$function->{overloads}}) {
2079 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($overload); 2079 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($overload);
2080 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); 2080 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
2081 $code .= " if ($parametersCheck) {\n"; 2081 $code .= " if ($parametersCheck) {\n";
2082 my $overloadedIndexString = $overload->{overloadIndex}; 2082 my $overloadedIndexString = $overload->{overloadIndex};
2083 $code .= " ${name}${overloadedIndexString}Method${forMainWorldSuf fix}(args);\n"; 2083 $code .= " ${name}${overloadedIndexString}Method${forMainWorldSuf fix}(args);\n";
2084 $code .= " return;\n"; 2084 $code .= " return;\n";
2085 $code .= " }\n"; 2085 $code .= " }\n";
2086 } 2086 }
2087 if ($leastNumMandatoryParams >= 1) { 2087 if ($leastNumMandatoryParams >= 1) {
2088 $code .= " if (args.Length() < $leastNumMandatoryParams) {\n"; 2088 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n";
2089 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n"; 2089 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n";
2090 $code .= " return;\n"; 2090 $code .= " return;\n";
2091 $code .= " }\n"; 2091 $code .= " }\n";
2092 } 2092 }
2093 $code .= <<END; 2093 $code .= <<END;
2094 throwTypeError(args.GetIsolate()); 2094 throwTypeError(args.GetIsolate());
2095 END 2095 END
2096 $code .= "}\n\n"; 2096 $code .= "}\n\n";
2097 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 2097 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
2098 $implementation{nameSpaceInternal}->add($code); 2098 $implementation{nameSpaceInternal}->add($code);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 if ($param->isOptional or $param->isVariadic) { 2319 if ($param->isOptional or $param->isVariadic) {
2320 $allowNonOptional = 0; 2320 $allowNonOptional = 0;
2321 } else { 2321 } else {
2322 die "An argument must not be declared to be optional unless all subs equent arguments to the operation are also optional." if !$allowNonOptional; 2322 die "An argument must not be declared to be optional unless all subs equent arguments to the operation are also optional." if !$allowNonOptional;
2323 $numMandatoryParams++; 2323 $numMandatoryParams++;
2324 } 2324 }
2325 } 2325 }
2326 2326
2327 my $argumentsCountCheckString = ""; 2327 my $argumentsCountCheckString = "";
2328 if ($numMandatoryParams >= 1) { 2328 if ($numMandatoryParams >= 1) {
2329 $argumentsCountCheckString .= " if (args.Length() < $numMandatoryPara ms) {\n"; 2329 $argumentsCountCheckString .= " if (UNLIKELY(args.Length() < $numMand atoryParams)) {\n";
2330 $argumentsCountCheckString .= " throwNotEnoughArgumentsError(args .GetIsolate());\n"; 2330 $argumentsCountCheckString .= " throwNotEnoughArgumentsError(args .GetIsolate());\n";
2331 $argumentsCountCheckString .= " return;\n"; 2331 $argumentsCountCheckString .= " return;\n";
2332 $argumentsCountCheckString .= " }\n"; 2332 $argumentsCountCheckString .= " }\n";
2333 } 2333 }
2334 return $argumentsCountCheckString; 2334 return $argumentsCountCheckString;
2335 } 2335 }
2336 2336
2337 sub GenerateParametersCheck 2337 sub GenerateParametersCheck
2338 { 2338 {
2339 my $function = shift; 2339 my $function = shift;
2340 my $interface = shift; 2340 my $interface = shift;
2341 my $forMainWorldSuffix = shift; 2341 my $forMainWorldSuffix = shift;
2342 my $style = shift || "new"; 2342 my $style = shift || "new";
2343 2343
2344 my $parameterCheckString = ""; 2344 my $parameterCheckString = "";
2345 my $paramIndex = 0; 2345 my $paramIndex = 0;
2346 my %replacements = (); 2346 my %replacements = ();
2347 2347
2348 foreach my $parameter (@{$function->parameters}) { 2348 foreach my $parameter (@{$function->parameters}) {
2349 my $nativeType = GetNativeType($parameter->type, $parameter->extendedAtt ributes, "parameter"); 2349 my $nativeType = GetNativeType($parameter->type, $parameter->extendedAtt ributes, "parameter");
2350 2350
2351 # Optional arguments without [Default=...] should generate an early call with fewer arguments. 2351 # Optional arguments without [Default=...] should generate an early call with fewer arguments.
2352 # Optional arguments with [Optional=...] should not generate the early c all. 2352 # Optional arguments with [Optional=...] should not generate the early c all.
2353 # Optional Dictionary arguments always considered to have default of emp ty dictionary. 2353 # Optional Dictionary arguments always considered to have default of emp ty dictionary.
2354 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) { 2354 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) {
2355 $parameterCheckString .= " if (args.Length() <= $paramIndex)"; 2355 $parameterCheckString .= " if (UNLIKELY(args.Length() <= $paramIn dex))";
2356 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interface, $forMainWorldSuffix, %replacements); 2356 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interface, $forMainWorldSuffix, %replacements);
2357 my $multiLine = ($functionCall =~ tr/\n//) > 1; 2357 my $multiLine = ($functionCall =~ tr/\n//) > 1;
2358 $parameterCheckString .= $multiLine ? " {\n" : "\n"; 2358 $parameterCheckString .= $multiLine ? " {\n" : "\n";
2359 $parameterCheckString .= $functionCall; 2359 $parameterCheckString .= $functionCall;
2360 $parameterCheckString .= $multiLine ? " }\n" : "\n"; 2360 $parameterCheckString .= $multiLine ? " }\n" : "\n";
2361 } 2361 }
2362 2362
2363 my $parameterName = $parameter->name; 2363 my $parameterName = $parameter->name;
2364 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2364 AddToImplIncludes("bindings/v8/ExceptionState.h");
2365 if (IsCallbackInterface($parameter->type)) { 2365 if (IsCallbackInterface($parameter->type)) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 foreach my $constructor (@{$interface->constructors}) { 2485 foreach my $constructor (@{$interface->constructors}) {
2486 my $name = "constructor" . $constructor->overloadedIndex; 2486 my $name = "constructor" . $constructor->overloadedIndex;
2487 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($constructor); 2487 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($constructor);
2488 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); 2488 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
2489 $code .= " if ($parametersCheck) {\n"; 2489 $code .= " if ($parametersCheck) {\n";
2490 $code .= " ${implClassName}V8Internal::${name}(args);\n"; 2490 $code .= " ${implClassName}V8Internal::${name}(args);\n";
2491 $code .= " return;\n"; 2491 $code .= " return;\n";
2492 $code .= " }\n"; 2492 $code .= " }\n";
2493 } 2493 }
2494 if ($leastNumMandatoryParams >= 1) { 2494 if ($leastNumMandatoryParams >= 1) {
2495 $code .= " if (args.Length() < $leastNumMandatoryParams) {\n"; 2495 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n";
2496 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n"; 2496 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n";
2497 $code .= " return;\n"; 2497 $code .= " return;\n";
2498 $code .= " }\n"; 2498 $code .= " }\n";
2499 } 2499 }
2500 $code .= <<END; 2500 $code .= <<END;
2501 throwTypeError(args.GetIsolate()); 2501 throwTypeError(args.GetIsolate());
2502 return; 2502 return;
2503 END 2503 END
2504 $code .= "}\n\n"; 2504 $code .= "}\n\n";
2505 $implementation{nameSpaceInternal}->add($code); 2505 $implementation{nameSpaceInternal}->add($code);
(...skipping 3492 matching lines...) Expand 10 before | Expand all | Expand 10 after
5998 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { 5998 if ($currentInterface->extendedAttributes->{$extendedAttribute}) {
5999 $found = 1; 5999 $found = 1;
6000 } 6000 }
6001 return 1 if $found; 6001 return 1 if $found;
6002 }, 0); 6002 }, 0);
6003 6003
6004 return $found; 6004 return $found;
6005 } 6005 }
6006 6006
6007 1; 6007 1;
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/tests/results/V8Float64Array.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698