Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyfilled Array.sort with callback fails when a breakpoint is added. #424

Open
jmkulwik opened this issue Mar 15, 2019 · 1 comment · Fixed by #425
Open

Polyfilled Array.sort with callback fails when a breakpoint is added. #424

jmkulwik opened this issue Mar 15, 2019 · 1 comment · Fixed by #425

Comments

@jmkulwik
Copy link

Code:

function swap(arr, first_Index, second_Index){
    var temp = arr[first_Index];
    arr[first_Index] = arr[second_Index];
    arr[second_Index] = temp;
}

var bubble_sort = function(comp){
    var len = this.length,
        i, j, stop;

    for (i=0; i < len; i++){
        for (j=0, stop=len-i; j < stop; j++){
            if (comp(this[j], this[j+1]) > 0){
                swap(this, j, j+1);
            }
        }
    }

    return this;
}

Array.prototype["sort"] = bubble_sort;
console.log([3, 0, 2, 5, -1, 4, 1].sort(
    function(a,b) {
        return b-a
    }
));

Error message:
Uncaught Error: step(onStep) requires the program to be paused

Screenshot:
StopifyBreakFailStep

arjunguha added a commit that referenced this issue Mar 15, 2019
Fixes #424

There were three issues:

1. There was a type error in the generated code, where the runtime
   system would check for the current line number in
   `$S.suspendRTS.linenum`, but the generated code would set the line
   number in `$__R.linenum`. JavaScript would silently create that field
   without blowing up.

2. Calling the `onBreakpoint` handler would not set the runtime's state
   to paused. (This is the error shown in #424). This is fixed and
   cleaned up a bit.

3. Unrelated error: we were instrumenting all blocks to support
   breakpoints, but not the top-level. The logic is identical and
   factored into a helper function in `suspendStep.ts`.
@arjunguha
Copy link
Member

Thanks for reporting this! I believe I've tracked the bug down and fixed it here (#425). We'll merge it in and update stopify.org shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants