From fc67a19feb0a3cbd2ae4fb5da4d317112eb016f1 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Fri, 11 Jan 2019 00:20:14 +0000 Subject: [PATCH] js_runtime: Fix bit mask to match comments The constant 0x3ffffff should have been 0x3fffffff Change-Id: Idc63745bf0527b487a16528a9bce5b048535d41f Reviewed-on: https://dart-review.googlesource.com/c/89044 Reviewed-by: Sigmund Cherem Commit-Queue: Stephen Adams --- .../js_runtime/lib/collection_patch.dart | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart index 7138c65bf4b..95e7a7a8aff 100644 --- a/sdk/lib/_internal/js_runtime/lib/collection_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/collection_patch.dart @@ -21,6 +21,8 @@ import 'dart:_internal' hide Symbol; const _USE_ES6_MAPS = const bool.fromEnvironment("dart2js.use.es6.maps"); +const int _mask30 = 0x3fffffff; // Low 30 bits. + @patch class HashMap { @patch @@ -306,14 +308,14 @@ class _HashMap extends MapBase implements HashMap { // Only treat unsigned 30-bit integers as numeric keys. This way, // we avoid converting them to strings when we use them as keys in // the JavaScript hash table object. - return key is num && JS('bool', '(# & 0x3ffffff) === #', key, key); + return key is num && JS('bool', '(# & #) === #', key, _mask30, key); } int _computeHashCode(var key) { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', key.hashCode); + return JS('int', '# & #', key.hashCode, _mask30); } static bool _hasTableEntry(var table, var key) { @@ -382,7 +384,7 @@ class _IdentityHashMap extends _HashMap { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', identityHashCode(key)); + return JS('int', '# & #', identityHashCode(key), _mask30); } int _findBucketIndex(var bucket, var key) { @@ -426,7 +428,7 @@ class _CustomHashMap extends _HashMap { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', _hashCode(key)); + return JS('int', '# & #', _hashCode(key), _mask30); } int _findBucketIndex(var bucket, var key) { @@ -576,7 +578,7 @@ class _LinkedIdentityHashMap extends JsLinkedHashMap { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', identityHashCode(key)); + return JS('int', '# & #', identityHashCode(key), _mask30); } int internalFindBucketIndex(var bucket, var key) { @@ -669,7 +671,7 @@ class _Es6LinkedIdentityHashMap extends _LinkedIdentityHashMap // always unboxed (Smi) values. Modification detection will be missed if you // make exactly some multiple of 2^30 modifications between advances of an // iterator. - _modifications = (_modifications + 1) & 0x3ffffff; + _modifications = _mask30 & (_modifications + 1); } } @@ -779,7 +781,7 @@ class _LinkedCustomHashMap extends JsLinkedHashMap { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', _hashCode(key)); + return JS('int', '# & #', _hashCode(key), _mask30); } int internalFindBucketIndex(var bucket, var key) { @@ -1050,7 +1052,7 @@ class _HashSet extends _SetBase implements HashSet { // way, we avoid converting them to strings when we use them as // keys in the JavaScript hash table object. return element is num && - JS('bool', '(# & 0x3ffffff) === #', element, element); + JS('bool', '(# & #) === #', element, _mask30, element); } int _computeHashCode(var element) { @@ -1058,7 +1060,7 @@ class _HashSet extends _SetBase implements HashSet { // issues with problematic elements like '__proto__'. Another // option would be to throw an exception if the hash code isn't a // number. - return JS('int', '# & 0x3ffffff', element.hashCode); + return JS('int', '# & #', element.hashCode, _mask30); } static bool _hasTableEntry(var table, var key) { @@ -1114,7 +1116,7 @@ class _IdentityHashSet extends _HashSet { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', identityHashCode(key)); + return JS('int', '# & #', identityHashCode(key), _mask30); } int _findBucketIndex(var bucket, var element) { @@ -1151,7 +1153,7 @@ class _CustomHashSet extends _HashSet { // issues with problematic elements like '__proto__'. Another // option would be to throw an exception if the hash code isn't a // number. - return JS('int', '# & 0x3ffffff', _hasher(element)); + return JS('int', '# & #', _hasher(element), _mask30); } bool add(E object) => super._add(object); @@ -1451,7 +1453,7 @@ class _LinkedHashSet extends _SetBase implements LinkedHashSet { // Value cycles after 2^30 modifications. If you keep hold of an // iterator for that long, you might miss a modification // detection, and iteration can go sour. Don't do that. - _modifications = (_modifications + 1) & 0x3ffffff; + _modifications = _mask30 & (_modifications + 1); } // Create a new cell and link it in as the last one in the list. @@ -1498,7 +1500,7 @@ class _LinkedHashSet extends _SetBase implements LinkedHashSet { // way, we avoid converting them to strings when we use them as // keys in the JavaScript hash table object. return element is num && - JS('bool', '(# & 0x3ffffff) === #', element, element); + JS('bool', '(# & #) === #', element, _mask30, element); } int _computeHashCode(var element) { @@ -1506,7 +1508,7 @@ class _LinkedHashSet extends _SetBase implements LinkedHashSet { // issues with problematic elements like '__proto__'. Another // option would be to throw an exception if the hash code isn't a // number. - return JS('int', '# & 0x3ffffff', element.hashCode); + return JS('int', '# & #', element.hashCode, _mask30); } static _getTableEntry(var table, var key) { @@ -1559,7 +1561,7 @@ class _LinkedIdentityHashSet extends _LinkedHashSet { // We force the hash codes to be unsigned 30-bit integers to avoid // issues with problematic keys like '__proto__'. Another option // would be to throw an exception if the hash code isn't a number. - return JS('int', '# & 0x3ffffff', identityHashCode(key)); + return JS('int', '# & #', identityHashCode(key), _mask30); } int _findBucketIndex(var bucket, var element) { @@ -1600,7 +1602,7 @@ class _LinkedCustomHashSet extends _LinkedHashSet { // issues with problematic elements like '__proto__'. Another // option would be to throw an exception if the hash code isn't a // number. - return JS('int', '# & 0x3ffffff', _hasher(element)); + return JS('int', '# & #', _hasher(element), _mask30); } bool add(E element) => super._add(element);