Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid redundant isUndefined() check for parameters that are both opti…
…onal and nullable in overloads

https://bugs.webkit.org/show_bug.cgi?id=158380

Reviewed by Brady Eidson.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheckExpression):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter):


Canonical link: https://commits.webkit.org/176467@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201681 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jun 4, 2016
1 parent 5bcbd4a commit b8bad5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,15 @@
2016-06-04 Chris Dumez <cdumez@apple.com>

Avoid redundant isUndefined() check for parameters that are both optional and nullable in overloads
https://bugs.webkit.org/show_bug.cgi?id=158380

Reviewed by Brady Eidson.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheckExpression):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter):

2016-06-04 Brent Fulgham <bfulgham@apple.com>

CSP: Content Security Policy directive, upgrade-insecure-requests (UIR)
Expand Down
8 changes: 5 additions & 3 deletions Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Expand Up @@ -1685,10 +1685,12 @@ sub GenerateParametersCheckExpression
$usedArguments{$parameterIndex} = 1;
} elsif ($codeGenerator->GetArrayOrSequenceType($type) || $codeGenerator->IsTypedArrayType($type) || $codeGenerator->IsWrapperType($type)) {
my $condition = "";
$condition .= "${value}.isUndefined() || " if $parameter->isOptional;

# http://heycam.github.io/webidl/#es-nullable-type
$condition .= "${value}.isUndefinedOrNull() || " if $parameter->isNullable;
if ($parameter->isNullable) {
$condition .= "${value}.isUndefinedOrNull() || ";
} elsif ($parameter->isOptional) {
$condition .= "${value}.isUndefined() || ";
}

if ($codeGenerator->GetArrayOrSequenceType($type)) {
# FIXME: Add proper support for T[], T[]?, sequence<T>.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Expand Up @@ -5467,7 +5467,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethodWithOptio
size_t argsCount = std::min<size_t>(2, state->argumentCount());
JSValue arg0(state->argument(0));
JSValue arg1(state->argument(1));
if ((argsCount == 1 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info())))) || (argsCount == 2 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info()))) && (arg1.isUndefined() || arg1.isUndefinedOrNull() || (arg1.isObject() && asObject(arg1)->inherits(JSTestObj::info())))))
if ((argsCount == 1 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info())))) || (argsCount == 2 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info()))) && (arg1.isUndefinedOrNull() || (arg1.isObject() && asObject(arg1)->inherits(JSTestObj::info())))))
return jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter1(state);
if ((argsCount == 1 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info())))) || (argsCount == 2 && (arg0.isUndefinedOrNull() || (arg0.isObject() && asObject(arg0)->inherits(JSTestObj::info())))))
return jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter2(state);
Expand Down

0 comments on commit b8bad5e

Please sign in to comment.