Convert null-marker in HashMap.forEach.

R=johnniwinther@google.com

Review URL: https://codereview.chromium.org//22561003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25925 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
karlklose@google.com 2013-08-08 13:49:13 +00:00
parent dd7d7f5012
commit 57f68eeb94
2 changed files with 20 additions and 1 deletions

View file

@ -94,7 +94,7 @@ patch class HashMap<K, V> {
for (int offset = 0; offset < table.length; offset += entrySize) {
Object entry = table[offset];
if (!_hashTable._isFree(entry)) {
K key = entry;
K key = identical(entry, _NULL) ? null : entry;
V value = _hashTable._value(offset);
action(key, value);
_hashTable._checkModification(modificationCount);

View file

@ -0,0 +1,19 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Regression test for using `null` as a key with `forEach`.
main() {
var x = new Map<int, int>();
x[1] = 2;
x[null] = 1;
int c = 0;
x.forEach((int i, int j) {
c++;
Expect.isTrue(i == null || i is int, 'int or null expected');
});
Expect.equals(2, c);
}