Skip to content

Commit

Permalink
fix(wpt): run subsetTest
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Jan 8, 2025
1 parent b6b277b commit b59668f
Show file tree
Hide file tree
Showing 2 changed files with 389 additions and 48 deletions.
53 changes: 41 additions & 12 deletions crates/jstz_api/tests/wpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::future::IntoFuture;
use anyhow::Result;
use boa_engine::{
js_string, object::FunctionObjectBuilder, property::PropertyDescriptor,
value::TryFromJs, Context, JsArgs, JsData, JsNativeError, JsResult, JsValue,
NativeFunction, Source,
value::TryFromJs, Context, JsArgs, JsData, JsNativeError, JsObject, JsResult,
JsValue, NativeFunction, Source,
};
use boa_gc::{Finalize, Trace};
use derive_more::{From, Into};
Expand All @@ -15,6 +15,8 @@ use jstz_wpt::{
WptSubtestStatus, WptTestStatus,
};

const TEST_SUBSET_SIZE: u8 = 5;

macro_rules! impl_try_from_js_for_enum {
($ty:ty) => {
impl TryFromJs for $ty {
Expand Down Expand Up @@ -248,6 +250,42 @@ pub fn register_apis(context: &mut Context) {
jstz_api::file::FileApi.init(context);
}

fn insert_global_properties(rt: &mut Runtime) {
// Define self
rt.global_object().insert_property(
js_string!("self"),
PropertyDescriptor::builder()
.value(rt.global_object().clone())
.configurable(true)
.writable(true)
.enumerable(true)
.build(),
);

// Define a dummy `location` object so that subsetTest can run
let location = JsObject::with_null_proto();

// `location.search` is used by wpt to determine how many tests in a subset test can run.
// Limiting this with a small enough `TEST_SUBSET_SIZE` here because those subsets
// can contain thousands of tests.
location
.create_data_property(
js_string!("search"),
js_string!(format!("?0-{TEST_SUBSET_SIZE}")),
rt.context(),
)
.unwrap();
rt.global_object().insert_property(
js_string!("location"),
PropertyDescriptor::builder()
.value(location)
.configurable(true)
.writable(true)
.enumerable(true)
.build(),
);
}

pub fn run_wpt_test_harness(bundle: &Bundle) -> JsResult<Box<TestHarnessReport>> {
let mut rt: Runtime = Runtime::new(usize::MAX)?;

Expand All @@ -260,16 +298,7 @@ pub fn run_wpt_test_harness(bundle: &Bundle) -> JsResult<Box<TestHarnessReport>>
// Register APIs
register_apis(&mut rt);

// Define self
rt.global_object().insert_property(
js_string!("self"),
PropertyDescriptor::builder()
.value(rt.global_object().clone())
.configurable(true)
.writable(true)
.enumerable(true)
.build(),
);
insert_global_properties(&mut rt);

// Run the bundle, evaluating each script in order
// Instead of loading the TestHarnessReport script, we initialize it manually
Expand Down
Loading

0 comments on commit b59668f

Please sign in to comment.