Skip to content

Fix emscripten_get_exported_function for names that are not exported - #28207

Merged
sbc100 merged 2 commits into
emscripten-core:mainfrom
Thanatos9404:exported-function-name
Nov 9, 2026
Merged

sbc100 merged 2 commits into
emscripten-core:mainfrom
Thanatos9404:exported-function-name

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

For a name that is not exported, emscripten_get_exported_function:

  • with ASSERTIONS, printed No exported function found by name "{exportedFunc}": the template literal had no $, and exportedFunc is always undefined at that point. It now prints the name that was looked up.
  • on wasm64, threw Cannot convert undefined to a BigInt: the function fell off the end and returned undefined, which the pointer return wrapper passes to BigInt. It now returns 0.

core/test_get_exported_function.cpp now also looks up a missing name and expects NULL, and the test checks the message in unoptimized modes (where ASSERTIONS is on by default). Without the fix it fails in core0 (message) and in wasm64 and wasm64_O2 (TypeError).

Follow-up to #28177.

With ASSERTIONS, a name that is not exported printed the text
`No exported function found by name "{exportedFunc}"`: the template
literal had no `$`, and `exportedFunc` is always undefined there. Print the
name that was looked up.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an error message in src/lib/libexports.js when an exported function is not found, correcting the string interpolation to use ${name} instead of {exportedFunc}. Additionally, a new test test_get_exported_function_missing is added to test/test_other.py to verify this behavior under assertions. There are no review comments to address, and I have no feedback to provide.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than add a new test can you update the existing test/core/test_get_exported_function.cpp?

Move the check from other.test_get_exported_function_missing into
core/test_get_exported_function.cpp, as asked in review. The test now
also looks up a name that is not exported and expects NULL. The error
that names it is checked in unoptimized modes, where ASSERTIONS is on by
default; the optimized modes keep their default settings, so they still
cover the -lexports.js export name handling.

In the wasm64 modes that lookup threw "Cannot convert undefined to a
BigInt", with or without ASSERTIONS: the function fell off the end and
returned undefined, which the pointer return wrapper passes to BigInt.
Return 0 explicitly.
@Thanatos9404 Thanatos9404 changed the title Name the missing function in emscripten_get_exported_function's error Fix emscripten_get_exported_function for names that are not exported Nov 9, 2026
@Thanatos9404

Copy link
Copy Markdown
Contributor Author

Done, thanks: the check now lives in test/core/test_get_exported_function.cpp and the test_other test is gone. The message is only checked in unoptimized modes, so the -O3/-Os/-Oz modes keep testing that -lexports.js leaves the export names unminified. Running it in the core matrix also showed that on wasm64 a missing name threw Cannot convert undefined to a BigInt (the function returned undefined rather than 0), so it now returns 0 explicitly.

@sbc100
sbc100 enabled auto-merge (squash) November 9, 2026 20:11
@sbc100
sbc100 merged commit a0bb696 into emscripten-core:main Nov 9, 2026
43 checks passed
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.

2 participants