Skip to content

Commit d4b93ba

Browse files
committed
Fix index out-of-bounds behavior
1 parent 4221f65 commit d4b93ba

File tree

1 file changed

+11
-7
lines changed
  • lib/node_modules/@stdlib/repl/presentation/lib

1 file changed

+11
-7
lines changed

lib/node_modules/@stdlib/repl/presentation/lib/main.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,34 @@ inherit( Presentation, EventEmitter );
239239
* @returns {(Object|null)} selected slide
240240
*/
241241
setNonEnumerableReadOnly( Presentation.prototype, '_select', function select( n, fragment ) {
242+
var sc;
243+
var fc;
242244
var N;
243245

244246
// Limit the slide cursor range to one position before/after the first/last slide in order to avoid multiple previous/next calls moving the cursors indefinitely away from the slide deck...
245247
N = this.length;
246-
this._slideCursor = clamp( n, -1, N );
247-
if ( this._slideCursor === -1 || this._slideCursor === N ) {
248+
sc = clamp( n, -1, N );
249+
if ( sc === -1 || sc === N ) {
248250
debug( 'Unable to select slide. Slide cursor out-of-range.' );
249251
this._slide = null;
250252
} else {
251-
this._slide = this._slides[ this._slideCursor ];
253+
this._slide = this._slides[ sc ];
252254
}
253255
if ( this._slide && arguments.length > 1 ) {
254256
// Limit the slide fragment cursor range:
255257
N = this._slide.fragments.length;
256-
this._fragmentCursor = clamp( fragment, -1, N );
257-
if ( this._fragmentCursor === -1 || this._fragmentCursor === N ) {
258+
fc = clamp( fragment, -1, N );
259+
if ( fc === -1 || fc === N ) {
258260
debug( 'Unable to select slide fragment. Fragment cursor out-of-range.' );
259261
this._slide = null;
260262
}
261263
} else {
262-
this._fragmentCursor = 0;
264+
fc = 0;
263265
}
264266
if ( this._slide ) {
265-
debug( 'Selected slide %d and fragment %d.', this._slideCursor, this._fragmentCursor );
267+
debug( 'Selected slide %d and fragment %d.', sc, fc );
268+
this._slideCursor = sc;
269+
this._fragmentCursor = fc;
266270
}
267271
return this._slide;
268272
});

0 commit comments

Comments
 (0)