swiftwasm / JavaScriptKit

Swift framework to interact with JavaScript through WebAssembly.
https://swiftpackageindex.com/swiftwasm/JavaScriptKit/main/documentation/javascriptkit
MIT License
664 stars 44 forks source link

`Int.construct(from:)` can crash instead of return `nil` #258

Closed stephencelis closed 1 month ago

stephencelis commented 1 month ago

While the JSValueCompatible APIs are failable, the underlying conversion of calling SignedInteger.init(_:) and UnsignedInteger.init(_:) directly can crash at runtime if:

Ideally, none of these would crash and return nil instead:

stephencelis commented 1 month ago

I think this would suffice:

-return Self(number)
+return Self(exactly: number.rounded(.towardZero))
kateinoigakukun commented 1 month ago

Thanks for reporting!