Repository: gchq/CyberChef
File: src/web/App.mjs (JavaScript)

Code before:

        // Reset attemptHighlight flag
        this.options.attemptHighlight = true;

        // Remove all current indicators
        this.manager.recipe.updateBreakpointIndicator(false);

        this.manager.worker.bake(
            this.getRecipeConfig(), // The configuration of the recipe
            this.options,           // Options set by the user
            this.progress,          // The current position in the recipe
            step                    // Whether or not to take one step or execute the whole recipe
        );
    }


    /**
     * Runs Auto Bake if it is set.
     */
    autoBake() {
        // If autoBakePause is set, we are loading a full recipe (and potentially input), so there is no
        // need to set the staleness indicator. Just exit and wait until auto bake is called after loading
        // has completed.
        if (this.autoBakePause) return false;

        if (this.autoBake_ && !this.baking) {
            log.debug("Auto-baking");
            this.manager.worker.bakeInputs({
                nums: [this.manager.tabs.getActiveTab("input")],
                step: false
            });
        } else {
            this.manager.controls.showStaleIndicator();
        }
    }


    /**
     * Executes the next step of the recipe.
     */
    step() {
        if (this.baking) return;

        // Reset status using cancelBake
        this.manager.worker.cancelBake(true, false);

        const activeTab = this.manager.tabs.getActiveTab("input");
        if (activeTab === -1) return;

        let progress = 0;
        if (this.manager.output.outputs[activeTab].progress !== false) {

Review comment (suggestion):
I do intend to review this properly in time, I just think this PR likely needs an extensive amount of testing to make sure it doesn't break any other aspects of the service.

In particular, I'm struggling to work out why the original implementation _explicitly excluded_ autobaking when an existing value was being computed.

As well as that, I'm worried there's a race case somewhere here.  Cancelling a bake in a worker looks asynchronous, as far as I can tell.

I should have more time tomorrow night to look into this, although I generally have more time for this project over the weekends.

Code after:

        // Reset attemptHighlight flag
        this.options.attemptHighlight = true;

        // Remove all current indicators
        this.manager.recipe.updateBreakpointIndicator(false);

        this.manager.worker.bake(
            this.getRecipeConfig(), // The configuration of the recipe
            this.options,           // Options set by the user
            this.progress,          // The current position in the recipe
            step                    // Whether or not to take one step or execute the whole recipe
        );
    }


    /**
     * Runs Auto Bake if it is set.
     */
    autoBake() {
        // If autoBakePause is set, we are loading a full recipe (and potentially input), so there is no
        // need to set the staleness indicator. Just exit and wait until auto bake is called after loading
        // has completed.
        if (this.autoBakePause) return false;

        if (this.baking) {
            this.manager.worker.cancelBakeForAutoBake();
            this.baking = false;
        }

        if (this.autoBake_) {
            log.debug("Auto-baking");
            this.manager.worker.bakeInputs({
                nums: [this.manager.tabs.getActiveTab("input")],
                step: false
            });
        } else {
            this.manager.controls.showStaleIndicator();
        }
    }


    /**
     * Executes the next step of the recipe.
     */
    step() {
        if (this.baking) return;

        // Reset status using cancelBake
        this.manager.worker.cancelBake(true, false);