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

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

Issue 152413005: IDL: allow optional values to be undefined in overload resolution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 deleteHiddenValue(info.GetIsolate(), info.Holder(), "${attrName}"); // Inval idate the cached value. 2187 deleteHiddenValue(info.GetIsolate(), info.Holder(), "${attrName}"); // Inval idate the cached value.
2188 END 2188 END
2189 } 2189 }
2190 2190
2191 $code .= "}\n"; # end of setter 2191 $code .= "}\n"; # end of setter
2192 $code .= "#endif // ${conditionalString}\n" if $conditionalString; 2192 $code .= "#endif // ${conditionalString}\n" if $conditionalString;
2193 $code .= "\n"; 2193 $code .= "\n";
2194 $implementation{nameSpaceInternal}->add($code); 2194 $implementation{nameSpaceInternal}->add($code);
2195 } 2195 }
2196 2196
2197 sub NullOrOptionalCheck
2198 {
2199 my $parameter = shift;
2200 my $value = shift;
2201
2202 # If undefined is passed for an optional argument, the argument should be
2203 # treated as missing; otherwise undefined is not allowed.
2204 if ($parameter->isNullable) {
2205 if ($parameter->isOptional) {
2206 return "isUndefinedOrNull($value)";
2207 }
2208 return "${value}->IsNull()";
2209 }
2210 if ($parameter->isOptional) {
2211 return "${value}->IsUndefined()";
2212 }
2213 }
2214
2197 sub GenerateParametersCheckExpression 2215 sub GenerateParametersCheckExpression
2198 { 2216 {
2199 my $numParameters = shift; 2217 my $numParameters = shift;
2200 my $function = shift; 2218 my $function = shift;
2201 2219
2202 my @andExpression = (); 2220 my @andExpression = ();
2203 push(@andExpression, "info.Length() == $numParameters"); 2221 push(@andExpression, "info.Length() == $numParameters");
2204 my $parameterIndex = 0; 2222 my $parameterIndex = 0;
2205 foreach my $parameter (@{$function->parameters}) { 2223 foreach my $parameter (@{$function->parameters}) {
2206 last if $parameterIndex >= $numParameters; 2224 last if $parameterIndex >= $numParameters;
2207 my $value = "info[$parameterIndex]"; 2225 my $value = "info[$parameterIndex]";
2208 my $type = $parameter->type; 2226 my $type = $parameter->type;
2209 2227
2228 my $undefinedOrNullCheck = NullOrOptionalCheck($parameter, $value);
2229
2210 # Only DOMString, wrapper types, and (to some degree) non-wrapper types 2230 # Only DOMString, wrapper types, and (to some degree) non-wrapper types
2211 # are checked. 2231 # are checked.
2212 # 2232 #
2213 # FIXME: If distinguishing non-primitive type from primitive type, 2233 # FIXME: If distinguishing non-primitive type from primitive type,
2214 # (e.g., sequence<DOMString> from DOMString or Dictionary from double) 2234 # (e.g., sequence<DOMString> from DOMString or Dictionary from double)
2215 # the non-primitive type must appear *first* in the IDL file, 2235 # the non-primitive type must appear *first* in the IDL file,
2216 # since we're not adding a check to primitive types. 2236 # since we're not adding a check to primitive types.
2217 # This can be avoided if compute overloads for whole overload set at 2237 # This can be avoided if compute overloads for whole overload set at
2218 # once, rather than one method at a time, but that requires a complete 2238 # once, rather than one method at a time, but that requires a complete
2219 # rewrite of this algorithm. 2239 # rewrite of this algorithm.
(...skipping 18 matching lines...) Expand all
2238 push(@andExpression, "${value}->IsArray()"); 2258 push(@andExpression, "${value}->IsArray()");
2239 } 2259 }
2240 } elsif (IsWrapperType($type)) { 2260 } elsif (IsWrapperType($type)) {
2241 if ($parameter->isNullable) { 2261 if ($parameter->isNullable) {
2242 push(@andExpression, "${value}->IsNull() || V8${type}::hasInstan ce($value, info.GetIsolate())"); 2262 push(@andExpression, "${value}->IsNull() || V8${type}::hasInstan ce($value, info.GetIsolate())");
2243 } else { 2263 } else {
2244 push(@andExpression, "V8${type}::hasInstance($value, info.GetIso late())"); 2264 push(@andExpression, "V8${type}::hasInstance($value, info.GetIso late())");
2245 } 2265 }
2246 } elsif ($nonWrapperTypes{$type}) { 2266 } elsif ($nonWrapperTypes{$type}) {
2247 # Non-wrapper types are just objects: we don't distinguish type 2267 # Non-wrapper types are just objects: we don't distinguish type
2248 if ($parameter->isNullable) { 2268 if ($undefinedOrNullCheck) {
2249 push(@andExpression, "${value}->IsNull() || ${value}->IsObject() "); 2269 push(@andExpression, "$undefinedOrNullCheck || ${value}->IsObjec t()");
2250 } else { 2270 } else {
2251 push(@andExpression, "${value}->IsObject()"); 2271 push(@andExpression, "${value}->IsObject()");
2252 } 2272 }
2253 } 2273 }
2254 2274
2255 $parameterIndex++; 2275 $parameterIndex++;
2256 } 2276 }
2257 @andExpression = map { "($_)" } @andExpression; 2277 @andExpression = map { "($_)" } @andExpression;
2258 my $res = "(" . join(" && ", @andExpression) . ")"; 2278 my $res = "(" . join(" && ", @andExpression) . ")";
2259 return $res; 2279 return $res;
(...skipping 4167 matching lines...) Expand 10 before | Expand all | Expand 10 after
6427 if ($parameter->type eq "SerializedScriptValue") { 6447 if ($parameter->type eq "SerializedScriptValue") {
6428 return 1; 6448 return 1;
6429 } elsif (IsIntegerType($parameter->type)) { 6449 } elsif (IsIntegerType($parameter->type)) {
6430 return 1; 6450 return 1;
6431 } 6451 }
6432 } 6452 }
6433 return 0; 6453 return 0;
6434 } 6454 }
6435 6455
6436 1; 6456 1;
OLDNEW
« no previous file with comments | « LayoutTests/storage/indexeddb/resources/index-basics.js ('k') | Source/bindings/tests/results/V8TestInterfaceConstructor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698