Closed MaxDesiatov closed 2 years ago
Time Change: +140ms (1%)
Total Time: 13,963ms
Test name | Duration | Change | |
---|---|---|---|
Serialization/Write JavaScript string directly | 352ms | +18ms (5%) | 🔍 |
Trying this in https://github.com/swiftwasm/WebAPIKit/pull/41, looks like there's more work to do. Marking this PR as a draft, but I'm still looking forward to any feedback on this as a general approach.
Overall I like this! I had been contemplating adding a Boolean supported
class var but this is a much better approach.
I've verified that this fully works with WebAPIKit, ready for review.
Force unwrapping in
class var constructor
may crash for classes that are unavailable in the current environment. For example, after https://github.com/swiftwasm/WebAPIKit/pull/38 was merged, it led to crashes ingetCanvas
calls due to these optional casts relying onclass var constructor
always succeeding:if let gpuCanvasContext: GPUCanvasContext = value.fromJSValue()
branch crashes on browsers that don't haveGPUCanvasContext
enabled.As we currently don't have a better way to handle unavailable features, I propose making the result type of
static var constructor
requirement optional. This means you can still declare classes that are unavailable in the host JS environment. Conditional type casts are also available as they were, they will just always returnnil
, and initializers for these classes will returnnil
as well.