Browse Source

Added the $262 object to Test262 test runner (#1296)

pull/1310/head
Iban Eguia 3 years ago committed by GitHub
parent
commit
e38a84155e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      Cargo.lock
  2. 4
      boa/src/object/internal_methods.rs
  3. 1
      boa_tester/Cargo.toml
  4. 72
      boa_tester/src/exec/js262.rs
  5. 7
      boa_tester/src/exec/mod.rs

34
Cargo.lock generated

@ -99,6 +99,7 @@ dependencies = [
"bitflags",
"colored",
"fxhash",
"gc",
"git2",
"hex",
"num-format",
@ -140,9 +141,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.6.1"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
[[package]]
name = "byteorder"
@ -161,9 +162,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.67"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
dependencies = [
"jobserver",
]
@ -283,9 +284,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52fb27eab85b17fbb9f6fd667089e07d6a2eb8743d02639ee7f6a7a7729c9c94"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -296,11 +297,10 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.4"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
@ -612,9 +612,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.94"
version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36"
[[package]]
name = "libgit2-sys"
@ -708,18 +708,18 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]]
name = "memmap2"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "397d1a6d6d0563c0f5462bbdae662cf6c784edf5e828e40c7257f85d82bf56dd"
checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4"
dependencies = [
"libc",
]
[[package]]
name = "memoffset"
version = "0.6.3"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83fb6581e8ed1f85fd45c116db8405483899489e38406156c25eb743554361d"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
@ -1373,9 +1373,9 @@ checksum = "07547e3ee45e28326cc23faac56d44f58f16ab23e413db526debce3b0bfd2742"
[[package]]
name = "unicode-normalization"
version = "0.1.17"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef"
checksum = "33717dca7ac877f497014e10d73f3acf948c342bee31b5ca7892faf94ccc6b49"
dependencies = [
"tinyvec",
]

4
boa/src/object/internal_methods.rs

@ -593,7 +593,7 @@ impl GcObject {
/// If a field was already in the object with the same name that a `Some` is returned
/// with that field, otherwise None is returned.
#[inline]
pub(crate) fn insert_property<K, V>(
pub fn insert_property<K, V>(
&mut self,
key: K,
value: V,
@ -711,7 +711,7 @@ impl Object {
/// If a field was already in the object with the same name that a `Some` is returned
/// with that field, otherwise None is retuned.
#[inline]
pub(crate) fn insert_property<K, V>(
pub fn insert_property<K, V>(
&mut self,
key: K,
value: V,

1
boa_tester/Cargo.toml

@ -24,3 +24,4 @@ fxhash = "0.2.1"
git2 = "0.13.20"
hex = "0.4.3"
num-format = "0.4.0"
gc = { version = "0.4.1", features = ["derive"] }

72
boa_tester/src/exec/js262.rs

@ -0,0 +1,72 @@
use boa::{
exec::Executable,
object::{GcObject, ObjectInitializer},
property::Attribute,
Context, Result, Value,
};
/// Initializes the object in the context.
pub(super) fn init(context: &mut Context) -> GcObject {
let global_obj = context.global_object();
let obj = ObjectInitializer::new(context)
.function(create_realm, "createRealm", 0)
.function(eval_script, "evalScript", 1)
.property("global", global_obj, Attribute::default())
// .property("agent", agent, Attribute::default())
.build();
context.register_global_property("$262", obj.clone(), Attribute::default());
obj
}
/// The `$262.createRealm()` function.
///
/// Creates a new ECMAScript Realm, defines this API on the new realm's global object, and
/// returns the `$262` property of the new realm's global object.
fn create_realm(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
// eprintln!("called $262.createRealm()");
let mut context = Context::new();
// add the $262 object.
let js_262 = init(&mut context);
Ok(Value::from(js_262))
}
/// The `$262.detachArrayBuffer()` function.
///
/// Implements the `DetachArrayBuffer` abstract operation.
#[allow(dead_code)]
fn detach_array_buffer(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
todo!()
}
/// The `$262.evalScript()` function.
///
/// Accepts a string value as its first argument and executes it as an ECMAScript script.
fn eval_script(_this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
// eprintln!("called $262.evalScript()");
if let Some(source_text) = args.get(0).and_then(|val| val.as_string()) {
match boa::parse(source_text.as_str(), false) {
// TODO: check strict
Err(e) => context.throw_type_error(format!("Uncaught Syntax Error: {}", e)),
Ok(script) => script.run(context),
}
} else {
Ok(Value::undefined())
}
}
/// The `$262.gc()` function.
///
/// 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)]
fn gc(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
todo!()
}

7
boa_tester/src/exec.rs → boa_tester/src/exec/mod.rs

@ -1,5 +1,7 @@
//! Execution module for the test runner.
mod js262;
use super::{
Harness, Outcome, Phase, SuiteResult, Test, TestFlags, TestOutcomeResult, TestResult,
TestSuite, IGNORED,
@ -260,7 +262,6 @@ impl Test {
/// Sets the environment up to run the test.
fn set_up_env(&self, harness: &Harness, strict: bool) -> Result<Context, String> {
// Create new Realm
// TODO: in parallel.
let mut context = Context::new();
// Register the print() function.
@ -272,7 +273,9 @@ impl Test {
e.display()
)
})?;
// TODO: add the $262 object.
// add the $262 object.
let _ = js262::init(&mut context);
if strict {
context
Loading…
Cancel
Save