Skip to content

Commit

Permalink
Bring back error handling for releaseLock()
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Sep 30, 2023
1 parent d89a21e commit 2f79117
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/readable/byob_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<sys::ReadableStreamReaderExt>()
.try_release_lock()
.map_err(|err| (err, self))
}

/// Converts this `ReadableStreamBYOBReader` into an [`AsyncRead`].
Expand Down
6 changes: 4 additions & 2 deletions src/readable/default_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<sys::ReadableStreamReaderExt>()
.try_release_lock()
.map_err(|err| (err, self))
}

/// Converts this `ReadableStreamDefaultReader` into a [`Stream`].
Expand Down
10 changes: 10 additions & 0 deletions src/readable/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ extern "C" {
) -> Result<Object, Error>;
}

#[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).
Expand Down

0 comments on commit 2f79117

Please sign in to comment.