script: Take away Fallible from new_resolved and new_rejected (#35473)

* script: Take away Fallible from new_resolved and new_rejected

Both Promise::new_resolved and new_rejected only return `Ok`. We don't
need them to be fallible. Simply return `Rc<Promise>`, instead of
`Fallible<Rc<Promise>>`. Also, clean up relevant code.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>

* script: pull_algorithm becomes infallible

The method pull_algorithm only returns `Some(Ok(_))`, which means it is
infallible. Clean up the returned type.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>

* script: generic_initialize becomes infallible

The method generic_initialize only returns `Ok(())`, which means it is
infallible. Clean up the returned type.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
Kingsley Yung 2025-02-16 05:29:34 +08:00 committed by GitHub
parent 3421185737
commit b4f48c561b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 23 additions and 44 deletions

View file

@ -107,7 +107,7 @@ impl DefaultTeeUnderlyingSource {
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee>
/// Let pullAlgorithm be the following steps:
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub(crate) fn pull_algorithm(&self, can_gc: CanGc) -> Option<Result<Rc<Promise>, Error>> {
pub(crate) fn pull_algorithm(&self, can_gc: CanGc) -> Rc<Promise> {
// If reading is true,
if self.reading.get() {
// Set readAgain to true.
@ -115,11 +115,7 @@ impl DefaultTeeUnderlyingSource {
// Return a promise resolved with undefined.
let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut rval = UndefinedValue());
return Some(Promise::new_resolved(
&self.stream.global(),
cx,
rval.handle(),
));
return Promise::new_resolved(&self.stream.global(), cx, rval.handle());
}
// Set reading to true.
@ -151,11 +147,7 @@ impl DefaultTeeUnderlyingSource {
// Return a promise resolved with undefined.
let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut rval = UndefinedValue());
Some(Promise::new_resolved(
&self.stream.global(),
GlobalScope::get_cx(),
rval.handle(),
))
Promise::new_resolved(&self.stream.global(), GlobalScope::get_cx(), rval.handle())
}
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee>