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

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

Issue 24203002: Improve generated "Not enough arguments." TypeError exceptions. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: FAIL. 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
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 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 AddToImplIncludes("bindings/v8/BindingSecurity.h"); 1443 AddToImplIncludes("bindings/v8/BindingSecurity.h");
1444 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($attribute) . "())) {\n"; 1444 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($attribute) . "())) {\n";
1445 $code .= " v8SetReturnValueNull(info);\n"; 1445 $code .= " v8SetReturnValueNull(info);\n";
1446 $code .= " return;\n"; 1446 $code .= " return;\n";
1447 $code .= " }\n"; 1447 $code .= " }\n";
1448 } 1448 }
1449 1449
1450 my $useExceptions = 1 if $attribute->extendedAttributes->{"GetterRaisesExcep tion"} || $attribute->extendedAttributes->{"RaisesException"}; 1450 my $useExceptions = 1 if $attribute->extendedAttributes->{"GetterRaisesExcep tion"} || $attribute->extendedAttributes->{"RaisesException"};
1451 my $isNullable = $attribute->isNullable; 1451 my $isNullable = $attribute->isNullable;
1452 if ($useExceptions) { 1452 if ($useExceptions) {
1453 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
1453 AddToImplIncludes("bindings/v8/ExceptionState.h"); 1454 AddToImplIncludes("bindings/v8/ExceptionState.h");
1454 $code .= " ExceptionState es(info.GetIsolate());\n"; 1455 $code .= " ExceptionState es(info.GetIsolate());\n";
1455 } 1456 }
1456 1457
1457 if ($isNullable) { 1458 if ($isNullable) {
1458 $code .= " bool isNull = false;\n"; 1459 $code .= " bool isNull = false;\n";
1459 } 1460 }
1460 1461
1461 my $returnType = $attribute->type; 1462 my $returnType = $attribute->type;
1462 my $getterString; 1463 my $getterString;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 } 1814 }
1814 1815
1815 my $svgNativeType = GetSVGTypeNeedingTearOff($interfaceName); 1816 my $svgNativeType = GetSVGTypeNeedingTearOff($interfaceName);
1816 if ($svgNativeType) { 1817 if ($svgNativeType) {
1817 my $svgWrappedNativeType = GetSVGWrappedTypeNeedingTearOff($interfaceNam e); 1818 my $svgWrappedNativeType = GetSVGWrappedTypeNeedingTearOff($interfaceNam e);
1818 if ($svgWrappedNativeType =~ /List$/) { 1819 if ($svgWrappedNativeType =~ /List$/) {
1819 $code .= <<END; 1820 $code .= <<END;
1820 $svgNativeType* imp = ${v8ClassName}::toNative(info.Holder()); 1821 $svgNativeType* imp = ${v8ClassName}::toNative(info.Holder());
1821 END 1822 END
1822 } else { 1823 } else {
1824 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
1823 AddToImplIncludes("bindings/v8/ExceptionState.h"); 1825 AddToImplIncludes("bindings/v8/ExceptionState.h");
1824 $code .= " $svgNativeType* wrapper = ${v8ClassName}::toNative(inf o.Holder());\n"; 1826 $code .= " $svgNativeType* wrapper = ${v8ClassName}::toNative(inf o.Holder());\n";
1825 $code .= " if (wrapper->isReadOnly()) {\n"; 1827 $code .= " if (wrapper->isReadOnly()) {\n";
1826 $code .= " setDOMException(NoModificationAllowedError, info.G etIsolate());\n"; 1828 $code .= " setDOMException(NoModificationAllowedError, info.G etIsolate());\n";
1827 $code .= " return;\n"; 1829 $code .= " return;\n";
1828 $code .= " }\n"; 1830 $code .= " }\n";
1829 $code .= " $svgWrappedNativeType& impInstance = wrapper->property Reference();\n"; 1831 $code .= " $svgWrappedNativeType& impInstance = wrapper->property Reference();\n";
1830 $code .= " $svgWrappedNativeType* imp = &impInstance;\n"; 1832 $code .= " $svgWrappedNativeType* imp = &impInstance;\n";
1831 } 1833 }
1832 } elsif ($attrExt->{"OnProto"}) { 1834 } elsif ($attrExt->{"OnProto"}) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 my $returnType = $attribute->type; 1889 my $returnType = $attribute->type;
1888 if (IsRefPtrType($returnType) && !GetArrayType($returnType)) { 1890 if (IsRefPtrType($returnType) && !GetArrayType($returnType)) {
1889 $expression = "WTF::getPtr(" . $expression . ")"; 1891 $expression = "WTF::getPtr(" . $expression . ")";
1890 } 1892 }
1891 1893
1892 $code .= GenerateCustomElementInvocationScopeIfNeeded($attribute->extendedAt tributes); 1894 $code .= GenerateCustomElementInvocationScopeIfNeeded($attribute->extendedAt tributes);
1893 1895
1894 my $useExceptions = 1 if $attribute->extendedAttributes->{"SetterRaisesExcep tion"} || $attribute->extendedAttributes->{"RaisesException"}; 1896 my $useExceptions = 1 if $attribute->extendedAttributes->{"SetterRaisesExcep tion"} || $attribute->extendedAttributes->{"RaisesException"};
1895 1897
1896 if ($useExceptions) { 1898 if ($useExceptions) {
1899 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
1897 AddToImplIncludes("bindings/v8/ExceptionState.h"); 1900 AddToImplIncludes("bindings/v8/ExceptionState.h");
1898 $code .= " ExceptionState es(info.GetIsolate());\n"; 1901 $code .= " ExceptionState es(info.GetIsolate());\n";
1899 } 1902 }
1900 1903
1901 if ($attribute->type eq "EventHandler") { 1904 if ($attribute->type eq "EventHandler") {
1902 my $implSetterFunctionName = FirstLetterToUpperCase($attrName); 1905 my $implSetterFunctionName = FirstLetterToUpperCase($attrName);
1903 AddToImplIncludes("bindings/v8/V8AbstractEventListener.h"); 1906 AddToImplIncludes("bindings/v8/V8AbstractEventListener.h");
1904 # Non callable input should be treated as null 1907 # Non callable input should be treated as null
1905 $code .= " if (!value->IsNull() && !value->IsFunction())\n"; 1908 $code .= " if (!value->IsNull() && !value->IsFunction())\n";
1906 $code .= " value = v8::Null(info.GetIsolate());\n"; 1909 $code .= " value = v8::Null(info.GetIsolate());\n";
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 my $interface = shift; 2062 my $interface = shift;
2060 my $forMainWorldSuffix = shift; 2063 my $forMainWorldSuffix = shift;
2061 2064
2062 # Generate code for choosing the correct overload to call. Overloads are 2065 # Generate code for choosing the correct overload to call. Overloads are
2063 # chosen based on the total number of arguments passed and the type of 2066 # chosen based on the total number of arguments passed and the type of
2064 # values passed in non-primitive argument slots. When more than a single 2067 # values passed in non-primitive argument slots. When more than a single
2065 # overload is applicable, precedence is given according to the order of 2068 # overload is applicable, precedence is given according to the order of
2066 # declaration in the IDL. 2069 # declaration in the IDL.
2067 2070
2068 my $name = $function->name; 2071 my $name = $function->name;
2072 my $implClassName = GetImplName($interface);
2069 2073
2070 my $conditionalString = GenerateConditionalString($function); 2074 my $conditionalString = GenerateConditionalString($function);
2071 my $leastNumMandatoryParams = 255; 2075 my $leastNumMandatoryParams = 255;
2072 my $code = ""; 2076 my $code = "";
2073 $code .= "#if ${conditionalString}\n\n" if $conditionalString; 2077 $code .= "#if ${conditionalString}\n\n" if $conditionalString;
2074 $code .= <<END; 2078 $code .= <<END;
2075 static void ${name}Method${forMainWorldSuffix}(const v8::FunctionCallbackInfo<v8 ::Value>& args) 2079 static void ${name}Method${forMainWorldSuffix}(const v8::FunctionCallbackInfo<v8 ::Value>& args)
2076 { 2080 {
2077 END 2081 END
2078 $code .= GenerateFeatureObservation($function->extendedAttributes->{"Measure As"}); 2082 $code .= GenerateFeatureObservation($function->extendedAttributes->{"Measure As"});
2079 $code .= GenerateDeprecationNotification($function->extendedAttributes->{"De precateAs"}); 2083 $code .= GenerateDeprecationNotification($function->extendedAttributes->{"De precateAs"});
2080 2084
2081 foreach my $overload (@{$function->{overloads}}) { 2085 foreach my $overload (@{$function->{overloads}}) {
2082 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($overload); 2086 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($overload);
2083 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); 2087 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
2084 $code .= " if ($parametersCheck) {\n"; 2088 $code .= " if ($parametersCheck) {\n";
2085 my $overloadedIndexString = $overload->{overloadIndex}; 2089 my $overloadedIndexString = $overload->{overloadIndex};
2086 $code .= " ${name}${overloadedIndexString}Method${forMainWorldSuf fix}(args);\n"; 2090 $code .= " ${name}${overloadedIndexString}Method${forMainWorldSuf fix}(args);\n";
2087 $code .= " return;\n"; 2091 $code .= " return;\n";
2088 $code .= " }\n"; 2092 $code .= " }\n";
2089 } 2093 }
2090 if ($leastNumMandatoryParams >= 1) { 2094 if ($leastNumMandatoryParams >= 1) {
2091 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n"; 2095 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n";
2092 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n"; 2096 $code .= " throwTypeError(ExceptionMessages::failedToExecute(\"$n ame\", \"$implClassName\", \"$leastNumMandatoryParams argument" . ($leastNumMand atoryParams > 1 ? "s" : "") . " required, but only \" + String::number(args.Len gth()) + \" present.\"), args.GetIsolate());\n";
marja 2013/09/18 10:24:08 Would it make sense to add a func to ExceptionMess
Mike West 2013/09/18 11:16:34 I've added it, but I'm not sure it makes sense. Ta
marja 2013/09/18 11:23:50 I like this version a lot better, merely the distr
2093 $code .= " return;\n"; 2097 $code .= " return;\n";
2094 $code .= " }\n"; 2098 $code .= " }\n";
2095 } 2099 }
2096 $code .= <<END; 2100 $code .= <<END;
2097 throwTypeError(args.GetIsolate()); 2101 throwTypeError(args.GetIsolate());
2098 END 2102 END
2099 $code .= "}\n\n"; 2103 $code .= "}\n\n";
2100 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString; 2104 $code .= "#endif // ${conditionalString}\n\n" if $conditionalString;
2101 $implementation{nameSpaceInternal}->add($code); 2105 $implementation{nameSpaceInternal}->add($code);
2102 } 2106 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 return; 2217 return;
2214 } 2218 }
2215 2219
2216 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGProperty Types($interfaceName); 2220 my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGProperty Types($interfaceName);
2217 2221
2218 if ($svgNativeType) { 2222 if ($svgNativeType) {
2219 my $nativeClassName = GetNativeType($interfaceName); 2223 my $nativeClassName = GetNativeType($interfaceName);
2220 if ($interfaceName =~ /List$/) { 2224 if ($interfaceName =~ /List$/) {
2221 $code .= " $nativeClassName imp = ${v8ClassName}::toNative(args.H older());\n"; 2225 $code .= " $nativeClassName imp = ${v8ClassName}::toNative(args.H older());\n";
2222 } else { 2226 } else {
2227 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2223 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2228 AddToImplIncludes("bindings/v8/ExceptionState.h");
2224 AddToImplIncludes("core/dom/ExceptionCode.h"); 2229 AddToImplIncludes("core/dom/ExceptionCode.h");
2225 $code .= " $nativeClassName wrapper = ${v8ClassName}::toNative(ar gs.Holder());\n"; 2230 $code .= " $nativeClassName wrapper = ${v8ClassName}::toNative(ar gs.Holder());\n";
2226 $code .= " if (wrapper->isReadOnly()) {\n"; 2231 $code .= " if (wrapper->isReadOnly()) {\n";
2227 $code .= " setDOMException(NoModificationAllowedError, args.G etIsolate());\n"; 2232 $code .= " setDOMException(NoModificationAllowedError, args.G etIsolate());\n";
2228 $code .= " return;\n"; 2233 $code .= " return;\n";
2229 $code .= " }\n"; 2234 $code .= " }\n";
2230 my $svgWrappedNativeType = GetSVGWrappedTypeNeedingTearOff($interfac eName); 2235 my $svgWrappedNativeType = GetSVGWrappedTypeNeedingTearOff($interfac eName);
2231 $code .= " $svgWrappedNativeType& impInstance = wrapper->property Reference();\n"; 2236 $code .= " $svgWrappedNativeType& impInstance = wrapper->property Reference();\n";
2232 $code .= " $svgWrappedNativeType* imp = &impInstance;\n"; 2237 $code .= " $svgWrappedNativeType* imp = &impInstance;\n";
(...skipping 11 matching lines...) Expand all
2244 # We have not find real use cases yet. 2249 # We have not find real use cases yet.
2245 AddToImplIncludes("bindings/v8/BindingSecurity.h"); 2250 AddToImplIncludes("bindings/v8/BindingSecurity.h");
2246 $code .= <<END; 2251 $code .= <<END;
2247 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 2252 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
2248 return; 2253 return;
2249 END 2254 END
2250 } 2255 }
2251 2256
2252 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"}; 2257 my $raisesExceptions = $function->extendedAttributes->{"RaisesException"};
2253 if ($raisesExceptions) { 2258 if ($raisesExceptions) {
2259 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2254 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2260 AddToImplIncludes("bindings/v8/ExceptionState.h");
2255 $code .= " ExceptionState es(args.GetIsolate());\n"; 2261 $code .= " ExceptionState es(args.GetIsolate());\n";
2256 } 2262 }
2257 2263
2258 if ($function->extendedAttributes->{"CheckSecurityForNode"}) { 2264 if ($function->extendedAttributes->{"CheckSecurityForNode"}) {
2259 AddToImplIncludes("bindings/v8/BindingSecurity.h"); 2265 AddToImplIncludes("bindings/v8/BindingSecurity.h");
2260 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($function) . "(es))) {\n"; 2266 $code .= " if (!BindingSecurity::shouldAllowAccessToNode(imp->" . Get ImplName($function) . "(es))) {\n";
2261 $code .= " v8SetReturnValueNull(args);\n"; 2267 $code .= " v8SetReturnValueNull(args);\n";
2262 $code .= " return;\n"; 2268 $code .= " return;\n";
2263 $code .= " }\n"; 2269 $code .= " }\n";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 push(@callWithArgs, "firstDOMWindow()"); 2314 push(@callWithArgs, "firstDOMWindow()");
2309 } 2315 }
2310 return ([@callWithArgs], $code); 2316 return ([@callWithArgs], $code);
2311 } 2317 }
2312 2318
2313 sub GenerateArgumentsCountCheck 2319 sub GenerateArgumentsCountCheck
2314 { 2320 {
2315 my $function = shift; 2321 my $function = shift;
2316 my $interface = shift; 2322 my $interface = shift;
2317 2323
2324 my $functionName = $function->name;
2325 my $implClassName = GetImplName($interface);
2326
2318 my $numMandatoryParams = 0; 2327 my $numMandatoryParams = 0;
2319 my $allowNonOptional = 1; 2328 my $allowNonOptional = 1;
2320 foreach my $param (@{$function->parameters}) { 2329 foreach my $param (@{$function->parameters}) {
2321 if ($param->isOptional or $param->isVariadic) { 2330 if ($param->isOptional or $param->isVariadic) {
2322 $allowNonOptional = 0; 2331 $allowNonOptional = 0;
2323 } else { 2332 } else {
2324 die "An argument must not be declared to be optional unless all subs equent arguments to the operation are also optional." if !$allowNonOptional; 2333 die "An argument must not be declared to be optional unless all subs equent arguments to the operation are also optional." if !$allowNonOptional;
2325 $numMandatoryParams++; 2334 $numMandatoryParams++;
2326 } 2335 }
2327 } 2336 }
2328 2337
2329 my $argumentsCountCheckString = ""; 2338 my $argumentsCountCheckString = "";
2330 if ($numMandatoryParams >= 1) { 2339 if ($numMandatoryParams >= 1) {
2331 $argumentsCountCheckString .= " if (UNLIKELY(args.Length() < $numMand atoryParams)) {\n"; 2340 $argumentsCountCheckString .= " if (UNLIKELY(args.Length() < $numMand atoryParams)) {\n";
2332 $argumentsCountCheckString .= " throwNotEnoughArgumentsError(args .GetIsolate());\n"; 2341 $argumentsCountCheckString .= " throwTypeError(ExceptionMessages: :failedToExecute(\"$functionName\", \"$implClassName\", \"$numMandatoryParams ar gument" . ($numMandatoryParams > 1 ? "s" : "") . " required, but only \" + Stri ng::number(args.Length()) + \" present.\"), args.GetIsolate());\n";
2333 $argumentsCountCheckString .= " return;\n"; 2342 $argumentsCountCheckString .= " return;\n";
2334 $argumentsCountCheckString .= " }\n"; 2343 $argumentsCountCheckString .= " }\n";
2335 } 2344 }
2336 return $argumentsCountCheckString; 2345 return $argumentsCountCheckString;
2337 } 2346 }
2338 2347
2339 sub GenerateParametersCheck 2348 sub GenerateParametersCheck
2340 { 2349 {
2341 my $function = shift; 2350 my $function = shift;
2342 my $interface = shift; 2351 my $interface = shift;
(...skipping 13 matching lines...) Expand all
2356 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) { 2365 if ($parameter->isOptional && !$parameter->extendedAttributes->{"Default "} && $nativeType ne "Dictionary" && !IsCallbackInterface($parameter->type)) {
2357 $parameterCheckString .= " if (UNLIKELY(args.Length() <= $paramIn dex))"; 2366 $parameterCheckString .= " if (UNLIKELY(args.Length() <= $paramIn dex))";
2358 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interface, $forMainWorldSuffix, %replacements); 2367 my $functionCall = GenerateFunctionCallString($function, $paramIndex , " " x 2, $interface, $forMainWorldSuffix, %replacements);
2359 my $multiLine = ($functionCall =~ tr/\n//) > 1; 2368 my $multiLine = ($functionCall =~ tr/\n//) > 1;
2360 $parameterCheckString .= $multiLine ? " {\n" : "\n"; 2369 $parameterCheckString .= $multiLine ? " {\n" : "\n";
2361 $parameterCheckString .= $functionCall; 2370 $parameterCheckString .= $functionCall;
2362 $parameterCheckString .= $multiLine ? " }\n" : "\n"; 2371 $parameterCheckString .= $multiLine ? " }\n" : "\n";
2363 } 2372 }
2364 2373
2365 my $parameterName = $parameter->name; 2374 my $parameterName = $parameter->name;
2375 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2366 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2376 AddToImplIncludes("bindings/v8/ExceptionState.h");
2367 if (IsCallbackInterface($parameter->type)) { 2377 if (IsCallbackInterface($parameter->type)) {
2368 my $v8ClassName = "V8" . $parameter->type; 2378 my $v8ClassName = "V8" . $parameter->type;
2369 AddToImplIncludes("$v8ClassName.h"); 2379 AddToImplIncludes("$v8ClassName.h");
2370 if ($parameter->isOptional) { 2380 if ($parameter->isOptional) {
2371 $parameterCheckString .= " RefPtr<" . $parameter->type . "> $ parameterName;\n"; 2381 $parameterCheckString .= " RefPtr<" . $parameter->type . "> $ parameterName;\n";
2372 $parameterCheckString .= " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n"; 2382 $parameterCheckString .= " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n";
2373 $parameterCheckString .= " if (!args[$paramIndex]->IsFunc tion()) {\n"; 2383 $parameterCheckString .= " if (!args[$paramIndex]->IsFunc tion()) {\n";
2374 $parameterCheckString .= " throwTypeError(args.GetIso late());\n"; 2384 $parameterCheckString .= " throwTypeError(args.GetIso late());\n";
2375 $parameterCheckString .= " return;\n"; 2385 $parameterCheckString .= " return;\n";
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 foreach my $constructor (@{$interface->constructors}) { 2497 foreach my $constructor (@{$interface->constructors}) {
2488 my $name = "constructor" . $constructor->overloadedIndex; 2498 my $name = "constructor" . $constructor->overloadedIndex;
2489 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($constructor); 2499 my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersC heck($constructor);
2490 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); 2500 $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
2491 $code .= " if ($parametersCheck) {\n"; 2501 $code .= " if ($parametersCheck) {\n";
2492 $code .= " ${implClassName}V8Internal::${name}(args);\n"; 2502 $code .= " ${implClassName}V8Internal::${name}(args);\n";
2493 $code .= " return;\n"; 2503 $code .= " return;\n";
2494 $code .= " }\n"; 2504 $code .= " }\n";
2495 } 2505 }
2496 if ($leastNumMandatoryParams >= 1) { 2506 if ($leastNumMandatoryParams >= 1) {
2507 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2497 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n"; 2508 $code .= " if (UNLIKELY(args.Length() < $leastNumMandatoryParams)) {\ n";
2498 $code .= " throwNotEnoughArgumentsError(args.GetIsolate());\n"; 2509
2510 $code .= " throwTypeError(ExceptionMessages::failedToConstruct(\" $implClassName\", \"$leastNumMandatoryParams argument" . ($leastNumMandatoryPara ms > 1 ? "s" : "") . " required, but only \" + String::number(args.Length()) + \" present.\"), args.GetIsolate());\n";
2499 $code .= " return;\n"; 2511 $code .= " return;\n";
2500 $code .= " }\n"; 2512 $code .= " }\n";
2501 } 2513 }
2502 $code .= <<END; 2514 $code .= <<END;
2503 throwTypeError(args.GetIsolate()); 2515 throwTypeError(args.GetIsolate());
2504 return; 2516 return;
2505 END 2517 END
2506 $code .= "}\n\n"; 2518 $code .= "}\n\n";
2507 $implementation{nameSpaceInternal}->add($code); 2519 $implementation{nameSpaceInternal}->add($code);
2508 } 2520 }
(...skipping 21 matching lines...) Expand all
2530 $code .= <<END; 2542 $code .= <<END;
2531 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& args) 2543 static void constructor${overloadedIndexString}(const v8::FunctionCallbackInfo<v 8::Value>& args)
2532 { 2544 {
2533 END 2545 END
2534 2546
2535 if ($function->overloadedIndex == 0) { 2547 if ($function->overloadedIndex == 0) {
2536 $code .= GenerateArgumentsCountCheck($function, $interface); 2548 $code .= GenerateArgumentsCountCheck($function, $interface);
2537 } 2549 }
2538 2550
2539 if ($raisesExceptions) { 2551 if ($raisesExceptions) {
2552 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2540 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2553 AddToImplIncludes("bindings/v8/ExceptionState.h");
2541 $code .= " ExceptionState es(args.GetIsolate());\n"; 2554 $code .= " ExceptionState es(args.GetIsolate());\n";
2542 } 2555 }
2543 2556
2544 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...] 2557 # FIXME: Currently [Constructor(...)] does not yet support optional argument s without [Default=...]
2545 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, ""); 2558 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface, "");
2546 $code .= $parameterCheckString; 2559 $code .= $parameterCheckString;
2547 2560
2548 if ($interface->extendedAttributes->{"ConstructorCallWith"}) { 2561 if ($interface->extendedAttributes->{"ConstructorCallWith"}) {
2549 if ($interface->extendedAttributes->{"ConstructorCallWith"} eq "ScriptEx ecutionContext") { 2562 if ($interface->extendedAttributes->{"ConstructorCallWith"} eq "ScriptEx ecutionContext") {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 foreach my $attribute (@{$interface->attributes}) { 2677 foreach my $attribute (@{$interface->attributes}) {
2665 if ($attribute->type eq "any") { 2678 if ($attribute->type eq "any") {
2666 push(@anyAttributeNames, $attribute->name); 2679 push(@anyAttributeNames, $attribute->name);
2667 if (!$attribute->extendedAttributes->{"Unserializable"}) { 2680 if (!$attribute->extendedAttributes->{"Unserializable"}) {
2668 push(@serializableAnyAttributeNames, $attribute->name); 2681 push(@serializableAnyAttributeNames, $attribute->name);
2669 } 2682 }
2670 } 2683 }
2671 } 2684 }
2672 2685
2673 AddToImplIncludes("bindings/v8/Dictionary.h"); 2686 AddToImplIncludes("bindings/v8/Dictionary.h");
2687 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2674 $implementation{nameSpaceInternal}->add(<<END); 2688 $implementation{nameSpaceInternal}->add(<<END);
2675 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& args) 2689 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& args)
2676 { 2690 {
2677 if (args.Length() < 1) { 2691 if (args.Length() < 1) {
2678 throwNotEnoughArgumentsError(args.GetIsolate()); 2692 throwTypeError(ExceptionMessages::failedToConstruct("$implClassName", "A n event name must be provided."), args.GetIsolate());
2679 return; 2693 return;
2680 } 2694 }
2681 2695
2682 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]); 2696 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]);
2683 END 2697 END
2684 2698
2685 foreach my $attrName (@anyAttributeNames) { 2699 foreach my $attrName (@anyAttributeNames) {
2686 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n"); 2700 $implementation{nameSpaceInternal}->add(" v8::Local<v8::Value> ${attr Name};\n");
2687 } 2701 }
2688 2702
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2819 2833
2820 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance 2834 // Make sure the document is added to the DOM Node map. Otherwise, the ${imp lClassName} instance
2821 // may end up being the only node in the map and get garbage-collected prema turely. 2835 // may end up being the only node in the map and get garbage-collected prema turely.
2822 toV8(document, args.Holder(), args.GetIsolate()); 2836 toV8(document, args.Holder(), args.GetIsolate());
2823 2837
2824 END 2838 END
2825 2839
2826 $code .= GenerateArgumentsCountCheck($function, $interface); 2840 $code .= GenerateArgumentsCountCheck($function, $interface);
2827 2841
2828 if ($raisesExceptions) { 2842 if ($raisesExceptions) {
2843 AddToImplIncludes("bindings/v8/ExceptionMessages.h");
2829 AddToImplIncludes("bindings/v8/ExceptionState.h"); 2844 AddToImplIncludes("bindings/v8/ExceptionState.h");
2830 $code .= " ExceptionState es(args.GetIsolate());\n"; 2845 $code .= " ExceptionState es(args.GetIsolate());\n";
2831 } 2846 }
2832 2847
2833 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface); 2848 my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersC heck($function, $interface);
2834 $code .= $parameterCheckString; 2849 $code .= $parameterCheckString;
2835 2850
2836 push(@beforeArgumentList, "*document"); 2851 push(@beforeArgumentList, "*document");
2837 2852
2838 if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { 2853 if ($interface->extendedAttributes->{"ConstructorRaisesException"}) {
(...skipping 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after
6024 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { 6039 if ($currentInterface->extendedAttributes->{$extendedAttribute}) {
6025 $found = 1; 6040 $found = 1;
6026 } 6041 }
6027 return 1 if $found; 6042 return 1 if $found;
6028 }, 0); 6043 }, 0);
6029 6044
6030 return $found; 6045 return $found;
6031 } 6046 }
6032 6047
6033 1; 6048 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698