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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 1135543003: Fixes #178 (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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 | « lib/runtime/dart_runtime.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 264cccc42e23de10153334825d9e0422fa09896f..b273673cf69ccbee9a9d9f909f27e141d31d8105 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -68,6 +68,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
ConstantEvaluator _constEvaluator;
+ InterfaceType _currentClass = null;
+
/// Imported libraries, and the temporaries used to refer to them.
final _imports = new Map<LibraryElement, JS.TemporaryId>();
final _exports = new Set<String>();
@@ -332,6 +334,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
if (jsName != null) return _emitJsType(node.name.name, jsName);
+ // Set current class
+ assert(_currentClass == null);
+ _currentClass = type;
Jennifer Messerly 2015/05/11 16:35:08 suggestion: maybe save the Element here, not the t
vsm 2015/05/11 17:51:09 Done.
+
var ctors = <ConstructorDeclaration>[];
var fields = <FieldDeclaration>[];
var staticFields = <FieldDeclaration>[];
@@ -355,6 +361,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var body = _finishClassMembers(
classElem, classExpr, ctors, fields, staticFields, jsPeerName);
+ // Unset current class
+ assert(_currentClass == type);
+ _currentClass = null;
+
var result = _finishClassDef(type, body);
if (jsPeerName != null) {
@@ -1235,7 +1245,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var typeArgs = null;
if (type is ParameterizedType) {
var args = type.typeArguments;
- if (args.any((a) => a != types.dynamicType)) {
+ // For a generic class with dynamic type parameters, try to use the
+ // raw form: new S() instead of new S<dynamic>() if possible.
+ var isCurrentClass =
Jennifer Messerly 2015/05/11 16:35:08 could this just be: var isCurrentClass = type
vsm 2015/05/11 17:51:09 Done.
+ type is InterfaceType ? type.element.type == _currentClass : false;
+ if (args.isNotEmpty && isCurrentClass ||
Jennifer Messerly 2015/05/11 16:35:08 maybe split these into two cases: if (args.any((a
vsm 2015/05/11 17:51:09 Ahh, nice. Done!
+ args.any((a) => a != types.dynamicType)) {
name = '$name\$';
typeArgs = args.map(_emitTypeName);
}
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698