jenkins-bot has submitted this change and it was merged. Change subject: ve.Range: Don't fixup invalid arguments ......................................................................
ve.Range: Don't fixup invalid arguments Hitherto, calls such as "new ve.Range( NaN, undefined )" that indicate a programming error were having their invalid arguments whitewashed to 0. This impeded debugging, particularly as range calculation errors can often propagate quite far before surfacing. Change-Id: I05a99fb8f6760af875aca64400832e9ade236fac --- M src/ve.Range.js 1 file changed, 7 insertions(+), 3 deletions(-) Approvals: Esanders: Looks good to me, approved jenkins-bot: Verified diff --git a/src/ve.Range.js b/src/ve.Range.js index c12dccf..43618f9 100644 --- a/src/ve.Range.js +++ b/src/ve.Range.js @@ -8,12 +8,16 @@ * @class * * @constructor - * @param {number} from Anchor offset + * @param {number} [from=0] Anchor offset * @param {number} [to=from] Focus offset */ ve.Range = function VeRange( from, to ) { - this.from = from || 0; - this.to = to === undefined ? this.from : to; + // For ease of debugging, check arguments.length when applying defaults, to preserve + // invalid arguments such as undefined and NaN that indicate a programming error. + // Range calculation errors can often propagate quite far before surfacing, so the + // indication is important. + this.from = arguments.length >= 1 ? from : 0; + this.to = arguments.length >= 2 ? to : this.from; this.start = this.from < this.to ? this.from : this.to; this.end = this.from < this.to ? this.to : this.from; }; -- To view, visit https://gerrit.wikimedia.org/r/315199 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I05a99fb8f6760af875aca64400832e9ade236fac Gerrit-PatchSet: 3 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Divec <da...@troi.org> Gerrit-Reviewer: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits