This is an automated email from the ASF dual-hosted git repository.

colegreer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ef1d32fc8 CTR Fix incorrect handling of Traverser in 
traversal.hasNext() in JS
5ef1d32fc8 is described below

commit 5ef1d32fc8df1ccd3377998b0bdc3afb6050f790
Author: Cole Greer <[email protected]>
AuthorDate: Fri Mar 27 13:29:41 2026 -0700

    CTR Fix incorrect handling of Traverser in traversal.hasNext() in JS
---
 gremlin-js/gremlin-javascript/lib/process/traversal.ts    | 15 ++++++++++-----
 .../test/integration/remote-connection-tests.js           | 11 +++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gremlin-js/gremlin-javascript/lib/process/traversal.ts 
b/gremlin-js/gremlin-javascript/lib/process/traversal.ts
index 6813911fa7..dad0650a77 100644
--- a/gremlin-js/gremlin-javascript/lib/process/traversal.ts
+++ b/gremlin-js/gremlin-javascript/lib/process/traversal.ts
@@ -73,11 +73,16 @@ export class Traversal {
    */
   hasNext() {
     return this._applyStrategies().then(
-      () =>
-        this.results &&
-        this.results.length > 0 &&
-        this._resultsIteratorIndex < this.results.length &&
-        this.results[this._resultsIteratorIndex] instanceof Traverser ? 
this.results[this._resultsIteratorIndex].bulk > 0 : true,
+      () => {
+        if (!this.results || this.results.length <= 0 || 
this._resultsIteratorIndex >= this.results.length) {
+          return false;
+        }
+        if (this.results[this._resultsIteratorIndex] instanceof Traverser) {
+          return this.results[this._resultsIteratorIndex].bulk > 0 || 
this._resultsIteratorIndex + 1 < this.results.length;
+        } else {
+          return true;
+        }
+      }
     );
   }
 
diff --git 
a/gremlin-js/gremlin-javascript/test/integration/remote-connection-tests.js 
b/gremlin-js/gremlin-javascript/test/integration/remote-connection-tests.js
index 7632e02d93..6de268f9f3 100644
--- a/gremlin-js/gremlin-javascript/test/integration/remote-connection-tests.js
+++ b/gremlin-js/gremlin-javascript/test/integration/remote-connection-tests.js
@@ -25,6 +25,7 @@ import assert from 'assert';
 import { Vertex } from '../../lib/structure/graph.js';
 import anon from '../../lib/process/anonymous-traversal.js';
 import { getConnection, getClient } from '../helper.js';
+import {P} from "../../lib/process/traversal.js";
 
 let connection;
 let client;
@@ -63,5 +64,15 @@ describe('DriverRemoteConnection', function () {
           assert.ok(err.statusAttributes.has('stackTrace'));
         });
     });
+    it('should iterate ordered results', async function () {
+      const g = anon.traversal().with_(connection);
+      const traversal = g.V().has('name', P.within('marko', 
'peter')).values('name').order();
+      const first = await traversal.next();
+      assert.strictEqual(first.value, 'marko');
+      assert.strictEqual(await traversal.hasNext(), true);
+      const second = await traversal.next();
+      assert.strictEqual(second.value, 'peter');
+      assert.strictEqual(await traversal.hasNext(), false);
+    });
   });
 });

Reply via email to