resourceloader: Remove use of $.isPlainObject() from mw.Map#set()
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 7 May 2018 22:34:20 +0000 (23:34 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 10 May 2018 20:10:28 +0000 (20:10 +0000)
commit89fbb363d4a792e345ce2026740db590522d5586
tree39ffac9dda5778ff4f288ebd20fe67abf500fecf
parentd888d84e60acf7d5284762d74a42a12615e045c8
resourceloader: Remove use of $.isPlainObject() from mw.Map#set()

Look for typeof 'object' instead. The set() method has good test
coverage which uncovered a few cases that were previously only
working implicitly due to isPlainObject.

* Test case `mw.config.set( [], 'value' )`
  This is invalid because `key` must be a string. This was previously
  rejected because while array is an object, it isn't a plain object.
  This commit intends to remove this distinction and allow any object
  to be used with the set(Object) signature. However, we should still
  reject set(non-string, string) no matter what kind of object is passed.

  Changing from isPlainObject to 'is an object' made this case
  wrongly pass instead of fail (because arrays are objects). Fix that,
  as well as any other case of non-string as key, by making the code
  explicitly reject non-string keys when two arguments are given.

  Added test case for `mw.config.set( {}, value ) === false` that did
  not pass without the changes in src/.

* Missing `> 1` check in global #set(). The check for arguments.length
  was asserting truthiness (non-zero) rather than >1 (2 or more).
  This was causing things like `mw.config.set('key')` to throw
  "ReferenceError: value not defined" when the underlying mw.Map
  is global. The normal #set() method for maps other than mw.config,
  was already fine.

  Fixed a bug in mediawiki.language.init that was revealed by this.
  The bug was not happening previously because when an object
  was passed, the second parameter was ignored.

Bug: T192623
Change-Id: Ib53647b324fe3d31e3389ed9aa14a08280d9c830
resources/src/mediawiki.language/mediawiki.language.init.js
resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js