From 2ed648c4db7fa88976648a4e313d6f360f1312ed Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 2 Dec 2014 14:00:32 -0800 Subject: [PATCH] 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 --- modules/ve-mw/init/ve.init.mw.LinkCache.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/ve-mw/init/ve.init.mw.LinkCache.js b/modules/ve-mw/init/ve.init.mw.LinkCache.js index 5df146faf4..87b85a377d 100644 --- a/modules/ve-mw/init/ve.init.mw.LinkCache.js +++ b/modules/ve-mw/init/ve.init.mw.LinkCache.js @@ -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 );