/* eslint-enable no-bitwise */
}
- // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
- StringSet = window.Set || ( function () {
- /**
- * @private
- * @class
- */
- function StringSet() {
- this.set = {};
- }
- StringSet.prototype.add = function ( value ) {
- this.set[ value ] = true;
- };
- StringSet.prototype.has = function ( value ) {
- return hasOwn.call( this.set, value );
- };
- return StringSet;
- }() );
+ function defineFallbacks() {
+ // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
+ StringSet = window.Set || ( function () {
+ /**
+ * @private
+ * @class
+ */
+ function StringSet() {
+ this.set = {};
+ }
+ StringSet.prototype.add = function ( value ) {
+ this.set[ value ] = true;
+ };
+ StringSet.prototype.has = function ( value ) {
+ return hasOwn.call( this.set, value );
+ };
+ return StringSet;
+ }() );
+ }
/**
* Create an object that can be read from or written to via methods that allow
}
};
+ defineFallbacks();
+
/* eslint-disable no-console */
log = ( function () {
// Also update the restoration of methods in mediawiki.log.js
* @class mw
*/
mw = {
+ redefineFallbacksForTest: function () {
+ if ( !window.QUnit ) {
+ throw new Error( 'Reset not allowed outside unit tests' );
+ }
+ defineFallbacks();
+ },
/**
* Get the current time, measured in milliseconds since January 1, 1970 (UTC).
},
teardown: function () {
mw.loader.store.enabled = false;
+ // Teardown for StringSet shim test
+ if ( this.nativeSet ) {
+ window.Set = this.nativeSet;
+ mw.redefineFallbacksForTest();
+ }
}
} ) );
} );
} );
- QUnit.test( '.using() Error: Circular dependency', function ( assert ) {
+ // Covers mw.loader#sortDependencies (with native Set if available)
+ QUnit.test( '.using() Error: Circular dependency [StringSet default]', function ( assert ) {
var done = assert.async();
mw.loader.register( [
.always( done );
} );
+ // @covers mw.loader#sortDependencies (with fallback shim)
+ QUnit.test( '.using() Error: Circular dependency [StringSet shim]', function ( assert ) {
+ var done = assert.async();
+
+ if ( !window.Set ) {
+ assert.expect( 0 );
+ done();
+ return;
+ }
+
+ this.nativeSet = window.Set;
+ window.Set = undefined;
+ mw.redefineFallbacksForTest();
+
+ mw.loader.register( [
+ [ 'test.shim.circle1', '0', [ 'test.shim.circle2' ] ],
+ [ 'test.shim.circle2', '0', [ 'test.shim.circle3' ] ],
+ [ 'test.shim.circle3', '0', [ 'test.shim.circle1' ] ]
+ ] );
+ mw.loader.using( 'test.shim.circle3' ).then(
+ function done() {
+ assert.ok( false, 'Unexpected resolution, expected error.' );
+ },
+ function fail( e ) {
+ assert.ok( /Circular/.test( String( e ) ), 'Detect circular dependency' );
+ }
+ )
+ .always( done );
+ } );
+
QUnit.test( '.load() - Error: Circular dependency', function ( assert ) {
mw.loader.register( [
[ 'test.circleA', '0', [ 'test.circleB' ] ],