Reject non-finite volume values
This commit is contained in:
@@ -182,7 +182,7 @@ export default class AudioManager {
|
||||
throw new AudioManagerStateError('Volume control requires volume.enabled to be true.');
|
||||
}
|
||||
|
||||
if (volumeInPercent < 0 || volumeInPercent > 100) {
|
||||
if (!Number.isFinite(volumeInPercent) || volumeInPercent < 0 || volumeInPercent > 100) {
|
||||
throw new AudioManagerConfigError('Volume must be between 0 and 100 percent.');
|
||||
}
|
||||
|
||||
|
||||
@@ -273,6 +273,11 @@ describe('AudioManager', () => {
|
||||
|
||||
expect(() => manager.setVolume(-1)).toThrow(AudioManagerConfigError);
|
||||
expect(() => manager.setVolume(101)).toThrow(AudioManagerConfigError);
|
||||
expect(() => manager.setVolume(Number.NaN)).toThrow(AudioManagerConfigError);
|
||||
expect(() => manager.setVolume(Number.POSITIVE_INFINITY)).toThrow(AudioManagerConfigError);
|
||||
expect(() => manager.setVolume(Number.NEGATIVE_INFINITY)).toThrow(AudioManagerConfigError);
|
||||
expect(() => manager.setVolume(0)).not.toThrow();
|
||||
expect(() => manager.setVolume(100)).not.toThrow();
|
||||
});
|
||||
|
||||
it('rejects volume changes before any resource exists', () => {
|
||||
|
||||
Reference in New Issue
Block a user