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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/code_generator_v8.pm
diff --git a/Source/bindings/scripts/code_generator_v8.pm b/Source/bindings/scripts/code_generator_v8.pm
index 138479fd4e922eff0b2c5b3fb8d815a18568791b..3bcb725567c383e5dd7cb8981b8911f691041d72 100644
--- a/Source/bindings/scripts/code_generator_v8.pm
+++ b/Source/bindings/scripts/code_generator_v8.pm
@@ -2194,6 +2194,24 @@ END
$implementation{nameSpaceInternal}->add($code);
}
+sub NullOrOptionalCheck
+{
+ my $parameter = shift;
+ my $value = shift;
+
+ # If undefined is passed for an optional argument, the argument should be
+ # treated as missing; otherwise undefined is not allowed.
+ if ($parameter->isNullable) {
+ if ($parameter->isOptional) {
+ return "isUndefinedOrNull($value)";
+ }
+ return "${value}->IsNull()";
+ }
+ if ($parameter->isOptional) {
+ return "${value}->IsUndefined()";
+ }
+}
+
sub GenerateParametersCheckExpression
{
my $numParameters = shift;
@@ -2207,6 +2225,8 @@ sub GenerateParametersCheckExpression
my $value = "info[$parameterIndex]";
my $type = $parameter->type;
+ my $undefinedOrNullCheck = NullOrOptionalCheck($parameter, $value);
+
# Only DOMString, wrapper types, and (to some degree) non-wrapper types
# are checked.
#
@@ -2245,8 +2265,8 @@ sub GenerateParametersCheckExpression
}
} elsif ($nonWrapperTypes{$type}) {
# Non-wrapper types are just objects: we don't distinguish type
- if ($parameter->isNullable) {
- push(@andExpression, "${value}->IsNull() || ${value}->IsObject()");
+ if ($undefinedOrNullCheck) {
+ push(@andExpression, "$undefinedOrNullCheck || ${value}->IsObject()");
} else {
push(@andExpression, "${value}->IsObject()");
}
« 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