From 681e6f64abb5f9ad37978dbeb64f814e7c196bb5 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Thu, 9 Jun 2022 18:00:05 +0200 Subject: [PATCH] Added some tester implementations needed for async/await testing --- Cargo.lock | 1 + boa_engine/Cargo.toml | 4 ++-- boa_tester/Cargo.toml | 1 + boa_tester/src/exec/js262.rs | 6 ++++-- boa_tester/src/exec/mod.rs | 10 ++++++++-- boa_tester/src/main.rs | 1 + boa_tester/src/read.rs | 6 +++++- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e82823eaf9..e88f0b56b9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,6 +164,7 @@ dependencies = [ "anyhow", "bitflags", "boa_engine", + "boa_gc", "boa_interner", "colored", "fxhash", diff --git a/boa_engine/Cargo.toml b/boa_engine/Cargo.toml index 3b20b2df0a3..89d22af0013 100644 --- a/boa_engine/Cargo.toml +++ b/boa_engine/Cargo.toml @@ -51,11 +51,11 @@ dyn-clone = "1.0.5" once_cell = "1.12.0" tap = "1.0.1" icu_locale_canonicalizer = { version = "0.6.0", features = ["serde"], optional = true } -icu_locid = { version = "0.6.0", features = ["serde"], optional = true } +icu_locid = { version = "0.6.0", features = ["serde"], optional = true } icu_datetime = { version = "0.6.0", features = ["serde"], optional = true } icu_plurals = { version = "0.6.0", features = ["serde"], optional = true } icu_provider = { version = "0.6.0", optional = true } -icu_testdata = {version = "0.6.0", optional = true} +icu_testdata = { version = "0.6.0", optional = true } sys-locale = { version = "0.2.0", optional = true } [dev-dependencies] diff --git a/boa_tester/Cargo.toml b/boa_tester/Cargo.toml index ce971546e1e..261ec496f64 100644 --- a/boa_tester/Cargo.toml +++ b/boa_tester/Cargo.toml @@ -14,6 +14,7 @@ publish = false [dependencies] boa_engine = { path = "../boa_engine", features = ["intl"], version = "0.14.0" } boa_interner = { path = "../boa_interner", version = "0.14.0" } +boa_gc = { path = "../boa_gc", version = "0.14.0" } structopt = "0.3.26" serde = { version = "1.0.137", features = ["derive"] } serde_yaml = "0.8.24" diff --git a/boa_tester/src/exec/js262.rs b/boa_tester/src/exec/js262.rs index 91bb507ed20..f6ad73dd210 100644 --- a/boa_tester/src/exec/js262.rs +++ b/boa_tester/src/exec/js262.rs @@ -13,6 +13,7 @@ pub(super) fn init(context: &mut Context) -> JsObject { .function(create_realm, "createRealm", 0) .function(detach_array_buffer, "detachArrayBuffer", 2) .function(eval_script, "evalScript", 1) + .function(gc, "gc", 0) .property("global", global_obj, Attribute::default()) // .property("agent", agent, Attribute::default()) .build(); @@ -99,7 +100,8 @@ fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsRe /// Wraps the host's garbage collection invocation mechanism, if such a capability exists. /// Must throw an exception if no capability exists. This is necessary for testing the /// semantics of any feature that relies on garbage collection, e.g. the `WeakRef` API. -#[allow(dead_code)] +#[allow(clippy::unnecessary_wraps)] fn gc(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> JsResult { - todo!() + boa_gc::force_collect(); + Ok(JsValue::undefined()) } diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index ff5748972ab..424275efcfb 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -318,12 +318,18 @@ impl Test { } context - .eval(&harness.assert.as_ref()) + .eval(harness.assert.as_ref()) .map_err(|e| format!("could not run assert.js:\n{}", e.display()))?; context - .eval(&harness.sta.as_ref()) + .eval(harness.sta.as_ref()) .map_err(|e| format!("could not run sta.js:\n{}", e.display()))?; + if self.flags.contains(TestFlags::ASYNC) { + context + .eval(harness.doneprint_handle.as_ref()) + .map_err(|e| format!("could not run doneprintHandle.js:\n{}", e.display()))?; + } + for include in self.includes.iter() { context .eval( diff --git a/boa_tester/src/main.rs b/boa_tester/src/main.rs index 8b33aa9062d..d2f18c12c2e 100644 --- a/boa_tester/src/main.rs +++ b/boa_tester/src/main.rs @@ -342,6 +342,7 @@ fn run_test_suite( struct Harness { assert: Box, sta: Box, + doneprint_handle: Box, includes: FxHashMap, Box>, } diff --git a/boa_tester/src/read.rs b/boa_tester/src/read.rs index 092737ed19f..86cadb7221a 100644 --- a/boa_tester/src/read.rs +++ b/boa_tester/src/read.rs @@ -84,7 +84,7 @@ pub(super) fn read_harness(test262_path: &Path) -> anyhow::Result { let file_name = entry.file_name(); let file_name = file_name.to_string_lossy(); - if file_name == "assert.js" || file_name == "sta.js" { + if file_name == "assert.js" || file_name == "sta.js" || file_name == "doneprintHandle.js" { continue; } @@ -102,10 +102,14 @@ pub(super) fn read_harness(test262_path: &Path) -> anyhow::Result { let sta = fs::read_to_string(test262_path.join("harness/sta.js")) .context("error reading harnes/sta.js")? .into_boxed_str(); + let doneprint_handle = fs::read_to_string(test262_path.join("harness/doneprintHandle.js")) + .context("error reading harnes/doneprintHandle.js")? + .into_boxed_str(); Ok(Harness { assert, sta, + doneprint_handle, includes, }) }