-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_for_loop.mjs
More file actions
20 lines (17 loc) · 913 Bytes
/
Copy pathtest_for_loop.mjs
File metadata and controls
20 lines (17 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// SPDX-License-Identifier: MIT OR AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2026 hyperpolymath
//
// Regression for #255: `for-in` loop bodies must execute. Before the
// fix, StmtFor read length from arr-4 and elem i from arr+i*4 (the
// canonical layout is length@arr+0, elem i@arr+4+i*4 — ExprArray /
// ExprIndex), so the loop ran zero times and main() returned 0.
// test_for_loop.affine existed but had NO harness, so nothing caught it.
import { readFile } from 'fs/promises';
const wasmBuffer = await readFile('./tests/codegen/test_for_loop.wasm');
const imports = { wasi_snapshot_preview1: { fd_write: () => 0 } };
const { instance } = await WebAssembly.instantiate(wasmBuffer, imports);
const result = instance.exports.main();
console.log(`Result: ${result}`);
console.log('Expected: 15');
console.log(`Test ${result === 15 ? 'PASSED ✓' : 'FAILED ✗'}`);
process.exit(result === 15 ? 0 : 1);