Skip to content

Commit 716898c

Browse files
committed
Shorter encoding for zero optional arguments.
[email protected] Review URL: https://codereview.chromium.org/2092243002 . Addresses: #26754
1 parent 844c82b commit 716898c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ class FragmentEmitter {
833833
// TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole].
834834
if (method.optionalParameterDefaultValues is List) {
835835
List<ConstantValue> defaultValues = method.optionalParameterDefaultValues;
836+
if (defaultValues.isEmpty) {
837+
return new js.LiteralNull();
838+
}
836839
Iterable<js.Expression> elements =
837840
defaultValues.map(generateConstantReference);
838841
return js.js('function() { return #; }',

sdk/lib/_internal/js_runtime/lib/js_helper.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,11 @@ class Primitives {
13691369
}
13701370

13711371
if (!acceptsOptionalArguments) {
1372+
if (namedArguments != null && namedArguments.isNotEmpty) {
1373+
// Tried to invoke a function that takes a fixed number of arguments
1374+
// with named (optional) arguments.
1375+
return functionNoSuchMethod(function, arguments, namedArguments);
1376+
}
13721377
if (argumentCount == requiredParameterCount) {
13731378
return JS('var', r'#.apply(#, #)', jsFunction, function, arguments);
13741379
}

0 commit comments

Comments
 (0)