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`).
This commit is contained in:
Diego 2024-07-11 09:31:28 -07:00 committed by Ali Mohammad Pur
parent 6d097a1aa9
commit da8633b2d0
Notes: sideshowbarker 2024-07-16 20:44:03 +09:00

View File

@ -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):