From 6de33a22919f099977e781248919be70cf0ba338 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Thu, 16 Mar 2023 16:10:42 -0600 Subject: [PATCH 1/5] Correctly run async tests --- boa_tester/src/exec/mod.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index 69d82715298..e33f27d2b72 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -198,8 +198,12 @@ impl Test { context.run_jobs(); - if let Err(e) = async_result.inner.borrow().as_ref() { - return (false, format!("Uncaught {e}")); + match *async_result.inner.borrow() { + UninitResult::Err(ref e) => return (false, format!("Uncaught {e}")), + UninitResult::Uninit if self.flags.contains(TestFlags::ASYNC) => { + return (false, "async test didn't call `print`".to_string()) + } + _ => {} } (true, value.display().to_string()) @@ -423,8 +427,10 @@ fn register_print_fn(context: &mut Context<'_>, async_result: AsyncResult) { .get_or_undefined(0) .to_string(context)? .to_std_string_escaped(); - if message != "Test262:AsyncTestComplete" { - *async_result.inner.borrow_mut() = Err(message); + if message == "Test262:AsyncTestComplete" { + *async_result.inner.borrow_mut() = UninitResult::Ok(()); + } else { + *async_result.inner.borrow_mut() = UninitResult::Err(message); } Ok(JsValue::undefined()) }) @@ -440,17 +446,26 @@ fn register_print_fn(context: &mut Context<'_>, async_result: AsyncResult) { Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ); } + +#[derive(Debug, Clone, Copy, Default)] +enum UninitResult { + #[default] + Uninit, + Ok(T), + Err(E), +} + /// Object which includes the result of the async operation. #[derive(Debug, Clone)] struct AsyncResult { - inner: Rc>>, + inner: Rc>>, } impl Default for AsyncResult { #[inline] fn default() -> Self { Self { - inner: Rc::new(RefCell::new(Ok(()))), + inner: Rc::new(RefCell::new(UninitResult::default())), } } } From ae58a6127e0f26217fd91642a1fe68bee9a89132 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Thu, 16 Mar 2023 16:45:39 -0600 Subject: [PATCH 2/5] Fix behaviour of `print` on multiple calls --- boa_tester/src/exec/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index e33f27d2b72..6336fdff533 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -427,11 +427,19 @@ fn register_print_fn(context: &mut Context<'_>, async_result: AsyncResult) { .get_or_undefined(0) .to_string(context)? .to_std_string_escaped(); - if message == "Test262:AsyncTestComplete" { - *async_result.inner.borrow_mut() = UninitResult::Ok(()); - } else { - *async_result.inner.borrow_mut() = UninitResult::Err(message); + let mut result = async_result.inner.borrow_mut(); + + match *result { + UninitResult::Uninit | UninitResult::Ok(_) => { + if message == "Test262:AsyncTestComplete" { + *result = UninitResult::Ok(()); + } else { + *result = UninitResult::Err(message); + } + } + UninitResult::Err(_) => {} } + Ok(JsValue::undefined()) }) }, From 573efe45d15de8fb48c4072605515b05685127a1 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Thu, 16 Mar 2023 21:16:20 -0600 Subject: [PATCH 3/5] Reword error message --- boa_tester/src/exec/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index 6336fdff533..a25b4a0002b 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -201,7 +201,7 @@ impl Test { match *async_result.inner.borrow() { UninitResult::Err(ref e) => return (false, format!("Uncaught {e}")), UninitResult::Uninit if self.flags.contains(TestFlags::ASYNC) => { - return (false, "async test didn't call `print`".to_string()) + return (false, "async test did not print \"Test262:AsyncTestComplete\"".to_string()) } _ => {} } From e146c736f89e87173ff9122bf825a22dc4389fc3 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Thu, 16 Mar 2023 21:16:37 -0600 Subject: [PATCH 4/5] cargo fmt --- boa_tester/src/exec/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index a25b4a0002b..c89290f134a 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -201,7 +201,10 @@ impl Test { match *async_result.inner.borrow() { UninitResult::Err(ref e) => return (false, format!("Uncaught {e}")), UninitResult::Uninit if self.flags.contains(TestFlags::ASYNC) => { - return (false, "async test did not print \"Test262:AsyncTestComplete\"".to_string()) + return ( + false, + "async test did not print \"Test262:AsyncTestComplete\"".to_string(), + ) } _ => {} } From 99800de4f55159a35eca3a5ed8ee47a9290df54e Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Fri, 17 Mar 2023 00:33:04 -0600 Subject: [PATCH 5/5] Document `UninitResult` --- boa_tester/src/exec/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index c89290f134a..38d285b64f9 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -458,6 +458,15 @@ fn register_print_fn(context: &mut Context<'_>, async_result: AsyncResult) { ); } +/// A `Result` value that is possibly uninitialized. +/// +/// This is mainly used to check if an async test did call `print` to signal the termination of +/// a test. Otherwise, all async tests that result in `UninitResult::Uninit` are considered +/// as failed. +/// +/// The Test262 [interpreting guide][guide] contains more information about how to run async tests. +/// +/// [guide]: https://github.com/tc39/test262/blob/main/INTERPRETING.md#flags #[derive(Debug, Clone, Copy, Default)] enum UninitResult { #[default]