fix(pitchstaircase): correct stair ratio corruption, undefined crash, and broken recursion termination#7469
Open
netram75 wants to merge 1 commit into
Open
Conversation
… and broken recursion termination - snapshot Stairs[n] metadata before splice loop in _dissectStair so inserting at i < n does not shift the source index and corrupt ratio values on the new stair - guard previousRowNumber >= 0 before _stepTables access in _playNext to prevent TypeError when index is undefined on negative array lookup - fix || to && in recursion termination guard so playback stops cleanly at both boundaries (-1 and Stairs.length) Fixes sugarlabs#7468
Contributor
|
🧪 Jest Test Results ❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Coverage: Statements: 48.29% | Branches: 39.82% | Functions: 52.98% | Lines: 48.68% Note: These failures may be introduced by this PR or may already exist in the master branch. Failed Tests: |
Contributor
Author
|
@walterbender Please have a look when you get time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Fixes #7468
PR Category
Description
Three bugs in
js/widgets/pitchstaircase.jsaffecting the dissect button and playback functions.Bug 1 - Stair ratio corruption in
_dissectStairAfter finding the source stair at index
n, the loop callssplice(i, 0, [...])to insert the new stair at positioni. Wheni < n, this shifts every element right by one sothis.Stairs[n]no longer points to the original source stair. The numerator, denominator, base frequency, and octave were being read from the wrong stair, silently storing incorrect ratio metadata on every new step created below the source.Fix: snapshot
this.Stairs[n][3],[4],[2], and[6]into local constants before the loop starts, so all three splice call sites use the correct values regardless of where insertion happens.Bug 2 - TypeError crash when
previousRowNumberis negative in_playNextOn the first descending step (
index = 0,next = 1),previousRowNumberbecomes-1. JavaScript returnsundefinedfor negative array indices, notnull. The guard waspscTableCell !== nullwhich passedundefinedthrough. The next line.rows[0].cells[1]then threw a TypeError, crashing Play Up-and-Down before the first note highlighted.Fix: guard
previousRowNumber >= 0before the array access and assignnullexplicitly when negative, then check!== null && !== undefinedto safely skip the cell reset.Bug 3 - Recursion never terminates due to
||instead of&&The recursive call at the bottom of
_playNextwas gated by:This is always true for any reachable index. The boundary exit handlers at the top of the function (index === -1 and index === this.Stairs.length) were meant to stop the recursion but they were effectively unreachable via normal flow.
Fix: changed to && so the condition correctly bounds the index on both sides.
Changes Made
Testing Performed