From 03b49ecc8ba8ff9c77d7470f4bcb1451bdef9591 Mon Sep 17 00:00:00 2001 From: GlassBricks <24237065+GlassBricks@users.noreply.github.com> Date: Sun, 17 Mar 2024 12:19:09 -0700 Subject: [PATCH 1/3] Don't crash if coroutine not supported --- src/lualib/Await.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lualib/Await.ts b/src/lualib/Await.ts index f5c368619..7f6a345ee 100644 --- a/src/lualib/Await.ts +++ b/src/lualib/Await.ts @@ -16,6 +16,7 @@ import { __TS__Promise } from "./Promise"; +const coroutine = _G.coroutine ?? {}; const cocreate = coroutine.create; const coresume = coroutine.resume; const costatus = coroutine.status; From b8f9b3459e0db1b37897a0e275a970a08c06dcf0 Mon Sep 17 00:00:00 2001 From: GlassBricks <24237065+GlassBricks@users.noreply.github.com> Date: Sun, 17 Mar 2024 12:39:08 -0700 Subject: [PATCH 2/3] Add test for environment without coroutine --- test/unit/builtins/loading.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/builtins/loading.spec.ts b/test/unit/builtins/loading.spec.ts index e4363eb8c..75781c9d5 100644 --- a/test/unit/builtins/loading.spec.ts +++ b/test/unit/builtins/loading.spec.ts @@ -67,6 +67,18 @@ test("lualib should not include tstl header", () => { ); }); +test("using lualib does not crash when coroutine is not defined", () => { + util.testModule` + declare const _G: any; + declare function require(this: void, name: string): any + + _G.coroutine = undefined; + require("lualib_bundle"); + export const result = 1 + ` + .expectToEqual({ result: 1 }); +}) + describe("Unknown builtin property", () => { test("access", () => { util.testExpression`Math.unknownProperty` From 1bcb478922eda3fda38773fad4a7d6515281c582 Mon Sep 17 00:00:00 2001 From: GlassBricks <24237065+GlassBricks@users.noreply.github.com> Date: Mon, 18 Mar 2024 00:17:42 -0700 Subject: [PATCH 3/3] Fix prettier --- test/unit/builtins/loading.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/builtins/loading.spec.ts b/test/unit/builtins/loading.spec.ts index 75781c9d5..563870f6d 100644 --- a/test/unit/builtins/loading.spec.ts +++ b/test/unit/builtins/loading.spec.ts @@ -75,9 +75,8 @@ test("using lualib does not crash when coroutine is not defined", () => { _G.coroutine = undefined; require("lualib_bundle"); export const result = 1 - ` - .expectToEqual({ result: 1 }); -}) + `.expectToEqual({ result: 1 }); +}); describe("Unknown builtin property", () => { test("access", () => {