Skip to content

fix: annotate asm.js integer return type - #230

Open
Justineo wants to merge 1 commit into
guybedford:mainfrom
Justineo:fix/asm-return-type
Open

fix: annotate asm.js integer return type#230
Justineo wants to merge 1 commit into
guybedford:mainfrom
Justineo:fix/asm-return-type

Conversation

@Justineo

@Justineo Justineo commented Aug 2, 2026

Copy link
Copy Markdown
AI disclosure — Codex, GPT-5.6 Sol (Extra High)

This PR was researched, implemented, tested, and drafted by Codex. I provided the requirements, requested alignment with project conventions, and approved publication.

Codex was asked to:

Codex reviewed the build history, asm.js rules, and V8 behavior; changed return b to return b | 0; and added an explicit asm.js validation test.

Validation covered published versions 2.0.0–2.3.1, Node 16–25, full and minimal bundles, and behavior comparison across 20 source files. The complete chomp test matrix is pending CI approval.

Summary

Since 2.2.0, invoking the es-module-lexer/js build under V8 emits:

Invalid asm.js: Invalid return type

The bundle remains valid JavaScript, so V8 falls back to normal JavaScript compilation and parsing still succeeds. This allows the existing functional tests to pass while the asm.js module itself fails validation.

The regression was introduced by #203. Its injected allocator helper returns an integer parameter without the result coercion required by asm.js:

function su(a, b) {
  a = a | 0;
  b = b | 0;
  v = a + b + 15 & -16;
  return b;
}

Returning b is the intended behavior; only its asm.js return type annotation is missing.

Changes

  • Change the allocator return to return b | 0
  • Add a V8-specific regression test for both full and minimal asm.js builds
  • Run validation in a child process with asm.js diagnostics enabled, so JavaScript fallback cannot hide validation or linking failures

The additional coercion does not change runtime behavior because b has already been converted with b = b | 0.

Test plan

  • Confirm the regression test fails for the unmodified 2.3.1 full and minimal asm.js bundles
  • Confirm the test passes for the patched full and minimal bundles
  • Run JavaScript syntax and diff checks
  • Run the complete chomp test matrix in CI with the Emscripten and Fastcomp toolchains

@Justineo
Justineo marked this pull request as ready for review August 2, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant