| Index: pkg/compiler/lib/src/js_backend/codegen/codegen.dart
|
| diff --git a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
|
| index cc9a406f7c9b46e8516c849efd5cbf4a888a27b6..d9f24032c5476e39a485df88927df8c4955b5a95 100644
|
| --- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
|
| @@ -72,6 +72,7 @@ class CodeGenerator extends tree_ir.StatementVisitor
|
|
|
| /// Generates JavaScript code for the body of [function].
|
| js.Fun buildFunction(tree_ir.FunctionDefinition function) {
|
| + registerDefaultParameterValues(function.element);
|
| currentFunction = function.element;
|
| visitStatement(function.body);
|
|
|
| @@ -1017,4 +1018,22 @@ class CodeGenerator extends tree_ir.StatementVisitor
|
| // We might need them if we want to emit raw JS nested functions.
|
| throw 'FunctionExpressions should not be used';
|
| }
|
| +
|
| + /// Ensures that parameter defaults will be emitted.
|
| + ///
|
| + /// Ideally, this should be done when generating the relevant stub methods,
|
| + /// since those are the ones that actually reference the constants, but those
|
| + /// are created by the emitter when it is too late to register new constants.
|
| + ///
|
| + /// For non-static methods, we have no way of knowing if the defaults are
|
| + /// actually used, so we conservatively register them all.
|
| + void registerDefaultParameterValues(ExecutableElement element) {
|
| + if (element is! FunctionElement) return;
|
| + FunctionElement function = element;
|
| + if (function.isStatic) return; // Defaults are inlined at call sites.
|
| + function.functionSignature.forEachOptionalParameter((param) {
|
| + ConstantValue constant = glue.getDefaultParameterValue(param);
|
| + registry.registerCompileTimeConstant(constant);
|
| + });
|
| + }
|
| }
|
|
|