Skip to content

Code Comment Inconsistency #548

Open
@YichiZhang0613

Description

@YichiZhang0613

In web-audio-api-rs-main/src/lib.rs, the comment "panic if the given value is not lower than or equal to zero" means panic if length >0 while the code panics if length <= 0.

/// Assert that the given value number is a valid buffer length, i.e. greater than zero
///
/// # Panics
///
/// This function will panic if:
/// - the given value is not lower than or equal to zero
///
#[track_caller]
#[inline(always)]
pub(crate) fn assert_valid_buffer_length(length: usize) {
    assert!(
        length > 0,
        "NotSupportedError - Invalid length: {:?} is less than or equal to minimum bound (0)",
        length,
    );
}

In web-audio-api-rs-main/src/lib.rs, this comment should be "value is not finite or lower than zero" instead of "value is not finite and lower than zero".

/// # Panics
/// This function will panic if:
/// - the given value is not finite and lower than zero
#[track_caller]
#[inline(always)]
pub(crate) fn assert_valid_time_value(value: f64) {
    assert!(
        value.is_finite(),
        "TypeError - The provided time value is non-finite.",
    );

    assert!(
        value >= 0.,
        "RangeError - The provided time value ({:?}) cannot be negative",
        value
    );
}

In web-audio-api-rs-main/src/render/quantum.rs, the comment means panic if index > self.channels.len() which should be index >= self.channels.len()

/// Get the samples from this specific channel.
    ///
    /// # Panics
    /// Panics if the index is greater than the available number of channels
    pub fn channel_data(&self, index: usize) -> &AudioRenderQuantumChannel {
        &self.channels[index]
    }

    /// Get the samples (mutable) from this specific channel.
    ///
    /// # Panics
    /// Panics if the index is greater than the available number of channels
    pub fn channel_data_mut(&mut self, index: usize) -> &mut AudioRenderQuantumChannel {
        &mut self.channels[index]
    }

Same problem in web-audio-api-rs-main/src/buffer.rs, the comment means panic if index > self.channels.len() which should be index >= self.channels.len().

/// Get the samples from this specific channel.
    ///
    /// Panics if the index is greater than the available number of channels
    // @note - this one is used in
    pub(crate) fn channel_data(&self, index: usize) -> &ChannelData {
        &self.channels[index]
    }

    /// Get the samples (mutable) from this specific channel.
    ///
    /// Panics if the index is greater than the available number of channels
    pub(crate) fn channel_data_mut(&mut self, index: usize) -> &mut ChannelData {
        &mut self.channels[index]
    }

So may be the comment should be changed from "Panics if the index is greater than the available number of channels" to "Panics if index >= self.channels.len()".

In web-audio-api-rs-main/src/node/panner.rs, I noticed you modify the question I mentioned before as "RangeError - maxDistance must be strictly positive" but the comment should be also modified.

///
    /// Panics if the provided value is negative.
    pub fn set_max_distance(&mut self, value: f64) {
        assert!(
            value > 0.,
            "RangeError - maxDistance must be strictly positive"
        );

In web-audio-api-rs-main/src/node/panner.rs, the comment indicates code will panic when value is not finite and lower than zero but actually it will panic when value > 1 or value < 0.

/// # Panics
///
/// This function will panic if:
/// - the given value is not finite and lower than zero
pub(crate) fn assert_valid_cone_outer_gain(value: f64) {
    assert!(
        value >= 0. && value <= 1.,
        "InvalidStateError - coneOuterGain must be in the range [0, 1]"
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions