dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git]
/
resources
/
src
/
startup
/
mediawiki.js
diff --git
a/resources/src/startup/mediawiki.js
b/resources/src/startup/mediawiki.js
index
c169487
..
fee69c0
100644
(file)
--- a/
resources/src/startup/mediawiki.js
+++ b/
resources/src/startup/mediawiki.js
@@
-13,7
+13,6
@@
'use strict';
var mw, StringSet, log,
'use strict';
var mw, StringSet, log,
- hasOwn = Object.prototype.hasOwnProperty,
trackQueue = [];
/**
trackQueue = [];
/**
@@
-49,22
+48,19
@@
function defineFallbacks() {
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set>
function defineFallbacks() {
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set>
- StringSet = window.Set || ( function () {
- /**
- * @private
- * @class
- */
- function StringSet() {
- this.set = Object.create( null );
- }
- StringSet.prototype.add = function ( value ) {
- this.set[ value ] = true;
+ /**
+ * @private
+ * @class
+ */
+ StringSet = window.Set || function StringSet() {
+ var set = Object.create( null );
+ this.add = function ( value ) {
+ set[ value ] = true;
};
};
-
StringSet.prototype
.has = function ( value ) {
- return value in
this.
set;
+
this
.has = function ( value ) {
+ return value in set;
};
};
- return StringSet;
- }() );
+ };
}
/**
}
/**
@@
-259,7
+255,6
@@
defineFallbacks();
defineFallbacks();
- /* eslint-disable no-console */
log = ( function () {
/**
* Write a verbose message to the browser's console in debug mode.
log = ( function () {
/**
* Write a verbose message to the browser's console in debug mode.
@@
-293,7
+288,7
@@
*
* @param {...string} msg Messages to output to console
*/
*
* @param {...string} msg Messages to output to console
*/
- log.warn = console && console.warn
&& Function.prototype.bind
?
+ log.warn = console && console.warn ?
Function.prototype.bind.call( console.warn, console ) :
function () {};
Function.prototype.bind.call( console.warn, console ) :
function () {};
@@
-308,7
+303,7
@@
* @since 1.26
* @param {...Mixed} msg Messages to output to console
*/
* @since 1.26
* @param {...Mixed} msg Messages to output to console
*/
- log.error = console && console.error
&& Function.prototype.bind
?
+ log.error = console && console.error ?
Function.prototype.bind.call( console.error, console ) :
function () {};
Function.prototype.bind.call( console.error, console ) :
function () {};
@@
-323,9
+318,7
@@
* @param {string} [logName=key] Optional custom name for the feature.
* This is used instead of `key` in the message and `mw.deprecate` tracking.
*/
* @param {string} [logName=key] Optional custom name for the feature.
* This is used instead of `key` in the message and `mw.deprecate` tracking.
*/
- log.deprecate = !Object.defineProperty ? function ( obj, key, val ) {
- obj[ key ] = val;
- } : function ( obj, key, val, msg, logName ) {
+ log.deprecate = function ( obj, key, val, msg, logName ) {
var stacks;
function maybeLog() {
var name,
var stacks;
function maybeLog() {
var name,
@@
-365,7
+358,6
@@
return log;
}() );
return log;
}() );
- /* eslint-enable no-console */
/**
* @class mw
/**
* @class mw
@@
-584,7
+576,7
@@
* @property
* @private
*/
* @property
* @private
*/
- var registry =
{}
,
+ var registry =
Object.create( null )
,
// Mapping of sources, keyed by source-id, values are strings.
//
// Format:
// Mapping of sources, keyed by source-id, values are strings.
//
// Format:
@@
-593,7
+585,7
@@
// 'sourceId': 'http://example.org/w/load.php'
// }
//
// 'sourceId': 'http://example.org/w/load.php'
// }
//
- sources =
{}
,
+ sources =
Object.create( null )
,
// For queueModuleScript()
handlingPendingRequests = false,
// For queueModuleScript()
handlingPendingRequests = false,
@@
-931,7
+923,7
@@
function sortDependencies( module, resolved, unresolved ) {
var i, deps, skip;
function sortDependencies( module, resolved, unresolved ) {
var i, deps, skip;
- if ( !
hasOwn.call( registry, module
) ) {
+ if ( !
( module in registry
) ) {
throw new Error( 'Unknown dependency: ' + module );
}
throw new Error( 'Unknown dependency: ' + module );
}
@@
-1061,7
+1053,7
@@
function queueModuleScript( src, moduleName, callback ) {
pendingRequests.push( function () {
// Keep in sync with execute()/runScript().
function queueModuleScript( src, moduleName, callback ) {
pendingRequests.push( function () {
// Keep in sync with execute()/runScript().
- if ( moduleName !== 'jquery'
&& hasOwn.call( registry, moduleName )
) {
+ if ( moduleName !== 'jquery' ) {
window.require = mw.loader.require;
window.module = registry[ moduleName ].module;
}
window.require = mw.loader.require;
window.module = registry[ moduleName ].module;
}
@@
-1196,9
+1188,6
@@
var key, value, media, i, urls, cssHandle, siteDeps, siteDepErr, runScript,
cssPending = 0;
var key, value, media, i, urls, cssHandle, siteDeps, siteDepErr, runScript,
cssPending = 0;
- if ( !hasOwn.call( registry, module ) ) {
- throw new Error( 'Module has not been registered yet: ' + module );
- }
if ( registry[ module ].state !== 'loaded' ) {
throw new Error( 'Module in state "' + registry[ module ].state + '" may not be executed: ' + module );
}
if ( registry[ module ].state !== 'loaded' ) {
throw new Error( 'Module in state "' + registry[ module ].state + '" may not be executed: ' + module );
}
@@
-1639,8
+1628,7
@@
* or null if the module does not exist
*/
function getModuleKey( module ) {
* or null if the module does not exist
*/
function getModuleKey( module ) {
- return hasOwn.call( registry, module ) ?
- ( module + '@' + registry[ module ].version ) : null;
+ return module in registry ? ( module + '@' + registry[ module ].version ) : null;
}
/**
}
/**
@@
-1672,7
+1660,7
@@
* @param {string} [skip]
*/
function registerOne( module, version, dependencies, group, source, skip ) {
* @param {string} [skip]
*/
function registerOne( module, version, dependencies, group, source, skip ) {
- if (
hasOwn.call( registry, module )
) {
+ if (
module in registry
) {
throw new Error( 'module already registered: ' + module );
}
registry[ module ] = {
throw new Error( 'module already registered: ' + module );
}
registry[ module ] = {
@@
-1725,7
+1713,7
@@
// Appends a list of modules from the queue to the batch
for ( q = 0; q < queue.length; q++ ) {
// Only load modules which are registered
// Appends a list of modules from the queue to the batch
for ( q = 0; q < queue.length; q++ ) {
// Only load modules which are registered
- if (
hasOwn.call( registry, queue[ q ] )
&& registry[ queue[ q ] ].state === 'registered' ) {
+ if (
queue[ q ] in registry
&& registry[ queue[ q ] ].state === 'registered' ) {
// Prevent duplicate entries
if ( batch.indexOf( queue[ q ] ) === -1 ) {
batch.push( queue[ q ] );
// Prevent duplicate entries
if ( batch.indexOf( queue[ q ] ) === -1 ) {
batch.push( queue[ q ] );
@@
-1802,7
+1790,7
@@
addSource: function ( ids ) {
var id;
for ( id in ids ) {
addSource: function ( ids ) {
var id;
for ( id in ids ) {
- if (
hasOwn.call( sources, id )
) {
+ if (
id in sources
) {
throw new Error( 'source already registered: ' + id );
}
sources[ id ] = ids[ id ];
throw new Error( 'source already registered: ' + id );
}
sources[ id ] = ids[ id ];
@@
-1881,7
+1869,7
@@
name = split.name,
version = split.version;
// Automatically register module
name = split.name,
version = split.version;
// Automatically register module
- if ( !
hasOwn.call( registry, name
) ) {
+ if ( !
( name in registry
) ) {
mw.loader.register( name );
}
// Check for duplicate implementation
mw.loader.register( name );
}
// Check for duplicate implementation
@@
-1964,13
+1952,13
@@
/**
* Change the state of one or more modules.
*
/**
* Change the state of one or more modules.
*
- * @param {Object}
modul
es Object of module name/state pairs
+ * @param {Object}
stat
es Object of module name/state pairs
*/
*/
- state: function (
modul
es ) {
+ state: function (
stat
es ) {
var module, state;
var module, state;
- for ( module in
modul
es ) {
- state =
modul
es[ module ];
- if ( !
hasOwn.call( registry, module
) ) {
+ for ( module in
stat
es ) {
+ state =
stat
es[ module ];
+ if ( !
( module in registry
) ) {
mw.loader.register( module );
}
setAndPropagate( module, state );
mw.loader.register( module );
}
setAndPropagate( module, state );
@@
-1985,7
+1973,7
@@
* in the registry.
*/
getVersion: function ( module ) {
* in the registry.
*/
getVersion: function ( module ) {
- return
hasOwn.call( registry, module )
? registry[ module ].version : null;
+ return
module in registry
? registry[ module ].version : null;
},
/**
},
/**
@@
-1996,7
+1984,7
@@
* in the registry.
*/
getState: function ( module ) {
* in the registry.
*/
getState: function ( module ) {
- return
hasOwn.call( registry, module )
? registry[ module ].state : null;
+ return
module in registry
? registry[ module ].state : null;
},
/**
},
/**