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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1411763002: dart2js cps: Ensure parameter default values are emitted. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove empty section from status file Created 5 years, 2 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ });
+ }
}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698