Skip to content

Expose try_table and throw_ref in C and JS API - #9057

Open
ospencer wants to merge 3 commits into
WebAssembly:mainfrom
ospencer:oscar/expose-new-exceptions
Open

ospencer wants to merge 3 commits into
WebAssembly:mainfrom
ospencer:oscar/expose-new-exceptions

Conversation

@ospencer

Copy link
Copy Markdown
Contributor

Adding these because I really want to use them. Let me know if there was a reason why these weren't there (I figure no one needed it yet).

@ospencer
ospencer requested a review from a team as a code owner August 28, 2026 19:38
@ospencer
ospencer requested review from aheejin and removed request for a team August 28, 2026 19:38

@chharvey chharvey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JS side looks good; I'd just suggest moving the TryTableId: 55 test in order

Comment thread src/binaryen-c.cpp
assert(expression->is<TryTable>());
assert(index < static_cast<TryTable*>(expression)->catchTags.size());
static_cast<TryTable*>(expression)->catchTags[index] =
catchTag ? Name(catchTag) : Name();

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.

@aheejin do we need to call refinalize() here so that sentTypes is repopulated?

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.

We don't have a Module anyway, so we can't get the type information from the tags.

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.

Then should we make this API receive the sent type?

Otherwise sentTypes will contain stale data after calls here?

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.

Yeah true... @ospencer Can we make this take sentTypes?

@ospencer
ospencer force-pushed the oscar/expose-new-exceptions branch from b15fd5c to b0d708b Compare August 29, 2026 05:04
@ospencer

Copy link
Copy Markdown
Contributor Author

Realized I had the ordering wrong everywhere; should be good now.

Comment thread src/binaryen-c.cpp
Comment thread src/binaryen-c.cpp
assert(expression->is<TryTable>());
assert(index < static_cast<TryTable*>(expression)->catchTags.size());
static_cast<TryTable*>(expression)->catchTags[index] =
catchTag ? Name(catchTag) : Name();

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.

We don't have a Module anyway, so we can't get the type information from the tags.

@aheejin aheejin left a comment

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.

Thanks!

Comment thread src/binaryen-c.cpp
@chharvey

Copy link
Copy Markdown
Contributor

@ospencer I opened ospencer#1 to sync the latest changes from main to your branch

@ospencer

Copy link
Copy Markdown
Contributor Author

Thanks! I merged it in.

@chharvey chharvey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

didn’t get a chance to review the JS tests before… just some minor cleanups needed but looks good overall

assert(theTryTable instanceof binaryen.TryTable);
assert(theTryTable instanceof binaryen.Expression);
assert(theTryTable.body === body);
assert(theTryTable.getNumCatches() == 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JS code should prefer strict equality (===) unless there's a good reason to use loose (==). In these tests, you’re checking against numbers (on lines 3325, 3330, etc.), so I would advise using ===.

assert(info.hasCatchAll === theTryTable.hasCatchAll());

theTryTable.body = body = module.unreachable();
assert(theTryTable.body === body);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the previous line assigns theTryTable.body = body so not sure why the assertion is needed


var newExnref = module.ref.null(binaryen.HeapType.noexn);
theThrowRef.exnref = newExnref;
assert(theThrowRef.exnref === newExnref);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also here, assertion is not needed since you just assigned theThrowRef.exnref = newExnref in previous line

@aheejin

aheejin commented Sep 21, 2026

Copy link
Copy Markdown
Member

Sorry, I didn't realize you didn't have commit access this needed merging. Will merge this in once you address new comments.

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.

5 participants