mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Fix stepping not working.
Use transferable object for sending arraybuffers to workers
This commit is contained in:
parent
d326cad611
commit
0e850b2a85
6 changed files with 47 additions and 32 deletions
|
@ -111,25 +111,14 @@ async function bake(data) {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof DOMException) {
|
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bakeError",
|
action: "bakeError",
|
||||||
data: {
|
data: {
|
||||||
error: err.message,
|
error: err.message || err,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
inputNum: data.inputNum
|
inputNum: data.inputNum
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
self.postMessage({
|
|
||||||
action: "bakeError",
|
|
||||||
data: {
|
|
||||||
error: err,
|
|
||||||
id: data.id,
|
|
||||||
inputNum: data.inputNum
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.inputNum = -1;
|
self.inputNum = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,22 @@ class ControlsWaiter {
|
||||||
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
||||||
*/
|
*/
|
||||||
stepClick() {
|
stepClick() {
|
||||||
|
if (this.manager.worker.step) {
|
||||||
|
// Step has already been clicked so get the data from the output
|
||||||
|
const activeTab = this.manager.input.getActiveTab();
|
||||||
|
this.manager.worker.queueInput({
|
||||||
|
input: this.manager.output.getOutput(activeTab, true),
|
||||||
|
inputNum: activeTab
|
||||||
|
});
|
||||||
|
this.app.progress = this.manager.output.outputs[activeTab].progress;
|
||||||
this.app.bake(true);
|
this.app.bake(true);
|
||||||
|
} else {
|
||||||
|
// First click of step, so get the output from the inputWorker
|
||||||
|
this.manager.input.inputWorker.postMessage({
|
||||||
|
action: "step",
|
||||||
|
data: this.manager.input.getActiveTab()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ class InputWaiter {
|
||||||
this.manager.worker.queueInput(r.data);
|
this.manager.worker.queueInput(r.data);
|
||||||
break;
|
break;
|
||||||
case "bake":
|
case "bake":
|
||||||
this.app.bake(false);
|
this.app.bake(r.data);
|
||||||
break;
|
break;
|
||||||
case "displayTabSearchResults":
|
case "displayTabSearchResults":
|
||||||
this.displayTabSearchResults(r.data);
|
this.displayTabSearchResults(r.data);
|
||||||
|
|
|
@ -82,7 +82,7 @@ self.addEventListener("message", function(e) {
|
||||||
self.changeTabLeft(r.data.activeTab, r.data.nums);
|
self.changeTabLeft(r.data.activeTab, r.data.nums);
|
||||||
break;
|
break;
|
||||||
case "autobake":
|
case "autobake":
|
||||||
self.autoBake(r.data);
|
self.autoBake(r.data, false);
|
||||||
break;
|
break;
|
||||||
case "filterTabs":
|
case "filterTabs":
|
||||||
self.filterTabs(r.data);
|
self.filterTabs(r.data);
|
||||||
|
@ -96,6 +96,9 @@ self.addEventListener("message", function(e) {
|
||||||
case "updateTabHeader":
|
case "updateTabHeader":
|
||||||
self.updateTabHeader(r.data);
|
self.updateTabHeader(r.data);
|
||||||
break;
|
break;
|
||||||
|
case "step":
|
||||||
|
self.autoBake(r.data, true);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log.error(`Unknown action '${r.action}'.`);
|
log.error(`Unknown action '${r.action}'.`);
|
||||||
}
|
}
|
||||||
|
@ -133,8 +136,10 @@ self.getLoadProgress = function(inputNum) {
|
||||||
* Queues the active input and sends a bake command.
|
* Queues the active input and sends a bake command.
|
||||||
*
|
*
|
||||||
* @param {number} inputNum - The input to be baked
|
* @param {number} inputNum - The input to be baked
|
||||||
|
* @param {boolean} [step=false] - Set to true if we should only execute one operation instead of the
|
||||||
|
* whole recipe
|
||||||
*/
|
*/
|
||||||
self.autoBake = function(inputNum) {
|
self.autoBake = function(inputNum, step=false) {
|
||||||
const input = self.getInputObj(inputNum);
|
const input = self.getInputObj(inputNum);
|
||||||
if (input) {
|
if (input) {
|
||||||
let inputData = input.data;
|
let inputData = input.data;
|
||||||
|
@ -150,7 +155,8 @@ self.autoBake = function(inputNum) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bake"
|
action: "bake",
|
||||||
|
data: step
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -179,7 +185,8 @@ self.bakeAllInputs = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bake"
|
action: "bake",
|
||||||
|
data: false
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,7 +114,8 @@ class OutputWaiter {
|
||||||
statusMessage: `Input ${inputNum} has not been baked yet.`,
|
statusMessage: `Input ${inputNum} has not been baked yet.`,
|
||||||
error: null,
|
error: null,
|
||||||
status: "inactive",
|
status: "inactive",
|
||||||
bakeId: -1
|
bakeId: -1,
|
||||||
|
progress: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
this.outputs[inputNum] = newOutput;
|
this.outputs[inputNum] = newOutput;
|
||||||
|
@ -1300,7 +1301,6 @@ class OutputWaiter {
|
||||||
});
|
});
|
||||||
} else if (output.status === "baked" && showBaked) {
|
} else if (output.status === "baked" && showBaked) {
|
||||||
let data = this.getOutput(iNum, false).slice(0, 4096);
|
let data = this.getOutput(iNum, false).slice(0, 4096);
|
||||||
log.error(output);
|
|
||||||
if (typeof data !== "string") {
|
if (typeof data !== "string") {
|
||||||
data = Utils.arrayBufferToStr(data);
|
data = Utils.arrayBufferToStr(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,11 +146,15 @@ class WorkerWaiter {
|
||||||
if (r.data.error) {
|
if (r.data.error) {
|
||||||
this.app.handleError(r.data.error);
|
this.app.handleError(r.data.error);
|
||||||
this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress);
|
this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress);
|
||||||
} else if (r.data.progress !== this.manager.recipe.getConfig().length) {
|
|
||||||
this.manager.output.updateOutputError(r.data.result, inputNum, r.data.progress);
|
|
||||||
} else {
|
} else {
|
||||||
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
|
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
|
||||||
}
|
}
|
||||||
|
this.app.progress = r.data.progress;
|
||||||
|
|
||||||
|
if (r.data.progress === this.recipeConfig.length) {
|
||||||
|
this.step = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.workerFinished(currentWorker);
|
this.workerFinished(currentWorker);
|
||||||
break;
|
break;
|
||||||
case "bakeError":
|
case "bakeError":
|
||||||
|
@ -328,7 +332,7 @@ class WorkerWaiter {
|
||||||
this.chefWorkers[workerIdx].inputNum = nextInput.inputNum;
|
this.chefWorkers[workerIdx].inputNum = nextInput.inputNum;
|
||||||
this.chefWorkers[workerIdx].active = true;
|
this.chefWorkers[workerIdx].active = true;
|
||||||
const input = nextInput.input;
|
const input = nextInput.input;
|
||||||
if (typeof input === "string") {
|
if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {
|
||||||
this.chefWorkers[workerIdx].worker.postMessage({
|
this.chefWorkers[workerIdx].worker.postMessage({
|
||||||
action: "bake",
|
action: "bake",
|
||||||
data: {
|
data: {
|
||||||
|
@ -340,7 +344,7 @@ class WorkerWaiter {
|
||||||
inputNum: nextInput.inputNum,
|
inputNum: nextInput.inputNum,
|
||||||
bakeId: this.bakeId
|
bakeId: this.bakeId
|
||||||
}
|
}
|
||||||
});
|
}, [input]);
|
||||||
} else {
|
} else {
|
||||||
this.chefWorkers[workerIdx].worker.postMessage({
|
this.chefWorkers[workerIdx].worker.postMessage({
|
||||||
action: "bake",
|
action: "bake",
|
||||||
|
@ -353,7 +357,7 @@ class WorkerWaiter {
|
||||||
inputNum: nextInput.inputNum,
|
inputNum: nextInput.inputNum,
|
||||||
bakeId: this.bakeId
|
bakeId: this.bakeId
|
||||||
}
|
}
|
||||||
}, [nextInput.input]);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue