swiftwasm / swiftwasm/JavaScriptKit

Ask for Feedback: Make `JSObject` / `JSFunction` calls be `throws`

Aperta
#272 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Swift
Stelle
986
Fork
76
Merge medio
21h 11m
PR unite (30g)
4

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

La issue indica JSObject e JSFunction come le API interessate, ma non fornisce alcun file né punto di ingresso per i test. Esamina le loro implementazioni delle chiamate e il comportamento esistente di .throws/.throwing, quindi misura il compromesso in termini di prestazioni e definisci test per le chiamate che generano eccezioni e per quelle che non le generano prima di decidere la modifica incompatibile dell’API.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, swift, wasm
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.