From cd66de16848c0bc4c0e7752bf40a9c397da2bdda Mon Sep 17 00:00:00 2001 From: Fomafix Date: Thu, 30 May 2019 00:56:46 +0200 Subject: [PATCH] jquery.suggestions: Use Object.create( null ) Object.create( null ) creates an Object without predefined methods like hasOwnProperty or constructor. This allow to use key in object instead of Object.prototype.hasOwnProperty.call( object, key ) even if the key is 'constructor'. Change-Id: I6ef9019309022a2a990deda685ba71ca61b86df3 --- resources/src/jquery/jquery.suggestions.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index 4a1d637de9..9c7573dda1 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -90,8 +90,6 @@ ( function () { - var hasOwn = Object.hasOwnProperty; - /** * Cancel any delayed maybeFetch() call and callback the context so * they can cancel any async fetching if they use AJAX or something. @@ -176,7 +174,7 @@ ) { context.data.prevText = val; // Try cache first - if ( context.config.cache && hasOwn.call( cache, val ) ) { + if ( context.config.cache && val in cache ) { if ( mw.now() - cache[ val ].timestamp < context.config.cacheMaxAge ) { context.data.$textbox.suggestions( 'suggestions', cache[ val ].suggestions ); if ( typeof context.config.update.after === 'function' ) { @@ -637,7 +635,7 @@ prevText: null, // Cache of fetched suggestions - cache: {}, + cache: Object.create( null ), // Number of results visible without scrolling visibleResults: 0, -- 2.20.1