Chromium Code Reviews| Index: sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart |
| diff --git a/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart b/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart |
| index f543e74d706e83feea70ade74a4eddb72705fde0..fbd5ed50a048a44cbfd1a75d0442cedcc75de6bf 100644 |
| --- a/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart |
| +++ b/sdk/lib/_internal/compiler/js_lib/linked_hash_map.dart |
| @@ -34,7 +34,6 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| JsLinkedHashMap(); |
| - |
| int get length => _length; |
| bool get isEmpty => _length == 0; |
| bool get isNotEmpty => !isEmpty; |
| @@ -51,13 +50,11 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| if (_isStringKey(key)) { |
| var strings = _strings; |
| if (strings == null) return false; |
| - LinkedHashMapCell cell = _getTableEntry(strings, key); |
| - return cell != null; |
| + return _containsTableEntry(strings, key); |
| } else if (_isNumericKey(key)) { |
| var nums = _nums; |
| if (nums == null) return false; |
| - LinkedHashMapCell cell = _getTableEntry(nums, key); |
| - return cell != null; |
| + return _containsTableEntry(nums, key); |
| } else { |
| return internalContainsKey(key); |
| } |
| @@ -124,7 +121,7 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| var rest = _rest; |
| if (rest == null) _rest = rest = _newHashTable(); |
| var hash = internalComputeHashCode(key); |
| - var bucket = JS('var', '#[#]', rest, hash); |
| + var bucket = _getTableEntry(rest, hash); |
| if (bucket == null) { |
| LinkedHashMapCell cell = _newLinkedCell(key, value); |
| _setTableEntry(rest, hash, JS('var', '[#]', cell)); |
| @@ -253,7 +250,7 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| } |
| static bool _isStringKey(var key) { |
| - return key is String && key != '__proto__'; |
|
Vyacheslav Egorov (Google)
2015/03/26 00:03:58
We need to check that all browsers switched to ES6
floitsch
2015/03/26 00:53:24
I just tried with IE10 and there it works. I would
|
| + return key is String; |
| } |
| static bool _isNumericKey(var key) { |
| @@ -270,22 +267,9 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| return JS('int', '# & 0x3ffffff', key.hashCode); |
| } |
| - static _getTableEntry(var table, var key) { |
| - return JS('var', '#[#]', table, key); |
| - } |
| - |
| - static void _setTableEntry(var table, var key, var value) { |
| - assert(value != null); |
| - JS('void', '#[#] = #', table, key, value); |
| - } |
| - |
| - static void _deleteTableEntry(var table, var key) { |
| - JS('void', 'delete #[#]', table, key); |
| - } |
| - |
| List _getBucket(var table, var key) { |
| var hash = internalComputeHashCode(key); |
| - return JS('var', '#[#]', table, hash); |
| + return _getTableEntry(table, hash); |
| } |
| int internalFindBucketIndex(var bucket, var key) { |
| @@ -298,7 +282,32 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| return -1; |
| } |
| - static _newHashTable() { |
| + String toString() => Maps.mapToString(this); |
| + |
| + static bool get supportsEs6Maps { |
| + return JS('returns:bool;depends:none;effects:none;', |
| + 'typeof Map != "undefined"'); |
| + } |
| + |
| + _getTableEntry(var table, var key) { |
| + return JS('var', '#[#]', table, key); |
| + } |
| + |
| + void _setTableEntry(var table, var key, var value) { |
| + assert(value != null); |
| + JS('void', '#[#] = #', table, key, value); |
| + } |
| + |
| + void _deleteTableEntry(var table, var key) { |
| + JS('void', 'delete #[#]', table, key); |
| + } |
| + |
| + bool _containsTableEntry(var table, var key) { |
| + LinkedHashMapCell cell = _getTableEntry(table, key); |
| + return cell != null; |
| + } |
| + |
| + _newHashTable() { |
| // Create a new JavaScript object to be used as a hash table. Use |
| // Object.create to avoid the properties on Object.prototype |
| // showing up as entries. |
| @@ -310,8 +319,34 @@ class JsLinkedHashMap<K, V> implements LinkedHashMap<K, V>, InternalMap { |
| _deleteTableEntry(table, temporaryKey); |
| return table; |
| } |
| +} |
| - String toString() => Maps.mapToString(this); |
| +class Es6LinkedHashMap<K, V> extends JsLinkedHashMap<K, V> { |
| + |
| + @override |
| + _getTableEntry(var table, var key) { |
| + return JS('var', '#.get(#)', table, key); |
| + } |
| + |
| + @override |
| + void _setTableEntry(var table, var key, var value) { |
| + JS('void', '#.set(#, #)', table, key, value); |
| + } |
| + |
| + @override |
| + void _deleteTableEntry(var table, var key) { |
| + JS('void', '#.delete(#)', table, key); |
| + } |
| + |
| + @override |
| + bool _containsTableEntry(var table, var key) { |
| + return JS('bool', '#.has(#)', table, key); |
| + } |
| + |
| + @override |
| + _newHashTable() { |
| + return JS('var', 'new Map()'); |
| + } |
| } |
| class LinkedHashMapCell { |