Skip to content

Commit

Permalink
FIXED: WASM: Query.next() to set done to true on last answer.
Browse files Browse the repository at this point in the history
This must be `false` when used as iterator.
  • Loading branch information
JanWielemaker committed Nov 21, 2024
1 parent 21f46ad commit d5192b2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/wasm/prolog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,10 @@ class Query {
prolog.open_queries.push(this);
}

[Symbol.iterator]() { return this; }
[Symbol.iterator]() {
this.is_iterator = true;
return this;
}

next()
{ const prolog = this.prolog;
Expand All @@ -1409,23 +1412,26 @@ class Query {

switch(prolog.bindings.PL_next_solution(this.qid))
{ case prolog.PL_S_EXCEPTION:
{ if ( (this.flags & prolog.PL_Q_NORMAL) )
{ /* `value` is `undefined` */
if ( (this.flags & prolog.PL_Q_NORMAL) )
{ this.close();
return { done: true, error: true }
return { done: !this.is_iterator, error: true }
} else
{ const msg = prolog.message_to_string(
prolog.bindings.PL_exception(this.qid));
console.log(msg);
this.close();
return { done: true, error: true, message: msg };
return { done: !this.is_iterator, error: true, message: msg };
}
}
case prolog.PL_S_FALSE:
this.close();
return { done: true };
case prolog.PL_S_LAST:
this.close();
/*FALLTHROUGH*/
return { done: !this.is_iterator,
value: this.map ? this.map.call(this, argv) : argv
};
case prolog.PL_S_TRUE:
return { done: false,
value: this.map ? this.map.call(this, argv) : argv
Expand Down

0 comments on commit d5192b2

Please sign in to comment.