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

Unified Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Issue 2820573005: dart2js: --fast-startup: share defaultValues property for closures with no default values (Closed)
Patch Set: Created 3 years, 8 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 | « pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
index 2f975d10e12769c25c54cb48339ed8e4e576dd4f..8869076cdf9e1a14d082f3f330f18c07d4760f5c 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
@@ -716,6 +716,7 @@ class FragmentEmitter {
List<js.Property> properties = <js.Property>[];
if (cls.superclass == null) {
+ // TODO(sra): What is this doing? Document or remove.
properties
.add(new js.Property(js.string("constructor"), classReference(cls)));
properties
@@ -731,6 +732,15 @@ class FragmentEmitter {
});
});
+ if (cls.isClosureBaseClass) {
+ // Closures extend a common base class, so we can put properties on the
+ // prototype for common values.
+
+ // Most closures have no optional arguments.
+ properties.add(new js.Property(
+ js.string(namer.defaultValuesField), new js.LiteralNull()));
+ }
+
return new js.ObjectInitializer(properties);
}
@@ -805,12 +815,23 @@ class FragmentEmitter {
}
if (method.isClosureCallMethod && method.canBeApplied) {
+ // TODO(sra): We should also add these properties for the user-defined
+ // `call` method on classes. Function.apply is currently broken for
+ // complex cases. [forceAdd] might be true when this is fixed.
+ bool forceAdd = !method.isClosureCallMethod;
+
properties[js.string(namer.callCatchAllName)] =
js.quoteName(method.name);
properties[js.string(namer.requiredParameterField)] =
js.number(method.requiredParameterCount);
- properties[js.string(namer.defaultValuesField)] =
+
+ js.Expression defaultValues =
_encodeOptionalParameterDefaultValues(method);
+ // Default values property of `null` is stored on the common JS
+ // superclass.
+ if (defaultValues is! js.LiteralNull || forceAdd) {
+ properties[js.string(namer.defaultValuesField)] = defaultValues;
+ }
}
}
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698