From: Timo Tijhof Date: Sat, 4 Mar 2017 00:36:46 +0000 (-0800) Subject: resourceloader: Undeprecate mw.Map#values X-Git-Tag: 1.31.0-rc.0~3874^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=9838bb9d19999bd814a5e162e1004b57ff955729;p=lhc%2Fweb%2Fwiklou.git resourceloader: Undeprecate mw.Map#values Follows-up dc0f9b3a3a, which renamed #values to #internalValues to ease migration to ES5 Map where such object could no longer exist in real-time as a plain object. However ES5 Map for mw.Map is no longer on the roadmap per T146432. The main reason for adopting ES5 was performance, which turns out to be invalid and was merely a bug in V8 that has since been fixed. Change this back and undeprecate it. If anything, for developer convience and type-ahead, which is fairly wildely used. Change-Id: Ic19641656e53068a0aa15c27f172d39eb13620dd --- diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 7872818594..00b275fb5e 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -82,9 +82,8 @@ * copied in one direction only. Changes to globals do not reflect in the map. */ function Map( global ) { - this.internalValues = {}; + this.values = {}; if ( global === true ) { - // Override #set to also set the global variable this.set = function ( selection, value ) { var s; @@ -102,15 +101,6 @@ return false; }; } - - // Deprecated since MediaWiki 1.28 - log.deprecate( - this, - 'values', - this.internalValues, - 'mw.Map#values is deprecated. Use mw.Map#get() instead.', - 'Map-values' - ); } /** @@ -123,7 +113,7 @@ * @param {Mixed} value */ function setGlobalMapValue( map, key, value ) { - map.internalValues[ key ] = value; + map.values[ key ] = value; log.deprecate( window, key, @@ -164,14 +154,13 @@ } if ( typeof selection === 'string' ) { - if ( !hasOwn.call( this.internalValues, selection ) ) { - return fallback; - } - return this.internalValues[ selection ]; + return hasOwn.call( this.values, selection ) ? + this.values[ selection ] : + fallback; } if ( selection === undefined ) { - return this.internalValues; + return this.values; } // Invalid selection key @@ -190,12 +179,12 @@ if ( $.isPlainObject( selection ) ) { for ( s in selection ) { - this.internalValues[ s ] = selection[ s ]; + this.values[ s ] = selection[ s ]; } return true; } if ( typeof selection === 'string' && arguments.length > 1 ) { - this.internalValues[ selection ] = value; + this.values[ selection ] = value; return true; } return false; @@ -208,17 +197,16 @@ * @return {boolean} True if the key(s) exist */ exists: function ( selection ) { - var s; - + var i; if ( $.isArray( selection ) ) { - for ( s = 0; s < selection.length; s++ ) { - if ( typeof selection[ s ] !== 'string' || !hasOwn.call( this.internalValues, selection[ s ] ) ) { + for ( i = 0; i < selection.length; i++ ) { + if ( typeof selection[ i ] !== 'string' || !hasOwn.call( this.values, selection[ i ] ) ) { return false; } } return true; } - return typeof selection === 'string' && hasOwn.call( this.internalValues, selection ); + return typeof selection === 'string' && hasOwn.call( this.values, selection ); } }; diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index d3e73ae26a..697f32d521 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -141,9 +141,7 @@ }, 'Map.get return includes keys that were not found as null values' ); // Interacting with globals and accessing the values object - this.suppressWarnings(); assert.strictEqual( conf.get(), conf.values, 'Map.get returns the entire values object by reference (if called without arguments)' ); - this.restoreWarnings(); conf.set( 'globalMapChecker', 'Hi' );