stack traces in the brush editor
after 35 thousand years it's finally here good erro message
This commit is contained in:
parent
c1612b2a94
commit
e49885c83a
11 changed files with 710 additions and 150 deletions
|
@ -244,7 +244,7 @@ export class Haku {
|
|||
w2.haku2_vm_destroy(this.#pVm2);
|
||||
w2.haku2_defs_destroy(this.#pDefs2);
|
||||
w2.haku2_limits_destroy(this.#pLimits2);
|
||||
w2.haku_dealloc(this.#bytecode2.ptr);
|
||||
freeString2(this.#bytecode2);
|
||||
}
|
||||
|
||||
setBrush(code) {
|
||||
|
@ -332,12 +332,49 @@ export class Haku {
|
|||
return exn;
|
||||
}
|
||||
|
||||
#stackTrace() {
|
||||
let count = w2.haku2_vm_stackframe_count(this.#pVm2);
|
||||
let trace = [];
|
||||
for (let i = 0; i < count; ++i) {
|
||||
let isSystem = w2.haku2_vm_stackframe_is_system(this.#pVm2, i) != 0;
|
||||
let pc = w2.haku2_vm_stackframe_pc(this.#pVm2, i);
|
||||
|
||||
let span = null;
|
||||
if (!isSystem && pc > 0) {
|
||||
// NOTE: We find the span at (pc - 1), because stack frames' program counters are
|
||||
// situated at where control flow _ought_ to return, and not where the function call
|
||||
// is located. Therefore, to pull the program counter back into the function call,
|
||||
// we subtract 1.
|
||||
let pSpan = w.haku_bytecode_find_span(this.#pInstance, Math.max(0, pc - 1));
|
||||
if (pSpan != 0) {
|
||||
span = {
|
||||
start: w.haku_span_start(pSpan),
|
||||
end: w.haku_span_end(pSpan),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
trace.push({
|
||||
isSystem,
|
||||
pc,
|
||||
span,
|
||||
functionName: readString(
|
||||
memory2,
|
||||
w2.haku2_vm_stackframe_function_name_len(this.#pVm2, i),
|
||||
w2.haku2_vm_stackframe_function_name(this.#pVm2, i),
|
||||
),
|
||||
});
|
||||
}
|
||||
return trace;
|
||||
}
|
||||
|
||||
#exceptionResult() {
|
||||
return {
|
||||
status: "error",
|
||||
errorKind: "exception",
|
||||
description: "Runtime error",
|
||||
message: this.#exceptionMessage(),
|
||||
stackTrace: this.#stackTrace(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue