jenkins-bot has submitted this change and it was merged. Change subject: Return null in Element#getDocument ......................................................................
Return null in Element#getDocument Because throwing an exception is overkill. Change-Id: I4b865c1397a76f732c4416b5348e58d46a80042b --- M src/Element.js M test/OO.ui.Element.test.js 2 files changed, 6 insertions(+), 15 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/src/Element.js b/src/Element.js index 14539cf..04cbaf0 100644 --- a/src/Element.js +++ b/src/Element.js @@ -72,13 +72,11 @@ * * @static * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Object to get the document for - * @return {HTMLDocument} Document object - * @throws {Error} If context is invalid + * @return {HTMLDocument|null} Document object */ OO.ui.Element.getDocument = function ( obj ) { - var doc = - // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable - ( obj[0] && obj[0].ownerDocument ) || + // jQuery - selections created "offscreen" won't have a context, so .context isn't reliable + return ( obj[0] && obj[0].ownerDocument ) || // Empty jQuery selections might have a context obj.context || // HTMLElement @@ -86,13 +84,8 @@ // Window obj.document || // HTMLDocument - ( obj.nodeType === 9 && obj ); - - if ( doc ) { - return doc; - } - - throw new Error( 'Invalid context' ); + ( obj.nodeType === 9 && obj ) || + null; }; /** diff --git a/test/OO.ui.Element.test.js b/test/OO.ui.Element.test.js index b5650e1..a98e894 100644 --- a/test/OO.ui.Element.test.js +++ b/test/OO.ui.Element.test.js @@ -29,7 +29,5 @@ assert.strictEqual( OO.ui.Element.getDocument( frameDiv ), frameDoc, 'HTMLElement (framed, detached)' ); assert.strictEqual( OO.ui.Element.getDocument( frameDoc ), frameDoc, 'HTMLDocument (framed)' ); - assert.throws( function () { - OO.ui.Element.getDocument( {} ); - }, 'Invalid' ); + assert.strictEqual( OO.ui.Element.getDocument( {} ), null, 'Invalid' ); } ); -- To view, visit https://gerrit.wikimedia.org/r/120969 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4b865c1397a76f732c4416b5348e58d46a80042b Gerrit-PatchSet: 3 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits