refactor: extremely cheap ass error reports

This commit is contained in:
cha0s 2024-07-28 10:37:07 -05:00
parent ce9a1aeba7
commit ab626f8f9a
2 changed files with 18 additions and 4 deletions

View File

@ -699,7 +699,7 @@ export default class Sandbox {
stack: [],
};
}
let result = this.executeSync(this.ast, 0);
const result = this.executeSync(this.ast, 0);
const stepResult = {async: false, done: false, value: undefined};
switch (result.yield) {
case YIELD_PROMISE: {

View File

@ -24,13 +24,14 @@ export const cache = new LRUCache({
export default class Script {
constructor(sandbox) {
constructor(sandbox, code) {
this.code = code;
this.sandbox = sandbox;
this.promise = null;
}
clone() {
return new this.constructor(this.sandbox.clone());
return new this.constructor(this.sandbox.clone(), this.code);
}
get context() {
@ -76,6 +77,7 @@ export default class Script {
}
return new this(
new Sandbox(await cache.get(code), this.createContext(context)),
code,
);
}
@ -102,7 +104,19 @@ export default class Script {
}
while (true) {
this.sandbox.context.elapsed = elapsed;
const {async, done, value} = this.sandbox.step();
let async, done, value;
try {
({async, done, value} = this.sandbox.step());
}
catch (error) {
const node = this.sandbox.$$execution.stack.pop();
console.warn('Script ran into a problem at', this.code.slice(node.start, node.end));
console.warn(error);
if (resolve) {
resolve();
}
return;
}
if (async) {
this.promise = value;
value