Changed argument type of VirtualMachineIO.prototype.error from string to Error.

Also lint.
This commit is contained in:
jtuu 2019-10-17 17:50:19 +03:00
parent bcc24e7a47
commit 4e9507cd3e
4 changed files with 27 additions and 8 deletions

View File

@ -17,5 +17,5 @@ export class VMIOStub implements VirtualMachineIO {
@stub winend(): void {}
@stub mesend(): void {}
@stub warning(msg: string, srcloc?: AsmToken): void {}
@stub error(msg: string, srcloc?: AsmToken): void {}
@stub error(err: Error, srcloc?: AsmToken): void {}
}

View File

@ -4,7 +4,8 @@ import { to_instructions } from "../../../../test/src/utils";
test("basic window_msg output", () => {
const messages = ["foo", "bar", "buz"];
const segments = to_instructions(`
const segments = to_instructions(
`
.code
0:
arg_pushs "${messages[0]}"
@ -14,7 +15,9 @@ test("basic window_msg output", () => {
arg_pushs "${messages[2]}"
add_msg
winend
`, true);
`,
true,
);
class TestIO extends VMIOStub {
window_msg = jest.fn((msg: string) => {
@ -27,8 +30,8 @@ test("basic window_msg output", () => {
winend = jest.fn(() => {});
error = jest.fn((msg: string, loc: any) => {
throw msg;
error = jest.fn((err: Error, loc: any) => {
throw err;
});
}

View File

@ -196,6 +196,10 @@ export class VirtualMachine {
return this.execute_instruction(exec, inst);
} catch (err) {
if (!(err instanceof Error)) {
err = new Error(String(err));
}
this.halt();
this.io.error(err, srcloc);
@ -653,7 +657,13 @@ export class VirtualMachine {
reg1: number,
reg2: number,
): void {
this.conditional_jump(exec, label, condition, this.get_register_signed(reg1), this.get_register_signed(reg2));
this.conditional_jump(
exec,
label,
condition,
this.get_register_signed(reg1),
this.get_register_signed(reg2),
);
}
private signed_conditional_jump_with_literal(
@ -673,7 +683,13 @@ export class VirtualMachine {
reg1: number,
reg2: number,
): void {
this.conditional_jump(exec, label, condition, this.get_register_unsigned(reg1), this.get_register_unsigned(reg2));
this.conditional_jump(
exec,
label,
condition,
this.get_register_unsigned(reg1),
this.get_register_unsigned(reg2),
);
}
private unsigned_conditional_jump_with_literal(

View File

@ -30,7 +30,7 @@ export interface VirtualMachineMetaIO {
* patterns that could possibly cause problems or have unintended effects.
*/
warning(msg: string, srcloc?: AsmToken): void;
error(msg: string, srcloc?: AsmToken): void;
error(err: Error, srcloc?: AsmToken): void;
}
/**