From 9382ea699d781936e2b10252640341a3e5bf739c Mon Sep 17 00:00:00 2001 From: FineArchs Date: Thu, 19 Nov 2026 21:05:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20Async:interval=E3=81=AE=E5=8D=B3?= =?UTF-8?q?=E6=99=82=E5=AE=9F=E8=A1=8C=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E8=A3=9C=E8=B6=B3=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interpreter/lib/std.ts | 2 +- unreleased/fix-async-interval-immidiate.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 unreleased/fix-async-interval-immidiate.md diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index 79a3c1f7..09a47619 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -434,7 +434,7 @@ export const std: Record = { assertFunction(callback); if (immediate) { assertBoolean(immediate); - if (immediate.value) opts.call(callback, []); + if (immediate.value) opts.topCall(callback, []); } let id: ReturnType; diff --git a/unreleased/fix-async-interval-immidiate.md b/unreleased/fix-async-interval-immidiate.md new file mode 100644 index 00000000..54b2c144 --- /dev/null +++ b/unreleased/fix-async-interval-immidiate.md @@ -0,0 +1 @@ +- fix: Async:intervalの即時実行時のエラーが補足されない不具合を修正 From 0fe4cb6c087e760cdc697c59f71cafd7a8f32e79 Mon Sep 17 00:00:00 2001 From: FineArchs Date: Thu, 19 Nov 2026 21:27:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20abortOnError=E6=99=82=E3=81=AB?= =?UTF-8?q?=E7=A9=BA=E3=81=AE=E7=84=A1=E9=99=90=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interpreter/index.ts | 16 ++++++++-------- test/interpreter.ts | 29 +++++++++++++++++++++++++++++ unreleased/fix-abort-loop.md | 1 + 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 unreleased/fix-abort-loop.md diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 1ea3d16c..8ba97b69 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -547,8 +547,7 @@ export class Interpreter { } case 'loop': { - // eslint-disable-next-line no-constant-condition - while (true) { + while (!this.stop) { const v = await this._run(node.statements, scope.createChildScope(), callStack); if (v.type === 'break') { if (v.label != null && v.label !== node.label) { @@ -573,7 +572,7 @@ export class Interpreter { return times; } assertNumber(times); - for (let i = 0; i < times.value; i++) { + for (let i = 0; i < times.value && !this.stop; i++) { const v = await this._evalClause(node.for, scope, callStack); if (v.type === 'break') { if (v.label != null && v.label !== node.label) { @@ -599,7 +598,7 @@ export class Interpreter { } assertNumber(from); assertNumber(to); - for (let i = from.value; i < from.value + to.value; i++) { + for (let i = from.value; i < from.value + to.value && !this.stop; i++) { const v = await this._eval(node.for, scope.createChildScope(new Map([ [node.var!, { isMutable: false, @@ -630,6 +629,7 @@ export class Interpreter { } assertArray(items); for (const item of items.value) { + if (this.stop) break; const eachScope = scope.createChildScope(); this.define(eachScope, node.var, item, false); const v = await this._eval(node.for, eachScope, callStack); @@ -1080,8 +1080,7 @@ export class Interpreter { } case 'loop': { - // eslint-disable-next-line no-constant-condition - while (true) { + while (!this.stop) { const v = this._runSync(node.statements, scope.createChildScope(), callStack); if (v.type === 'break') { if (v.label != null && v.label !== node.label) { @@ -1106,7 +1105,7 @@ export class Interpreter { return times; } assertNumber(times); - for (let i = 0; i < times.value; i++) { + for (let i = 0; i < times.value && !this.stop; i++) { const v = this._evalClauseSync(node.for, scope, callStack); if (v.type === 'break') { if (v.label != null && v.label !== node.label) { @@ -1132,7 +1131,7 @@ export class Interpreter { } assertNumber(from); assertNumber(to); - for (let i = from.value; i < from.value + to.value; i++) { + for (let i = from.value; i < from.value + to.value && !this.stop; i++) { const v = this._evalSync(node.for, scope.createChildScope(new Map([ [node.var!, { isMutable: false, @@ -1163,6 +1162,7 @@ export class Interpreter { } assertArray(items); for (const item of items.value) { + if (this.stop) break; const eachScope = scope.createChildScope(); this.define(eachScope, node.var, item, false); const v = this._evalSync(node.for, eachScope, callStack); diff --git a/test/interpreter.ts b/test/interpreter.ts index 0b8bc0ea..f8a27a95 100644 --- a/test/interpreter.ts +++ b/test/interpreter.ts @@ -66,6 +66,35 @@ describe('error handler', () => { }); }); +describe('abort', () => { + const repetitions = [ + ['loop', 'loop { abort() }'], + ['while', 'while true { abort() }'], + ['do-while', 'do { abort() } while true'], + ['for times', 'for Math:Infinity { abort() }'], + ['for range', 'for let i, Math:Infinity { abort() }'], + ['each', 'each let item, [1, 2, 3] { abort() }'], + ]; + + test.each(repetitions)('stops %s during async evaluation', async (_name, source) => { + let interpreter: Interpreter; + interpreter = new Interpreter({ + abort: FN_NATIVE(() => interpreter.abort()), + }); + + await interpreter.exec(Parser.parse(source)); + }); + + test.each(repetitions)('stops %s during sync evaluation', (_name, source) => { + let interpreter: Interpreter; + interpreter = new Interpreter({ + abort: FN_NATIVE(() => interpreter.abort()), + }); + + interpreter.execSync(Parser.parse(source)); + }); +}); + describe('error location', () => { const exeAndGetErrPos = (src: string): Promise => new Promise((ok, ng) => { const aiscript = new Interpreter({ diff --git a/unreleased/fix-abort-loop.md b/unreleased/fix-abort-loop.md new file mode 100644 index 00000000..8cf170f0 --- /dev/null +++ b/unreleased/fix-abort-loop.md @@ -0,0 +1 @@ +- fix: abortOnError時に空の無限ループが発生する