Skip to content

Code Comment Inconsistency #540

Closed
Closed
@YichiZhang0613

Description

@YichiZhang0613

In web-audio-api-rs-main/src/node/channel_merger.rs, the comment indicates code will panic when count <= 2, while the code will panic when count != 1.

/// # Panics
///
/// This function panics if given count is greater than 2
///
#[track_caller]
#[inline(always)]
fn assert_valid_channel_count(count: usize) {
    assert!(
        count == 1,
        "InvalidStateError - channel count of ChannelMergerNode must be equal to 1"
    );
}

In web-audio-api-rs-main/src/lib.rs

/// # Panics
///
/// This function will panic if:
/// - the given sample rate is lower than 4000 or greater than 192000
///
#[track_caller]
#[inline(always)]
pub(crate) fn assert_valid_sample_rate(sample_rate: f32) {
    // Arbitrary cutoffs defined as:
    // min_sample_rate = min_required_in_spec / 4
    // max_sample_rate = max_required_in_spec * 4
    let min_sample_rate = 2_000.;
    let max_sample_rate = 384_000.;

    assert!(
        sample_rate >= min_sample_rate && sample_rate <= max_sample_rate,
        "NotSupportedError - Invalid sample rate: {:?}, should be in the range [{:?}, {:?}]",
        sample_rate,
        min_sample_rate,
        max_sample_rate,
    );
}

In web-audio-api-rs-new-main/src/node/panner.rs, the comment indicates code will panic when value < 0.0, while the code will panic when value <= 0.0 .

/// # Panics
///
/// Panics if the provided value is negative.
pub fn set_max_distance(&mut self, value: f64) {
    assert!(value > 0., "RangeError - maxDistance must be positive");
    self.max_distance = value;
    self.registration
        .post_message(ControlMessage::MaxDistance(value));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions