diff --git a/app/astride/sandbox.js b/app/astride/sandbox.js index b49d585..2c8a9cd 100644 --- a/app/astride/sandbox.js +++ b/app/astride/sandbox.js @@ -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: { diff --git a/app/util/script.js b/app/util/script.js index 472518d..204c4ba 100644 --- a/app/util/script.js +++ b/app/util/script.js @@ -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