Make LinkCache fail more gracefully when given undefined

If you tried to do styleElement( undefined, $element ), you'd
get an exception in the mw.Title constructor from a setTimeout.
That's not very nice, and there's no point sending non-strings
through the queue and other data structures in LinkCache, so
instead just make get() return a rejected promise when given
non-string values.

Change-Id: Iab06929d7e232a8ecd8eb1eff9d1190c303421c1
This commit is contained in:
Roan Kattouw 2014-12-02 14:00:32 -08:00
parent 6c4c3408b8
commit 2ed648c4db

View file

@ -62,6 +62,12 @@
* @returns {jQuery.Promise} Promise that will be resolved with the data once it's available
*/
ve.init.mw.LinkCache.prototype.get = function ( name ) {
if ( typeof name !== 'string' ) {
// Don't bother letting things like undefined or null make it all the way through,
// just reject them here. Otherwise they'll cause problems or exceptions at random
// other points in this file.
return $.Deferred().reject().promise();
}
if ( !hasOwn.call( this.cache, name ) ) {
this.cache[name] = $.Deferred();
this.queue.push( name );