Merge "mw.Map: add ability to map over an existing object other than 'window'"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 7 Nov 2013 15:58:42 +0000 (15:58 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 7 Nov 2013 15:58:42 +0000 (15:58 +0000)
resources/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 9267a49..1f89792 100644 (file)
@@ -75,11 +75,11 @@ var mw = ( function ( $, undefined ) {
         * @class mw.Map
         *
         * @constructor
-        * @param {boolean} [global=false] Whether to store the values in the global window
-        *  object or a exclusively in the object property 'values'.
+        * @param {Object|boolean} [values] Value-bearing object to map, or boolean
+        *  true to map over the global object. Defaults to an empty object.
         */
-       function Map( global ) {
-               this.values = global === true ? window : {};
+       function Map( values ) {
+               this.values = values === true ? window : ( values || {} );
                return this;
        }
 
index 502b55b..3ce52e3 100644 (file)
@@ -43,7 +43,7 @@
                assert.strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
        } );
 
-       QUnit.test( 'mw.Map', 27, function ( assert ) {
+       QUnit.test( 'mw.Map', 28, function ( assert ) {
                var arry, conf, funky, globalConf, nummy, someValues;
 
                conf = new mw.Map();
                        'lorem': 'ipsum'
                }, 'Map.get returns multiple values correctly as an object' );
 
+               assert.deepEqual( conf, new mw.Map( conf.values ), 'new mw.Map maps over existing values-bearing object' );
+
                assert.deepEqual( conf.get( ['foo', 'notExist'] ), {
                        'foo': 'bar',
                        'notExist': null