Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xavierm02/streams/underlying source #240

Closed
wants to merge 6 commits into from

Conversation

xavierm02
Copy link
Contributor

@xavierm02 xavierm02 commented Dec 4, 2023

Description

Implemented UnderlyingSource, and added a trivial ReadableStream constructor that only transforms its first input into an UnderlyingSource.

A few other things were added to make this possible / easier:

  • A wrapper type JsFn<T, N, I, O> for JsFunction that allows to be more explicit about the JS function we expect to have, and to automatically handle the TryFromJs and IntoJs conversion for inputs and outputs.
  • A Todo placeholder type for types from the spec that have not been defined yet.
  • Type aliases that allow referring to some types by their WebIDL names.

Manual testing

cargo run --bin jstz -- repl
>> new ReadableStream()
thread 'main' panicked at 'not yet implemented', jstz_api/src/stream/readable/mod.rs:39:9
cargo run --bin jstz -- repl
>> new ReadableStream({type:"bytes"})
thread 'main' panicked at 'not yet implemented', jstz_api/src/stream/readable/mod.rs:39:9
cargo run --bin jstz -- repl
>> new ReadableStream({type:"invalid"})
Uncaught TypeError: invalid is not a valid value for enumeration ReadableStreamType.

One can also add

underlying_source.cancel(Some(boa_engine::js_string!("reason").into()), context);

in the constructor of ReadableStreamClass and then test it with

cargo run --bin jstz -- repl
>> >> new ReadableStream({cancel:function(reason){console.log(reason);}})
[🪵] reason
thread 'main' panicked at 'not yet implemented', jstz_api/src/stream/readable/mod.rs:42:9
Uncaught TypeError: invalid is not a valid value for enumeration ReadableStreamType.

Checklist

  • Changes follow the existing code style (use make fmt-check to check)
  • Tests for changes have been added
  • Internal documentation has been added (if appropriate)
  • Testing instructions have been added to PR

@xavierm02 xavierm02 mentioned this pull request Dec 4, 2023
@xavierm02 xavierm02 requested review from johnyob and Lesenr1 December 4, 2023 17:28
@xavierm02 xavierm02 force-pushed the xavierm02/streams/underlying-source branch from 65c10c3 to 732af92 Compare December 4, 2023 18:02
@xavierm02
Copy link
Contributor Author

(I pushed the same thing again because the first commit had the wrong email address)

@xavierm02 xavierm02 force-pushed the xavierm02/streams/underlying-source branch from 732af92 to 85387e7 Compare December 5, 2023 10:56
@xavierm02
Copy link
Contributor Author

Moved to PR 254.

@xavierm02 xavierm02 closed this Dec 5, 2023
@xavierm02 xavierm02 deleted the xavierm02/streams/underlying-source branch December 5, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant