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

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

Issue 994323002: Support static getters and setters in the new dart2js code generator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 98b87270ea68df1aa7354114a2c0229612ea4adf..f6c7e21608b46c268c89575c9d7531f6141c63e8 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
@@ -257,15 +257,27 @@ class CodeGenerator extends tree_ir.Visitor<dynamic, js.Expression> {
@override
js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) {
checkStaticTargetIsValid(node, node.target);
-
- if (node.target is! FunctionElement) {
- giveup(node, 'static getters and setters are not supported.');
- }
Selector selector = node.selector;
- FunctionElement target = node.target;
- List<js.Expression> arguments = visitArguments(node.arguments);
- return buildStaticInvoke(selector, target, arguments,
- sourceInformation: node.sourceInformation);
+ if (node.target is FunctionElement) {
+ assert(selector.isGetter || selector.isSetter || selector.isCall);
+ FunctionElement target = node.target;
+ List<js.Expression> arguments = visitArguments(node.arguments);
+ return buildStaticInvoke(selector, target, arguments,
+ sourceInformation: node.sourceInformation);
+ } else {
+ assert(selector.isGetter || selector.isSetter);
+ FieldElement target = node.target;
+ registry.registerStaticUse(target);
+ js.Expression field = glue.staticFieldAccess(target);
+ if (selector.isGetter) {
+ assert(node.arguments.isEmpty);
+ return field;
+ } else {
+ assert(node.arguments.length == 1);
+ js.Expression value = visitExpression(node.arguments.first);
+ return new js.Assignment(field, value);
+ }
+ }
}
@override
« 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