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

Unified Diff: sdk/lib/_internal/lib/js_helper.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: Updated cf. comments. 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
« no previous file with comments | « sdk/lib/_internal/lib/constant_map.dart ('k') | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_helper.dart
diff --git a/sdk/lib/_internal/lib/js_helper.dart b/sdk/lib/_internal/lib/js_helper.dart
index fe0fcc1b7cae1cb4fa568ec23fc95cbf4409f169..b2df5a4e4b30662e1f559d7897a2a21e278c3349 100644
--- a/sdk/lib/_internal/lib/js_helper.dart
+++ b/sdk/lib/_internal/lib/js_helper.dart
@@ -1421,17 +1421,35 @@ class _StackTrace implements StackTrace {
}
}
+int _objectHashCode(var object) {
+ if (object == null || JS('bool', "typeof # != 'object'", object)) {
+ return object.hashCode;
+ } else {
+ return Primitives.objectHashCode(object);
+ }
+}
+
/**
* Called by generated code to build a map literal. [keyValuePairs] is
* a list of key, value, key, value, ..., etc.
*/
-makeLiteralMap(List keyValuePairs) {
- Iterator iterator = keyValuePairs.iterator;
- Map result = new LinkedHashMap();
- while (iterator.moveNext()) {
- String key = iterator.current;
- iterator.moveNext();
- var value = iterator.current;
+makeLiteralMap(keyValuePairs) {
+ return fillLiteralMap(keyValuePairs, new LinkedHashMap());
+}
+
+makeConstantMap(keyValuePairs) {
+ return fillLiteralMap(keyValuePairs,
+ new LinkedHashMap(equals: identical, hashCode: _objectHashCode));
+}
+
+fillLiteralMap(keyValuePairs, Map result) {
+ // TODO(johnniwinther): Use JSArray to optimize this code instead of calling
+ // [getLength] and [getIndex].
+ int index = 0;
+ int length = getLength(keyValuePairs);
+ while (index < length) {
+ var key = getIndex(keyValuePairs, index++);
+ var value = getIndex(keyValuePairs, index++);
result[key] = value;
}
return result;
« no previous file with comments | « sdk/lib/_internal/lib/constant_map.dart ('k') | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698