* 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;
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'
- );
}
/**
* @param {Mixed} value
*/
function setGlobalMapValue( map, key, value ) {
- map.internalValues[ key ] = value;
+ map.values[ key ] = value;
log.deprecate(
window,
key,
}
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
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;
* @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 );
}
};
}, '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' );