Divec has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315199

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(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/99/315199/1

diff --git a/src/ve.Range.js b/src/ve.Range.js
index c12dccf..4047200 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 often seem to 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: newchange
Gerrit-Change-Id: I05a99fb8f6760af875aca64400832e9ade236fac
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <da...@troi.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to