ennuicastr / libavjs-webcodecs-polyfill

A polyfill for the WebCodecs API. No, really.
82 stars 8 forks source link

getAudioDecoder can't be spread safely #1

Closed stevenwaterman closed 2 years ago

stevenwaterman commented 2 years ago

In the event that the requested configuration is unsupported when calling getAudioDecoder, it returns null. The return type is Promise<{...}> so it looks like you can spread it, but doing so will cause a runtime error if it returns null.

Relevant line: https://github.com/ennuicastr/libavjs-webcodecs-polyfill/blob/401a3876600a891907816321f3f67496c84eca56/src/main.ts#L107

It'd be better to throw an error or reject the promise. At the very least the return type should be updated to use a union type with null, so that it's a compiler error if you try and spread it / don't check for null.

This applies to to both the video/audio methods and the encoder/decoder methods, ie all 4 of them

Yahweasel commented 2 years ago

Now why didn't github notify me of new issues :thinking:

You're right, returning null is quite inelegant. I live too much in C land where returning null is a sensible way to handle an error :). Throwing an exception is the right solution, and I'll swap it around Soon™.

Yahweasel commented 2 years ago

Fixed in af760c3