Skip to content

Commit

Permalink
fix conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian50 committed Jan 22, 2025
1 parent 5966286 commit da4ef9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/packages/web-worker/command-handlers/host-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ const hostCall = async ({
}: {
pvm: PvmApiInterface;
hostCallIdentifier: HostCallIdentifiers;
storage: Storage;
storage: Storage | null;
serviceId: number;
}): Promise<HostCallResponse> => {
if (hostCallIdentifier === HostCallIdentifiers.READ) {
if (storage === null) {
throw new Error("Storage is uninitialized.");
}

const readAccounts = new ReadAccounts(storage);
const jamHostCall = new read.Read(readAccounts);
// TODO the types are the same, but exported from different packages and lost track of the type
Expand All @@ -159,6 +163,10 @@ const hostCall = async ({

return { hostCallIdentifier, status: CommandStatus.SUCCESS };
} else if (hostCallIdentifier === HostCallIdentifiers.WRITE) {
if (storage === null) {
throw new Error("Storage is uninitialized.");
}

const writeAccounts = new WriteAccounts(storage);
const jamHostCall = new write.Write(writeAccounts);

Expand Down Expand Up @@ -186,10 +194,6 @@ export const runHostCall = async ({
throw new Error("PVM is uninitialized.");
}

if (storage === null) {
throw new Error("Storage is uninitialized.");
}

if (serviceId === null) {
throw new Error("Service ID is uninitialized.");
}
Expand Down
5 changes: 4 additions & 1 deletion src/store/workers/workersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ export const handleHostCall = createAsyncThunk(
async ({ workerId }: { workerId?: string }, { getState, dispatch }) => {
const state = getState() as RootState;

if (state.debugger.storage === null) {
if (
state.debugger.storage === null &&
state.workers.findIndex((worker: WorkerState) => worker.exitArg === HostCallIdentifiers.READ) !== -1
) {
return dispatch(setHasHostCallOpen(true));
} else {
const previousInstruction = nextInstruction(
Expand Down

0 comments on commit da4ef9a

Please sign in to comment.