From 492407bcc98745577a68c0813c8cf529fa3d4da4 Mon Sep 17 00:00:00 2001 From: Jordan Walke Date: Wed, 24 Jul 2013 17:19:23 -0700 Subject: [PATCH] Fix OrderedMap. Tim caught a bug. Squashing it so he can rebase on top of it. --- src/utils/OrderedMap.js | 9 +++++++++ src/utils/__tests__/OrderedMap-test.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/utils/OrderedMap.js b/src/utils/OrderedMap.js index b4ea88216f..1bf238fd32 100644 --- a/src/utils/OrderedMap.js +++ b/src/utils/OrderedMap.js @@ -18,6 +18,7 @@ "use strict"; +var invariant = require('invariant'); var mixInto = require('mixInto'); var throwIf = require('throwIf'); @@ -349,6 +350,10 @@ var OrderedMapMethods = { mapKeyRange: function(cb, startKey, endKey, context) { var startIndex = this.indexOfKey(startKey); var endIndex = this.indexOfKey(endKey); + invariant( + startIndex !== undefined && endIndex !== undefined, + 'mapKeyRange must be given keys that are present.' + ); if (endIndex < startIndex) { throw new Error(RANGE_ARGS); } @@ -358,6 +363,10 @@ var OrderedMapMethods = { forEachKeyRange: function(cb, startKey, endKey, context) { var startIndex = this.indexOfKey(startKey); var endIndex = this.indexOfKey(endKey); + invariant( + startIndex !== undefined && endIndex !== undefined, + 'forEachKeyRange must be given keys that are present.' + ); if (endIndex < startIndex) { throw new Error(RANGE_ARGS); } diff --git a/src/utils/__tests__/OrderedMap-test.js b/src/utils/__tests__/OrderedMap-test.js index a65c996986..361142df24 100644 --- a/src/utils/__tests__/OrderedMap-test.js +++ b/src/utils/__tests__/OrderedMap-test.js @@ -739,10 +739,16 @@ describe('OrderedMap', function() { }).not.toThrow(); expect(function() { om.mapKeyRange(duplicate, 'x' , 3, scope); - }).not.toThrow(); + }).toThrow( + 'Invariant Violation: mapKeyRange must be given keys ' + + 'that are present.' + ); expect(function() { om.forEachKeyRange(duplicate, 'x', 3, scope); - }).not.toThrow(); + }).toThrow( + 'Invariant Violation: forEachKeyRange must be given keys ' + + 'that are present.' + ); expect(function() { om.mapRange(duplicate, 0, 4, scope);