Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for Feedback: Make JSObject / JSFunction calls be throws #272

Open
kateinoigakukun opened this issue Nov 25, 2024 · 0 comments
Open

Comments

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Nov 25, 2024

Every dynamic JS function calls can throw an exception, but the current JSObject and JSFunction are non-throws by default.
They can be throws by .throws or .throwing but it's still opt-in.

For example, if an exception is thrown during a JS function call but the call site in Swift side is not throws, the control unwinding wasm call frames without executing function epilogues even if there is do { } catch {} clause in Swift. And also in that case, defer blocks won't be called.

This behavior is quite tricky and unwinding wasm call frames without executing function epilogues can lead to memory and resource leak.

I'm going to introduce an API breaking change to make JSObject / JSFunction calls be throws in the next next release to improve the situation.

This change has a performance tradeoff as throws variants are typically a little bit slower than non-throwing variants. We should measure the amount of the penalty but it shouldn't be a big deal. We can make non throwing calls as an opt-in feature so that those who want best performance can satisfy their needs.

// Before
let foo = JSObject.global.document.getElementById!("foo")
let foo = try JSObject.global.document.throwing.getElementById!("foo")

// After
let foo = try JSObject.global.document.getElementById!("foo")
let foo = JSObject.global.document.nonthrowing.getElementById!("foo")

Let me know here if you have a strong objection 🙏 Thanks.

@kateinoigakukun kateinoigakukun changed the title Make JSObject / JSFunction calls be throws Ask for Feedback: Make JSObject / JSFunction calls be throws Nov 25, 2024
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

No branches or pull requests

1 participant