From da8633b2d0ab3b9d8f1cdad39a8ad85ca2accf03 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:31:28 -0700 Subject: [PATCH] LibWasm: Fix spec-test gen for inline commands and special characters `linking.wast` has an unusual pattern for invoke commands, which is now accounted-for. Also, special unicode characters are now properly serialized in JavaScript as string literals (this is only relevant for `names.wast`). --- Meta/generate-libwasm-spec-test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Meta/generate-libwasm-spec-test.py b/Meta/generate-libwasm-spec-test.py index a064b9077da..0e0606738d1 100644 --- a/Meta/generate-libwasm-spec-test.py +++ b/Meta/generate-libwasm-spec-test.py @@ -316,12 +316,19 @@ def gen_invoke( *, fail_msg: str | None = None, ): + if not ctx.has_unclosed: + print(f'describe("inline (line {line}))", () => {{\nlet _test = test;\n') module = "module" if invoke.module is not None: module = f'namedModules["{invoke.module}"]' + utf8 = ( + str(invoke.field.encode("utf8"))[2:-1] + .replace("\\'", "'") + .replace("`", "${'`'}") + ) print( - f"""_test("execution of {ctx.current_module_name}: {escape(invoke.field)} (line {line})", () => {{ -let _field = {module}.getExport("{escape(invoke.field)}"); + f"""_test(`execution of {ctx.current_module_name}: {utf8} (line {line})`, () => {{ +let _field = {module}.getExport(decodeURIComponent(escape(`{utf8}`))); expect(_field).not.toBeUndefined();""" ) if fail_msg is not None: @@ -331,6 +338,8 @@ expect(_field).not.toBeUndefined();""" if result is not None: print(f"expect(_result).toBe({gen_value(result)});") print("});") + if not ctx.has_unclosed: + print("});") def gen_get(line: int, get: Get, result: WasmValue | None, ctx: Context):