fix(wasm): enable C++ exception catching in the Emscripten build - #136
Closed
charlieh0tel wants to merge 2 commits into
Closed
charlieh0tel wants to merge 2 commits into
charlieh0tel wants to merge 2 commits into
Conversation
Emscripten disables exception catching by default, so throws abort and catch blocks are elided. nec_context uses `throw 1` to unwind a finished solve, and nec_process_input relies on catching nec_exception to report errors. Pass -fexceptions at both compile and link time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CI wasm job only checked that nec2pp.js/nec2pp.wasm were produced. Load the module under Node, feed nec_process_input a deck that makes the geometry parser throw, and require rc -2 with the error in the output. Without exception catching the throw escapes into JS and the test fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 2, 2026
charlieh0tel
added a commit
to charlieh0tel/nec2-js
that referenced
this pull request
Oct 2, 2026
tmolteno/necpp#129 was closed as superseded by d0f3259 upstream. The -fexceptions fix for NECPP_BUILD_WASM went up as tmolteno/necpp#136 and was withdrawn: that target is a stub, and build.sh already passes the flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uri4eguGitqE1abazuTstd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Emscripten disables C++ exception catching by default: a
throwaborts the module andcatchblocks are dropped. TheNECPP_BUILD_WASMtarget didn't pass-fexceptions, so this adds it to both the compile and link options ofnec2pp_wasm. It has to be a compile flag too; the link flag alone can't restore acatchthat was already dropped from the objects.Two places depend on it:
nec_context::simulateusesthrow 1/catch (int)to end a finished run and return to card input (src/nec_context.cpp).nec_process_inputinsrc/nec_wasm.cppcatchesnec_exceptionso it can return-2with the error message.nec_process_inputis still a stub that parses geometry from stdin and never callssimulate(), so today only the error path is reachable from the WASM API.Also adds
tests/wasm_smoke.js, which runs in the CIwasmjob. Until now that job only checked thatnec2pp.jsandnec2pp.wasmwere produced, and the build succeeds with or without exception support. The test loads the module under Node, givesnec_process_inputempty stdin so the geometry parser throws, and requires rc-2with the error message in the output.Test plan
node tests/wasm_smoke.js nec2pp.jspasses against a build of this branch (emscripten/emsdk:4.0.7, viascripts/build_wasm_docker.sh)wasmjob passes🤖 Generated with Claude Code
https://claude.ai/code/session_01Uri4eguGitqE1abazuTstd