Skip to content

Commit

Permalink
Fix detection of Test262Error in boa_tester
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 15, 2022
1 parent ec7a94d commit 4d84f7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 11 additions & 1 deletion boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,17 @@ impl Test {
_ => false,
}
} else {
e.to_string().starts_with(&error_type.to_string())
e.as_opaque()
.expect("try_native cannot fail if e is not opaque")
.as_object()
.and_then(|o| o.get("constructor", &mut context).ok())
.as_ref()
.and_then(JsValue::as_object)
.and_then(|o| o.get("name", &mut context).ok())
.as_ref()
.and_then(JsValue::as_string)
.map(|s| *s == error_type.as_str())
.unwrap_or_default()
};

(passed, format!("Uncaught {e}"))
Expand Down
7 changes: 3 additions & 4 deletions boa_tester/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{Harness, Locale, Phase, Test, TestSuite, IGNORED};
use anyhow::Context;
use fxhash::FxHashMap;
use serde::Deserialize;
use std::{fmt::Display, fs, io, path::Path, str::FromStr};
use std::{fs, io, path::Path, str::FromStr};

/// Representation of the YAML metadata in Test262 tests.
#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -47,16 +47,15 @@ pub(super) enum ErrorType {
TypeError,
}

impl Display for ErrorType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl ErrorType {
pub(super) fn as_str(self) -> &'static str {
match self {
ErrorType::Test262Error => "Test262Error",
ErrorType::SyntaxError => "SyntaxError",
ErrorType::ReferenceError => "ReferenceError",
ErrorType::RangeError => "RangeError",
ErrorType::TypeError => "TypeError",
}
.fmt(f)
}
}

Expand Down

0 comments on commit 4d84f7d

Please sign in to comment.