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

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

Issue 1061543004: small refactor to move JsPeer code out of _finishClassDef (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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 | « no previous file | 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 6635ad69c937c2e70a19e52c9a9c449c6e9a6c8c..f5844c65761728921a3bf47a68cca07f49f1f8e7 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -277,7 +277,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
_emitTypeName(node.element.type, lowerTypedef: true)
]);
- return _finishClassDef(type, result, null);
+ return _finishClassDef(type, result);
}
@override
@@ -295,7 +295,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var classDecl = new JS.ClassDeclaration(
new JS.ClassExpression(new JS.Identifier(name), heritage, []));
- return _finishClassDef(type, classDecl, null);
+ return _finishClassDef(type, classDecl);
}
JS.Statement _emitJsType(String dartClassName, DartObjectImpl jsName) {
@@ -340,13 +340,25 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var body =
_finishClassMembers(classElem, classExpr, ctors, fields, staticFields);
+ var result = _finishClassDef(type, body);
+
var jsPeer = getAnnotationValue(node, _isJsPeerInterface);
- String jsPeerName = null;
if (jsPeer != null) {
- jsPeerName = getConstantField(jsPeer, 'name', types.stringType);
+ var jsPeerName = getConstantField(jsPeer, 'name', types.stringType);
+ if (jsPeerName != null) {
+ // TODO(jmesserly): this copies the dynamic members.
+ // Probably fine for objects coming from JS, but not if we actually
+ // want to support construction of instances with generic types other
+ // than dynamic. See issue #154 for Array and List<E> related bug.
+ var copyMembers = js.statement(
+ 'dart.copyProperties(dart.global.#.prototype, #.prototype);', [
Jennifer Messerly 2015/04/23 17:05:43 hmmm, it occurs to me we should assert !_lazyClass
Jacob 2015/04/23 17:09:14 make it so.
+ _propertyName(jsPeerName),
+ classElem.name
+ ]);
+ return _statement([result, copyMembers]);
+ }
}
-
- return _finishClassDef(type, body, jsPeerName);
+ return result;
}
@override
@@ -356,8 +368,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
/// Given a class element and body, complete the class declaration.
/// This handles generic type parameters, laziness (in library-cycle cases),
/// and ensuring dependencies are loaded first.
- JS.Statement _finishClassDef(
- ParameterizedType type, JS.Statement body, String jsPeerName) {
+ JS.Statement _finishClassDef(ParameterizedType type, JS.Statement body) {
var name = type.name;
var genericName = '$name\$';
@@ -416,13 +427,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
_emitClassIfNeeded(classDefs, types.functionType);
}
classDefs.add(body);
- if (jsPeerName != null) {
- classDefs.add(js.statement(
- 'dart.copyProperties(dart.global.#.prototype, #.prototype);', [
- _propertyName(jsPeerName),
- name
- ]));
- }
return _statement(classDefs);
}
@@ -642,7 +646,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
var lazy = _emitLazyFields(new JS.Identifier(name), lazyStatics);
if (lazy != null) body.add(lazy);
-
return _statement(body);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698