@@ -178,14 +178,14 @@ impl AudioContext {
178
178
/// The `AudioContext` constructor will panic when an invalid `sinkId` is provided in the
179
179
/// `AudioContextOptions`. In a future version, a `try_new` constructor will be introduced that
180
180
/// never panics.
181
- #[ allow( clippy:: needless_pass_by_value) ]
182
181
#[ must_use]
183
- pub fn new ( mut options : AudioContextOptions ) -> Self {
184
- // Log, but ignore invalid sinks
185
- if !is_valid_sink_id ( & options. sink_id ) {
186
- log:: error!( "NotFoundError: invalid sinkId {:?}" , options. sink_id) ;
187
- options. sink_id = String :: from ( "" ) ;
188
- }
182
+ pub fn new ( options : AudioContextOptions ) -> Self {
183
+ // https://webaudio.github.io/web-audio-api/#validating-sink-identifier
184
+ assert ! (
185
+ is_valid_sink_id( & options. sink_id) ,
186
+ "NotFoundError - Invalid sinkId: {:?}" ,
187
+ options. sink_id
188
+ ) ;
189
189
190
190
// Set up the audio output thread
191
191
let ( control_thread_init, render_thread_init) = io:: thread_init ( ) ;
@@ -783,4 +783,14 @@ mod tests {
783
783
require_send_sync ( context. resume ( ) ) ;
784
784
require_send_sync ( context. close ( ) ) ;
785
785
}
786
+
787
+ #[ test]
788
+ #[ should_panic]
789
+ fn test_invalid_sink_id ( ) {
790
+ let options = AudioContextOptions {
791
+ sink_id : "invalid" . into ( ) ,
792
+ ..AudioContextOptions :: default ( )
793
+ } ;
794
+ let _ = AudioContext :: new ( options) ;
795
+ }
786
796
}
0 commit comments