diff --git a/src/readable/byob_reader.rs b/src/readable/byob_reader.rs index 473f00b..61c1e0e 100644 --- a/src/readable/byob_reader.rs +++ b/src/readable/byob_reader.rs @@ -179,8 +179,10 @@ impl<'stream> ReadableStreamBYOBReader<'stream> { /// return an error and leave the reader locked to the stream. #[inline] pub fn try_release_lock(self) -> Result<(), (js_sys::Error, Self)> { - self.as_raw().release_lock(); - Ok(()) + self.as_raw() + .unchecked_ref::() + .try_release_lock() + .map_err(|err| (err, self)) } /// Converts this `ReadableStreamBYOBReader` into an [`AsyncRead`]. diff --git a/src/readable/default_reader.rs b/src/readable/default_reader.rs index 4d4e696..21ab949 100644 --- a/src/readable/default_reader.rs +++ b/src/readable/default_reader.rs @@ -112,8 +112,10 @@ impl<'stream> ReadableStreamDefaultReader<'stream> { /// return an error and leave the reader locked to the stream. #[inline] pub fn try_release_lock(self) -> Result<(), (js_sys::Error, Self)> { - self.as_raw().release_lock(); - Ok(()) + self.as_raw() + .unchecked_ref::() + .try_release_lock() + .map_err(|err| (err, self)) } /// Converts this `ReadableStreamDefaultReader` into a [`Stream`]. diff --git a/src/readable/sys.rs b/src/readable/sys.rs index 62078d4..23b0968 100644 --- a/src/readable/sys.rs +++ b/src/readable/sys.rs @@ -29,6 +29,16 @@ extern "C" { ) -> Result; } +#[wasm_bindgen] +extern "C" { + /// Additional methods for [`ReadableStreamDefaultReader`](web_sys::ReadableStreamDefaultReader) + /// and [`ReadableStreamByobReader`](web_sys::ReadableStreamByobReader). + pub(crate) type ReadableStreamReaderExt; + + #[wasm_bindgen(method, catch, js_name = releaseLock)] + pub(crate) fn try_release_lock(this: &ReadableStreamReaderExt) -> Result<(), Error>; +} + #[wasm_bindgen] extern "C" { /// A result returned by [`ReadableStreamDefaultReader.read`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader/read).