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

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

Issue 1145833004: fixes #173, ability to use native JS indexers (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merged Created 5 years, 6 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 | lib/src/utils.dart » ('j') | test/codegen/expect/sunflower/dom.js » ('J')
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 95fcf811ffe8cdd8a3dd926da67403e1f569c24b..d3f5b351cd2f6efbdfb47d019447cfeb084e3dfd 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -109,7 +109,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
if (unit.directives.isNotEmpty) {
var libraryDir = unit.directives.first;
if (libraryDir is LibraryDirective) {
- var jsName = getAnnotationValue(libraryDir, _isJsNameAnnotation);
+ var jsName = findAnnotation(libraryDir.element, _isJsNameAnnotation);
jsDefaultValue = getConstantField(jsName, 'name', types.stringType);
}
}
@@ -328,7 +328,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
// If we've already emitted this class, skip it.
var classElem = node.element;
var type = classElem.type;
- var jsName = getAnnotationValue(node, _isJsNameAnnotation);
+ var jsName = findAnnotation(classElem, _isJsNameAnnotation);
if (jsName != null) return _emitJsType(node.name.name, jsName);
@@ -349,7 +349,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
_classHeritage(classElem), _emitClassMethods(node, ctors, fields));
String jsPeerName;
- var jsPeer = getAnnotationValue(node, _isJsPeerInterface);
+ var jsPeer = findAnnotation(classElem, _isJsPeerInterface);
if (jsPeer != null) {
jsPeerName = getConstantField(jsPeer, 'name', types.stringType);
}
@@ -474,7 +474,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
jsMethods.add(_emitImplicitConstructor(node, fields));
}
- bool hasJsPeer = getAnnotationValue(node, _isJsPeerInterface) != null;
+ bool hasJsPeer = findAnnotation(element, _isJsPeerInterface) != null;
bool hasIterator = false;
for (var m in node.members) {
@@ -1404,7 +1404,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
JS.Expression _emitSet(Expression lhs, Expression rhs) {
if (lhs is IndexExpression) {
- return _emitSend(_getTarget(lhs), '[]=', [lhs.index, rhs]);
+ var target = _getTarget(lhs);
+ if (_useNativeJsIndexer(target.staticType)) {
+ return js.call(
+ '#[#] = #', [_visit(target), _visit(lhs.index), _visit(rhs)]);
+ }
+ return _emitSend(target, '[]=', [lhs.index, rhs]);
}
Expression target = null;
@@ -2195,9 +2200,18 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
@override
visitIndexExpression(IndexExpression node) {
- return _emitSend(_getTarget(node), '[]', [node.index]);
+ var target = _getTarget(node);
+ if (_useNativeJsIndexer(target.staticType)) {
+ return new JS.PropertyAccess(_visit(target), _visit(node.index));
+ }
+ return _emitSend(target, '[]', [node.index]);
}
+ // TODO(jmesserly): ideally we'd check the method and see if it is marked
+ // `external`, but that doesn't work because it isn't in the element model.
+ bool _useNativeJsIndexer(DartType type) =>
+ findAnnotation(type.element, _isJsNameAnnotation) != null;
+
/// Gets the target of a [PropertyAccess] or [IndexExpression].
/// Those two nodes are special because they're both allowed on left side of
/// an assignment expression and cascades.
« no previous file with comments | « no previous file | lib/src/utils.dart » ('j') | test/codegen/expect/sunflower/dom.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698