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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart

Issue 22909056: Support general expressions as keys in literal maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
Index: sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
index ae5c1f05e1f959279f5517958804d7b177db1f99..1747075daeee59ffbe3182ae44dad850e3d6f6b0 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart
@@ -232,12 +232,25 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> {
return new jsAst.ObjectInitializer(properties);
}
- void badFieldCountError() {
- compiler.internalError(
- "Compiler and ConstantMap disagree on number of fields.");
+ jsAst.Expression jsGeneralMap() {
+ List<jsAst.Expression> data = <jsAst.Expression>[];
+ int valueIndex = 0;
+ for (int i = 0; i < constant.keys.entries.length; i++) {
+ jsAst.Expression keyExpression =
+ _reference(constant.keys.entries[valueIndex]);
+ jsAst.Expression valueExpression =
+ _reference(constant.values[valueIndex++]);
+ data.add(keyExpression);
+ data.add(valueExpression);
+ }
+ if (valueIndex != constant.values.length) {
+ compiler.internalError("Bad value count.");
+ }
+ return new jsAst.ArrayInitializer.from(data);
}
ClassElement classElement = constant.type.element;
+ SourceString className = classElement.name;
List<jsAst.Expression> arguments = <jsAst.Expression>[];
@@ -256,16 +269,24 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> {
} else if (field.name == MapConstant.PROTO_VALUE) {
assert(constant.protoValue != null);
arguments.add(_reference(constant.protoValue));
+ } else if (field.name == MapConstant.JS_DATA_NAME) {
+ arguments.add(jsGeneralMap());
} else {
- badFieldCountError();
+ compiler.internalError(
+ "Compiler has unexpected field ${field.name} for "
+ "${className}.");
}
emittedArgumentCount++;
},
includeSuperAndInjectedMembers: true);
-
- if ((constant.protoValue == null && emittedArgumentCount != 3) ||
- (constant.protoValue != null && emittedArgumentCount != 4)) {
- badFieldCountError();
+ if ((className == MapConstant.DART_STRING_CLASS &&
+ emittedArgumentCount != 3) ||
+ (className == MapConstant.DART_PROTO_CLASS &&
+ emittedArgumentCount != 4) ||
+ (className == MapConstant.DART_GENERAL_CLASS &&
+ emittedArgumentCount != 1)) {
+ compiler.internalError(
+ "Compiler and ${className} disagree on number of fields.");
}
jsAst.Expression value = new jsAst.New(

Powered by Google App Engine
This is Rietveld 408576698