use crate::utils::primordials::Primordial;
use rquickjs::{class::Trace, methods, Ctx, Function, JsLifetime, Result};
use super::{NativeSizeFunctionPrimordials, QueueingStrategyInit};
#[derive(JsLifetime, Trace)]
#[rquickjs::class]
pub(crate) struct ByteLengthQueuingStrategy<'js> {
high_water_mark: f64,
size: Function<'js>,
}
#[methods(rename_all = "camelCase")]
impl<'js> ByteLengthQueuingStrategy<'js> {
#[qjs(constructor)]
pub(crate) fn new(ctx: Ctx<'js>, init: QueueingStrategyInit) -> Result<Self> {
Ok(Self {
high_water_mark: init.high_water_mark,
size: NativeSizeFunctionPrimordials::get(&ctx)?
.byte_length
.clone(),
})
}
#[qjs(get)]
pub(crate) fn size(&self) -> Function<'js> {
self.size.clone()
}
#[qjs(get)]
pub(crate) fn high_water_mark(&self) -> f64 {
self.high_water_mark
}
}