Skip to content

[JS API] support BinaryenAddFunctionWithHeapType - #9437

Open
chharvey wants to merge 1 commit into
WebAssembly:mainfrom
chharvey:feat/jsapi-add-func-heaptype
Open

chharvey wants to merge 1 commit into
WebAssembly:mainfrom
chharvey:feat/jsapi-add-func-heaptype

Conversation

@chharvey

Copy link
Copy Markdown
Contributor

Adds JS support for BinaryenAddFunctionWithHeapType by adding a new overload
to the Module#addFunction method, taking only four arguments:

mod.addFunction(name, heapType, varTypes, body);

This is a non-breaking change. When users don’t have a heap type,
they can still call the five-argument form:

mod.addFunction(name, paramType, resultType, varTypes, body);

@github-actions
github-actions Bot requested a review from aheejin November 30, 2026 16:39
* 2. `addFunction(name, heapType, varTypes, body)` - when you already have a signature heap type created by a type builder
*/
self['addFunction'] = function (name, arg1, arg2, arg3, arg4) {
if (arguments.length >= 5) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this would be the first place we use arguments.length to disambiguate an API. I'm not necessarily opposed to this, but what do you think about other options like a different name addFunctionWithType - ?

@chharvey chharvey Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

arguments.length is non-standard (and also probably not recommended), I just used it to get the job done. I can either change it to if (arg4 !== undefined) or just make it a completely separate function like you suggest. I figured both functions are so similar that multiple overloads under the same name would reduce surface area, but if you think it warrants a separate API point then I can split it.

This branch has not been deployed

No deployments
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