Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit d9605d4

Browse files
author
Tim Kuijsten
committed
fix iterator when limit is 0
uncovered when testing with abstract-leveldown2 tests
1 parent 6ac2eb8 commit d9605d4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

iterator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ function Iterator (db, options) {
99
this.options = options
1010
AbstractIterator.call(this, db)
1111
this._order = options.reverse ? 'DESC': 'ASC'
12-
this._limit = options.limit
13-
if (!this._limit || this._limit === -1) {
12+
this._limit = options.limit;
13+
if (this._limit == null || this._limit === -1) {
1414
this._limit = Infinity;
1515
}
16+
if (typeof this._limit !== 'number') throw new TypeError('options.limit must be a number')
17+
if (this._limit === 0) return // skip further processing and wait for first call to _next
1618

1719
this._count = 0
1820
this._done = false
@@ -85,7 +87,7 @@ Iterator.prototype.onItem = function (value, cursor, cursorTransaction) {
8587
}
8688

8789
Iterator.prototype._next = function (callback) {
88-
if (this._keyRangeError) return callback()
90+
if (this._keyRangeError || this._limit === 0) return callback()
8991

9092
if (this._emitAndContinue) {
9193
this._emitAndContinue(callback)

0 commit comments

Comments
 (0)