/* eslint-enable no-bitwise */
}
+ // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
StringSet = window.Set || ( function () {
/**
* @private
this.set[ value ] = true;
};
StringSet.prototype.has = function ( value ) {
- return this.set.hasOwnProperty( value );
+ return hasOwn.call( this.set, value );
};
return StringSet;
}() );
* 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,
*
* @param {string|Array} [selection] Key or array of keys to retrieve values for.
* @param {Mixed} [fallback=null] Value for keys that don't exist.
- * @return {Mixed|Object| null} If selection was a string, returns the value,
+ * @return {Mixed|Object|null} If selection was a string, returns the value,
* If selection was an array, returns an object of key/values.
- * If no selection is passed, the internal container is returned. (Beware that,
- * as is the default in JavaScript, the object is returned by reference.)
+ * If no selection is passed, a new object with all key/values is returned.
*/
get: function ( selection, fallback ) {
var results, i;
- // If we only do this in the `return` block, it'll fail for the
- // call to get() from the mutli-selection block.
fallback = arguments.length > 1 ? fallback : null;
if ( $.isArray( selection ) ) {
- selection = slice.call( selection );
results = {};
for ( i = 0; i < selection.length; i++ ) {
- results[ selection[ i ] ] = this.get( selection[ i ], fallback );
+ if ( typeof selection[ i ] === 'string' ) {
+ results[ selection[ i ] ] = hasOwn.call( this.values, selection[ i ] ) ?
+ this.values[ selection[ i ] ] :
+ fallback;
+ }
}
return results;
}
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;
+ results = {};
+ for ( i in this.values ) {
+ results[ i ] = this.values[ i ];
+ }
+ return results;
}
// Invalid selection key
- return null;
+ return fallback;
},
/**
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 );
}
};