* @singleton
*/
+/* global mwNow */
/* eslint-disable no-use-before-define */
( function ( $ ) {
/* 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 );
}
};
*
* @return {number} Current time
*/
- now: ( function () {
- var perf = window.performance,
- navStart = perf && perf.timing && perf.timing.navigationStart;
- return navStart && typeof perf.now === 'function' ?
- function () { return navStart + perf.now(); } :
- function () { return +new Date(); };
- }() ),
+ now: mwNow,
+ // mwNow is defined in startup.js
/**
* Format a string. Replace $1, $2 ... $N with positional arguments.
el.media = media;
}
// If you end up here from an IE exception "SCRIPT: Invalid property value.",
- // see #addEmbeddedCSS, bug 31676, and bug 47277 for details.
+ // see #addEmbeddedCSS, T33676, and T49277 for details.
el.href = url;
$( getMarker() ).before( el );
* { <media>: css }
* { <media>: [url, ..] }
*
- * The reason css strings are not concatenated anymore is bug 31676. We now check
+ * The reason css strings are not concatenated anymore is T33676. We now check
* whether it's safe to extend the stylesheet.
*
* @protected
// Support: IE 7-8
// Use properties instead of attributes as IE throws security
// warnings when inserting a <link> tag with a protocol-relative
- // URL set though attributes - when on HTTPS. See bug 41331.
+ // URL set though attributes - when on HTTPS. See T43331.
l = document.createElement( 'link' );
l.rel = 'stylesheet';
l.href = modules;
// Whether the store is in use on this page.
enabled: null,
+ // Modules whose string representation exceeds 100 kB are
+ // ineligible for storage. See bug T66721.
MODULE_SIZE_MAX: 100 * 1000,
// The contents of the store, mapping '[name]@[version]' keys
return $.when.apply( $, all );
} );
loading.then( function () {
+ /* global mwPerformance */
mwPerformance.mark( 'mwLoadEnd' );
mw.hook( 'resourceloader.loadEnd' ).fire();
} );