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

[Merged by Bors] - Correctly run async tests #2683

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved
}
_ => {}
}

(true, value.display().to_string())
Expand Down Expand Up @@ -423,9 +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() = 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())
})
},
Expand All @@ -440,17 +454,26 @@ fn register_print_fn(context: &mut Context<'_>, async_result: AsyncResult) {
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
);
}

#[derive(Debug, Clone, Copy, Default)]
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved
enum UninitResult<T, E> {
#[default]
Uninit,
Ok(T),
Err(E),
}

/// Object which includes the result of the async operation.
#[derive(Debug, Clone)]
struct AsyncResult {
inner: Rc<RefCell<Result<(), String>>>,
inner: Rc<RefCell<UninitResult<(), String>>>,
}

impl Default for AsyncResult {
#[inline]
fn default() -> Self {
Self {
inner: Rc::new(RefCell::new(Ok(()))),
inner: Rc::new(RefCell::new(UninitResult::default())),
}
}
}